[PR #60] dxgi: let shaders sample swap-chain back buffers #111

Open
opened 2026-11-26 20:16:50 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/60
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/9783


📝 Commits (1)

  • 6d0afc8 dxgi: support sampling swap-chain back buffers

📊 Changes

8 files changed (+481 additions, -83 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+7 -4)
📝 runtime/CMakeLists.txt (+7 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+81 -39)
📝 runtime/shims/dxgi_com.cpp (+27 -11)
📝 runtime/shims/dxgi_swapchain.h (+34 -26)
📝 runtime/src/vulkan_backend.h (+28 -3)
📝 runtime/src/vulkan_replay.h (+1 -0)
➕ runtime/test/dxgi_backbuffer_srv_test.cpp (+296 -0)

📄 Description

Carried over from old PR 9783 by Michael-M51 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9783, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
Michael-M51: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Claimed in the coordination issue as: DXGI shader-input back buffers

Depends on: #4317, #5248

These PRs have overlapping refcount and Vulkan image-lifetime edits. This patch builds directly on a60e5eab5, which includes the round-robin buffer change from #9602.

What and why

A swap chain can request DXGI_USAGE_SHADER_INPUT so a later pass can sample a rendered frame. Leonida returned a valid resource from GetBuffer, but CreateShaderResourceView left its descriptor empty. A compute shader read zero after a successful colour clear. DXGI usage flags

Register shader-input back buffers with the existing texture descriptor path. A default view or an explicit view matching the buffer format can now be sampled. An application reference to the buffer keeps its swap chain alive. Resize and teardown retire the cached views before destroying the Vulkan images. Cross-format sRGB views still need mutable images, which #5248 supplies for render-target views.

Tested

Windows 11, MSVC 19.44 Release, NVIDIA RTX 4070 SUPER, driver 621.24, Vulkan validation enabled. The new test uses a hand-written shader and synthetic colours.

  • The ordinary texture control matched 64/64 texels on both builds. The unpatched shim matched 0/64 before Present, after Present, and after ResizeBuffers. The patched shim matched 64/64 in all three and after release of the application's final swap-chain reference. The new test reported zero Vulkan validation errors.
  • A separate native D3D12 WARP run matched 64/64 for both default and explicit views before and after Present, including through a retained buffer, with zero D3D12 debug errors.
  • 14 of 16 graphics CTests passed. The two failures reproduced on the comparison build with the same command-list assertion and depth-clear validation messages. Both were previously reported on #9569. The two DXGI host-parity tests also passed with PROBE_WARP=1.
  • The full translator suite ran 6,015 tests across 456 files. The 48 failing subtests in test_image_atomics_guard and test_image_store_d16 matched the unmodified base.

Draft while the upstream Windows runtime build is broken. Stock a60e5eab5 and this commit both hit the compiler errors reported on #9576. For the GPU comparison only, I locally reversed 3630610ca on both sides. The workaround is absent from the submitted diff.

AI-assisted: yes

Checklist

  • Ran scripts/check_no_game_data.py on all eight changed files and git diff --check. No game data, keys or decryption.
  • Translator contract table: N/A for a runtime change.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/60 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/9783` --- ### 📝 Commits (1) - [`6d0afc8`](https://github.com/ubiquitarianism/leonida/commit/6d0afc8cc8a6862b32c286530709662006879471) dxgi: support sampling swap-chain back buffers ### 📊 Changes **8 files changed** (+481 additions, -83 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+7 -4) 📝 `runtime/CMakeLists.txt` (+7 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+81 -39) 📝 `runtime/shims/dxgi_com.cpp` (+27 -11) 📝 `runtime/shims/dxgi_swapchain.h` (+34 -26) 📝 `runtime/src/vulkan_backend.h` (+28 -3) 📝 `runtime/src/vulkan_replay.h` (+1 -0) ➕ `runtime/test/dxgi_backbuffer_srv_test.cpp` (+296 -0) </details> ### 📄 Description > Carried over from **old PR 9783** by `Michael-M51` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9783`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `Michael-M51`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Claimed in the coordination issue as: [DXGI shader-input back buffers](https://github.com/ProjectLeonida/Leonida/issues/9522#issuecomment-7114996659) Depends on: `#4317`, `#5248` These PRs have overlapping refcount and Vulkan image-lifetime edits. This patch builds directly on `a60e5eab5`, which includes the round-robin buffer change from `#9602`. ### What and why A swap chain can request `DXGI_USAGE_SHADER_INPUT` so a later pass can sample a rendered frame. Leonida returned a valid resource from `GetBuffer`, but `CreateShaderResourceView` left its descriptor empty. A compute shader read zero after a successful colour clear. [DXGI usage flags](https://learn.microsoft.com/windows/win32/direct3ddxgi/dxgi-usage) Register shader-input back buffers with the existing texture descriptor path. A default view or an explicit view matching the buffer format can now be sampled. An application reference to the buffer keeps its swap chain alive. Resize and teardown retire the cached views before destroying the Vulkan images. Cross-format sRGB views still need mutable images, which `#5248` supplies for render-target views. ### Tested Windows 11, MSVC 19.44 Release, NVIDIA RTX 4070 SUPER, driver 621.24, Vulkan validation enabled. The new test uses a hand-written shader and synthetic colours. - The ordinary texture control matched 64/64 texels on both builds. The unpatched shim matched 0/64 before Present, after Present, and after ResizeBuffers. The patched shim matched 64/64 in all three and after release of the application's final swap-chain reference. The new test reported zero Vulkan validation errors. - A separate native D3D12 WARP run matched 64/64 for both default and explicit views before and after Present, including through a retained buffer, with zero D3D12 debug errors. - 14 of 16 graphics CTests passed. The two failures reproduced on the comparison build with the same command-list assertion and depth-clear validation messages. Both were previously reported on `#9569`. The two DXGI host-parity tests also passed with `PROBE_WARP=1`. - The full translator suite ran 6,015 tests across 456 files. The 48 failing subtests in `test_image_atomics_guard` and `test_image_store_d16` matched the unmodified base. Draft while the upstream Windows runtime build is broken. Stock `a60e5eab5` and this commit both hit the [compiler errors reported on `#9576`](https://github.com/ProjectLeonida/Leonida/pull/9576#issuecomment-7114788903). For the GPU comparison only, I locally reversed `3630610ca` on both sides. The workaround is absent from the submitted diff. AI-assisted: yes ### Checklist - [x] Ran `scripts/check_no_game_data.py` on all eight changed files and `git diff --check`. No game data, keys or decryption. - Translator contract table: N/A for a runtime change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#111
No description provided.