[PR #1937] d3d12: replay a compound signature's vertex/index buffer views and root arguments (D3D-INDIRECT-STATE-REPLAY) #1945

Open
opened 2026-11-26 21:19:29 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1937
Author: @fiestorra
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: carry/indirect-state-replay


📝 Commits (3)

  • cdeac21 d3d12: replay a compound signature's per-record state (D3D-INDIRECT-STATE-REPLAY)
  • d653c7b docs: say when the compound signature's argument bytes are read
  • 3d1dadb docs: the recorded-count rule covers the count buffer, and a compound signature is guarded only when its bytes are not mappable

📊 Changes

5 files changed (+411 additions, -15 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+20 -4)
📝 runtime/CMakeLists.txt (+4 -1)
📝 runtime/shims/d3d12_com.cpp (+130 -3)
📝 runtime/test/d3d12_draw_test.cpp (+10 -0)
📝 runtime/test/d3d12_stateful_indirect_pixels.cpp (+247 -7)

📄 Description

Claimed in the coordination issue as: D3D-INDIRECT-STATE-REPLAY

Depends on: #1737 — not for code, but for the same rules from the other end: that pull request refuses multi-argument signatures in CreateCommandSignature, which is exactly the shape this one replays. Whichever lands second has to take the other's part. If #1737 lands first it must keep the vertex/index-buffer shapes creatable (its own description says so) and it also has to update runtime/test/d3d12_stateful_indirect_pixels.cpp, which creates a two-argument and a five-argument signature and checks that both are created. Textually both edit the ExecuteIndirect paragraph of docs/d3d12_vulkan.md section 4.7. It also shares runtime/shims/d3d12_com.cpp with #1896, in different hunks.

What and why

The finding: of 2026-11-25T12:04:43Z (BubsMcgee): a compound graphics command signature — VERTEX_BUFFER_VIEW, INDEX_BUFFER_VIEW or root arguments before its DRAW/DRAW_INDEXED — bound nothing. ExecuteIndirect reset the bindings the signature writes and recorded no draw at all, so a signature that carries state arguments never drew, and a record's own vertex and index buffer views, root constants and root CBV/SRV/UAVs were lost.

A driver applies those per record on the GPU. Vulkan has no indirect call that rebinds state, and the replay's Draw carries one state snapshot per command, so the layer expands the record list in the command list instead — the expansion that section 4.7 of docs/d3d12_vulkan.md already names for state arguments:

  • runtime/shims/d3d12_com.cpp: expand_compound_indirect(). For each record, in the signature's argument order, it applies both vertex buffer views, the index buffer view, the root constants (and tier 1.1's incrementing constant, which occupies no record bytes) and the root CBV/SRV/UAV addresses, then records the record's DRAW or DRAW_INDEXED as an ordinary draw. Every argument shape is checked before the first record is recorded, so a shape this code cannot decode leaves the list as it was instead of expanding half of it. The bindings the signature writes are still reset after the call: that is D3D12's state-leakage rule, and this pull request keeps it, records or not.
  • The boundary: the expansion needs the bytes on the CPU, so it covers a compound signature whose argument and count buffers are host-visible (upload or readback) — the buffers an application fills on the CPU, which is the case the tests cover. A device-local argument buffer, which the GPU may have written, keeps today's reset-only path and draws nothing; Vulkan offers no GPU-side expansion.
  • runtime/test/d3d12_stateful_indirect_pixels.cpp: a new compound pixel fixture, and the existing record-only compound scenario now checks the replay record by record instead of the reset alone.
  • runtime/test/d3d12_draw_test.cpp, runtime/CMakeLists.txt: the d3d12_compound_indirect_pixels mode and its ctest entry.
  • docs/d3d12_vulkan.md section 4.7 and the test list say what is replayed and what is not.

Tested

Built with VS 2022 Build Tools (MSVC 14.44), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, RelWithDebInfo, on current main b0f3d3998. No game files.

d3d12_compound_indirect_pixels (new): one compound signature, two records, each carrying two vertex buffer views, the index buffer view, two root constants and a root CBV. The list binds a different vertex buffer, a different index buffer and different root arguments before the call. The test renders the record list through ExecuteIndirect, the same calls made by hand, and the pre-bound state alone, into three offscreen targets, then compares every pixel:

  • With this change: 1536 lit pixels, 0/4096 RGBA pixel mismatches against the hand-made calls; the pre-bound state lights 1024, and its image differs.
  • Negative control — only the runtime/shims/d3d12_com.cpp hunk reverted, test kept: the indirect list lights 0 pixels and 1536/4096 pixels differ, i.e. it draws nothing, which is main's behaviour.
  • LEONIDA_VK_VALIDATION=1: the same numbers, 0 validation errors.

d3d12_stateful_indirect_pixels: the record-only compound scenario now asserts the two expanded draws carry slot 5's vertex buffer view and the index buffer view from the argument buffer and the record's root constant (recorded.size() is 4, was 2), and a fourth scenario pins the boundary — the same records in a device-local buffer are not expanded, draw nothing and only reset. The state-leakage postcondition is unchanged.

  • ctest -R "^(d3d12_draw|d3d12_stateful_indirect|d3d12_compound_indirect|xbox_geometry_upload_batch)": 9 of 9 pass. With the shim hunk reverted, 3 of those 9 fail: d3d12_stateful_indirect_pixels, d3d12_stateful_indirect_nonindexed_pixels and d3d12_compound_indirect_pixels.
  • The 15 adjacent tests of the same module also pass: d3d12_state_map, d3d12_execute_indirect_validation, d3d12_indirect_zero, d3d12_indirect_rt, d3d12_indirect_rt_upload_sysmem, d3d12_bundle, d3d12_bundle_indirect_warp, d3d12_bundle_indirect_layer, d3d12_bundle_indirect_off, d3d12_bundle_forbidden and the four d3d12_indirect_policy modes. The whole runtime suite was not run on this machine.

What the measurement does not prove: that a GPU-written (device-local) record list replays — it does not, and the fourth scenario pins that. It also says nothing about frames: no title uses a compound signature today (section 4.9 lists its five startup signatures, one argument each), so this path was measured only by the synthetic test, not in a frame.

GPUs tested: AMD Radeon(TM) Graphics (gfx1036 iGPU), driver 32.0.21045.29003, Windows 11 Pro build 26300

AI-assisted: yes (DeepSeek Harness)

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. (n/a: D3D12 layer, no translator change)

Written with an AI assistant.


