d3d12: graphics draws supply the directly indexed heaps after their root arguments (RT-DIRECT-HEAP-GRAPHICS) #1232

Manually merged
github merged 6 commits from gh-pr/1232/head into gh-pr/1232/base 2026-11-26 09:43:51 +00:00
Owner

@⁠iFeyz on GitHub · 2026-11-24 20:39 UTC · original
iFeyz:feat/direct-heap-graphics → main · +401 −18 · 6 files · 6 commits · merged 2026-11-25 03:26 UTC

Claimed in the coordination issue as: RT-DIRECT-HEAP-GRAPHICS (#14)

Depends on: #974 (graphics root arguments in the console layout), #1064 (RT-DIRECT-HEAP-COMPUTE). This branch is #974 with #1064 merged in; its last commit is this pull request.

What and why

With CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED / SAMPLER_HEAP_DIRECTLY_INDEXED, a console program finds the descriptor heaps in the dwords right after its root arguments. @⁠DadaCap measured on the retail library that this holds for every stage: from s4 in compute, s8 in VS/PS/GS and s16 in mesh shaders, the resource heap's address in the first dword after the root arguments and the sampler heap's in the next (issue #14, comment 7143020922, item 4). #1064 supplies them for compute. A graphics draw with a bound heap only got a note that its heap-base SGPR was not supplied, so a directly indexed VS/PS/MS read a zero heap base.

  • runtime/shims/d3d12_com.cpp: graphics_user_data(), the graphics side of #1064's compute_user_data(). Each DrawInstanced, DrawIndexedInstanced and DispatchMesh records the bound heaps' 32-bit addresses at graphics_arguments_end and the next dword.
    • An unbound heap contributes zero, and rebinding affects later draws.
    • A heap past s31 is reported once.
    • A mesh shader reads the same push dwords through #974's window, so the mesh case needs nothing of its own.
    • LEONIDA_GRAPHICS_DIRECT_HEAPS=0 restores the previous arguments.
  • runtime/shims/d3d12_vulkan_device.cpp / d3d12_com.h: RootArgumentLayout::graphics_arguments_end (from pack_stage's end_sgpr). It is not set for a signature with parameters in the argument block, or under LEONIDA_GRAPHICS_ROOT_LAYOUT=pc, because no slot is measured there; nothing is written then, with one note.
  • Docs: docs/d3d12_vulkan.md section 3.4, next to #1064's compute paragraph.

Tested

  • d3d12_mesh_test (RX 9070 XT), through rt::d3d12::recorded_commands:
    • 4 root constants: a vertex draw and a mesh draw record the constants at s8..s11, the resource heap at s12 and the sampler heap at s13, and the mesh draw's dwords are the vertex draw's.
    • Rebinding only the resource heap: the sampler dword goes to 0.
    • 23 constants: the resource heap takes s31 and the sampler heap has no room (noted).
    • 30 constants (spilled): nothing is written.
  • d3d12_compute_test (#1064's checks) and root_signature_test pass on the merge.
  • Runtime (Windows 11, MSVC 2022 Build Tools, RelWithDebInfo, full build): ctest 303 of 307 pass. The 4 failures are the same as on main here (d3d12_clear, d3d12_execute_indirect_validation, d3d12_texture_tiles, d3d12_pipeline_library_host, reported in #14).
  • tests/test_docs_env_vars.py, tests/test_docs_links.py, scripts/check_no_game_data.py on every changed file.

Not run here: the retail title. On main's own address path (no boot-prototype arena), a directly indexed draw now gets the same heap addresses a compute dispatch gets under #1064.

GPUs tested: AMD Radeon RX 9070 XT, AMD Adrenalin 26.11.2 (Vulkan 1.4.359), Windows 11

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • 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.
**@⁠iFeyz** on GitHub · 2026-11-24 20:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1232) `iFeyz:feat/direct-heap-graphics` → `main` · +401 −18 · 6 files · 6 commits · merged 2026-11-25 03:26 UTC Claimed in the coordination issue as: RT-DIRECT-HEAP-GRAPHICS (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) Depends on: #974 (graphics root arguments in the console layout), #1064 (RT-DIRECT-HEAP-COMPUTE). This branch is #974 with #1064 merged in; its last commit is this pull request. ### What and why With `CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED` / `SAMPLER_HEAP_DIRECTLY_INDEXED`, a console program finds the descriptor heaps in the dwords right after its root arguments. @⁠DadaCap measured on the retail library that this holds for every stage: from s4 in compute, s8 in VS/PS/GS and s16 in mesh shaders, the resource heap's address in the first dword after the root arguments and the sampler heap's in the next (issue #14, comment 7143020922, item 4). #1064 supplies them for compute. A graphics draw with a bound heap only got a note that its heap-base SGPR was not supplied, so a directly indexed VS/PS/MS read a zero heap base. - **`runtime/shims/d3d12_com.cpp`**: `graphics_user_data()`, the graphics side of #1064's `compute_user_data()`. Each `DrawInstanced`, `DrawIndexedInstanced` and `DispatchMesh` records the bound heaps' 32-bit addresses at `graphics_arguments_end` and the next dword. - An unbound heap contributes zero, and rebinding affects later draws. - A heap past s31 is reported once. - A mesh shader reads the same push dwords through #974's window, so the mesh case needs nothing of its own. - `LEONIDA_GRAPHICS_DIRECT_HEAPS=0` restores the previous arguments. - **`runtime/shims/d3d12_vulkan_device.cpp` / `d3d12_com.h`**: `RootArgumentLayout::graphics_arguments_end` (from `pack_stage`'s `end_sgpr`). It is not set for a signature with parameters in the argument block, or under `LEONIDA_GRAPHICS_ROOT_LAYOUT=pc`, because no slot is measured there; nothing is written then, with one note. - **Docs**: `docs/d3d12_vulkan.md` section 3.4, next to #1064's compute paragraph. ### Tested - `d3d12_mesh_test` (RX 9070 XT), through `rt::d3d12::recorded_commands`: - **4 root constants:** a vertex draw and a mesh draw record the constants at s8..s11, the resource heap at s12 and the sampler heap at s13, and the mesh draw's dwords are the vertex draw's. - **Rebinding only the resource heap:** the sampler dword goes to 0. - **23 constants:** the resource heap takes s31 and the sampler heap has no room (noted). - **30 constants (spilled):** nothing is written. - `d3d12_compute_test` (#1064's checks) and `root_signature_test` pass on the merge. - Runtime (Windows 11, MSVC 2022 Build Tools, RelWithDebInfo, full build): `ctest` 303 of 307 pass. The 4 failures are the same as on `main` here (`d3d12_clear`, `d3d12_execute_indirect_validation`, `d3d12_texture_tiles`, `d3d12_pipeline_library_host`, reported in #14). - `tests/test_docs_env_vars.py`, `tests/test_docs_links.py`, `scripts/check_no_game_data.py` on every changed file. Not run here: the retail title. On `main`'s own address path (no `boot-prototype` arena), a directly indexed draw now gets the same heap addresses a compute dispatch gets under #1064. GPUs tested: AMD Radeon RX 9070 XT, AMD Adrenalin 26.11.2 (Vulkan 1.4.359), Windows 11 AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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.
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]>
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.
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]>
This merges #1064 as prepared (its head + a merge of main), so it brings #1232 up to date with main and
with #1064. #1232's branch carried #974 (merged into main since) and an older head of #1064 (7c47fd946).

main already supplies the directly indexed heaps to graphics draws (integration #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 #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 #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 #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 #974).
- runtime/test/glsl/cs_user_data.comp: main's (identical direct-indexing mode).
- docs/d3d12_vulkan.md: main's section 3.4 with #1064's compute paragraph; the graphics paragraph's
  "a mesh shader ... is not modelled" replaced by the mesh window position, cited to issue #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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:43:50 +00:00
github manually merged commit 3ee0037fd3 into gh-pr/1232/base 2026-11-26 09:43:51 +00:00
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-24 21:30 UTC · original

Checked 9b8707c merged into current main (6293c1c). Cross-built with clang-cl 19 + xwin (MSVC CRT / SDK 10.0.26100) and run under Wine 11.22 on llvmpipe (Mesa 25.2.8), so no hardware driver.

Conflict with main: runtime/shims/d3d12_com.cpp conflicts with the multi-viewport change (#510) in DispatchMesh and record_draw. The resolution that built for me keeps main's any_nonempty_viewport() and draw.viewports, keeps this PR's mesh_ok check and graphics_user_data(), and drops main's separate note_direct_heap_indexing(graphics_.layout) in record_draw, since graphics_user_data() now makes that call (with the two-argument signature from #1064).

Tests on that merge: d3d12_mesh, d3d12_compute and root_signature pass. The new checks did run on llvmpipe: direct heaps on graphics draws: resource heap at s12, sampler heap at s13, plus the s31 note ("no inline SGPR for the sampler heap") and the spilled-signature note.

One question on mesh draws: a mesh shader reads push dword i as s(i+8), and mesh_ok accepts a signature that fills its 16-dword window, which means graphics root arguments ending at push dword 24. Then the heap dwords go to push dwords 24 and 25, which a mesh shader would read as s32/s33, past its last user SGPR. The range check in graphics_user_data() is slot < data.size() (the VS/PS numbering), so for that mesh draw both addresses are written but unreadable, with no note. The resource heap is visible to a mesh shader only up to graphics_arguments_end <= 23, and the sampler heap up to <= 22. If the retail library never has such a mesh signature this is moot, but a note in DispatchMesh when graphics_arguments_end + 8 (+1 with both flags) passes s31 would say so the same way the VS/PS case does.

AI-assisted (Claude).

**@⁠tiguan26** on GitHub · 2026-11-24 21:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1232#issuecomment-7145021028) Checked 9b8707c merged into current `main` (6293c1c). Cross-built with clang-cl 19 + xwin (MSVC CRT / SDK 10.0.26100) and run under Wine 11.22 on llvmpipe (Mesa 25.2.8), so no hardware driver. **Conflict with main:** `runtime/shims/d3d12_com.cpp` conflicts with the multi-viewport change (#510) in `DispatchMesh` and `record_draw`. The resolution that built for me keeps main's `any_nonempty_viewport()` and `draw.viewports`, keeps this PR's `mesh_ok` check and `graphics_user_data()`, and drops main's separate `note_direct_heap_indexing(graphics_.layout)` in `record_draw`, since `graphics_user_data()` now makes that call (with the two-argument signature from #1064). **Tests on that merge:** `d3d12_mesh`, `d3d12_compute` and `root_signature` pass. The new checks did run on llvmpipe: `direct heaps on graphics draws: resource heap at s12, sampler heap at s13`, plus the s31 note ("no inline SGPR for the sampler heap") and the spilled-signature note. **One question on mesh draws:** a mesh shader reads push dword *i* as s(*i*+8), and `mesh_ok` accepts a signature that fills its 16-dword window, which means graphics root arguments ending at push dword 24. Then the heap dwords go to push dwords 24 and 25, which a mesh shader would read as s32/s33, past its last user SGPR. The range check in `graphics_user_data()` is `slot < data.size()` (the VS/PS numbering), so for that mesh draw both addresses are written but unreadable, with no note. The resource heap is visible to a mesh shader only up to `graphics_arguments_end <= 23`, and the sampler heap up to `<= 22`. If the retail library never has such a mesh signature this is moot, but a note in `DispatchMesh` when `graphics_arguments_end + 8` (+1 with both flags) passes s31 would say so the same way the VS/PS case does. AI-assisted (Claude).
Author
Owner

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

Merged, after merging main and #1064 into it (3ee0037fd). Thanks. main already supplies the graphics heaps (#984's graphics_user_data() and d3d12_graphics_direct_heaps_test), so main's form stays and what this adds is the mesh case:

  • Claim: RT-DIRECT-HEAP-GRAPHICS, valid, before this PR.
  • Dropped as duplicates of main: this PR's own graphics_user_data() and its Spill::block-based end (main keeps the s0 fallback, see #974).
  • Kept from this PR:
    • the d3d12_mesh_test checks (a vertex and a mesh draw record the same dwords, a resource-only rebind, 23 and 30 constants);
    • the mesh text. The comment and docs/d3d12_vulkan.md section 3.4 no longer say the mesh stage gets nothing: through #974's window a mesh shader reads the heaps at s(16 + end − 8). This cites issue #14 comment 7143020922 as a report not yet reproduced here.
  • Added before merging, answering the open review point: DispatchMesh logs once when a heap falls past the mesh window (push dword 24 or above), where a mesh shader would read it as s32 or higher.
  • Mutation check: with DispatchMesh recording no heap dwords, d3d12_mesh fails on llvmpipe, so the test guards the path.
  • Windows suite under Wine (llvmpipe and an RDNA2 iGPU): nothing changes against main. The translator suite passes.
  • Checked on main 98efc22ca + 3ee0037fd: 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 3 changed files.

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

**@⁠aslan2142** on GitHub · 2026-11-25 03:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1232#issuecomment-7151924113) Merged, after merging `main` and #1064 into it (`3ee0037fd`). Thanks. `main` already supplies the graphics heaps (#984's `graphics_user_data()` and `d3d12_graphics_direct_heaps_test`), so `main`'s form stays and what this adds is the mesh case: - **Claim:** `RT-DIRECT-HEAP-GRAPHICS`, valid, before this PR. - **Dropped as duplicates of `main`:** this PR's own `graphics_user_data()` and its `Spill::block`-based end (`main` keeps the s0 fallback, see #974). - **Kept from this PR:** - the `d3d12_mesh_test` checks (a vertex and a mesh draw record the same dwords, a resource-only rebind, 23 and 30 constants); - the mesh text. The comment and `docs/d3d12_vulkan.md` section 3.4 no longer say the mesh stage gets nothing: through #974's window a mesh shader reads the heaps at s(16 + end − 8). This cites issue #14 comment 7143020922 as a report not yet reproduced here. - **Added before merging, answering the open review point:** `DispatchMesh` logs once when a heap falls past the mesh window (push dword 24 or above), where a mesh shader would read it as s32 or higher. - **Mutation check:** with `DispatchMesh` recording no heap dwords, `d3d12_mesh` fails on llvmpipe, so the test guards the path. - **Windows suite under Wine (llvmpipe and an RDNA2 iGPU):** nothing changes against `main`. The translator suite passes. - **Checked on `main` `98efc22ca` + `3ee0037fd`:** 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 3 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.