Skip to content

d3d12: compute root arguments in the table behind s[0:1], for programs that read them there (XboxBvhBuilder) - #7318

Open
sennecools wants to merge 3 commits into
ItsNotRexed:mainfrom
sennecools:compute-argument-table
Open

sennecools wants to merge 3 commits into
ItsNotRexed:mainfrom
sennecools:compute-argument-table

Conversation

@sennecools

@sennecools sennecools commented Nov 23, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue as: D3D-707 (RT-5), #7049 (comment) (part 2 of 2)

Depends on: none to build. #7211 is the measurement this implements.

What and why

The retail boot starts XboxBvhBuilder.dll, whose 52 compute programs take every root argument from a packed table behind s[0:1]. The layer only knew the user-SGPR layout, so it refused the larger signatures and would hand the others their arguments in the wrong place.

  • rt::rootsig::pack_table: the measured layout (root order, a root view two dwords, a constant one). A descriptor table is refused: none was measured.
  • The shader library flags a compute program that reads the table (user_sgprs 4 and s0 used as a pointer in the translator's index).
  • At dispatch, such a program gets its arguments in a table in the GPU address arena, with the table's VA in s0 and the low byte of s1. The command allocator owns that memory until Reset.
  • A signature that only fits the table is now created and usable by such a program; a program that reads user SGPRs is still refused with it.

Tested

Windows 11, MSVC 14.44, RX 9070 XT (driver 32.0.32029.2010).

  • New d3d12_argument_table (GPU): two dispatches and a second recording after Reset read the right arguments, for the 7-dword and the 30-dword table (the 30-dword readback is @TripleJ160's commit 269a9e526; it fails when the table's last dword is dropped, which the 7-dword case alone does not catch); clean under LEONIDA_VK_VALIDATION=1.
  • root_signature, shader_library, d3d12_compute, d3d12_fspx_compute, d3d12_set0_compute, d3d12_draw: pass.
  • Local check with my own package, not in the PR: a real builder program, dispatched through the layer with its own signature shape, wrote exactly the 80 words its code says.
  • d3d12_vulkan_device fails at line 6564 on this base, in a slot 78 path this PR does not touch; d3d12_indirect_dispatch_count fails as on main.

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (not a translator change)

@MatyEjsr

Copy link
Copy Markdown

Independent native Windows + NVIDIA GPU verification and code review of 8e58eafd221f23b5def18e9fad090097bc5400a6: pass.

Environment: Windows 11 x64, MSVC 19.44.35207 (RelWithDebInfo, Ninja -j 8), NVIDIA GeForce RTX 3090 (driver 617.42), Vulkan SDK 1.4.363.0 (VK_LAYER_KHRONOS_validation with LEONIDA_VK_VALIDATION=1), synthetic fixtures only (no game files).
Depends on: none (implements the #7211 measurement).

Build & GPU / CPU Verification (-j 8)

  • Build (cmake --build runtime/build --config RelWithDebInfo -j 8): gta6rt, d3d12_argument_table_test, root_signature_test, shader_library_test, d3d12_compute_test, d3d12_fspx_compute_test, and d3d12_set0_compute_test compiled and linked cleanly under /W4 /permissive- (including glslangValidator --target-env vulkan1.3 compilation of runtime/test/glsl/cs_argument_table.comp).
  • d3d12_argument_table_test on NVIDIA GeForce RTX 3090 (normal and LEONIDA_VK_VALIDATION=1):
    • device: NVIDIA GeForce RTX 3090 (validation on)
    • subgroup sizes: 32..32 (default 32), requirable in stages 0x3fff, subgroupSizeControl on, computeFullSubgroups on
    • d3d12_argument_table_test: two dispatches and a second recording read their arguments from the table behind s[0:1]; a 30-dword signature is usable by a program that reads the table (exit 0, 0 validation errors, 9 arena allocations, 0 refused).
  • CTest suite (ctest -C RelWithDebInfo -j 8 -R "^(d3d12_argument_table|root_signature|root_signature_oracle|root_sig|shader_library|d3d12_compute|d3d12_fspx_compute|d3d12_set0_compute)$"): 8/8 passed in 0.97 s (root_signature, root_signature_oracle, root_sig, shader_library, d3d12_argument_table, d3d12_fspx_compute, d3d12_set0_compute, d3d12_compute).
  • Repository & hygiene checks: python -I scripts/check_no_game_data.py on all 12 changed files and python -I tests/test_ctest_registration.py (4/4 tests) passed.

Code Review Notes

  • rt::rootsig::pack_table (runtime/src/root_signature.cpp / root_signature.h): Cleanly packs root views (2 dwords) and root constants (1 dword per value) in root-signature order without padding, enforces the 64-parameter and 64-dword D3D12 cost limits, and explicitly rejects unmeasured descriptor tables and 0-value root constant entries.
  • ShaderLibrary detection (runtime/src/shader_library.h): Restricts ShaderEntry::argument_table to stage == "cs" with user_sgprs == 4 and a ptr64_lo read at sgpr == 0, matching the measured XboxBvhBuilder.dll contract without affecting graphics stages or compute shaders with root SGPRs from s4.
  • Arena allocation & lifetime (runtime/shims/d3d12_com.cpp / d3d12_vulkan_device.cpp):
    • CommandAllocator::place_table sub-allocates 8-byte-aligned slices from 64 KiB arena_buffer blocks, zeroes kTableOverreadDwords (15 dwords / 60 bytes) past the packed table so wide s_load_dwordx16 loads past the last parameter read zeros inside mapped arena memory, and frees all blocks on CommandAllocator::Reset() or destruction (device.arena_release).
    • GraphicsCommandList::compute_user_data covers both direct Dispatch and ExecuteIndirect (IndirectKind::dispatch), writes the 40-bit console VA into s0 and s1 & 0xff, reuses the placed table when root arguments have not changed (table_placed), and invalidates the list at Dispatch if a non-table compute shader is paired with a table-only root signature.

AI-assisted review and test report.

runtime/shims/d3d12_com.cpp conflicted in record_dispatch with main's direct heap indexing note (ItsNotRexed#6674);
both are kept: the note runs before the dispatch takes its user data from compute_user_data.

AI-assisted.
@sennecools

Copy link
Copy Markdown
Author

Merged main b33fa5b1c into the branch (7368f3b9f): #6674 and #6644 had made it conflict in runtime/shims/d3d12_com.cpp. One hunk needed a hand, record_dispatch: main's note_direct_heap_indexing now runs first and the dispatch still takes its user data from compute_user_data. Against main the diff is the same 12 files (+638 −25) as before.

Re-tested on the RX 9070 XT (driver 32.0.32029.2010): root_signature, shader_library, d3d12_argument_table, d3d12_compute, d3d12_com, d3d12_close_parity and d3d12_set_descriptor_heaps pass; d3d12_argument_table_test is clean under LEONIDA_VK_VALIDATION=1. d3d12_indirect_dispatch_count fails with the same message as on plain main. AI-assisted.

@DeSunShine

Copy link
Copy Markdown
Contributor

Tested 7368f3b9f merged into main dde82f27e on NVIDIA GeForce RTX 4090 (driver 621.24), Windows 11 Pro 26200, MSVC (VS Build Tools 18) + Ninja, Vulkan SDK 1.4.363: pass.

  • ctest -R "argument_table|root_signature|shader_library|d3d12_compute|d3d12_draw" --output-on-failure: all passed except the one skipped by the test itself (shader_library_corpus): d3d12_argument_table, root_signature, root_signature_oracle, shader_library, d3d12_compute, d3d12_draw.

AI-assisted (Claude Code).

@lohant27-netizen

Copy link
Copy Markdown

Tested 7368f3b9f (this head, after the merge of main) on Windows 11 (10.0.26300), NVIDIA GeForce RTX 5070 (driver 32.0.16.2101, subgroup 32), MSVC with SDK 10.0.26100, Release: pass.

@mrp1no

mrp1no commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 7368f3b9f merged onto current main (clean merge) on Windows 11, MSVC 2026 RelWithDebInfo + Ninja, LEONIDA_VK_VALIDATION=1: pass. The Intel run is the first on this PR as far as I can see.

  • Intel UHD 750 (32.0.101.7088) and RTX 3060 (610.88): d3d12_argument_table, root_signature, root_signature_oracle, shader_library, d3d12_com, d3d12_compute, d3d12_fspx_compute, d3d12_set0_compute and d3d12_draw all pass on both, with no validation messages.
  • shader_library_corpus over my own 1.0.2.1 translation (LEONIDA_SHADERS), which the other checks skipped: 26,503 containers, 26,501 index entries reached, 24 FSPX entries, 0 failures with this PR's index reading. The test still exits 1, but only because my work folder is an older translation that left 2 containers without an index entry (the test says so itself). This PR doesn't change that.
  • bvh_builder with LEONIDA_GAME_DIR passes too, but it only exercises the static side, not a dispatch through the table.

Counts only, no game data. AI-assisted (Claude Code).

@TripleJ160

Copy link
Copy Markdown

Independent Windows GPU validation of 7368f3b9f passed on both an RTX 5090 (driver 32.0.16.1692) and the Ryzen 7 9800X3D's Radeon iGPU (32.0.21030.31). Each adapter passed all seven targeted tests with LEONIDA_VK_VALIDATION=1: d3d12_argument_table, d3d12_compute, d3d12_fspx_compute, d3d12_set0_compute, d3d12_draw, root_signature, and shader_library. Windows 11 build 26200, MSVC 19.44, Vulkan SDK 1.4.363. No Vulkan validation errors or skips.

The existing 30-dword case checks Close(). I extended the synthetic fixture to submit that case and check GPU readback. Two dispatches with independent outputs and constants, followed by another recording after allocator reset, matched on both GPUs for both the 7- and 30-dword layouts. A local negative control that dropped the 30th dword failed the readback assertion on both adapters. The runtime was restored and all seven tests passed again.

@sennecools The test-only commit is based directly on your PR head and can be cherry-picked if you want the wider GPU regression check in this PR. This was an AI-assisted contribution using hand-written synthetic inputs.

@trick-ye

Copy link
Copy Markdown

Tested 7368f3b9f merged onto main dde82f27e on AMD Radeon RX 7800 XT (RDNA3), AMD 26.11.2 (Windows driver 32.0.32029.2010), Windows 11 26200: the new d3d12_argument_table passes, and no other recorded test status changed against main.

  • d3d12_argument_table passes; root_signature and shader_library (CPU only) and d3d12_compute pass as on main.
  • Whole suite, ctest -j 1: 273 tests, 254 pass, 13 skipped, 6 fail. main dde82f27e on this card: 272 tests, 253 pass, 13 skipped, 6 fail. The six failures are the same in both runs: vk_queue_query_sync, d3d12_vulkan_device, d3d12_texture_tiles, d3d12_indirect_dispatch_count, d3d12_depth_resolve and d3d12_pipeline_library_host. The only change in recorded test status is the added test.
  • The build has 22 compiler warnings, the same count as main.
  • MSVC 14.42 (VS 2022), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, llvm-mc 23.1.6, RelWithDebInfo, LEONIDA_VK_DEVICE=7800; the configured build completed (GameInput shim not built: no SDL3, so gameinput is listed as disabled and not counted). Synthetic tests only, no game files.

AI-assisted (Claude Code).

@sennecools

Copy link
Copy Markdown
Author

@TripleJ160 thank you, cherry-picked as 269a9e526 with your authorship (the head is now that commit; it is test-only, two files).

I checked it here before taking it: d3d12_argument_table passes on the RX 9070 XT and the gfx1036 iGPU, also with LEONIDA_VK_VALIDATION=1. With the copy in place_table deliberately dropping the table's last dword, your version fails at the readback while the previous test still passed (its 7-dword table ends in the high half of an address, which is zero), so it closes a real gap.

@trick-ye thanks for the RX 7800 XT run. AI-assisted.

@ElsCiber

Copy link
Copy Markdown

Windows + NVIDIA check of the current head 7368f3b9 (after the main b33fa5b1 merge): pass. AI-assisted.

@KarloZ7715

Copy link
Copy Markdown

Tested 269a9e52622100f51afe0476b80b028ad08d9e41 merged cleanly onto 867d922f09b86583859796a174df89555fb32da8 on native Windows 11 Pro x64 (build 26300), AMD Radeon RX 6600 (RDNA2, driver 32.0.21045.29003, default subgroup size 64), MSVC 19.44.35230, Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.0, Ninja RelWithDebInfo.

With LEONIDA_VK_DEVICE=RX 6600 and LEONIDA_VK_VALIDATION=1, 7/7 focused CTests passed: d3d12_argument_table, d3d12_compute, d3d12_fspx_compute, d3d12_set0_compute, d3d12_draw, root_signature, and shader_library. The loader confirmed Khronos validation was active on all five GPU tests. The test logs contained no validation warnings or errors.

The 7- and 30-dword cases both matched their GPU readbacks across two dispatches before and after allocator reset. As a negative control, I temporarily zeroed dword 29 only for the 30-dword table immediately after copying it in place_table. d3d12_argument_table failed at the first readback comparison (line 277). Restoring the source and rebuilding returned all seven tests to passing.

Synthetic inputs only. All 12 changed files passed check_no_game_data.py. Retail boot and the full runtime suite were outside this check. AI-assisted (Codex).

@caiodstx

Copy link
Copy Markdown

Tested 269a9e526 merged alone on main dde82f27e on AMD Radeon RX 6700 XT (RDNA2, gfx1031), AMD 26.9.1 (Vulkan 1.4.315), Windows 11 IoT Enterprise LTSC 2024 (26100), MSVC 14.51 + Ninja, RelWithDebInfo, Vulkan headers via -DLEONIDA_VULKAN_HEADERS_FETCH=ON, no game files: no regressions, but the new GPU test was not built here.

  • root_signature, shader_library, d3d12_queue_list_type pass.
  • d3d12_argument_table was not built: it sits behind Vulkan_GLSLANG_VALIDATOR_EXECUTABLE, and this machine has no Vulkan SDK / glslangValidator. So this run doesn't cover the s[0:1] table path on the GPU.
  • d3d12_vulkan_device fails, as it does on main alone (I didn't compare the failure line).
  • Full ctest: no test fails with this PR that doesn't also fail on main alone. (The previous head 7368f3b9f gave the same result.)

On main alone, on this GPU, the full ctest fails these: d3d12_vulkan_device, d3d12_texture_tiles and d3d12_pipeline_library_host (each has an open fix PR), d3d12_depth_resolve (from #6610, fixed by #7905), and vk_queue_query_sync, which is flaky on main here (line 468: progress_loss_ok, 5 of 10 serial runs fail; also seen in #8426).

Ran the full ctest --test-dir runtime/build -j 6 with the PR merged alone and compared the failures with main alone. AI-assisted (Claude Code).

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.

10 participants