fix(gpu): respect indirect count buffer and bind null root views #583

Open
github-bot wants to merge 1 commit from github-bot/gh-583 into main AGit
Owner

@⁠matheusfrta on GitHub · 2026-11-24 05:13 UTC · original
matheusfrta:patch-1795497178 → main · +260 −49 · 4 files · 1 commits · open

Rebased shadow.rs cleanly onto main so null addresses skip loose shadow allocation, and updated State::root_view and ROOT_VIEW_OFFSET to bind a cached null raw view with offset 0 when a root view is null or unset instead of dropping the draw or dispatch.

**@⁠matheusfrta** on GitHub · 2026-11-24 05:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/583) `matheusfrta:patch-1795497178` → `main` · +260 −49 · 4 files · 1 commits · open Rebased shadow.rs cleanly onto main so null addresses skip loose shadow allocation, and updated State::root_view and ROOT_VIEW_OFFSET to bind a cached null raw view with offset 0 when a root view is null or unset instead of dropping the draw or dispatch.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:09:12 +00:00
Author
Owner

@⁠rouges78 on GitHub · 2026-11-24 09:12 UTC · original

Hardware data point on the budget loop, RTX 4080, Windows 11. I added one test to this branch: N draw records of one vertex instance each (kind 0, stride 16, no count buffer), which all fit the budget, clamp alone, timing host.execute.

records main (plain add) this PR
1,024 1.4 ms 165 ms
4,096 1.9 ms 2.07 s
16,384 2.4 ms device removed
65,536 5.8 ms device removed (3 of 3)

When many records fit, each successful compare-exchange makes the other threads retry, so the work grows roughly with the square of the record count. 4,096 small records already sit at the host's 2 s time-out. Each device loss came with an nvlddmkm event 153. WARP does not show this (no time-out), and the garbage-record tests don't either, because the budget saturates after a few reservations and everything else exits early.

main does not have the problem but still wraps. A single thread walking the records with a saturating count avoids both (27 ms for 65,536 records here): https://github.com/rouges78/VIctory/tree/fix/indirect-budget-wrap, test records_within_the_budget_all_run. It has no count-buffer awareness, which this PR has; the two could be combined.

AI-assisted; the numbers are from real runs on the card.

**@⁠rouges78** on GitHub · 2026-11-24 09:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/583#issuecomment-7127101996) Hardware data point on the budget loop, RTX 4080, Windows 11. I added one test to this branch: N draw records of one vertex instance each (kind 0, stride 16, no count buffer), which all fit the budget, clamp alone, timing `host.execute`. | records | main (plain add) | this PR | |---|---|---| | 1,024 | 1.4 ms | 165 ms | | 4,096 | 1.9 ms | 2.07 s | | 16,384 | 2.4 ms | device removed | | 65,536 | 5.8 ms | device removed (3 of 3) | When many records fit, each successful compare-exchange makes the other threads retry, so the work grows roughly with the square of the record count. 4,096 small records already sit at the host's 2 s time-out. Each device loss came with an nvlddmkm event 153. WARP does not show this (no time-out), and the garbage-record tests don't either, because the budget saturates after a few reservations and everything else exits early. main does not have the problem but still wraps. A single thread walking the records with a saturating count avoids both (27 ms for 65,536 records here): https://github.com/rouges78/VIctory/tree/fix/indirect-budget-wrap, test `records_within_the_budget_all_run`. It has no count-buffer awareness, which this PR has; the two could be combined. AI-assisted; the numbers are from real runs on the card.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:28 UTC · original · edited 2026-11-26 00:21 UTC

Automated triage for the maintainers.

Needs work. This PR now does two separate things, and only one of them is ready.

  1. Count buffer in the indirect clamp (crates/victory-gpu/src/indirect.rs, bound, and the call in draw.rs). Lane 0 reads min(records, count) into a groupshared limit behind a barrier, so records past the title's count no longer use up the list's budget or get zeroed. It fits main's single-group walk, which already answers @⁠rouges78's timing report. clamp_honours_count_buffer_and_does_not_wrap_budget covers it. This part looks right.
  2. Null and unset root views (State::root_view, the ROOT_VIEW_OFFSET entry, the root-view loop, and Host::null_root_view/null_root_uav). A draw or dispatch that used to be dropped now runs against a zeroed 64 KiB buffer. That changes GPU state handling, and the PR gives no evidence for what the title expects: no log of which draws hit a null or unset root view, and no run comparing the result. Two concrete problems:
    • The null UAV buffer is shared by every draw and never cleared, so after one shader writes through it, later "null" reads are not zeros.
    • Root descriptors are not bounds-checked, so a shader that reads past 64 KiB of the null SRV reads outside the buffer.

