d3d12: supply directly indexed heaps to compute dispatches (RT-DIRECT-HEAP-COMPUTE) #1064

Manually merged
github merged 2 commits from gh-pr/1064/head into gh-pr/1064/base 2026-11-26 09:36:13 +00:00
Owner

@⁠Moriz82 on GitHub · 2026-11-24 17:34 UTC · original
split/rt-direct-heap-compute → main · +306 −9 · 5 files · 2 commits · merged 2026-11-25 03:25 UTC

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=0 to 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.md now say so. tools/compute_heap_layout_census.py compares 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.

Compute carve Entries Direct indexing Layout matched and register agrees Register disagrees No room Layout unavailable
Shader archive 2,689 1,484 0 0 0 1,484
Pipeline library 2,680 1,475 7 0 0 1,468
Upscaler and builder 81 0 0 0 0 0
Total 5,450 2,959 7 0 0 2,952

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.

for group in dxbc fspx bvh exe; do
    python3 -I tools/compute_heap_layout_census.py "$SHADERS/$group/disasm"
done
python3 -I tools/compute_heap_layout_census.py "$PIPELINE_COMPUTE/disasm" \
    --group fspx_compute --dispatch-log "$DISPATCH_LOG"

SHADERS and PIPELINE_COMPUTE are 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 main 66d4f5aa3 (one conflict, in record_draw, where main now tests every bound viewport); everything below was run again on it. The previous heads were run under Proton Experimental.

cmake -S runtime -B runtime/build/boot -G Ninja -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_TOOLCHAIN_FILE="$PWD/runtime/cmake/clang-cl-xwin.cmake" -DXWIN_DIR="$HOME/.local/share/xwin-sdk" \
  -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON -DLEONIDA_SDL3=ON \
  -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
  -DFETCHCONTENT_SOURCE_DIR_SDL3="$SDL3_SOURCE_DIR"
cmake --build runtime/build/boot --target gta6rt d3d12_compute_test d3d12_bundle_test d3d12_set_descriptor_heaps_test -j6
python3 -I tests/test_compute_heap_layout_census.py
python3 -I tests/test_heap_index_census.py
python3 -I tests/test_rootsig_census.py
spirv-val --target-env vulkan1.3 runtime/build/boot/generated/cs_user_data.spv
cd runtime/build/boot
export WINEDEBUG=-all WINEPREFIX=<a fresh prefix>
unset LEONIDA_COMPUTE_DIRECT_HEAPS
timeout 240 wine d3d12_compute_test.exe
LEONIDA_COMPUTE_DIRECT_HEAPS=0 timeout 240 wine d3d12_compute_test.exe
timeout 240 wine d3d12_bundle_test.exe
timeout 240 wine d3d12_set_descriptor_heaps_test.exe

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) and d3d12_set_descriptor_heaps_test passed. 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_test was 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 on 7c47fd946, 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

  • One commit based on upstream main 66d4f5aa3. Merges cleanly.
  • One topic with its own GPU regression and rollback control.
  • No game data. The changed files passed scripts/check_no_game_data.py.
  • Runtime packing only. No translator rule changed.

🤖 Generated with Claude Code

