Skip to content

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

Open
matheusfrta wants to merge 1 commit into
Marvisak:mainfrom
matheusfrta:patch-1795497178
Open

matheusfrta wants to merge 1 commit into
Marvisak:mainfrom
matheusfrta:patch-1795497178

Conversation

@matheusfrta

@matheusfrta matheusfrta commented Nov 24, 2026 •

Copy link
Copy Markdown

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.

@LAKSHYA-cmd-tech LAKSHYA-cmd-tech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and verified on Windows 11 x64 (D3D12 WARP + Hardware).

  • Confirmed indirect argument clamp properly honors count_buffer (via count_arg), preventing trailing unreferenced garbage beyond the valid count from depleting execution budget.
  • Confirmed budget accumulation saturation preventing uint32 overflow.
  • Confirmed host.null_root_view() safely binds a 64 KiB zero-initialized buffer on unbound root views instead of undefined GPU address references.
  • cargo test -p victory-gpu: 45 passed, 0 failed.
  • cargo clippy -p victory-gpu --lib -- -D warnings: 0 warnings.
  • cargo xtask policy: 151 files clean.

@rouges78

Copy link
Copy Markdown
Contributor

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.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested merged cleanly onto main (ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC) with NVIDIA GeForce RTX 5090 (Blackwell) and WARP (VICTORY_D3D12_WARP=1):

  • cargo test -p victory-gpu (RTX 5090): 52 passed, 0 failed, 1 ignored (including host::tests::null_root_view_is_aligned and indirect::tests::clamp_honours_count_buffer_and_does_not_wrap_budget)
  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu (WARP): 52 passed, 0 failed, 1 ignored
  • cargo clippy -p victory-gpu --all-targets: 0 warnings
  • cargo xtask policy: ok

Both new indirect-clamp and aligned null-root-view tests pass cleanly on RTX 5090 and WARP with zero warnings. Approving.

AI-assisted (Gemini 4 Neon).

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

matheusfrta added a commit to matheusfrta/VIctory that referenced this pull request Nov 25, 2026
@matheusfrta matheusfrta changed the title fix(gpu): respect indirect count buffer, guard budget overflow, and bind null root views fix(gpu): respect indirect count buffer and bind null root views Nov 25, 2026
@matheusfrta

Copy link
Copy Markdown
Author

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.

@Mericas77

Copy link
Copy Markdown

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

@matheusfrta

Copy link
Copy Markdown
Author

@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 matheusfrta changed the title fix(gpu): respect indirect count buffer and bind null root views fix(gpu): handle null root views in user data and resolve shadow conflict (#583) Nov 25, 2026
matheusfrta added a commit to matheusfrta/VIctory that referenced this pull request Nov 25, 2026
@matheusfrta matheusfrta changed the title fix(gpu): handle null root views in user data and resolve shadow conflict (#583) fix(gpu): respect indirect count buffer and bind null root views Nov 25, 2026
@matheusfrta

Copy link
Copy Markdown
Author

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

@Mericas77

Mericas77 commented Nov 25, 2026 •

Copy link
Copy Markdown

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)

@matheusfrta

Copy link
Copy Markdown
Author

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

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants