Repository navigation
d3d12: supply directly indexed heaps to compute dispatches (RT-DIRECT-HEAP-COMPUTE) - #1064
Conversation
|
Review of #1064 (RT-DIRECT-HEAP-COMPUTE), head 90bbf5e Environment: Windows 11 Pro 26300, MSVC 19.50 (Visual Studio 18 2026 generator), RelWithDebInfo, NVIDIA GeForce RTX 5070 Ti, driver 617.42 (LEONIDA_VK_DEVICE=5070). Claim: RT-DIRECT-HEAP-COMPUTE is claimed by the author in #14 (issuecomment-7139398473), and the scope there matches the PR: inline compute layout only, with a GPU test and a rollback switch. What I ran All four targets built. The new test code adds one warning: C4996 for
Mutation: I changed Merge: What the change does
Findings
Verdict: approve with comments. The change is small, the snapshot semantics are right (record-time heap capture, rebinding, reset, bundle inheritance by deferral), and it passes on the RTX 5070 Ti with and without validation. The mutation shows the GPU test catches a missing heap word. Before merge I would like finding 1 fixed: a cited count, or the ABI marked as a hypothesis. Findings 2-4 can come in a follow-up. AI-assisted. |
90bbf5e to
667dea2
Compare
|
Native Windows check, AI-assisted (Claude Code). Windows 11, i9-13900K, 64 GB, RTX 4070 Ti 12 GB (NVIDIA 630.20), MSVC 2022 (VS 17 generator, Release), Vulkan. Head
1 passed, 0 failed. |
|
Independent Windows verification of Host: Windows 11 Pro 26300, NVIDIA GeForce RTX 5070 Ti (driver 621.24, Resizable BAR), live WARP, MSVC 19.44.35207 (VS 2022 Build Tools), Ninja, RelWithDebInfo,
Failures shared with the merge base |
667dea2 to
7c47fd9
Compare
|
Thank you for the review, the mutation check and the native Windows runs. The branch is updated; the numbered points follow your findings.
Run on the new head (CachyOS, Proton Experimental, RTX 4070, NVIDIA 620.73.04): 🤖 Generated with Claude Code |
|
AMD run (the gap the description lists): RX 9070 XT (RDNA4, GFX1201), AMD proprietary Windows driver 26.11.2 (LLPC, Vulkan 1.4.359), Windows 11, MSVC 2022 RelWithDebInfo. Head |
…-HEAP-COMPUTE) Compute shaders using direct resource indexing received a zero heap pointer. Snapshot each bound heap offset after the explicit inline root arguments on direct and indirect dispatches, so each command retains the bindings it had when recorded. When the explicit arguments leave no SGPR, keep them and report the missing heap slot once. The placement is a hypothesis with partial evidence. Of 2,959 direct-indexing compute entries, seven could be paired with recorded layouts. All seven resource reads agree with the predicted slot. The other 2,952 have no paired layout, and no paired sampler read establishes the relative heap order. tools/compute_heap_layout_census.py reproduces the count, with synthetic tests for agreement, disagreement and missing evidence. Built gta6rt and d3d12_compute_test with clang-cl. The Proton Vulkan fixture passed 64 buffer reads and 64 null controls on an RTX 4070. With the rollback switch, all 128 controls read zero. Both runs check the recorded arguments for bundle inheritance, indirect heap rebinding and the last inline SGPR. The synthetic SPIR-V fixture passed validation. AI-assisted (Codex and Claude Code agents). Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
7c47fd9 to
c8f7515
Compare
|
Rebased onto Run again on the rebased head (CachyOS, Wine 11.22, RTX 4070, NVIDIA 620.73.04): @iFeyz thank you for the AMD run on 🤖 Generated with Claude Code |
main already supplies the directly indexed heaps to compute dispatches (integration #984, the tree this pull request was split from): with_direct_heaps()/compute_user_data() on Dispatch and the ExecuteIndirect dispatch path, RootArgumentLayout::compute_arguments_end (kNoSgpr for a spilled signature), LEONIDA_COMPUTE_DIRECT_HEAPS=0, and the first form of this test (direct dispatch, indirect after a resource-only rebind, the GPU read through the heap). That form stays. What this pull request adds beyond it is carried onto it: the review-round reports, the extra recorded-argument checks, the census tool and its evidence. Conflicts: - runtime/shims/d3d12_com.cpp: main's with_direct_heaps()/compute_user_data() and its one-argument note_direct_heap_indexing(). Carried: compute_user_data() makes the note itself, so an ExecuteIndirect dispatch with no heap bound is reported too (record_dispatch's own call removed), and a heap with no inline dword left is reported once per heap kind ("compute root arguments leave no inline SGPR for the resource/sampler heap"); a spilled signature (main: kNoSgpr) gets one note of its own. Dropped: the PR's GetEnvironmentVariableA switch (main's direct_heaps_enabled) and its "graphics heap-base SGPR is not supplied" notes (main supplies the graphics heaps). - runtime/shims/d3d12_com.h, runtime/shims/d3d12_vulkan_device.cpp: main's (compute_arguments_end and graphics_arguments_end with their comment; compute_arguments_end only when the compute arguments do not spill). - runtime/test/glsl/cs_user_data.comp: main's; its direct-indexing mode (s5 = 0xFFFFFFFC, heap at s9) is this pull request's, byte for byte. - runtime/test/d3d12_compute_test.cpp: the PR's block replaces main's earlier form of it (a superset: adds the bundle dispatch that inherits the parent's heaps, an indirect dispatch with only the sampler heap, signatures ending at s30 and s31, and the LEONIDA_COMPUTE_DIRECT_HEAPS=0 expectations). - docs/d3d12_vulkan.md: main's section 3.4 (the BatchCull s7 and PreSkin s9 evidence), with the PR's census paragraph (tools/compute_heap_layout_census.py, the seven paired layouts, the heap order as a hypothesis) and the no-room and spill reports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged, after merging
AI-assisted (Claude Code, Claude Opus 5.5). |
This merges ProjectLeonida#1064 as prepared (its head + a merge of main), so it brings ProjectLeonida#1232 up to date with main and with ProjectLeonida#1064. ProjectLeonida#1232's branch carried ProjectLeonida#974 (merged into main since) and an older head of ProjectLeonida#1064 (7c47fd9). main already supplies the directly indexed heaps to graphics draws (integration ProjectLeonida#984): graphics_user_data() on DrawInstanced, DrawIndexedInstanced and DispatchMesh, at RootArgumentLayout::graphics_arguments_end (pack_stage(Stage::Pixel)'s end_sgpr, set when the console layout places the signature), LEONIDA_GRAPHICS_DIRECT_HEAPS=0, its notes for a signature on the s0 layout or one that fills s31, and d3d12_graphics_direct_heaps_test (recorded draws and the VS/PS GPU reads). That form stays. What this pull request adds beyond it is carried onto it: the mesh case. Conflicts (all taken from ProjectLeonida#1064's merged branch, then the PR's mesh parts carried over): - runtime/shims/d3d12_com.cpp: main's graphics_user_data()/with_direct_heaps() and notes. The PR's own graphics_user_data(), GetEnvironmentVariableA switch and no-room notes are main's in another form and dropped. Carried: the comment says a mesh shader reads push dword d as s(d + 8) through ProjectLeonida#974's window, so it gets the heaps after its arguments from s16 (main's comment still said the mesh stage gets none); and DispatchMesh reports once when a heap falls past the mesh window (push dword 24 and up, s32 for the mesh shader), the case raised in the review of ProjectLeonida#1232 (mesh_ok accepts arguments up to push dword 24). - runtime/shims/d3d12_com.h, runtime/shims/d3d12_vulkan_device.cpp: main's (graphics_arguments_end from pixel.end_sgpr; the PR set it from its Spill::block form, which main did not take from ProjectLeonida#974). - runtime/test/glsl/cs_user_data.comp: main's (identical direct-indexing mode). - docs/d3d12_vulkan.md: main's section 3.4 with ProjectLeonida#1064's compute paragraph; the graphics paragraph's "a mesh shader ... is not modelled" replaced by the mesh window position, cited to issue ProjectLeonida#14 comment 7143020922 as a report not reproduced here, the window-overflow note and the mesh test. - runtime/test/d3d12_mesh_test.cpp (no conflict): the PR's recorded-argument checks kept (vertex and mesh draw with 4 constants, resource-only rebind, 23 constants, 30 constants); the 30-constant comment now says it keeps pack()'s s0 layout on main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eaps after their root arguments With CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED / SAMPLER_HEAP_DIRECTLY_INDEXED a console program reads the resource heap's address in the dword after its root arguments and the sampler heap's in the next, from s8 in VS/PS/GS and s16 in mesh shaders (DadaCap, issue #14 comment 7143020922), as #1064 does for compute. DrawInstanced, DrawIndexedInstanced and DispatchMesh now record them at RootArgumentLayout::graphics_arguments_end; a mesh shader reads the same push dwords through the #974 window. Nothing is written for a signature with parameters in the argument block or under LEONIDA_GRAPHICS_ROOT_LAYOUT=pc (no slot is measured there); LEONIDA_GRAPHICS_DIRECT_HEAPS=0 restores the previous arguments. d3d12_mesh_test checks a vertex and a mesh draw, a rebind, a signature ending at s30 and a spilled one.
Claimed in the coordination issue as: RT-DIRECT-HEAP-COMPUTE (claim).
Part of the split of #984 into small pull requests.
Depends on: none
Overlaps: #683 serializes the heap-indexing flags and #974 handles graphics-stage root layouts. #1009 changes the same dispatch paths: whichever of this pull request and #1009 lands second must carry
compute_user_data()into the block-based direct and indirect dispatch paths, and spilled signatures still need a measured location for their heap words. This child uses the existing inline compute layout.What and why
On Linux/Proton and native Windows, a compute dispatch could bind a shader-visible heap and still give its shader a zero resource-heap pointer. The shader used that pointer to look up a buffer descriptor.
For an inline signature, direct and indirect dispatches now snapshot each flagged heap's 32-bit byte offset from the arena after the explicit root arguments. An unbound heap contributes zero. Rebinding affects later commands. When the explicit arguments leave no SGPR, they are kept and the heap that cannot fit is reported once per heap kind. A dispatch with a flag set and no heap bound is reported, and a graphics draw with a bound heap reports that its heap-base SGPR is not supplied. Set
LEONIDA_COMPUTE_DIRECT_HEAPS=0to restore the previous arguments.The GPU fixture reads through a descriptor at its original heap index. It also reads a null descriptor and checks the recorded arguments: a direct dispatch, a bundle dispatch that inherits the parent's heaps, an indirect dispatch after rebinding the resource heap only, one with only the sampler heap, and signatures whose explicit arguments end at s30 and s31.
Evidence for the layout
Putting the resource heap in the first SGPR after the explicit arguments, and the sampler heap in the next one when both flags are set, is a hypothesis with partial evidence. The code comment and section 3.4 of
docs/d3d12_vulkan.mdnow say so.tools/compute_heap_layout_census.pycompares role-tagged dynamic descriptor loads with a root layout that is known independently: an embedded RTS0, or a layout recorded in a dispatch log of integration #984. It excludes known explicit table bases and counts ambiguous reads separately.No flagged entry embeds RTS0. The seven paired entries all read the resource heap at the end of the explicit layout. No sampler-indexing entry had a paired layout, so the relative order of the two heaps is not verified on retail code. For the other 2,952 entries the layout is unknown. Counts are per indexed entry, and the carves can contain the same program.
SHADERSandPIPELINE_COMPUTEare local carve directories, and the dispatch logs (13 of them) hold both compute-layout and named compute-input records from a single process each. None of that is in the repository: only the tool and its synthetic test are. The census was run again on the tree before this rebase and gave the counts above (the rebase does not touch the tool). The archive-only counts can be reproduced without a dispatch log.Tested
CachyOS, kernel 7.3.5-2-cachyos, Wine 11.22 (the distribution's package, in a fresh prefix), Ryzen 5 5600X, 16 GB RAM, RTX 4070 12 GB, NVIDIA 620.73.04. Cross-built with clang-cl 23.1.5 and an xwin SDK in a Ninja Release build directory. The configuration used the Linux cross-toolchain in the repository and a cached SDL3 checkout. This head is the previous one rebased onto
main66d4f5aa3(one conflict, inrecord_draw, wheremainnow tests every bound viewport); everything below was run again on it. The previous heads were run under Proton Experimental.All four build targets succeeded. The census test passed (2 tests), as did the two census tests it builds on (13 and 25 tests). The synthetic fixture passed SPIR-V validation. Both runs of the compute test exited zero. The default run matched all 64 buffer reads and 64 null controls and logged the four expected reports (no resource heap bound, no sampler heap bound, no inline SGPR for either heap). The rollback run matched all 128 zero controls. Both runs checked the recorded arguments listed above.
d3d12_bundle_test(14 scenarios, 0 failures) andd3d12_set_descriptor_heaps_testpassed. Wine skipped the existing native D3D12 CachedPSO comparison and the bundle test's host comparisons. CMake could not build the optional XMA decoder (cargo has no Rust Windows MSVC target here), which only silences XMA voices.Not run on this head: the Vulkan validation layer (it is not installed on this machine), native Windows, AMD or Intel, and a game boot with this child alone.
d3d12_indirect_dispatch_count_testwas not run again; on the previous head it exited 1 under Wine on this machine without printing anything, as builds of unrelated trees did. The reviewers' runs were on earlier heads: native Windows on an RTX 5070 Ti (with and without validation) and an RTX 4070 Ti, and an AMD RX 9070 XT on7c47fd946, the head before this rebase.GPUs tested: NVIDIA GeForce RTX 4070 (standalone child). The integration branch also confirmed the resource-heap argument during world loading on Windows 11, i9-13900K, 64 GB, RTX 4070 Ti, NVIDIA 630.20.
AI-assisted: yes. Claude Code and Codex agents contributed to the integration. Codex prepared this child and Claude Code re-ran the tests above on the published tree.
Checklist
66d4f5aa3. Merges cleanly.scripts/check_no_game_data.py.🤖 Generated with Claude Code