[PR #1064] [MERGED] d3d12: supply directly indexed heaps to compute dispatches (RT-DIRECT-HEAP-COMPUTE) #1101

Closed
opened 2026-11-26 20:20:05 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1064
Author: @Moriz82
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: split/rt-direct-heap-compute


📝 Commits (2)

  • c8f7515 d3d12: supply directly indexed heaps to compute dispatches (RT-DIRECT-HEAP-COMPUTE)
  • 5115f08 Merge main into RT-DIRECT-HEAP-COMPUTE (#1064)

📊 Changes

5 files changed (+306 additions, -9 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+12 -1)
📝 runtime/shims/d3d12_com.cpp (+17 -2)
📝 runtime/test/d3d12_compute_test.cpp (+45 -6)
➕ tests/test_compute_heap_layout_census.py (+64 -0)
➕ tools/compute_heap_layout_census.py (+168 -0)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1064 **Author:** [@Moriz82](https://github.com/Moriz82) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `split/rt-direct-heap-compute` --- ### 📝 Commits (2) - [`c8f7515`](https://github.com/ubiquitarianism/leonida/commit/c8f7515e2e6fb2a2a61eb1e986ee8c6fd4431399) d3d12: supply directly indexed heaps to compute dispatches (RT-DIRECT-HEAP-COMPUTE) - [`5115f08`](https://github.com/ubiquitarianism/leonida/commit/5115f0887940595aa0f46fed7fc9db28b64151ff) Merge main into RT-DIRECT-HEAP-COMPUTE (#1064) ### 📊 Changes **5 files changed** (+306 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+12 -1) 📝 `runtime/shims/d3d12_com.cpp` (+17 -2) 📝 `runtime/test/d3d12_compute_test.cpp` (+45 -6) ➕ `tests/test_compute_heap_layout_census.py` (+64 -0) ➕ `tools/compute_heap_layout_census.py` (+168 -0) </details> ### 📄 Description Claimed in the coordination issue as: RT-DIRECT-HEAP-COMPUTE ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7139398473)). 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:20:05 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1101
No description provided.