**@⁠Moriz82** on GitHub · 2026-11-24 17:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1064) `split/rt-direct-heap-compute` → `main` · +306 −9 · 5 files · 2 commits · merged 2026-11-25 03:25 UTC Claimed in the coordination issue as: RT-DIRECT-HEAP-COMPUTE ([claim](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14)). 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=0` to 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.md` now say so. `tools/compute_heap_layout_census.py` compares 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. | Compute carve | Entries | Direct indexing | Layout matched and register agrees | Register disagrees | No room | Layout unavailable | | --- | ---: | ---: | ---: | ---: | ---: | ---: | | Shader archive | 2,689 | 1,484 | 0 | 0 | 0 | 1,484 | | Pipeline library | 2,680 | 1,475 | 7 | 0 | 0 | 1,468 | | Upscaler and builder | 81 | 0 | 0 | 0 | 0 | 0 | | **Total** | **5,450** | **2,959** | **7** | **0** | **0** | **2,952** | 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. ```sh for group in dxbc fspx bvh exe; do python3 -I tools/compute_heap_layout_census.py "$SHADERS/$group/disasm" done python3 -I tools/compute_heap_layout_census.py "$PIPELINE_COMPUTE/disasm" \ --group fspx_compute --dispatch-log "$DISPATCH_LOG" ``` `SHADERS` and `PIPELINE_COMPUTE` are 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 `main` `66d4f5aa3` (one conflict, in `record_draw`, where `main` now tests every bound viewport); everything below was run again on it. The previous heads were run under Proton Experimental. ```sh cmake -S runtime -B runtime/build/boot -G Ninja -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_TOOLCHAIN_FILE="$PWD/runtime/cmake/clang-cl-xwin.cmake" -DXWIN_DIR="$HOME/.local/share/xwin-sdk" \ -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON -DLEONIDA_SDL3=ON \ -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DFETCHCONTENT_SOURCE_DIR_SDL3="$SDL3_SOURCE_DIR" cmake --build runtime/build/boot --target gta6rt d3d12_compute_test d3d12_bundle_test d3d12_set_descriptor_heaps_test -j6 python3 -I tests/test_compute_heap_layout_census.py python3 -I tests/test_heap_index_census.py python3 -I tests/test_rootsig_census.py ``` ```sh spirv-val --target-env vulkan1.3 runtime/build/boot/generated/cs_user_data.spv cd runtime/build/boot export WINEDEBUG=-all WINEPREFIX=<a fresh prefix> unset LEONIDA_COMPUTE_DIRECT_HEAPS timeout 240 wine d3d12_compute_test.exe LEONIDA_COMPUTE_DIRECT_HEAPS=0 timeout 240 wine d3d12_compute_test.exe timeout 240 wine d3d12_bundle_test.exe timeout 240 wine d3d12_set_descriptor_heaps_test.exe ``` 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) and `d3d12_set_descriptor_heaps_test` passed. 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_test` was 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 on `7c47fd946`, 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 - [x] One commit based on upstream main `66d4f5aa3`. Merges cleanly. - [x] One topic with its own GPU regression and rollback control. - [x] No game data. The changed files passed `scripts/check_no_game_data.py`. - [x] Runtime packing only. No translator rule changed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:36:12 +00:00
github manually merged commit 5115f08879 into gh-pr/1064/base 2026-11-26 09:36:13 +00:00
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-24 18:13 UTC · original

Review of #1064 (RT-DIRECT-HEAP-COMPUTE), head 90bbf5e606bc466275342a5e6b6c79e337468580

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

cmake -S runtime -B runtime/build -G "Visual Studio 18 2026" -DBUILD_TESTING=ON
cmake --build runtime/build --config RelWithDebInfo --target d3d12_compute_test d3d12_bundle_test d3d12_indirect_dispatch_count_test d3d12_set_descriptor_heaps_test -- /m:3

All four targets built. The new test code adds one warning: C4996 for getenv at runtime/test/d3d12_compute_test.cpp:598.

Run LEONIDA_VK_VALIDATION=0 LEONIDA_VK_VALIDATION=1
d3d12_compute_test (default) exit 0, "64 buffer reads and 64 null controls matched" exit 0, same, no VUID output
d3d12_compute_test, LEONIDA_COMPUTE_DIRECT_HEAPS=0 exit 0, "128 zero controls matched" exit 0, same
d3d12_bundle_test exit 0, 14 scenarios, 25 host comparisons, 0 failures exit 0, same
d3d12_indirect_dispatch_count_test exit 0 exit 0
d3d12_set_descriptor_heaps_test exit 0 exit 0

Mutation: I changed record_dispatch (runtime/shims/d3d12_com.cpp:1415) back to compute_.data, so a direct dispatch gets no heap words, rebuilt and ran with validation. d3d12_compute_test exited 1. I restored the file with git checkout --, rebuilt, and it passed again.

Merge: git merge-tree against origin/main 3aa975421 shows no conflicts. With #1009 (ROOT-SIG-SPILL-MODEL, head b477602aa) it has a content conflict in runtime/shims/d3d12_com.cpp, and the change to RootArgumentLayout in d3d12_com.h sits next to #1009's own change. Both PRs change record_dispatch and the ExecuteIndirect dispatch path. It merges cleanly with #974 (head 161314c26). #683 and #990 touch other files. The open-PR searches for "DIRECT-HEAP" and "directly indexed" find only #1064, #683 and the integration branch #984.

What the change does

  • SetDescriptorHeaps already tracked the CBV/SRV/UAV and sampler heap bases on the list (d3d12_com.cpp:1330). The new compute_user_data() (d3d12_com.cpp:1396-1410) copies the compute root-argument block for each command and writes the flagged heap bases at compute_arguments_end, resource heap first. compute_arguments_end is pack_stage(...).end_sgpr, set in d3d12_vulkan_device.cpp:6047. A heap that is not bound gives 0.
  • The heap words are read when the Dispatch or ExecuteIndirect is recorded. So a later SetDescriptorHeaps affects only later commands, and reset_state clears the heaps. The test checks both of these on recorded commands: a direct dispatch, then a rebind with only the resource heap, then an ExecuteIndirect dispatch.
  • Bundles: a Dispatch in a bundle is deferred (d3d12_com.cpp:371) and runs on the parent list at ExecuteBundle. It therefore uses the parent's heaps, which is the D3D12 rule. This works by construction, but no test covers it.
  • The arena is capped at 4095 MiB (docs/d3d12_vulkan.md:776), so the 32-bit truncation of the heap base is safe.

Findings

  1. The ABI the code depends on is stated as fact, without a source. The comment at d3d12_com.cpp:1394 says "The compiled compute ABI appends directly indexed heaps after the explicit root arguments", and the doc text at docs/d3d12_vulkan.md:1612-1616 says the same, with the resource heap first. Section 3.4 (D3D-329) measures that the bases are compute user SGPRs and gives s10/s11 as an example. It does not measure that they come right after the last root parameter, or in that order. The PR body cites a run of the integration branch during world loading, but that is not written down where a reader can check it. AGENTS.md asks to quote the source of a claim or call it a hypothesis. Please do one of these:
    • add a corpus count, e.g. in tools/heap_index_census.py, showing that for each heap-indexing CS the resource and sampler base SGPRs equal the end of its root signature's inline layout, and +1 for the sampler;
    • or call the order a hypothesis in the comment and in the doc, and cite the #984 observation.
  2. When the explicit arguments end at s31 or s30, there is no room for the heap words, and the code drops them without a word (d3d12_com.cpp:1405-1408). The doc says "with room", but the runtime logs nothing. A note_once there would make this case easy to see in a game log.
  3. Log text: note_direct_heap_indexing (d3d12_com.cpp:1344-1358) runs for draws too. With "(SGPR slot open, section 3.4)" removed, a graphics draw now logs "heap base tracked on list", although graphics still gets no heap words. I suggest keeping the "open" text for graphics, or making the message depend on the bind point. The ExecuteIndirect dispatch path (d3d12_com.cpp:860) does not call note_direct_heap_indexing at all, so an indirect dispatch with no heap bound logs nothing. This is minor.
  4. Test gaps (not blocking):
    • nothing reads through the sampler base on the GPU; only the recorded word is checked;
    • no dispatch with no resource heap bound, which by symmetry should give 0;
    • no bundle dispatch that inherits the parent's heaps;
    • the ExecuteIndirect dispatch is checked on recorded arguments only and is never submitted.
      A bundle case and an "explicit arguments fill s31" case would each take a few lines in the existing block.
  5. LEONIDA_COMPUTE_DIRECT_HEAPS=0 is a rollback switch for a runtime packing change, not a skip list, so I don't read it as breaking fix-don't-disable. The test runs correctly under both settings.
  6. The conflict with #1009 needs a decision on order: whichever lands second has to carry compute_user_data() into #1009's block-based dispatch. For spilled signatures, #1009 also needs a decision on where the heap words go. It would help to say this in both PRs.

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.

**@⁠kawaii-shakal** on GitHub · 2026-11-24 18:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1064#issuecomment-7140331718) Review of #1064 (RT-DIRECT-HEAP-COMPUTE), head 90bbf5e606bc466275342a5e6b6c79e337468580 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 ``` cmake -S runtime -B runtime/build -G "Visual Studio 18 2026" -DBUILD_TESTING=ON cmake --build runtime/build --config RelWithDebInfo --target d3d12_compute_test d3d12_bundle_test d3d12_indirect_dispatch_count_test d3d12_set_descriptor_heaps_test -- /m:3 ``` All four targets built. The new test code adds one warning: C4996 for `getenv` at runtime/test/d3d12_compute_test.cpp:598. | Run | LEONIDA_VK_VALIDATION=0 | LEONIDA_VK_VALIDATION=1 | |---|---|---| | d3d12_compute_test (default) | exit 0, "64 buffer reads and 64 null controls matched" | exit 0, same, no VUID output | | d3d12_compute_test, LEONIDA_COMPUTE_DIRECT_HEAPS=0 | exit 0, "128 zero controls matched" | exit 0, same | | d3d12_bundle_test | exit 0, 14 scenarios, 25 host comparisons, 0 failures | exit 0, same | | d3d12_indirect_dispatch_count_test | exit 0 | exit 0 | | d3d12_set_descriptor_heaps_test | exit 0 | exit 0 | Mutation: I changed `record_dispatch` (runtime/shims/d3d12_com.cpp:1415) back to `compute_.data`, so a direct dispatch gets no heap words, rebuilt and ran with validation. d3d12_compute_test exited 1. I restored the file with `git checkout --`, rebuilt, and it passed again. Merge: `git merge-tree` against origin/main 3aa975421 shows no conflicts. With #1009 (ROOT-SIG-SPILL-MODEL, head b477602aa) it has a content conflict in runtime/shims/d3d12_com.cpp, and the change to `RootArgumentLayout` in d3d12_com.h sits next to #1009's own change. Both PRs change `record_dispatch` and the `ExecuteIndirect` dispatch path. It merges cleanly with #974 (head 161314c26). #683 and #990 touch other files. The open-PR searches for "DIRECT-HEAP" and "directly indexed" find only #1064, #683 and the integration branch #984. What the change does - SetDescriptorHeaps already tracked the CBV/SRV/UAV and sampler heap bases on the list (d3d12_com.cpp:1330). The new `compute_user_data()` (d3d12_com.cpp:1396-1410) copies the compute root-argument block for each command and writes the flagged heap bases at `compute_arguments_end`, resource heap first. `compute_arguments_end` is `pack_stage(...).end_sgpr`, set in d3d12_vulkan_device.cpp:6047. A heap that is not bound gives 0. - The heap words are read when the Dispatch or ExecuteIndirect is recorded. So a later SetDescriptorHeaps affects only later commands, and `reset_state` clears the heaps. The test checks both of these on recorded commands: a direct dispatch, then a rebind with only the resource heap, then an ExecuteIndirect dispatch. - Bundles: a Dispatch in a bundle is deferred (d3d12_com.cpp:371) and runs on the parent list at ExecuteBundle. It therefore uses the parent's heaps, which is the D3D12 rule. This works by construction, but no test covers it. - The arena is capped at 4095 MiB (docs/d3d12_vulkan.md:776), so the 32-bit truncation of the heap base is safe. Findings 1. The ABI the code depends on is stated as fact, without a source. The comment at d3d12_com.cpp:1394 says "The compiled compute ABI appends directly indexed heaps after the explicit root arguments", and the doc text at docs/d3d12_vulkan.md:1612-1616 says the same, with the resource heap first. Section 3.4 (D3D-329) measures that the bases are compute user SGPRs and gives `s10`/`s11` as an example. It does not measure that they come right after the last root parameter, or in that order. The PR body cites a run of the integration branch during world loading, but that is not written down where a reader can check it. AGENTS.md asks to quote the source of a claim or call it a hypothesis. Please do one of these: - add a corpus count, e.g. in `tools/heap_index_census.py`, showing that for each heap-indexing CS the resource and sampler base SGPRs equal the end of its root signature's inline layout, and +1 for the sampler; - or call the order a hypothesis in the comment and in the doc, and cite the #984 observation. 2. When the explicit arguments end at s31 or s30, there is no room for the heap words, and the code drops them without a word (d3d12_com.cpp:1405-1408). The doc says "with room", but the runtime logs nothing. A `note_once` there would make this case easy to see in a game log. 3. Log text: note_direct_heap_indexing (d3d12_com.cpp:1344-1358) runs for draws too. With "(SGPR slot open, section 3.4)" removed, a graphics draw now logs "heap base tracked on list", although graphics still gets no heap words. I suggest keeping the "open" text for graphics, or making the message depend on the bind point. The ExecuteIndirect dispatch path (d3d12_com.cpp:860) does not call note_direct_heap_indexing at all, so an indirect dispatch with no heap bound logs nothing. This is minor. 4. Test gaps (not blocking): - nothing reads through the sampler base on the GPU; only the recorded word is checked; - no dispatch with no resource heap bound, which by symmetry should give 0; - no bundle dispatch that inherits the parent's heaps; - the ExecuteIndirect dispatch is checked on recorded arguments only and is never submitted. A bundle case and an "explicit arguments fill s31" case would each take a few lines in the existing block. 5. `LEONIDA_COMPUTE_DIRECT_HEAPS=0` is a rollback switch for a runtime packing change, not a skip list, so I don't read it as breaking fix-don't-disable. The test runs correctly under both settings. 6. The conflict with #1009 needs a decision on order: whichever lands second has to carry `compute_user_data()` into #1009's block-based dispatch. For spilled signatures, #1009 also needs a decision on where the heap words go. It would help to say this in both PRs. 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.
Author
Owner

@⁠Plaaasma on GitHub · 2026-11-24 18:29 UTC · original

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 667dea2ae. Built d3d12_compute_test, then ctest -C Release -R "^d3d12_compute$" --output-on-failure --timeout 300:

  • d3d12_compute: passed, 1.11 s
  • direct-heap case: directly indexed compute heap: 64 buffer reads and 64 null controls matched
  • the rest of the binary (CBV / buffer SRV bounds, root constants + root UAV + table dispatches) also matched

1 passed, 0 failed.

**@⁠Plaaasma** on GitHub · 2026-11-24 18:29 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1064#issuecomment-7140708327) 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 `667dea2ae`. Built `d3d12_compute_test`, then `ctest -C Release -R "^d3d12_compute$" --output-on-failure --timeout 300`: - `d3d12_compute`: **passed**, 1.11 s - direct-heap case: `directly indexed compute heap: 64 buffer reads and 64 null controls matched` - the rest of the binary (CBV / buffer SRV bounds, root constants + root UAV + table dispatches) also matched 1 passed, 0 failed.
Author
Owner

@⁠Luna-OS on GitHub · 2026-11-24 19:04 UTC · original

Independent Windows verification of 90bbf5e60 (merge base 3295055).

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, LEONIDA_VULKAN_HEADERS_FETCH=ON, LEONIDA_SDL3_FETCH=ON. Two full runs per head: without glslang (272 tests), and with glslang (KhronosGroup main-tot) so d3d12_compute, d3d12_draw and d3d12_mesh are built too (298 tests). No game files. AI-assisted (Claude Code).

base this PR
build OK OK
ctest (no glslang) 271/272 271/272
ctest (glslang) 296/298 296/298
changed d3d12_compute (needs glslang; not built without it) Passed Passed
d3d12_com, d3d12_close_parity, vk_command_replay Passed Passed

Failures shared with the merge base 3295055 and not caused by this PR: d3d12_execute_indirect_validation (the five rows of #504), and with glslang d3d12_draw SEGFAULTs on the base too (slot-14 false positive, claimed as D3D-SLOT14-TAIL-NULL-PAGE, PR follows).

**@⁠Luna-OS** on GitHub · 2026-11-24 19:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1064#issuecomment-7141559571) Independent Windows verification of `90bbf5e60` (merge base `3295055`). **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, `LEONIDA_VULKAN_HEADERS_FETCH=ON`, `LEONIDA_SDL3_FETCH=ON`. Two full runs per head: without glslang (272 tests), and with glslang (KhronosGroup `main-tot`) so `d3d12_compute`, `d3d12_draw` and `d3d12_mesh` are built too (298 tests). No game files. AI-assisted (Claude Code). | | base | this PR | |---|---|---| | build | OK | OK | | ctest (no glslang) | 271/272 | 271/272 | | ctest (glslang) | 296/298 | 296/298 | | changed `d3d12_compute` (needs glslang; not built without it) | Passed | **Passed** | | `d3d12_com`, `d3d12_close_parity`, `vk_command_replay` | Passed | Passed | Failures shared with the merge base `3295055` and not caused by this PR: `d3d12_execute_indirect_validation` (the five rows of #504), and with glslang `d3d12_draw` SEGFAULTs on the base too (slot-14 false positive, claimed as D3D-SLOT14-TAIL-NULL-PAGE, PR follows).
Author
Owner

@⁠Moriz82 on GitHub · 2026-11-24 19:13 UTC · original

Thank you for the review, the mutation check and the native Windows runs. The branch is updated; the numbered points follow your findings.

  1. Added tools/compute_heap_layout_census.py and a synthetic test for it. Of 5,450 compute entries, 2,959 advertise direct indexing and none of those embeds RTS0. Matching dispatch records of integration #984 to the pipeline library gave seven comparable resource reads. All seven agree with the end of the explicit layout, zero disagree, and zero lack room. The other 2,952 have no paired signature, and no sampler read was paired. So the code comment and section 3.4 now call the general ordering a hypothesis, cite #984 and give the reproduction command. The description has the table per carve. --per-program prints the resource and the sampler result separately.
  2. The recorder reports an exhausted inline slot once per heap kind and keeps the last explicit word. With one slot left, the resource heap takes it and the sampler shortage is reported.
  3. Direct and indirect compute dispatches share one diagnostic path now. A dispatch reports a missing binding. A graphics draw with a bound heap says that its heap-base SGPR is not supplied.
  4. Added record-time checks for a bundle dispatch that inherits both parent heaps, an indirect dispatch with only the sampler heap bound, and signatures whose explicit arguments end at s30 and at s31. Still open: nothing dereferences the sampler base on the GPU (that needs a shader fixture), and the indirect cases check recorded state only. The test's getenv is replaced by GetEnvironmentVariableA, which removes the C4996 warning you saw.
  5. The rollback switch stays. It restores the previous compute words.
  6. The description now records the order with #1009: whichever lands second carries compute_user_data() into both block-based dispatch paths, and the placement for spilled signatures stays open.

Run on the new head (CachyOS, Proton Experimental, RTX 4070, NVIDIA 620.73.04): d3d12_compute_test exits 0 in both settings (64 buffer reads and 64 null controls by default, 128 zero controls with LEONIDA_COMPUTE_DIRECT_HEAPS=0), d3d12_bundle_test and d3d12_set_descriptor_heaps_test pass, and the three census tests pass. Not run here: the validation layer (not installed on this machine) and native Windows. d3d12_indirect_dispatch_count_test exits 1 under Wine on this machine with builds of unrelated trees too, so I could not use it. If you rerun your four targets on this head, that would cover both gaps.

🤖 Generated with Claude Code

**@⁠Moriz82** on GitHub · 2026-11-24 19:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1064#issuecomment-7141786041) Thank you for the review, the mutation check and the native Windows runs. The branch is updated; the numbered points follow your findings. 1. Added `tools/compute_heap_layout_census.py` and a synthetic test for it. Of 5,450 compute entries, 2,959 advertise direct indexing and none of those embeds RTS0. Matching dispatch records of integration #984 to the pipeline library gave seven comparable resource reads. All seven agree with the end of the explicit layout, zero disagree, and zero lack room. The other 2,952 have no paired signature, and no sampler read was paired. So the code comment and section 3.4 now call the general ordering a hypothesis, cite #984 and give the reproduction command. The description has the table per carve. `--per-program` prints the resource and the sampler result separately. 2. The recorder reports an exhausted inline slot once per heap kind and keeps the last explicit word. With one slot left, the resource heap takes it and the sampler shortage is reported. 3. Direct and indirect compute dispatches share one diagnostic path now. A dispatch reports a missing binding. A graphics draw with a bound heap says that its heap-base SGPR is not supplied. 4. Added record-time checks for a bundle dispatch that inherits both parent heaps, an indirect dispatch with only the sampler heap bound, and signatures whose explicit arguments end at s30 and at s31. Still open: nothing dereferences the sampler base on the GPU (that needs a shader fixture), and the indirect cases check recorded state only. The test's `getenv` is replaced by `GetEnvironmentVariableA`, which removes the C4996 warning you saw. 5. The rollback switch stays. It restores the previous compute words. 6. The description now records the order with #1009: whichever lands second carries `compute_user_data()` into both block-based dispatch paths, and the placement for spilled signatures stays open. Run on the new head (CachyOS, Proton Experimental, RTX 4070, NVIDIA 620.73.04): `d3d12_compute_test` exits 0 in both settings (64 buffer reads and 64 null controls by default, 128 zero controls with `LEONIDA_COMPUTE_DIRECT_HEAPS=0`), `d3d12_bundle_test` and `d3d12_set_descriptor_heaps_test` pass, and the three census tests pass. Not run here: the validation layer (not installed on this machine) and native Windows. `d3d12_indirect_dispatch_count_test` exits 1 under Wine on this machine with builds of unrelated trees too, so I could not use it. If you rerun your four targets on this head, that would cover both gaps. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠iFeyz on GitHub · 2026-11-24 19:51 UTC · original

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 7c47fd946: d3d12_compute built from it passes; tests/test_compute_heap_layout_census.py: OK.

**@⁠iFeyz** on GitHub · 2026-11-24 19:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1064#issuecomment-7142681133) 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 `7c47fd946`: `d3d12_compute` built from it **passes**; `tests/test_compute_heap_layout_census.py`: OK.
Author
Owner

@⁠Moriz82 on GitHub · 2026-11-24 21:01 UTC · original

Rebased onto main 66d4f5aa3: the branch had started to conflict in runtime/shims/d3d12_com.cpp. The one conflict was in record_draw, where main now tests every bound viewport; the resolution keeps main's test and this change's diagnostic call. Nothing else moved (still 8 files, +422/−14).

Run again on the rebased head (CachyOS, Wine 11.22, RTX 4070, NVIDIA 620.73.04): d3d12_compute_test exits 0 in both settings (64 buffer reads and 64 null controls by default, 128 zero controls with LEONIDA_COMPUTE_DIRECT_HEAPS=0), d3d12_bundle_test and d3d12_set_descriptor_heaps_test pass, and the three census tests pass. Not run here: the validation layer and native Windows.

@⁠iFeyz thank you for the AMD run on 7c47fd946; that was the gap in the description. The code is the same after the rebase except for the conflict above.

🤖 Generated with Claude Code

**@⁠Moriz82** on GitHub · 2026-11-24 21:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1064#issuecomment-7144384751) Rebased onto `main` `66d4f5aa3`: the branch had started to conflict in `runtime/shims/d3d12_com.cpp`. The one conflict was in `record_draw`, where `main` now tests every bound viewport; the resolution keeps `main`'s test and this change's diagnostic call. Nothing else moved (still 8 files, +422/−14). Run again on the rebased head (CachyOS, Wine 11.22, RTX 4070, NVIDIA 620.73.04): `d3d12_compute_test` exits 0 in both settings (64 buffer reads and 64 null controls by default, 128 zero controls with `LEONIDA_COMPUTE_DIRECT_HEAPS=0`), `d3d12_bundle_test` and `d3d12_set_descriptor_heaps_test` pass, and the three census tests pass. Not run here: the validation layer and native Windows. @⁠iFeyz thank you for the AMD run on `7c47fd946`; that was the gap in the description. The code is the same after the rebase except for the conflict above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 03:25 UTC · original

Merged, after merging main into it (5115f0887). Thanks, and thanks to everyone who tested it. main already took the core of this from #984, so main's form stays and what this adds is carried onto it:

  • Claim: RT-DIRECT-HEAP-COMPUTE, valid, before this PR.
  • Already in main: with_direct_heaps() and compute_user_data() on Dispatch and the ExecuteIndirect dispatch, compute_arguments_end, LEONIDA_COMPUTE_DIRECT_HEAPS=0 and the same mode in cs_user_data.comp.
  • Carried from this PR:
    • compute_user_data() now makes the missing-heap note, so an ExecuteIndirect dispatch reports it too.
    • A heap with no inline SGPR left is reported once per kind, and a spilled signature (kNoSgpr on main) gets its own note.
    • The bundle, sampler-only, s30/s31 and switch-off checks in d3d12_compute_test.
    • tools/compute_heap_layout_census.py, its test and the evidence paragraph (the resource-then-sampler order is marked as a hypothesis).
  • Dropped: the notes saying a graphics heap-base SGPR "is not supplied" (main supplies it now) and the separate GetEnvironmentVariableA switch (main has direct_heaps_enabled).
  • Windows suite under Wine (llvmpipe and an RDNA2 iGPU): nothing changes against main; the narrow tests pass.
  • Next: #1232 builds on this and is merged right after it.
  • Checked on main 0bc810504 + 5115f0887: it merges cleanly; the semantic suite passes (487 files, 6,279 tests, 0 files failed); the 14 docs and writer tests pass; check_no_game_data.py is clean on the 5 changed files.

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

**@⁠aslan2142** on GitHub · 2026-11-25 03:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1064#issuecomment-7151904570) Merged, after merging `main` into it (`5115f0887`). Thanks, and thanks to everyone who tested it. `main` already took the core of this from #984, so `main`'s form stays and what this adds is carried onto it: - **Claim:** `RT-DIRECT-HEAP-COMPUTE`, valid, before this PR. - **Already in `main`:** `with_direct_heaps()` and `compute_user_data()` on `Dispatch` and the `ExecuteIndirect` dispatch, `compute_arguments_end`, `LEONIDA_COMPUTE_DIRECT_HEAPS=0` and the same mode in `cs_user_data.comp`. - **Carried from this PR:** - `compute_user_data()` now makes the missing-heap note, so an `ExecuteIndirect` dispatch reports it too. - A heap with no inline SGPR left is reported once per kind, and a spilled signature (`kNoSgpr` on `main`) gets its own note. - The bundle, sampler-only, s30/s31 and switch-off checks in `d3d12_compute_test`. - `tools/compute_heap_layout_census.py`, its test and the evidence paragraph (the resource-then-sampler order is marked as a hypothesis). - **Dropped:** the notes saying a graphics heap-base SGPR "is not supplied" (`main` supplies it now) and the separate `GetEnvironmentVariableA` switch (`main` has `direct_heaps_enabled`). - **Windows suite under Wine (llvmpipe and an RDNA2 iGPU):** nothing changes against `main`; the narrow tests pass. - **Next:** #1232 builds on this and is merged right after it. - **Checked on `main` `0bc810504` + `5115f0887`:** it merges cleanly; the semantic suite passes (487 files, 6,279 tests, 0 files failed); the 14 docs and writer tests pass; `check_no_game_data.py` is clean on the 5 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.