[PR #333] dxgi: an _SRGB shader-resource view samples an 8-bit UNORM back buffer (stacked on #9783) #387

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

📋 Pull Request Information

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

Base: main ← Head: old-pr/10068


📝 Commits (2)

  • 6d0afc8 dxgi: support sampling swap-chain back buffers
  • c6b8d70 dxgi: an _SRGB shader-resource view samples an 8-bit UNORM back buffer

📊 Changes

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

View changed files

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

📄 Description

Carried over from old PR 10068 by LoukaAyariPignel in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/10068, 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.
LoukaAyariPignel: 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: Michael-M51's sRGB back-buffer SRV finding (finding here)

Depends on: #9783 (stacked: this branch is #9783's 6d0afc8cc plus one commit, c6b8d70f7; only that commit is new here). Draft while #9783 is a draft.

What and why

D3D12 lets an application view a DXGI back buffer in R8G8B8A8_UNORM or B8G8R8A8_UNORM through its _SRGB format, so a later pass reads the frame as linear colour. @Michael-M51 measured it on WARP: 64/64 gamma-decoded texels before and after Present, no debug-layer errors. With #9783, the layer accepts only a default view or a view in the buffer's own format. An _SRGB view leaves the descriptor empty, because the offscreen back buffers are plain Vulkan images, and Vulkan can only view those in their own format.

  • dxgi_swapchain.h: the offscreen back buffers of those two formats are created with VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT and a VkImageFormatListCreateInfo that names the UNORM/sRGB pair. The binding records the sRGB partner (ResourceBinding::srgb_view_format).
  • d3d12_vulkan_device.cpp: CreateShaderResourceView on a back buffer also accepts a view whose format is that partner. vulkan_view_format already maps the T# to the _SRGB Vulkan view of the UNORM image. Any other view format is still refused, now with a log_once instead of silently.
  • Other back-buffer formats (R10G10B10A2_UNORM, R16G16B16A16_FLOAT) have no sRGB pair and are unchanged.

Tested

Windows 11 Pro 26300, NVIDIA GeForce RTX 3060, driver 610.88, Vulkan validation on, MSVC 14.44 RelWithDebInfo. Built on this branch with #9809 merged locally, only so that main's runtime compiles; that merge is not in the diff.

  • dxgi_backbuffer_srv gains two cases: an _SRGB view after Present, and an _SRGB view of the resized back buffer kept after the swap chain is released. Each clears the bytes e1 c6 80 7f through a UNORM RTV and expects c0 90 37 7f. Each decoded channel is within 0.05 of a whole step on the D3D12 sRGB curve, so packUnorm4x8 gives exact bytes.
  • With this commit: 7/7 cases match 64/64, exit 0, no validation errors.
  • Negative control: the same test with only the source changes reverted reads 0/64 (00000000) in both sRGB cases. The five #9783 cases still pass.

AI-assisted: yes (Claude Code)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. The test uses #9783's hand-written shader and synthetic colours.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (not applicable: runtime change)

🤖 Generated with Claude Code


🔄 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/333 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/10068` --- ### 📝 Commits (2) - [`6d0afc8`](https://github.com/ubiquitarianism/leonida/commit/6d0afc8cc8a6862b32c286530709662006879471) dxgi: support sampling swap-chain back buffers - [`c6b8d70`](https://github.com/ubiquitarianism/leonida/commit/c6b8d70f7ccea1fd4e6bbdff2c80d92e5eca6deb) dxgi: an _SRGB shader-resource view samples an 8-bit UNORM back buffer ### 📊 Changes **8 files changed** (+526 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` (+86 -39) 📝 `runtime/shims/dxgi_com.cpp` (+27 -11) 📝 `runtime/shims/dxgi_swapchain.h` (+56 -26) 📝 `runtime/src/vulkan_backend.h` (+28 -3) 📝 `runtime/src/vulkan_replay.h` (+2 -0) ➕ `runtime/test/dxgi_backbuffer_srv_test.cpp` (+313 -0) </details> ### 📄 Description > Carried over from **old PR 10068** by `LoukaAyariPignel` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/10068`, 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. > `LoukaAyariPignel`: 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: [Michael-M51's sRGB back-buffer SRV finding](https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7116863098) (finding [here](https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7116687262)) Depends on: `#9783` (stacked: this branch is `#9783`'s `6d0afc8cc` plus one commit, `c6b8d70f7`; only that commit is new here). Draft while `#9783` is a draft. ### What and why D3D12 lets an application view a DXGI back buffer in `R8G8B8A8_UNORM` or `B8G8R8A8_UNORM` through its `_SRGB` format, so a later pass reads the frame as linear colour. `@Michael-M51` measured it on WARP: 64/64 gamma-decoded texels before and after Present, no debug-layer errors. With `#9783`, the layer accepts only a default view or a view in the buffer's own format. An `_SRGB` view leaves the descriptor empty, because the offscreen back buffers are plain Vulkan images, and Vulkan can only view those in their own format. - `dxgi_swapchain.h`: the offscreen back buffers of those two formats are created with `VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT` and a `VkImageFormatListCreateInfo` that names the UNORM/sRGB pair. The binding records the sRGB partner (`ResourceBinding::srgb_view_format`). - `d3d12_vulkan_device.cpp`: `CreateShaderResourceView` on a back buffer also accepts a view whose format is that partner. `vulkan_view_format` already maps the T# to the `_SRGB` Vulkan view of the UNORM image. Any other view format is still refused, now with a `log_once` instead of silently. - Other back-buffer formats (`R10G10B10A2_UNORM`, `R16G16B16A16_FLOAT`) have no sRGB pair and are unchanged. ### Tested Windows 11 Pro 26300, **NVIDIA GeForce RTX 3060**, driver 610.88, Vulkan validation on, MSVC 14.44 RelWithDebInfo. Built on this branch with `#9809` merged locally, only so that `main`'s runtime compiles; that merge is not in the diff. - `dxgi_backbuffer_srv` gains two cases: an `_SRGB` view after Present, and an `_SRGB` view of the resized back buffer kept after the swap chain is released. Each clears the bytes `e1 c6 80 7f` through a UNORM RTV and expects `c0 90 37 7f`. Each decoded channel is within 0.05 of a whole step on the D3D12 sRGB curve, so `packUnorm4x8` gives exact bytes. - With this commit: 7/7 cases match 64/64, exit 0, no validation errors. - Negative control: the same test with only the source changes reverted reads `0/64` (`00000000`) in both sRGB cases. The five `#9783` cases still pass. AI-assisted: yes (Claude Code) ### Checklist - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. The test uses `#9783`'s hand-written shader and synthetic colours. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (not applicable: runtime change) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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#387
No description provided.