Suggestion: split part 1 into its own PR, which could go forward as is. For part 2, give evidence that the dropped draws should run, for example a diagnostics run listing the shaders and slots and an A/B of the frame. Also clear or size the null UAV for its use.

On your reply: thanks for the rebase that moves the count buffer to SRV t1 next to the per-list argument buffer. That part reads correctly.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/583#issuecomment-7148541060) · edited 2026-11-26 00:21 UTC <!-- victory-triage v1 head=33f61e5d161bb6acf3bffdba8fa2b8741c686a5d verdict=needs-work at=2026-11-26T00:21:33Z --> Automated triage for the maintainers. **Needs work.** This PR now does two separate things, and only one of them is ready. 1. **Count buffer in the indirect clamp** (`crates/victory-gpu/src/indirect.rs`, `bound`, and the call in `draw.rs`). Lane 0 reads `min(records, count)` into a groupshared `limit` behind a barrier, so records past the title's count no longer use up the list's budget or get zeroed. It fits `main`'s single-group walk, which already answers @⁠rouges78's timing report. `clamp_honours_count_buffer_and_does_not_wrap_budget` covers it. This part looks right. 2. **Null and unset root views** (`State::root_view`, the `ROOT_VIEW_OFFSET` entry, the root-view loop, and `Host::null_root_view`/`null_root_uav`). A draw or dispatch that used to be dropped now runs against a zeroed 64 KiB buffer. That changes GPU state handling, and the PR gives no evidence for what the title expects: no log of which draws hit a null or unset root view, and no run comparing the result. Two concrete problems: - The null UAV buffer is shared by every draw and never cleared, so after one shader writes through it, later "null" reads are not zeros. - Root descriptors are not bounds-checked, so a shader that reads past 64 KiB of the null SRV reads outside the buffer. Suggestion: split part 1 into its own PR, which could go forward as is. For part 2, give evidence that the dropped draws should run, for example a diagnostics run listing the shaders and slots and an A/B of the frame. Also clear or size the null UAV for its use. On your reply: thanks for the rebase that moves the count buffer to SRV `t1` next to the per-list argument buffer. That part reads correctly. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠matheusfrta on GitHub · 2026-11-25 01:19 UTC · original

Rebased onto main and integrated count_buf into the single-group tile clamp, keeping a separate sink buffer for null root UAVs so writes do not dirty the zeroed CBV/SRV buffer.

Regarding the failing CI check: both clippy steps passed, and cargo test --workspace failed on the two victory-shader::emit::synthetic_tests hardware-adapter tests (gathers_at_a_level_match_the_hardware and permutes_read_the_lane_named_and_zero_from_lanes_left_out) on the GitHub runner, which are unrelated to victory-gpu.

**@⁠matheusfrta** on GitHub · 2026-11-25 01:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/583#issuecomment-7149438771) Rebased onto `main` and integrated `count_buf` into the single-group tile clamp, keeping a separate sink buffer for null root UAVs so writes do not dirty the zeroed CBV/SRV buffer. Regarding the failing CI check: both `clippy` steps passed, and `cargo test --workspace` failed on the two `victory-shader::emit::synthetic_tests` hardware-adapter tests (`gathers_at_a_level_match_the_hardware` and `permutes_read_the_lane_named_and_zero_from_lanes_left_out`) on the GitHub runner, which are unrelated to `victory-gpu`.
Author
Owner

@⁠Mericas77 on GitHub · 2026-11-25 08:31 UTC · original

Thanks for this one. One gap I noticed while reading the diff (code reading only, I have not reproduced it in a title):

