Skip to content

d3d12: support Xbox depth/stencil UAVs on committed and placed textures (D3D-991) - #9480

Closed
channa317 wants to merge 3 commits into
ProjectLeonida:mainfrom
channa317:codex/d3d-991-depth-stencil-uav
Closed

channa317 wants to merge 3 commits into
ProjectLeonida:mainfrom
channa317:codex/d3d-991-depth-stencil-uav

Conversation

@channa317

@channa317 channa317 commented Nov 23, 2026 •

Copy link
Copy Markdown

D3D-991

Xbox depth/stencil textures can hold shader-writable data as well as depth-test and stencil values. This change keeps attachment writes visible to a UAV shader and shader writes visible through the original texture after a transition. It covers the Xbox committed and placed paths, typed plane and array views, and fence-ordered graphics/compute queue handoffs. Original claim · D3D12 coordination

Contract Implementation
Resources Xbox slot 76 creates committed resources. Slot 133 preserves the guest address for placed resources. Identical live placements have distinct COM identities and share the contents, including after one alias is released. Partial overlaps and incompatible reinterpretations return an explicit error.
Views Single-mip, single-sample 2D textures and arrays. R32G8X24_TYPELESS exposes depth as R32_FLOAT and stencil as R8_UINT. R16_TYPELESS exposes raw D16 bits as R16_UINT. DSVs and SRVs keep the attachment image. A UAV view selects its own plane and layer range.
Ordering Legacy and enhanced barriers transfer selected subresources. Graphics can perform the transfers around a fenced compute dispatch. A dedicated compute family can also perform the transfers when maintenance10 and the per-format capability bits allow it. Compute-only rectangular clears use buffer-to-image copies.
Boundaries Queue-specific COMMON layouts with implicit UAV access are rejected. Generic COMMON remains usable for a handoff, and an explicit UAV access mask in generic COMMON is rejected. Heap flags requested for shader atomics follow the storage resources and round-trip through the logical texture. General XMem page remapping, CPU uploads and first-frame debugging are separate work.

Xbox sizing integration

Depends on: #7110
Depends on: #7679

The integration run used the return-buffer-first slot-25 implementation from #7679 at 7c1dc142e before both creation calls. It checked the returned pointer, input descriptor, size and alignment. A 2560×1440 D32/S8 texture required 31,457,280 bytes at 65,536-byte alignment. The standalone GitHub base uses native sizing when that dependency is absent. Hubcio511 demonstrated the Vulkan plane round-trip, and danekbiglike established a placed R16 array precedent. Vulkan prototype · R16 array work

Verification on 73b52fbfe

  • Windows 11 Pro for Workstations x64 build 26300, Intel Core i9-14900K, 128 GB RAM, NVIDIA GeForce RTX 4090 (driver 621.14), x64 Release, MSVC 19.44.35228, Windows SDK 10.0.26100.0, glslang 16.6.0. All fixtures are synthetic.
  • Nine end-to-end GPU cases passed both standalone and with the slot-25 dependency. Graphics family 0 and compute family 2 exchanged real shader writes via GPU fences. The tests checked every pixel, including untouched layers and planes. Khronos validation and synchronization validation were enabled with the Windows SDK 1.4.363.1 layer. No Vulkan validation errors were reported.
  • The 35 selected runtime tests passed 34/35 on the submitted tree. d3d12_vulkan_device failed the pre-existing reserved-resource tiles == 1 assertion. Applying only d3d12_vulkan_device: check PC CreateReservedResource2 behind the Xbox proxy, not through slot 78 #7125 gave 35/35 with zero skips.
  • Full translator suite: 5,957 tests, 447 files. test_image_atomics_guard and test_image_store_d16 also fail on the unchanged parent with identical failing cases.
  • Git merge checks against main 5d74c2723 and the overlapping pipeline-cache PR d3d12: the Vulkan pipeline cache is also saved while the session runs (LEONIDA_PIPELINE_CACHE_SAVE_SECONDS) #9467 (291b10c9a) were clean.