🔄 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/1937 **Author:** [@fiestorra](https://github.com/fiestorra) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `carry/indirect-state-replay` --- ### 📝 Commits (3) - [`cdeac21`](https://github.com/ubiquitarianism/leonida/commit/cdeac210e2acfb0ff5cb50130783b6d5c4eda66e) d3d12: replay a compound signature's per-record state (D3D-INDIRECT-STATE-REPLAY) - [`d653c7b`](https://github.com/ubiquitarianism/leonida/commit/d653c7b999dc6b892f0136ca150904bc37e3732e) docs: say when the compound signature's argument bytes are read - [`3d1dadb`](https://github.com/ubiquitarianism/leonida/commit/3d1dadbd33ed534a0161466f2277f027e5218753) docs: the recorded-count rule covers the count buffer, and a compound signature is guarded only when its bytes are not mappable ### 📊 Changes **5 files changed** (+411 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+20 -4) 📝 `runtime/CMakeLists.txt` (+4 -1) 📝 `runtime/shims/d3d12_com.cpp` (+130 -3) 📝 `runtime/test/d3d12_draw_test.cpp` (+10 -0) 📝 `runtime/test/d3d12_stateful_indirect_pixels.cpp` (+247 -7) </details> ### 📄 Description Claimed in the coordination issue as: [D3D-INDIRECT-STATE-REPLAY](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7167234491) Depends on: #1737 — not for code, but for the same rules from the other end: that pull request refuses multi-argument signatures in `CreateCommandSignature`, which is exactly the shape this one replays. Whichever lands second has to take the other's part. If #1737 lands first it must keep the vertex/index-buffer shapes creatable (its own description says so) and it also has to update `runtime/test/d3d12_stateful_indirect_pixels.cpp`, which creates a two-argument and a five-argument signature and checks that both are created. Textually both edit the `ExecuteIndirect` paragraph of `docs/d3d12_vulkan.md` section 4.7. It also shares `runtime/shims/d3d12_com.cpp` with #1896, in different hunks. ### What and why The `finding:` of 2026-11-25T12:04:43Z (BubsMcgee): a compound graphics command signature — `VERTEX_BUFFER_VIEW`, `INDEX_BUFFER_VIEW` or root arguments before its `DRAW`/`DRAW_INDEXED` — bound nothing. `ExecuteIndirect` reset the bindings the signature writes and recorded no draw at all, so a signature that carries state arguments never drew, and a record's own vertex and index buffer views, root constants and root CBV/SRV/UAVs were lost. A driver applies those per record on the GPU. Vulkan has no indirect call that rebinds state, and the replay's `Draw` carries one state snapshot per command, so the layer expands the record list in the command list instead — the expansion that section 4.7 of `docs/d3d12_vulkan.md` already names for state arguments: - `runtime/shims/d3d12_com.cpp`: `expand_compound_indirect()`. For each record, in the signature's argument order, it applies both vertex buffer views, the index buffer view, the root constants (and tier 1.1's incrementing constant, which occupies no record bytes) and the root CBV/SRV/UAV addresses, then records the record's `DRAW` or `DRAW_INDEXED` as an ordinary draw. Every argument shape is checked before the first record is recorded, so a shape this code cannot decode leaves the list as it was instead of expanding half of it. The bindings the signature writes are still reset after the call: that is D3D12's [state-leakage rule](https://microsoft.github.io/DirectX-Specs/d3d/IndirectDrawing.html#state-leakage), and this pull request keeps it, records or not. - The boundary: the expansion needs the bytes on the CPU, so it covers a compound signature whose argument and count buffers are host-visible (upload or readback) — the buffers an application fills on the CPU, which is the case the tests cover. A device-local argument buffer, which the GPU may have written, keeps today's reset-only path and draws nothing; Vulkan offers no GPU-side expansion. - `runtime/test/d3d12_stateful_indirect_pixels.cpp`: a new compound pixel fixture, and the existing record-only compound scenario now checks the replay record by record instead of the reset alone. - `runtime/test/d3d12_draw_test.cpp`, `runtime/CMakeLists.txt`: the `d3d12_compound_indirect_pixels` mode and its ctest entry. - `docs/d3d12_vulkan.md` section 4.7 and the test list say what is replayed and what is not. ### Tested Built with VS 2022 Build Tools (MSVC 14.44), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, RelWithDebInfo, on current `main` `b0f3d3998`. No game files. `d3d12_compound_indirect_pixels` (new): one compound signature, two records, each carrying two vertex buffer views, the index buffer view, two root constants and a root CBV. The list binds a different vertex buffer, a different index buffer and different root arguments before the call. The test renders the record list through `ExecuteIndirect`, the same calls made by hand, and the pre-bound state alone, into three offscreen targets, then compares every pixel: - With this change: 1536 lit pixels, **0/4096 RGBA pixel mismatches** against the hand-made calls; the pre-bound state lights 1024, and its image differs. - Negative control — only the `runtime/shims/d3d12_com.cpp` hunk reverted, test kept: the indirect list lights **0** pixels and 1536/4096 pixels differ, i.e. it draws nothing, which is `main`'s behaviour. - `LEONIDA_VK_VALIDATION=1`: the same numbers, 0 validation errors. `d3d12_stateful_indirect_pixels`: the record-only compound scenario now asserts the two expanded draws carry slot 5's vertex buffer view and the index buffer view from the argument buffer and the record's root constant (`recorded.size()` is 4, was 2), and a fourth scenario pins the boundary — the same records in a device-local buffer are not expanded, draw nothing and only reset. The state-leakage postcondition is unchanged. - `ctest -R "^(d3d12_draw|d3d12_stateful_indirect|d3d12_compound_indirect|xbox_geometry_upload_batch)"`: 9 of 9 pass. With the shim hunk reverted, 3 of those 9 fail: `d3d12_stateful_indirect_pixels`, `d3d12_stateful_indirect_nonindexed_pixels` and `d3d12_compound_indirect_pixels`. - The 15 adjacent tests of the same module also pass: `d3d12_state_map`, `d3d12_execute_indirect_validation`, `d3d12_indirect_zero`, `d3d12_indirect_rt`, `d3d12_indirect_rt_upload_sysmem`, `d3d12_bundle`, `d3d12_bundle_indirect_warp`, `d3d12_bundle_indirect_layer`, `d3d12_bundle_indirect_off`, `d3d12_bundle_forbidden` and the four `d3d12_indirect_policy` modes. The whole runtime suite was not run on this machine. What the measurement does not prove: that a GPU-written (device-local) record list replays — it does not, and the fourth scenario pins that. It also says nothing about frames: no title uses a compound signature today (section 4.9 lists its five startup signatures, one argument each), so this path was measured only by the synthetic test, not in a frame. GPUs tested: AMD Radeon(TM) Graphics (gfx1036 iGPU), driver 32.0.21045.29003, Windows 11 Pro build 26300 AI-assisted: yes (DeepSeek Harness) ### 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. (n/a: D3D12 layer, no translator change) Written with an AI assistant. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#1945
No description provided.