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

Closed
Andretuta wants to merge 2 commits from upstream-pr/333 into main
Andretuta commented 2026-11-24 03:12:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T03:12:25Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5465380839 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/333). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T03:12:25Z. --- > 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)
aslan2142 commented 2026-12-01 16:29:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:29:35Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317696937 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/333#issuecomment-7317696937). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:29:35Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!333
No description provided.