Thanks to the testers of the original 943df6400 commit. The two edge cases raised in the RTX 3090 report are covered by the updated tests. RTX 3090 feedback · D3D12 layout/access compatibility

AI-assisted (Codex).

@sodove

sodove commented Nov 23, 2026

Copy link
Copy Markdown

Independent Windows/Vulkan check of 943df640 (GitHub test merge 4a4bcd68 on 5d74c272). Windows 11 x64 build 26100, RTX 5070 Ti, NVIDIA 610.74, Vulkan loader 1.4.341, MSVC 19.44, SDK 10.0.26100.

  • The committed Xbox slot-76 round-trip passed 3/3. Each run verified 63/63 samples per plane with legacy barriers and 3,686,400/3,686,400 per plane with enhanced barriers. Both paths exercised the clear, real shader read-modify-write, and readback on the Vulkan device.
  • A local negative control disabled only the copy from UAV storage back to the depth/stencil image. The test then failed at pixel comparison.
  • replay_texture_barrier, device_proxy, and device_proxy_trace also passed all three runs. The synthetic compute fixture built with glslang 16.2.0 and passed spirv-val --target-env vulkan1.3.

Scope is committed resources and graphics-queue replay. Synthetic inputs and Vulkan validation layer off. AI-assisted.

@DeerSilver

Copy link
Copy Markdown

Tested 943df6400 merged onto main 6312c057f (clean merge) on one laptop with two GPUs, picked with LEONIDA_VK_DEVICE: pass, no regressions. This is the first run on Intel and on Blackwell.

  • Intel UHD Graphics (Raptor Lake-S mobile, Xe-LP, 8086:a788), driver 32.0.101.7088
  • NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell), driver 621.24 (32.0.16.2124)
  • Windows 11 26300, MSVC 19.44 Ninja RelWithDebInfo, Vulkan headers 1.4.363 (fetched), glslangValidator 16.6, synthetic fixtures only, no game files

New and touched tests, LEONIDA_VK_VALIDATION=1 (Khronos layer 1.4.357): pass on both GPUs, with no validation messages.

  • d3d12_depth_stencil_uav: legacy barriers at 9×7 (all 63 pixels on each plane) and enhanced barriers at 2560×1440 (all 3 686 400 pixels on each plane).
  • replay_texture_barrier, device_proxy, device_proxy_trace and the seven xs_proxy_mock* tests.
  • Neighbouring depth/stencil and clear tests are unchanged: d3d12_stencil_copy, d3d12_clear, d3d12_copy_xfmt, d3d12_view_slices, clear_color.

Full ctest: 264/266 pass on NVIDIA and 261/266 on Intel. Every failure is one plain main already has on this machine:

