gpu: bind the view-stride table shaders read at root SRV 255 #264

Manually merged
github merged 1 commit from github-bot/gh-264 into main 2026-11-27 12:26:59 +00:00 AGit
Owner

@⁠Ketan-Kapse on GitHub · 2026-11-27 06:41 UTC · original
Ketan-Kapse:pr/view-stride-table → main · +292 −19 · 7 files · 1 commits · merged 2026-11-27 12:22 UTC

Refs #258 (cause 2)

What and why

A translated shader that takes a buffer view from the resource heap itself looks up the entry's stride in the translator's own table before it reads the entry (root SRV t255, emit::VIEW_STRIDES). Where the table holds 0 it reads the host's null buffer view instead. The native host bound no such table. So every draw and dispatch of such a shader was dropped at submission as "root parameter 255 was never set". It was counted only in NativeHost::unset_roots and warned about only with VICTORY_TRACE_TARGETS=1. The title's culling shaders are among them.

This PR adds, on the native host only:

  • NativeHost::view_strides: one table per resource heap, with one dword for every index a shader can compute (HEAP_VIEWS). It holds the buffer view's element size at the title's entries and 0 elsewhere. The dword comes from descriptors::stride_word, which gives what view_stride and view_kind give the D3D12 host. The table is made the first time such a shader is bound with the heap, from the title's records, and mirror() keeps it current.
  • Heap length. A resource heap is now as long as the translator's index clamp (HEAP_VIEWS entries), with the null raw buffer views at NULL_BUFFER_VIEW and the entry below it. This part is needed: the shader clamps its index to that range and reads the null view at that index, so both must be entries the heap has. The D3D12 host's heaps are sized the same way.
  • Visibility. The unset-root drops are in the "native draws so far" line as dropped_unset_root, with dropped_unmapped and dropped_failed. The first drop for each root parameter warns without a switch. This is what would have shown the problem at once.

This branch does not depend on the span buffers PR. It is cut from main and passes on its own. The two touch the same lines of NativeHost::mirror, so whichever lands second needs a small rebase there (one conflict, both sides kept). I built and tested the two merged together, with the store order PR as well: same results as each alone.

Cost

  • 48 MiB of zeroed host memory per resource heap (2^21 entries of 24 bytes), where it was the title's entries plus 512.
  • 8 MiB for the stride table of a heap, once a shader that reads it is bound with that heap.

Not measured: how much of either becomes resident. Only the title's own entries, the view pairs and the two null views are ever written, but a heap's buffer is made resident for the passes that use the heap, so the whole 48 MiB may count. Please weigh this for 16 GB machines. If it is too much, the alternative is a change in the translator's clamp and null index, which this PR does not touch.

Limits (marked in the code)

  • An entry the title copies as bytes outside a bound table keeps its old stride until it is mirrored. A record the title zeroes keeps its stride too, because the table check skips empty records.
  • A resource heap too long for the reserved entries below the clamp cannot have the null views. A shader that needs the table with such a heap is dropped and counted in dropped_failed.

Tests

  • heap_tests::a_compute_shader_stores_through_a_buffer_view_it_takes_from_the_heap (new, on Metal): a hand-assembled compute program loads a buffer view from the heap by index and stores through it. While the entry is empty the table holds 0 and nothing is stored. After the title writes a view there and it is mirrored, the stores land. The view is inside one pool run, so the test does not need span buffers. Without the table binding the dispatch is dropped and the test fails.
  • descriptors::tests::stride_words_of_buffer_views (new): the dword for structured, raw, constant and typed views, the integer kinds, and 0 for what is not a buffer view.

How it was verified

Apple M4 Pro, macOS 27.0.1, Xcode 27.0, Metal Shader Converter 4.0 beta 3. Tests run as x86_64 under Rosetta (--target x86_64-apple-darwin, release):

  • victory-gpu: 317 passed, 1 failed, 1 ignored (315 passed on main, plus the 2 new ones). The failure is list::tests::unordered_access_clears_have_the_same_slots_in_both_layouts, which fails the same way on main.
  • victory-shader: 312 passed, 3 ignored. victory-metal: 30, 12 and 14 passed. Both as on main.
  • Run natively as arm64 too (debug, no --target, as AGENTS.md asks for victory-gpu): victory-gpu 318 passed, none failed (316 on main).
  • cargo build --release --target x86_64-apple-darwin -p victory builds. cargo xtask policy passes. tools/macos/run-summary.sh --self-test passes. clippy on the macOS target for the four crates reports the same findings as main.
  • The Windows clippy gate (cargo clippy --workspace --all-targets --locked -- -D warnings, and the same with --all-features) passes for x86_64-pc-windows-msvc, checked from this Mac with blake3's C build skipped (CARGO_FEATURE_PURE=1): a check, not a link. The gnullvm cross tools are not installed here, so the documented gnullvm command itself was not run.

