d3d12: depth-stencil UAVs for console D16S8 (format 118) made as D24S8 #2123

Manually merged
github merged 3 commits from gh-pr/2123/head into gh-pr/2123/base 2026-11-26 10:18:45 +00:00
Owner

@⁠qhukz13 on GitHub · 2026-11-25 21:35 UTC · original
qhukz13:cont/d16s8-d24-uav → main · +413 −62 · 6 files · 3 commits · merged 2026-11-26 01:52 UTC

Item: RT-D16S8-D24-UAV (follow-up of #1558)

Problem

Where console D16S8 (format 118) is made as D24_UNORM_S8_UINT (LEONIDA_CONSOLE_D16S8=d24, the default on every NVIDIA GPU), Resource::enable_depth_stencil_uav refuses the texture with E_INVALIDARG. Since #1558, slots 76 and 133 then make it without ALLOW_UNORDERED_ACCESS, so the title's R16/R8 UAVs over those depth planes have nothing behind them.

Change

  • enable_depth_stencil_uav takes a D24S8 texture that came from format 118 (Resource::console_d16s8_, recorded in create_committed and create_placed before pc_format()), with the storage planes of the widened D16S8 path: R16_TYPELESS (mutable R16_UNORM) for depth, R8_UINT for stencil, and an R32_FLOAT conversion image.
  • copy_depth_uav (runtime/src/vulkan_replay.h) moves depth between the D24 aspect and the 16-bit plane as D24 words (scratch) -> Depth24Converter -> R32_FLOAT -> vkCmdBlitImage(NEAREST) -> R16_UNORM, and the reverse when the UAV state ends; stencil is copied directly. Depth24Converter (depth24_convert.comp) is used unchanged. Across all 65,536 16-bit values the round trip u -> u/65535 -> D24 -> float -> round(f*65535) gives back u exactly.
  • CreateUnorderedAccessView accepts R16_UINT and R16_UNORM on plane 0 of such a texture, R8_UINT on plane 1.
  • castable_view_formats allows the D16S8/R16/R8 view formats only for textures made from format 118; a plain PC D24_UNORM_S8_UINT texture keeps main's rules.
  • enable_copy_scratch adds STORAGE_BUFFER usage so the copy scratch can be the converter's buffer. VulkanContext::has_depth24() reports whether the converter exists.
  • CreateReservedResource already refuses format 118 (a stencil format has no tile shape), so it needs no change; the test checks that it still does.
  • Found on the way (own commit): create_placed turned a format-118 description into D24S8 before committed_resource_refusal but left the clear value as 118, so every placed format-118 depth texture with a clear value was refused ("clear value") on D24S8 backing, with or without UAV access. The clear value now goes through pc_format() too.

Testing

Windows 10 Pro 19045, GeForce GTX 1050 Ti (Pascal, 4 GB; D24_UNORM_S8_UINT attachments yes, D16_UNORM_S8_UINT no), NVIDIA 582.66, MSVC (VS 18 Build Tools), RelWithDebInfo, base 9f9a7c5f3.

  • New xbox_d16s8_d24_storage (replaces xbox_d16s8_refused_uav): slot 76 six-layer DSV clear with legacy and enhanced UAV transitions and an R16_UINT UAV clear, read back exactly (6,144 depth words, 6,144 stencil bytes); slot 133 and slot 127 placements keep ALLOW_UNORDERED_ACCESS and resolve R16_UINT/R16_UNORM/R8_UINT descriptors to the storage planes; CreateCommittedResource2/3 and CreatePlacedResource/2 with format 118, clear values and castable lists; plain PC D24S8 refusing the R16/R8 castable views and the UAV; the parent D24S8 attachment read back after R16_UNORM float, R16_UINT and R8_UINT UAV clears. On main the same checks fail at slot 76 (the depth provider refused ... format 118, hr=0x80070057).
  • Full ctest: 449 tests, 15 failed, all of which also fail on plain 9f9a7c5f3 (16 there; the extra one is xmem, flaky on this host). xmem, xmem_no_write_watch and xmem_write_watch pass 5/5 each on this branch.
  • 3x, plain and with LEONIDA_VK_VALIDATION=1: d3d12_depth_stencil_uav, xbox_depth_storage, xbox_d16s8_storage, xbox_d16s8_d24_storage, xbox_d16s8_surface, xs_proxy_mock* (9), device_proxy* (2), d3d12_xmem_placed: 17/17 pass, no validation messages.

Overlap: #695 also touches the R16 depth UAV view code in d3d12_vulkan_device.cpp (normalized views for plain D16); different case, a small textual conflict is possible. #1716 fixes the same Ref = {} leak in tests generally; this PR only uses reset() in the test it changes.

AI-assisted (Claude Code, Opus 5.5, with Antigravity / Gemini 4 Neon for the first draft of the code; reviewed, and the reserved-path change dropped by hand).

🤖 Generated with Claude Code

**@⁠qhukz13** on GitHub · 2026-11-25 21:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2123) `qhukz13:cont/d16s8-d24-uav` → `main` · +413 −62 · 6 files · 3 commits · merged 2026-11-26 01:52 UTC Item: `RT-D16S8-D24-UAV` (follow-up of #1558) ### Problem Where console D16S8 (format 118) is made as `D24_UNORM_S8_UINT` (`LEONIDA_CONSOLE_D16S8=d24`, the default on every NVIDIA GPU), `Resource::enable_depth_stencil_uav` refuses the texture with `E_INVALIDARG`. Since #1558, slots 76 and 133 then make it without `ALLOW_UNORDERED_ACCESS`, so the title's R16/R8 UAVs over those depth planes have nothing behind them. ### Change - `enable_depth_stencil_uav` takes a D24S8 texture that came from format 118 (`Resource::console_d16s8_`, recorded in `create_committed` and `create_placed` before `pc_format()`), with the storage planes of the widened D16S8 path: `R16_TYPELESS` (mutable `R16_UNORM`) for depth, `R8_UINT` for stencil, and an `R32_FLOAT` conversion image. - `copy_depth_uav` (`runtime/src/vulkan_replay.h`) moves depth between the D24 aspect and the 16-bit plane as `D24 words (scratch) -> Depth24Converter -> R32_FLOAT -> vkCmdBlitImage(NEAREST) -> R16_UNORM`, and the reverse when the UAV state ends; stencil is copied directly. `Depth24Converter` (`depth24_convert.comp`) is used unchanged. Across all 65,536 16-bit values the round trip `u -> u/65535 -> D24 -> float -> round(f*65535)` gives back `u` exactly. - `CreateUnorderedAccessView` accepts `R16_UINT` and `R16_UNORM` on plane 0 of such a texture, `R8_UINT` on plane 1. - `castable_view_formats` allows the D16S8/R16/R8 view formats only for textures made from format 118; a plain PC `D24_UNORM_S8_UINT` texture keeps main's rules. - `enable_copy_scratch` adds `STORAGE_BUFFER` usage so the copy scratch can be the converter's buffer. `VulkanContext::has_depth24()` reports whether the converter exists. - `CreateReservedResource` already refuses format 118 (a stencil format has no tile shape), so it needs no change; the test checks that it still does. - Found on the way (own commit): `create_placed` turned a format-118 description into D24S8 before `committed_resource_refusal` but left the clear value as 118, so every placed format-118 depth texture with a clear value was refused ("clear value") on D24S8 backing, with or without UAV access. The clear value now goes through `pc_format()` too. ### Testing Windows 10 Pro 19045, GeForce GTX 1050 Ti (Pascal, 4 GB; `D24_UNORM_S8_UINT` attachments yes, `D16_UNORM_S8_UINT` no), NVIDIA 582.66, MSVC (VS 18 Build Tools), RelWithDebInfo, base `9f9a7c5f3`. - New `xbox_d16s8_d24_storage` (replaces `xbox_d16s8_refused_uav`): slot 76 six-layer DSV clear with legacy and enhanced UAV transitions and an `R16_UINT` UAV clear, read back exactly (6,144 depth words, 6,144 stencil bytes); slot 133 and slot 127 placements keep `ALLOW_UNORDERED_ACCESS` and resolve `R16_UINT`/`R16_UNORM`/`R8_UINT` descriptors to the storage planes; `CreateCommittedResource2/3` and `CreatePlacedResource/2` with format 118, clear values and castable lists; plain PC D24S8 refusing the R16/R8 castable views and the UAV; the parent D24S8 attachment read back after `R16_UNORM` float, `R16_UINT` and `R8_UINT` UAV clears. On main the same checks fail at slot 76 (`the depth provider refused ... format 118, hr=0x80070057`). - Full ctest: 449 tests, 15 failed, all of which also fail on plain `9f9a7c5f3` (16 there; the extra one is `xmem`, flaky on this host). `xmem`, `xmem_no_write_watch` and `xmem_write_watch` pass 5/5 each on this branch. - 3x, plain and with `LEONIDA_VK_VALIDATION=1`: `d3d12_depth_stencil_uav`, `xbox_depth_storage`, `xbox_d16s8_storage`, `xbox_d16s8_d24_storage`, `xbox_d16s8_surface`, `xs_proxy_mock*` (9), `device_proxy*` (2), `d3d12_xmem_placed`: 17/17 pass, no validation messages. Overlap: #695 also touches the R16 depth UAV view code in `d3d12_vulkan_device.cpp` (normalized views for plain D16); different case, a small textual conflict is possible. #1716 fixes the same `Ref = {}` leak in tests generally; this PR only uses `reset()` in the test it changes. AI-assisted (Claude Code, Opus 5.5, with Antigravity / Gemini 4 Neon for the first draft of the code; reviewed, and the reserved-path change dropped by hand). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
On GPUs with native VK_FORMAT_D24_UNORM_S8_UINT attachments (NVIDIA),
pc_format() maps Xbox format 118 (D16_UNORM_S8_UINT) to
DXGI_FORMAT_D24_UNORM_S8_UINT before Resource construction. Previously,
Resource::enable_depth_stencil_uav only accepted R16_TYPELESS, 118, and
R32G8X24_TYPELESS, returning E_INVALIDARG so slots 76 and 133 fell back
to creating the texture without unordered access (#1558).

Track console format 118 origin on Resource before pc_format(), extend
enable_depth_stencil_uav and CreateUnorderedAccessView to serve D24S8-made
118 through the existing widened R16_TYPELESS (R16_UINT/R16_UNORM views)
plus R8_UINT storage planes and R32_FLOAT conversion image, and convert
plane-0 D24 depth words in transfer scratch to/from R32_SFLOAT via the
existing Depth24Converter compute pass in copy_depth_uav. Add
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT to copy scratch, accept D16S8/D24S8
castable lists in castable_view_formats, and keep #1558's refusal fallback
in d3d12_xs_device.cpp for any other provider refusal.

Replace xbox_d16s8_refused_uav with xbox_d16s8_d24_storage covering slot 76
6-layer round-trips, slot 133 1280x720 placement, CreateCommittedResource3
castable formats, R16_UNORM/R16_UINT/R8_UINT UAV clears, and direct D24S8
parent attachment readback.

Verified on Windows 10 19045 / GeForce GTX 1050 Ti (NVIDIA 582.66):
17/17 related CTests pass plain and with LEONIDA_VK_VALIDATION=1 (0
validation errors).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Follow-up review fixes for D24S8-made Xbox D16S8 (format 118) depth UAVs:
- Pass the console origin (recorded before pc_format()) into
  castable_view_formats() instead of widening on format.d24, so a plain PC
  D24_UNORM_S8_UINT texture keeps main's castable-format rules and refuses
  the R16/R8/118-120 depth-UAV views.
- Set mark_console_d16s8() in create_placed() as well as
  create_committed(). CreateReservedResource refuses format 118 before it
  makes anything (a stencil format has no tile shape), so it needs no mark.
- Extend xbox_d16s8_d24_storage to cover slot 127, incompatible castable
  views, plain PC D24S8 castable/UAV refusal, CreateCommittedResource2,
  CreatePlacedResource/2, and the CreateReservedResource refusal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
create_placed turns a console D16S8 (format 118) description into its PC
format before committed_resource_refusal, but left the clear value as
118, so the clear format's family no longer matched the resource's and
every placed format-118 depth texture with a clear value was refused
("clear value"), with D24S8 backing. The clear value now goes through
pc_format() too, as the description does. Found by
xbox_d16s8_d24_storage's CreatePlacedResource case on a GTX 1050 Ti.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:18:44 +00:00
github manually merged commit 40a69e0084 into gh-pr/2123/base 2026-11-26 10:18:45 +00:00
Author
Owner

@⁠JordanWebDev on GitHub · 2026-11-25 23:41 UTC · original · approved these changes

**@⁠JordanWebDev** on GitHub · 2026-11-25 23:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2123#pullrequestreview-6066540034) · **approved these changes**
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-26 01:52 UTC · original

Merged, thanks! Depth-stencil UAVs for the console's D16S8 (format 118) now work when it is stored as D24S8.

  • Checked: the D24 to 16-bit round trip is exact for all 65,536 values when the blit rounds to nearest (as main's D32 path already assumes); stencil is copied byte for byte; a GPU without D24S8 keeps format 118 native or takes the D32 path, and a missing converter is a logged refusal.
  • Tested: the depth tests pass on llvmpipe (native D24S8, so the new path ran) and on the gfx1036 iGPU (RADV, the D32 fallback); xbox_d16s8_d24_storage fails without the change. The full Windows suite under Wine on both devices, merged onto main f1afede5e, had nothing go from pass to fail because of this.
  • Small follow-up: CreatePlacedResource passes from_xbox_d16s8 to castable_view_formats with depth_uav_planes=false, where it has no effect.
  • Claim: c0pperlane listed this item in #1608 at 20:18Z (RT-D16S8-UAV-D24-STORAGE) without a PR; this one lands as the implementation.
  • Checked on main 8ff7bc5b2 + 40a69e008: it merges cleanly; the semantic suite passes (495 files, 6,333 tests, 0 files failed); the 15 docs and writer tests pass; check_no_game_data.py is clean on the 6 changed files.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-26 01:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2123#issuecomment-7180230394) Merged, thanks! Depth-stencil UAVs for the console's D16S8 (format 118) now work when it is stored as D24S8. - **Checked:** the D24 to 16-bit round trip is exact for all 65,536 values when the blit rounds to nearest (as `main`'s D32 path already assumes); stencil is copied byte for byte; a GPU without D24S8 keeps format 118 native or takes the D32 path, and a missing converter is a logged refusal. - **Tested:** the depth tests pass on llvmpipe (native D24S8, so the new path ran) and on the gfx1036 iGPU (RADV, the D32 fallback); `xbox_d16s8_d24_storage` fails without the change. The full Windows suite under Wine on both devices, merged onto `main` `f1afede5e`, had nothing go from pass to fail because of this. - **Small follow-up:** `CreatePlacedResource` passes `from_xbox_d16s8` to `castable_view_formats` with `depth_uav_planes=false`, where it has no effect. - **Claim:** c0pperlane listed this item in #1608 at 20:18Z (`RT-D16S8-UAV-D24-STORAGE`) without a PR; this one lands as the implementation. - **Checked on `main` `8ff7bc5b2` + `40a69e008`:** it merges cleanly; the semantic suite passes (495 files, 6,333 tests, 0 files failed); the 15 docs and writer tests pass; `check_no_game_data.py` is clean on the 6 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.