Test GPU Cause
d3d12_vulkan_device both tiles == 1, fixed by #7125
d3d12_depth_resolve both refused resolves change the destination, fixed by #7905
d3d12_clear_formats Intel 10 sRGB clears one step below WARP (D3D-993, #9353)
d3d12_buffer_tiles, d3d12_dxr_validation_khr Intel features this iGPU lacks

I didn't test placed resources, array layers or queue handoffs, which the description leaves for later.

AI-assisted (Claude Code).

@OliverMarcusson

Copy link
Copy Markdown

Tested 943df6400 (merged cleanly onto main 5d74c272) on NVIDIA GeForce RTX 5070 Ti (driver 621.01, Vulkan 1.4.357), Windows 11 10.0.26200, MSVC 19.44 (RelWithDebInfo, Windows SDK 10.0.26100.0, glslangValidator 16.6.0): pass.

  • d3d12_depth_stencil_uav: PASS (legacy barriers, 9x7, read back all 63 pixels on each plane; enhanced barriers, 2560x1440, read back all 3686400 pixels on each plane)
  • device_proxy: PASS (0 failures)
  • replay_texture_barrier: PASS (OK)
  • Regression slice (d3d12_descriptor, d3d12_typeless_families, d3d12_compute, d3d12_draw): 4/4 PASS (d3d12_vulkan_device failed only at the pre-existing line 6574: tiles == 1)
  • Code read of the C++ diff: storage-plane ownership/deferred cleanup in ~Resource() + storage_pending_.erase(id), single-plane discard sibling preservation, and T#/parent mismatch rejection all look clean.

AI-assisted (Gemini).

@tidyhf

tidyhf commented Nov 23, 2026

Copy link
Copy Markdown

Tested 943df64 on NVIDIA GeForce RTX 4080, driver 617.42, Windows 11 Pro (26300), MSVC 14.41, Vulkan SDK 1.4.363.0: pass.

AI-assisted (Claude Code) test run.

@adorted

adorted commented Nov 23, 2026

Copy link
Copy Markdown

Windows 10 data point (the runs above are all Windows 11): tested 943df6400 merged onto main 5d74c2723 (clean merge) on NVIDIA GeForce RTX 5090 (desktop Blackwell), driver 610.88, Windows 10 Pro 19045, MSVC 19.44.35230 (VS 2022 Build Tools), Windows SDK 10.0.26100, CMake 3.31.6 + Ninja, RelWithDebInfo, Vulkan SDK 1.4.363.0. No game files. Pass, no regression.

  • d3d12_depth_stencil_uav passes (9×7 legacy, 2560×1440 enhanced), and again with LEONIDA_VK_VALIDATION=1 (Khronos layer 1.4.363, which this harness runs with synchronization validation): 0 validation messages, exit 0. replay_texture_barrier and device_proxy pass.
  • Full runtime ctest -j4: 258/266. All 8 failures also fail on plain main 5d74c2723 built and run on this machine (root_signature_oracle, d3d12_vulkan_device, d3d12_close_parity, d3d12_execute_indirect_validation, d3d12_depth_resolve, d3d12_indirect_rt, d3d12_pso_validation, d3d12_set_descriptor_heaps). Several are this host's older D3D12 runtime (e.g. root-signature 1.1 flags 0xc7f rejected by the serializer, DYNAMIC_DEPTH_BIAS returning E_INVALIDARG on the host), not this PR.
  • Build nit: the new prepare_depth_uav code at runtime/src/vulkan_replay.h:2670 and :2673 adds two MSVC C4459 warnings (texels and bytes hide a global declaration) in some test targets that include the header. main already has the same warning for bytes at line 2883, so it is cosmetic.

AI-assisted (Claude Code).

@kristofbarany

Copy link
Copy Markdown

Tested 943df64 merged onto main 5d74c27 (clean merge) on NVIDIA GeForce RTX 4070, driver 621.24, native Windows 11 Pro 26300, MSVC 14.44.35207, Ninja RelWithDebInfo: pass.

  • device_proxy_test and replay_texture_barrier_test: 3 of 3 runs each exit 0.
  • No compiler warnings in these builds.

No game data used. AI-assisted (Claude Code).

@MatyEjsr

Copy link
Copy Markdown

Tested 943df6400d191e6a35e83ac37f45581e56e35a0b on NVIDIA GeForce RTX 3090 (driver 617.42, Vulkan SDK 1.4.363.0, Windows x64 build 26200.7171, MSVC 19.44.35207, RelWithDebInfo): pass.

What was run

  • Merge & hygiene checks (against origin/main 5d74c2723):
    • git merge-tree --write-tree HEAD origin/main: clean (no conflicts).
    • git diff --check: clean.
    • python -I scripts/check_no_game_data.py on all 14 modified/added files: pass (exit 0; synthetic inputs only).
  • Build & SPIR-V validation:
    • Full runtime/ build (cmake --build runtime/build --parallel 8, RelWithDebInfo): 331/331 targets built and linked cleanly with zero new compiler warnings.
    • spirv-val --target-env vulkan1.3 on generated cs_depth_stencil_uav.spv: pass.
  • Targeted GPU & unit tests (default + Vulkan validation / synchronization validation):
    • ctest -R "^(d3d12_depth_stencil_uav|device_proxy|replay_texture_barrier)$": 3/3 passed (d3d12_depth_stencil_uav verified all 63 pixels/plane at 9Ă—7 with legacy barriers and all 3,686,400 pixels/plane at 2560Ă—1440 with enhanced barriers).
    • With LEONIDA_VK_VALIDATION=1 (VK_LAYER_KHRONOS_validation + VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXT):
      • d3d12_depth_stencil_uav: pass (0 validation/sync errors on both 9Ă—7 legacy and 2560Ă—1440 enhanced runs).
      • d3d12_uav_clear, d3d12_typeless_depth, d3d12_stencil_copy, vk_sync_validation: 4/4 passed.
  • Full runtime CTest suite (ctest -j 8):
    • 263 passed, 11 skipped (game-copy / optional gates), 1 disabled (gameinput), 2 failed (d3d12_vulkan_device at the known reserved-resource tiles == 1 assertion from d3d12_vulkan_device: check PC CreateReservedResource2 behind the Xbox proxy, not through slot 78 #7125, and d3d12_depth_resolve due to RTX 3090 D3D12 host behavior on refused resolves; WARP matched 71/71).
    • Rebuilt and re-ran both d3d12_vulkan_device and d3d12_depth_resolve on untouched origin/main (5d74c2723) and confirmed both fail identically on baseline.

Code review notes (non-blocking)

The design is clean: separate per-plane storage resources avoid clobbering the parent SRV in bindless set 0, uav_image_resource() prevents cross-resource or SRV-handle UAV clears, storage_pending_.erase(id) in remove_resource() prevents stale entries, and coupled-layout single-plane discard preservation in emit() is carefully handled. Two edge cases worth noting for follow-up or tightening:

  1. D3D12_HEAP_FLAG_ALLOW_SHADER_ATOMICS in slot 76 (runtime/shims/d3d12_xs_device.cpp, proxy_create_resource): stripping D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS from pc_desc.Flags while passing heap_flags unchanged to CreateCommittedResource will be refused by committed_resource_refusal() (runtime/shims/d3d12_vulkan_device.cpp: "ALLOW_SHADER_ATOMICS without ALLOW_UNORDERED_ACCESS") if a title sets D3D12_HEAP_FLAG_ALLOW_SHADER_ATOMICS on a depth/stencil UAV texture. Masking D3D12_HEAP_FLAG_ALLOW_SHADER_ATOMICS out of the inner depth resource's heap_flags avoids that mismatch.
  2. Enhanced D3D12_BARRIER_LAYOUT_COMMON with UAV access (runtime/src/vulkan_replay.h, prepare): queue_common_layout() rejects DIRECT_QUEUE_COMMON and COMPUTE_QUEUE_COMMON, while d3d12_layout::common is permitted (which is needed for non-UAV transitions such as generic_read -> common with copy_source). If a caller enters or leaves d3d12_layout::common with d3d12_access::unordered_access (or d3d12_access::common), texture_uav_layout() returns false so it is neither rejected nor synchronized between parent and storage planes. Rejecting d3d12_layout::common when the corresponding access mask can include UAV access would close that gap without breaking copy_source transitions to common.

AI-assisted: yes. All test inputs are synthetic; no game data was used.

@comtek21516

Copy link
Copy Markdown

Tested 943df6400 on main at 867d922f0, in one tree with #8213, #9486, #9492, #9328, #9467 (six clean merges): pass.

For this change. The new d3d12_depth_stencil_uav is skipped on the Windows machine (no Vulkan driver), so the GPU run is the one that counts: under Wine on the RTX 4000 it passes. The existing depth tests keep their status there (d3d12_depth24_draw passes; d3d12_depth_resolve fails with and without the change).

Setup. Built with MSVC 14.52 (Visual Studio 18), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.1, Ninja RelWithDebInfo on Windows Server 2025 (no Vulkan driver there), then the same binaries run through scripts/run_wine_tests.py under wine-11.0 (WineHQ stable, xvfb-run) on a Quadro RTX 4000 (Turing), NVIDIA 615.71.09, Ubuntu 22.04.5, where the layer tests report device: Quadro RTX 4000.

passed failed skipped
native Windows, this tree 149 4 129
Wine on the GPU, main 867d922f0 210 12 54
Wine on the GPU, this tree 214 12 57

Against main under Wine the only differences are the seven tests this tree adds (four pass, three are skipped because the Wine runner does not start cmake-driven tests); every test that exists on main has the status it has there. The four native failures are gameinput_host, d3d12_sparse_queue_family, vk_bindless_ps_tex and vk_bindless_ps_imgatomic, which fail the same way on main on that machine (#7452). The 12 under Wine are the same 12 as on main (host comparisons Wine cannot answer, and d3d12_xdxr_rt, d3d12_indirect_rt, d3d12_indirect_dispatch_count).

This was a combined run: the six PRs were built into one tree, so it is weaker evidence than a run of this PR alone, and there is no per-PR negative control. A regression would have shown as a difference from main, and there is none. No game files used. AI-assisted (Claude Code).

@RAINighty

Copy link
Copy Markdown

Tested 943df6400 merged with main 5d74c2723 (clean merge) on Windows 11 (10.0.26300), Intel Core i7-14650HX, hybrid-GPU laptop (RTX 5060 + Intel UHD, no adapter forced), MSVC 19.44.35228, RelWithDebInfo (Ninja): pass.

AI-assisted (Claude Code).

@singul-oss

Copy link
Copy Markdown

AI-assisted test. Pass, with 0 validation errors.

Tested 943df640 merged onto main 5d74c272 (clean) on Windows 11 Home 10.0.26200, NVIDIA GeForce RTX 5080 (driver 610.88, subgroup 32..32), MSVC 14.44.35207, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, llvm-mc 23.1.6, RelWithDebInfo. glslangValidator from the SDK builds cs_depth_stencil_uav.spv.

A question, not a blocker: after enable_depth_stencil_uav(), GetDesc() reports ALLOW_UNORDERED_ACCESS even though the title's description didn't ask for it. Is that meant to mirror what the console reports for these textures? If so, a line in docs/d3d12_vulkan.md would help. I read the description as leaving placed resources (slot 133), array layers and queue handoffs open under D3D-991, and the diff matches that, since only the slot-76 committed path calls the provider.

@channa317 channa317 changed the title d3d12: support depth and stencil UAVs on Xbox R32G8X24 textures (D3D-991) d3d12: support Xbox depth/stencil UAVs on committed and placed textures (D3D-991) Nov 23, 2026
@AAyberkU

Copy link
Copy Markdown
Contributor

A retail-boot case that this PR covers exactly. The crash is reproducible, so I'm testing this PR against it now.

Base: GitHub main + the boot PRs + #7021 + #9137 + #9276/#9014 + #7858 (new head) + #9586, with LEONIDA_STUB_COMPUTE_WORDS=100000 (#9250) so that loading gets this far. RTX 5060 Ti, driver 621.01. AI-assisted.

  • About 50 s into the retail 1.0.2.1 boot, the title creates three textures through CreateCommittedResource3:
    • TEXTURE2D, R16_TYPELESS;
    • ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS (0x6);
    • default heap, a depth clear value, initial state COMMON;
    • one single texture, one 3-slice array and one 6-slice array. They look like shadow maps the console lets you write as UAVs.
  • The Vulkan layer's committed-resource check refuses all three as a "resource flag combination". The title gets no resource back and asserts (skipped with LEONIDA_SKIP_INT3). A title worker thread then dereferences the missing object (a read at offset 0x30), and the process exits with an access violation.
  • d3d12_xs: a console depth-stencil texture with unordered access is sized and created without it (stand-in) #7679's stand-in is in our stack, but it does not cover this CreateCommittedResource3 path.

I'll report here whether this PR clears it.

@LooperSalty

Copy link
Copy Markdown

Tested 73b52fbf on NVIDIA GeForce RTX 4070 SUPER (driver 610.88), Windows 11, MSVC RelWithDebInfo, clean build: pass.

  • d3d12_depth_stencil_uav passes alone and in the full ctest run. Every pixel matches for slots 76 and 133 (committed and placed), 9x7, 13x9 and 2560x1440, 1 and 3 layers, 1 and 2 planes, legacy and enhanced barriers, plane transfers on the graphics family and, in one case, on the compute family. On this device the compute-side depth transfer is unavailable for one format (VkFormat 130) and the test takes the graphics-side handoff, as the PR describes.
  • ctest: 273/276 pass. The 3 failures (d3d12_vulkan_device, d3d12_depth_resolve, d3d12_indirect_rt) are the same 3 that fail on vulkan_bindless: grow dim_2d_array (binding 3) in size_bindings() #9273 here, and they fail on main too (seen on main dde82f27, not re-run on this head). No new failure from this PR.
  • GPU tests: 192/241 pass, 48 skipped, 1 fail (ms_wave_info_s3, same as on main on this GPU).
  • Not checked: the effect on a retail run (no local stack reaches the depth-UAV message yet), and Vulkan validation layers.

AI-assisted (Claude Code).

@kyulucas

Copy link
Copy Markdown

Tested 943df64 on NVIDIA GeForce RTX 3060 12 GB, driver 621.24, Windows 10 Pro: pass

Ran:

  • RelWithDebInfo build of this PR
  • d3d12_depth_stencil_uav_test.exe (legacy 9x7 + enhanced 2560x1440): exit 0
  • ctest -R d3d12_depth_stencil_uav: Passed

No game files used.

@corpse240

Copy link
Copy Markdown

Tested 73b52fbfe merged onto main 5d74c2723 (clean → 24fc7f86b) on Intel Arc B580 (Battlemage, 0xe20b), Intel Windows driver 101.9150, Vulkan 1.4.359, Windows 11 Pro 26200; RelWithDebInfo, VS 2022 Build Tools, Vulkan SDK 1.4.363.0: pass. First Intel run here, as far as I can see.

  • d3d12_depth_stencil_uav_test: exit 0, all 7 cases every pixel matched (slot 76 and 133; 9x7, 13x9 and 2560x1440; 1 and 3 layers; 1 and 2 planes; legacy and enhanced barriers; shader family 0 and 1, so the cross-family cases ran on this card's separate compute family).
  • The same with LEONIDA_VK_VALIDATION=1: exit 0, no VUID messages.
  • The four existing tests the PR changes, PR build vs main build: replay_texture_barrier_test, replay_uav_clear_offset_test (all passed), vulkan_scratch_test (all checks passed) and device_proxy_test (every PASS line, including slot 76) all exit 0 on both.

AI-assisted (Claude Code); no game files.

@AAyberkU

Copy link
Copy Markdown
Contributor

Result on the retail boot. Same base as above, plus this PR at 73b52fbfe.

The three DS+UAV textures are now created.

  • No "resource flag combination" refusal and no failed CreateCommittedResource3.
  • RTX 5060 Ti, driver 621.01. This PR's d3d12_depth_stencil_uav_test passes every variant.

One gap for the retail path: the title creates these textures through the console CreateCommittedResource3 (device slot 127), and some through the placed path (slot 133). This PR only routes slot 76. In our merge we sent slot 127 and slot 133 depth+UAV textures to your depth-UAV path as well; slot 133 goes to proxy_create_placed_depth when the provider is installed. Slot 127 also converts the initial layout to a legacy state.

Slot 133's state word is ambiguous. Our measurements show the title passes a barrier layout there, while this PR's tests pass a legacy state. We read all-ones as UNDEFINED, 0..8 as a layout, and anything larger as a legacy state. If you'd like that in this PR, I can send the diff.

It does not clear the crash by itself. The title still asserts and reads a null object at +0x30 in the same function, but now through the next object of the same call sequence, so one object is fixed and another is still unset. Details on #8851.

AI-assisted.

Capi360 added a commit to Capi360/Leonida that referenced this pull request Nov 23, 2026
Adapt upstream PR ProjectLeonida#9480 (943df64) to the local boot stack, preserving the packed texture backend and title-owned heap changes. Six focused tests passed, including the native depth/stencil UAV GPU fixture, on Windows 11 with an RTX 3060 Ti (NVIDIA 616.56). AI-assisted with Codex.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.