Not verified

  • No game run on this branch. On our fork, with this change and the span buffers together, the dispatches that were dropped for root parameter 255 ran.
  • Resident memory, as said above.

🤖 Generated with Claude Code

**@⁠Ketan-Kapse** on GitHub · 2026-11-27 06:41 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/264) `Ketan-Kapse:pr/view-stride-table` → `main` · +292 −19 · 7 files · 1 commits · merged 2026-11-27 12:22 UTC Refs #258 (cause 2) ## What and why A translated shader that takes a buffer view from the resource heap itself looks up the entry's stride in the translator's own table before it reads the entry (root SRV `t255`, `emit::VIEW_STRIDES`). Where the table holds 0 it reads the host's null buffer view instead. The native host bound no such table. So every draw and dispatch of such a shader was dropped at submission as "root parameter 255 was never set". It was counted only in `NativeHost::unset_roots` and warned about only with `VICTORY_TRACE_TARGETS=1`. The title's culling shaders are among them. This PR adds, on the native host only: - `NativeHost::view_strides`: one table per resource heap, with one dword for every index a shader can compute (`HEAP_VIEWS`). It holds the buffer view's element size at the title's entries and 0 elsewhere. The dword comes from `descriptors::stride_word`, which gives what `view_stride` and `view_kind` give the D3D12 host. The table is made the first time such a shader is bound with the heap, from the title's records, and `mirror()` keeps it current. - Heap length. A resource heap is now as long as the translator's index clamp (`HEAP_VIEWS` entries), with the null raw buffer views at `NULL_BUFFER_VIEW` and the entry below it. This part is needed: the shader clamps its index to that range and reads the null view at that index, so both must be entries the heap has. The D3D12 host's heaps are sized the same way. - Visibility. The unset-root drops are in the "native draws so far" line as `dropped_unset_root`, with `dropped_unmapped` and `dropped_failed`. The first drop for each root parameter warns without a switch. This is what would have shown the problem at once. This branch does not depend on the span buffers PR. It is cut from main and passes on its own. The two touch the same lines of `NativeHost::mirror`, so whichever lands second needs a small rebase there (one conflict, both sides kept). I built and tested the two merged together, with the store order PR as well: same results as each alone. ## Cost - 48 MiB of zeroed host memory per resource heap (2^21 entries of 24 bytes), where it was the title's entries plus 512. - 8 MiB for the stride table of a heap, once a shader that reads it is bound with that heap. Not measured: how much of either becomes resident. Only the title's own entries, the view pairs and the two null views are ever written, but a heap's buffer is made resident for the passes that use the heap, so the whole 48 MiB may count. Please weigh this for 16 GB machines. If it is too much, the alternative is a change in the translator's clamp and null index, which this PR does not touch. ## Limits (marked in the code) - An entry the title copies as bytes outside a bound table keeps its old stride until it is mirrored. A record the title zeroes keeps its stride too, because the table check skips empty records. - A resource heap too long for the reserved entries below the clamp cannot have the null views. A shader that needs the table with such a heap is dropped and counted in `dropped_failed`. ## Tests - `heap_tests::a_compute_shader_stores_through_a_buffer_view_it_takes_from_the_heap` (new, on Metal): a hand-assembled compute program loads a buffer view from the heap by index and stores through it. While the entry is empty the table holds 0 and nothing is stored. After the title writes a view there and it is mirrored, the stores land. The view is inside one pool run, so the test does not need span buffers. Without the table binding the dispatch is dropped and the test fails. - `descriptors::tests::stride_words_of_buffer_views` (new): the dword for structured, raw, constant and typed views, the integer kinds, and 0 for what is not a buffer view. ## How it was verified Apple M4 Pro, macOS 27.0.1, Xcode 27.0, Metal Shader Converter 4.0 beta 3. Tests run as x86_64 under Rosetta (`--target x86_64-apple-darwin`, release): - victory-gpu: 317 passed, 1 failed, 1 ignored (315 passed on main, plus the 2 new ones). The failure is `list::tests::unordered_access_clears_have_the_same_slots_in_both_layouts`, which fails the same way on main. - victory-shader: 312 passed, 3 ignored. victory-metal: 30, 12 and 14 passed. Both as on main. - Run natively as arm64 too (debug, no `--target`, as AGENTS.md asks for victory-gpu): victory-gpu 318 passed, none failed (316 on main). - `cargo build --release --target x86_64-apple-darwin -p victory` builds. `cargo xtask policy` passes. `tools/macos/run-summary.sh --self-test` passes. clippy on the macOS target for the four crates reports the same findings as main. - The Windows clippy gate (`cargo clippy --workspace --all-targets --locked -- -D warnings`, and the same with `--all-features`) passes for `x86_64-pc-windows-msvc`, checked from this Mac with blake3's C build skipped (`CARGO_FEATURE_PURE=1`): a check, not a link. The gnullvm cross tools are not installed here, so the documented gnullvm command itself was not run. ## Not verified - No game run on this branch. On our fork, with this change and the span buffers together, the dispatches that were dropped for root parameter 255 ran. - Resident memory, as said above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A translated shader that takes a buffer view from the resource heap
itself looks up the entry's stride in the translator's own table (root
SRV t255, emit::VIEW_STRIDES) before it reads the entry, and reads the
host's null buffer view where the table holds 0. The native host bound
no such table: every draw and dispatch of such a shader was dropped at
submission as "root parameter 255 was never set", counted only in
NativeHost::unset_roots and warned about only with
VICTORY_TRACE_TARGETS=1. The title's culling shaders are among them
(#258).

- NativeHost::view_strides: one table per resource heap, a dword for
  every index a shader can compute (HEAP_VIEWS): the buffer view's
  element size at the title's entries (descriptors::stride_word, the
  D3D12 host's view_stride and view_kind), 0 elsewhere. Made the first
  time such a shader is bound with the heap, kept current by mirror().
- A resource heap is as long as the translator's index clamp, with the
  null raw buffer views at NULL_BUFFER_VIEW and the entry below: the
  clamped index and the null view a shader reads must be entries the
  heap has. This is 48 MiB of zeroed host memory a resource heap, plus
  8 MiB for the table once it is made.
- The unset-root drops are in the "native draws so far" line
  (dropped_unset_root, with dropped_unmapped and dropped_failed) and
  warn without a switch, the first time for each root parameter.

Tests: heap_tests::a_compute_shader_stores_through_a_buffer_view_it_takes_from_the_heap
(a hand-assembled compute program stores through a buffer view it loads
from the heap by index, on Metal; without the table its dispatch is
dropped) and descriptors::tests::stride_words_of_buffer_views.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 06:46:28 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 08:08 UTC · original

Thank you. This is the second input the cullers lacked, and the new warning without a switch is what would have shown it at once.

Before it can merge:

  1. Memory. Every resource heap is now at least 48 MiB of zeroed host memory, and each stride table is 8 MiB. Please say how many resource heaps the title makes in a world run, and measure the resident size (the footprint of the process before and after) on any Mac you have. I will weigh it for 16 GB (#8, #79). If it is too much, the clamp change you mention is the alternative.
  2. The stale stride. A record the title zeroes with plain stores keeps its stride, and the shader then reads that empty entry instead of the null view. Please add a test: write a view, mirror it, zero the record with a plain store, run the dispatch, and say what happens; or say why the title cannot do this.
  3. marcus-4's test in #255 fails on main for the same missing table. Please include it in this pull request so the test and the fix land together.
  4. The text names a "span buffers" pull request that is not open. If it is your held alias version, #267 replaced it; please say so, so nobody waits for it.

Sheffy007 has opened #278 in the same files for a second cause of the lost formatted stores in #255. Whichever of you lands second will need a rebase; please look at each other's changes.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 08:08 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/264#issuecomment-7213188830) Thank you. This is the second input the cullers lacked, and the new warning without a switch is what would have shown it at once. Before it can merge: 1. Memory. Every resource heap is now at least 48 MiB of zeroed host memory, and each stride table is 8 MiB. Please say how many resource heaps the title makes in a world run, and measure the resident size (the footprint of the process before and after) on any Mac you have. I will weigh it for 16 GB (#8, #79). If it is too much, the clamp change you mention is the alternative. 2. The stale stride. A record the title zeroes with plain stores keeps its stride, and the shader then reads that empty entry instead of the null view. Please add a test: write a view, mirror it, zero the record with a plain store, run the dispatch, and say what happens; or say why the title cannot do this. 3. marcus-4's test in #255 fails on main for the same missing table. Please include it in this pull request so the test and the fix land together. 4. The text names a "span buffers" pull request that is not open. If it is your held alias version, #267 replaced it; please say so, so nobody waits for it. Sheffy007 has opened #278 in the same files for a second cause of the lost formatted stores in #255. Whichever of you lands second will need a rebase; please look at each other's changes.
Author
Owner

@⁠Ketan-Kapse on GitHub · 2026-11-27 08:34 UTC · original

Thanks for the review. Taking the points in order; the ones that need a measurement or new code will follow as commits here.

  1. Memory. I will count the resource heaps of a world run and post the process footprint before and after on a 24 GB Mac. If the resident cost turns out to be the whole 48 MiB per heap, I will switch to the smaller form (clamp and null index in the translator) instead of asking you to weigh it.
  2. Stale stride after a plain-store zeroing. Agreed that this is a hole as written; I will add the test you describe and either fix it (the table check should treat a zeroed record as "no view" and clear the dword) or document why it cannot happen, whichever the test shows.
  3. #255's test. Will include it.
  4. "Span buffers" PR. That was my held alias version. #267 replaces it, and I am not opening it. What I may still send after #267 lands is only the piece it does not cover (refreshing entries outside every bound table when the pool table changes), as a small follow-up on top of #267. I will fix the wording in this PR's text.

I will look at #278 before pushing so the two do not collide in mirror.

**@⁠Ketan-Kapse** on GitHub · 2026-11-27 08:34 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/264#issuecomment-7213676412) Thanks for the review. Taking the points in order; the ones that need a measurement or new code will follow as commits here. 1. **Memory.** I will count the resource heaps of a world run and post the process footprint before and after on a 24 GB Mac. If the resident cost turns out to be the whole 48 MiB per heap, I will switch to the smaller form (clamp and null index in the translator) instead of asking you to weigh it. 2. **Stale stride after a plain-store zeroing.** Agreed that this is a hole as written; I will add the test you describe and either fix it (the table check should treat a zeroed record as "no view" and clear the dword) or document why it cannot happen, whichever the test shows. 3. **#255's test.** Will include it. 4. **"Span buffers" PR.** That was my held alias version. #267 replaces it, and I am not opening it. What I may still send after #267 lands is only the piece it does not cover (refreshing entries outside every bound table when the pool table changes), as a small follow-up on top of #267. I will fix the wording in this PR's text. I will look at #278 before pushing so the two do not collide in `mirror`.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 10:32 UTC · original

Thank you for the answers. Nothing is pushed yet, so I am waiting for: the count of resource heaps and the footprint before and after, the test for the record the title zeroes with plain stores, marcus-4's test from #255, and the corrected text about the held version (#267 replaces it).

Your workflow has not run; it needs my approval. The branch is behind main, and #267 and #278 also change mirror, so please look at both before you push. I cannot say what #264 did alone in my run in #258: it was one of five.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 10:32 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/264#issuecomment-7216004436) Thank you for the answers. Nothing is pushed yet, so I am waiting for: the count of resource heaps and the footprint before and after, the test for the record the title zeroes with plain stores, marcus-4's test from #255, and the corrected text about the held version (#267 replaces it). Your workflow has not run; it needs my approval. The branch is behind main, and #267 and #278 also change `mirror`, so please look at both before you push. I cannot say what #264 did alone in my run in #258: it was one of five.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 11:35 UTC · original

#267 is merged now, and this branch conflicts with main in mirror. Please rebase on main when you push the four items. Your workflow has been approved and has run.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 11:35 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/264#issuecomment-7217253676) #267 is merged now, and this branch conflicts with main in `mirror`. Please rebase on main when you push the four items. Your workflow has been approved and has run.
github manually merged commit 1e30a59f48 into main 2026-11-27 12:26:59 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 12:22 UTC · original

Merged, together with #278. I resolved the one conflict with main myself (the draw-count log line in native/glue.rs; your counters are kept and main's heap report follows them). My game run of main with this, #253 and #278 gives a G-buffer that is 60 to 87% covered. Two follow-ups I am testing before they go in: a record the title zeroes with plain stores kept its old stride until it was mirrored again (I have a fix and a test), and each resource heap now costs about 56 MiB at its first dispatch, which cannot be made smaller without changing the shader's index clamp. Thank you @⁠Ketan-Kapse.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 12:22 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/264#issuecomment-7218170464) Merged, together with #278. I resolved the one conflict with main myself (the draw-count log line in `native/glue.rs`; your counters are kept and main's heap report follows them). My game run of main with this, #253 and #278 gives a G-buffer that is 60 to 87% covered. Two follow-ups I am testing before they go in: a record the title zeroes with plain stores kept its old stride until it was mirrored again (I have a fix and a test), and each resource heap now costs about 56 MiB at its first dispatch, which cannot be made smaller without changing the shader's index clamp. Thank you @⁠Ketan-Kapse.
This discussion has been locked. Commenting is limited to contributors.
No description provided.