d3d12: order ExecuteIndirect argument reads after earlier writes #298

Merged
NickStallman merged 2 commits from upstream-pr/298 into main 2026-11-27 08:25:30 +00:00
NickStallman commented 2026-11-27 04:11:45 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-27T04:11:45Z.


Refs #232. ExecuteIndirect can read its argument or count buffer before an earlier write to it in the same batch has landed, when the title separates the two with anything other than an exact INDIRECT_ARGUMENT transition. There are two separate mechanisms.

Measured with a new Lanes scenario, gpu-indirect-order: 48 rounds in one list and one submission, each rewriting the same argument buffer (and count buffer) with a compute dispatch, then reading it with ExecuteIndirect, with no CPU wait in between.

Barrier between write and read RTX 5090 (620.70.10) AMD Raphael iGPU (RADV 26.0.8)
exact INDIRECT_ARGUMENT transition, with or without a count buffer 0/48 wrong 0/48 wrong
combined state (INDIRECT_ARGUMENT | NON_PIXEL_SHADER_RESOURCE), no count buffer 0/48 0/48
combined state + count buffer 48/48, all pre-batch values 48/48
UAV barrier only, no count buffer 48/48 (10 pre-batch, 38 previous round) 0/48
UAV barrier + count buffer 48/48, all pre-batch values 48/48
  • With a count buffer, vkd3d-proton prepares the arguments in a pass it submits ahead of the list. Only a barrier that names indirect arguments keeps that pass after the write, so the call reads values from before the batch on both vendors.
  • Without a count buffer, the NVIDIA driver also races a plain UAV barrier.

Change (commands/indirect_order.rs): each native list tracks, since its last buffer write, whether it has seen a barrier whose after-state includes INDIRECT_ARGUMENT (synced), and one vkd3d-proton honours for its argument pass (named).

  • execute_indirect records one global barrier (ALL/COMMON → EXECUTE_INDIRECT/INDIRECT_ARGUMENT) only when the call lacks what it needs. A counted dispatch needs both; anything else needs synced.
  • The flags clear at every dispatch, copy or other buffer write, and a fresh native list starts unordered.
  • A title that already transitions to exact INDIRECT_ARGUMENT gets no extra barrier.
  • Indirect draws are covered as readers. A draw doesn't clear the flags, so a barrier doesn't end the render pass before every indirect draw.

Not a fix for #232's hang: in ProjectScarlett, an ALL/COMMON barrier before every compute ExecuteIndirect didn't move the Xid 109. This is a correctness fix for stale indirect arguments.

Tests: gpu-indirect-order is in all and the verify suite. It fails on main as shown above and passes with this change on both cards. The unit tests in src/tests/commands/indirect_order.rs are typechecked only, since the crate targets Windows.

Checks (on 5444f38)

  • python -m unittest discover -s tests -q: OK.
  • AMD Raphael iGPU (1002:13c0), RADV (Mesa 26.0.8), GE-Proton11-14: the full python tuxbox.py check passed, 134 gates, including lanes-selftest-gpu-indirect-order.
  • RTX 5090 (10de:2b85), driver 620.70.10, GE-Proton11-14: the same full check passed, 134 gates.

Not covered: bundles and lists without enhanced barriers (logged once, unchanged), and vkd3d-proton's predication fallback.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5521062950 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/298). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-27T04:11:45Z. --- Refs #232. `ExecuteIndirect` can read its argument or count buffer before an earlier write to it in the same batch has landed, when the title separates the two with anything other than an exact `INDIRECT_ARGUMENT` transition. There are two separate mechanisms. **Measured** with a new Lanes scenario, `gpu-indirect-order`: 48 rounds in one list and one submission, each rewriting the same argument buffer (and count buffer) with a compute dispatch, then reading it with `ExecuteIndirect`, with no CPU wait in between. | Barrier between write and read | RTX 5090 (620.70.10) | AMD Raphael iGPU (RADV 26.0.8) | |---|---:|---:| | exact `INDIRECT_ARGUMENT` transition, with or without a count buffer | 0/48 wrong | 0/48 wrong | | combined state (`INDIRECT_ARGUMENT \| NON_PIXEL_SHADER_RESOURCE`), no count buffer | 0/48 | 0/48 | | **combined state + count buffer** | **48/48**, all pre-batch values | **48/48** | | **UAV barrier only, no count buffer** | **48/48** (10 pre-batch, 38 previous round) | 0/48 | | **UAV barrier + count buffer** | **48/48**, all pre-batch values | **48/48** | - **With a count buffer,** vkd3d-proton prepares the arguments in a pass it submits ahead of the list. Only a barrier that names indirect arguments keeps that pass after the write, so the call reads values from before the batch on both vendors. - **Without a count buffer,** the NVIDIA driver also races a plain UAV barrier. **Change** (`commands/indirect_order.rs`): each native list tracks, since its last buffer write, whether it has seen a barrier whose after-state includes `INDIRECT_ARGUMENT` (`synced`), and one vkd3d-proton honours for its argument pass (`named`). - `execute_indirect` records one global barrier (`ALL`/`COMMON` → `EXECUTE_INDIRECT`/`INDIRECT_ARGUMENT`) only when the call lacks what it needs. A counted dispatch needs both; anything else needs `synced`. - The flags clear at every dispatch, copy or other buffer write, and a fresh native list starts unordered. - A title that already transitions to exact `INDIRECT_ARGUMENT` gets no extra barrier. - Indirect draws are covered as readers. A draw doesn't clear the flags, so a barrier doesn't end the render pass before every indirect draw. **Not a fix for #232's hang:** in ProjectScarlett, an `ALL`/`COMMON` barrier before every compute `ExecuteIndirect` didn't move the Xid 109. This is a correctness fix for stale indirect arguments. **Tests:** `gpu-indirect-order` is in `all` and the verify suite. It fails on `main` as shown above and passes with this change on both cards. The unit tests in `src/tests/commands/indirect_order.rs` are typechecked only, since the crate targets Windows. **Checks** (on `5444f38`) - `python -m unittest discover -s tests -q`: OK. - AMD Raphael iGPU (1002:13c0), RADV (Mesa 26.0.8), GE-Proton11-14: the full `python tuxbox.py check` passed, 134 gates, including `lanes-selftest-gpu-indirect-order`. - RTX 5090 (10de:2b85), driver 620.70.10, GE-Proton11-14: the same full check passed, 134 gates. Not covered: bundles and lists without enhanced barriers (logged once, unchanged), and vkd3d-proton's predication fallback. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
brcly/TuxBox!298
No description provided.