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

Merged
iFeyz merged 6 commits from upstream-pr/1232 into main 2026-11-25 03:26:54 +00:00
iFeyz commented 2026-11-24 20:39:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by iFeyz on 2026-11-24T20:39:04Z.


Claimed in the coordination issue as: RT-DIRECT-HEAP-GRAPHICS (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7143274207)

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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5479950623 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1232). Originally posted by [iFeyz](https://github.com/iFeyz) on 2026-11-24T20:39:04Z. --- Claimed in the coordination issue as: RT-DIRECT-HEAP-GRAPHICS (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7143274207) 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.
tiguan26 commented 2026-11-24 21:30:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-24T21:30:28Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7145021028 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1232#issuecomment-7145021028). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-24T21:30:28Z. --- 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).
aslan2142 commented 2026-11-25 03:26:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-25T03:26:57Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7151924113 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1232#issuecomment-7151924113). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-25T03:26:57Z. --- 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).
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1232
No description provided.