With shadow::find(0, _) now returning None, the null fallback only covers the stage.root_cbvs / root_srvs / root_uavs loop. Since d71c388, root SRVs and UAVs in programs that don't use title memory no longer go through that loop (it only holds VIEW_STRIDES for them now, see the emit module notes, "Root SRVs and root UAVs"). They go through the user-data entries instead, and both of those paths drop the whole draw/dispatch when find fails:

  • ROOT_VIEW_OFFSET entry: crate::shadow::find(address, 1) -> None => return false (draw.rs#L617-L627)
  • ROOT_SRV_VIEW / ROOT_UAV_VIEW entries: self.root_view(...) -> None => return false (draw.rs#L629-L634), because State::root_view does crate::shadow::find(address, 1)? (draw.rs#L779)

On the base, find(0, 1) falls through to loose() and returns a 4 MiB copy of [0, 4 MiB) (its refresh just fails in ReadProcessMemory), so those draws were still bound and ran. With this PR, any draw or dispatch whose shader reads a root SRV/UAV the title left at 0 is dropped instead, which looks like the opposite of what the null-view change is meant to do.

A possible fix: in State::root_view, when address == 0, hand out a raw view of null_root_view() / null_root_uav() (cached in root_slots like the others) with offset 0, and make the ROOT_VIEW_OFFSET branch return 0 for address 0 instead of return false. The page-table path (L603, title-memory programs) already just skips a failed find, so it seems fine as is.

Happy to test a rebased version on an RTX 4070 (NVIDIA) if useful.

AI-assisted review, read against 586d7da and current main (940d32f).

**@⁠Mericas77** on GitHub · 2026-11-25 08:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/583#issuecomment-7157122056) Thanks for this one. One gap I noticed while reading the diff (code reading only, I have not reproduced it in a title): With `shadow::find(0, _)` now returning `None`, the null fallback only covers the `stage.root_cbvs / root_srvs / root_uavs` loop. Since d71c388, root SRVs and UAVs in programs that don't use title memory no longer go through that loop (it only holds `VIEW_STRIDES` for them now, see the `emit` module notes, "Root SRVs and root UAVs"). They go through the user-data entries instead, and both of those paths drop the whole draw/dispatch when `find` fails: - `ROOT_VIEW_OFFSET` entry: `crate::shadow::find(address, 1)` -> `None => return false` ([draw.rs#L617-L627](https://github.com/Marvisak/VIctory/blob/586d7da3938396e3131bc0506849cd7aba154bfa/crates/victory-gpu/src/draw.rs#L617-L627)) - `ROOT_SRV_VIEW` / `ROOT_UAV_VIEW` entries: `self.root_view(...)` -> `None => return false` ([draw.rs#L629-L634](https://github.com/Marvisak/VIctory/blob/586d7da3938396e3131bc0506849cd7aba154bfa/crates/victory-gpu/src/draw.rs#L629-L634)), because `State::root_view` does `crate::shadow::find(address, 1)?` ([draw.rs#L779](https://github.com/Marvisak/VIctory/blob/586d7da3938396e3131bc0506849cd7aba154bfa/crates/victory-gpu/src/draw.rs#L779)) On the base, `find(0, 1)` falls through to `loose()` and returns a 4 MiB copy of `[0, 4 MiB)` (its refresh just fails in `ReadProcessMemory`), so those draws were still bound and ran. With this PR, any draw or dispatch whose shader reads a root SRV/UAV the title left at 0 is dropped instead, which looks like the opposite of what the null-view change is meant to do. A possible fix: in `State::root_view`, when `address == 0`, hand out a raw view of `null_root_view()` / `null_root_uav()` (cached in `root_slots` like the others) with offset 0, and make the `ROOT_VIEW_OFFSET` branch return 0 for address 0 instead of `return false`. The page-table path ([L603](https://github.com/Marvisak/VIctory/blob/586d7da3938396e3131bc0506849cd7aba154bfa/crates/victory-gpu/src/draw.rs#L603), title-memory programs) already just skips a failed `find`, so it seems fine as is. Happy to test a rebased version on an RTX 4070 (NVIDIA) if useful. _AI-assisted review, read against 586d7da and current main (940d32f)._
Author
Owner

@⁠matheusfrta on GitHub · 2026-11-25 10:50 UTC · original

@⁠Mericas77 Thanks for pointing this out! Feel free to test the rebased version on your RTX 4070. I’ll test it on my PC as well to verify the behavior. I’ll submit an updated PR with any necessary fixes as soon as I can.

**@⁠matheusfrta** on GitHub · 2026-11-25 10:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/583#issuecomment-7160251472) @⁠Mericas77 Thanks for pointing this out! Feel free to test the rebased version on your RTX 4070. I’ll test it on my PC as well to verify the behavior. I’ll submit an updated PR with any necessary fixes as soon as I can.
Author
Owner

@⁠matheusfrta on GitHub · 2026-11-25 14:26 UTC · original

@⁠Mericas77 Rebased onto current main (keeping the write-marks changes in draw.rs and shadow.rs) and fixed the gap you spotted:

  • State::root_view now caches and binds a null raw view with offset 0 for null (0) or unset root SRVs/UAVs instead of dropping the draw/dispatch (clearing any stale mark entry on UAV slots).
  • ROOT_VIEW_OFFSET now returns 0 for null/unset root views instead of returning false.
  • Added unit tests covering shadow::find(0, _) and null/unset root views in State::root_view.

CI is green and victory-gpu clippy + WARP tests (with --skip a_texture_written_in_one_format_reads_in_another_through_a_placed_view, which fails on this host's WARP due to castable format support) pass. Still worth checking on your RTX 4070 if you want to verify on hardware.

**@⁠matheusfrta** on GitHub · 2026-11-25 14:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/583#issuecomment-7165270172) @⁠Mericas77 Rebased onto current `main` (keeping the write-marks changes in `draw.rs` and `shadow.rs`) and fixed the gap you spotted: - `State::root_view` now caches and binds a null raw view with offset `0` for null (`0`) or unset root SRVs/UAVs instead of dropping the draw/dispatch (clearing any stale mark entry on UAV slots). - `ROOT_VIEW_OFFSET` now returns `0` for null/unset root views instead of returning `false`. - Added unit tests covering `shadow::find(0, _)` and null/unset root views in `State::root_view`. CI is green and `victory-gpu` clippy + WARP tests (with `--skip a_texture_written_in_one_format_reads_in_another_through_a_placed_view`, which fails on this host's WARP due to castable format support) pass. Still worth checking on your RTX 4070 if you want to verify on hardware.
Author
Owner

@⁠Mericas77 on GitHub · 2026-11-25 15:04 UTC · original · edited 2026-11-25 15:05 UTC

Thanks, the rebased version (f99ec1b) looks right to me: ROOT_VIEW_OFFSET now gives 0 and State::root_view binds a cached null raw view for null/unset root SRVs/UAVs, so those draws are no longer dropped.

Tested on an RTX 4070 (Windows), plain debug cargo test -p victory-gpu, against main at 940d32f:

passed failed ignored
main 940d32f 141 2 2
#583 f99ec1b 145 2 2
  • The 4 new tests pass on hardware: draw::tests::null_and_unset_root_views_read_zeros, shadow::tests::null_address_does_not_allocate_shadow_copy, host::tests::null_root_view_is_aligned, indirect::tests::clamp_honours_count_buffer_and_does_not_wrap_budget.
  • The 2 failures are the same on both sides and already fail on NVIDIA on main (unrelated to this PR): descriptor::host::tests::dynamic_slots_are_held_until_released (descriptor heap cap, NumDescriptors >= HEAP_VIEWS) and memory::tests::lists_share_a_table_and_copies_keep_their_views.
  • draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view, the one you skipped on WARP, passes on the 4070 on both sides.
  • cargo clippy -p victory-gpu --all-targets: clean.

No regressions on NVIDIA from what I can see.

Me and AI-assisted. (Gemini+Claude)

**@⁠Mericas77** on GitHub · 2026-11-25 15:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/583#issuecomment-7166251351) · edited 2026-11-25 15:05 UTC Thanks, the rebased version (f99ec1b) looks right to me: `ROOT_VIEW_OFFSET` now gives 0 and `State::root_view` binds a cached null raw view for null/unset root SRVs/UAVs, so those draws are no longer dropped. Tested on an RTX 4070 (Windows), plain debug `cargo test -p victory-gpu`, against `main` at 940d32f: | | passed | failed | ignored | |---|---|---|---| | main 940d32f | 141 | 2 | 2 | | #583 f99ec1b | 145 | 2 | 2 | - The 4 new tests pass on hardware: `draw::tests::null_and_unset_root_views_read_zeros`, `shadow::tests::null_address_does_not_allocate_shadow_copy`, `host::tests::null_root_view_is_aligned`, `indirect::tests::clamp_honours_count_buffer_and_does_not_wrap_budget`. - The 2 failures are the same on both sides and already fail on NVIDIA on main (unrelated to this PR): `descriptor::host::tests::dynamic_slots_are_held_until_released` (descriptor heap cap, `NumDescriptors >= HEAP_VIEWS`) and `memory::tests::lists_share_a_table_and_copies_keep_their_views`. - `draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view`, the one you skipped on WARP, passes on the 4070 on both sides. - `cargo clippy -p victory-gpu --all-targets`: clean. No regressions on NVIDIA from what I can see. Me and _AI-assisted._ (Gemini+Claude)
Author
Owner

@⁠matheusfrta on GitHub · 2026-11-25 23:18 UTC · original

Rebased onto main (adapted count_buf in indirect::bound as read-only SRV t1 alongside the new per-list argument buffer, and kept shadow.page_range / not_run diagnostics in State::root_view).

**@⁠matheusfrta** on GitHub · 2026-11-25 23:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/583#issuecomment-7177386433) Rebased onto `main` (adapted `count_buf` in `indirect::bound` as read-only SRV `t1` alongside the new per-list argument buffer, and kept `shadow.page_range` / `not_run` diagnostics in `State::root_view`).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/583/head:github-bot/gh-583'
git switch 'github-bot/gh-583'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-583'
git switch 'github-bot/gh-583'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-583'
git switch 'github-bot/gh-583'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-583'
git switch 'main'
git merge --squash 'github-bot/gh-583'
git switch 'main'
git merge --ff-only 'github-bot/gh-583'
git switch 'main'
git merge 'github-bot/gh-583'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!583
No description provided.