fix(gpu): respect indirect count buffer and bind null root views #583
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/583"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by matheusfrta on 2026-11-24T05:13:06Z.
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.
Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T05:23:08Z.
Review: APPROVED
Tested and verified on Windows 11 x64 (D3D12 WARP + Hardware).
Imported from Marvisak/VIctory. Originally posted by rouges78 on 2026-11-24T09:12:35Z.
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.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.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T13:52:50Z.
Review: APPROVED
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 (includinghost::tests::null_root_view_is_alignedandindirect::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 ignoredcargo clippy -p victory-gpu --all-targets: 0 warningscargo xtask policy: okBoth 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).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:28:09Z.
Automated triage for the maintainers.
Needs work. This PR now does two separate things, and only one of them is ready.
crates/victory-gpu/src/indirect.rs,bound, and the call indraw.rs). Lane 0 readsmin(records, count)into a groupsharedlimitbehind a barrier, so records past the title's count no longer use up the list's budget or get zeroed. It fitsmain's single-group walk, which already answers @rouges78's timing report.clamp_honours_count_buffer_and_does_not_wrap_budgetcovers it. This part looks right.State::root_view, theROOT_VIEW_OFFSETentry, the root-view loop, andHost::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: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
t1next to the per-list argument buffer. That part reads correctly.CI: passing.
Generated by Claude Code
[PR #583] fix(gpu): respect indirect count buffer, guard budget overflow, and bind null root viewsto [PR #583] fix(gpu): respect indirect count buffer and bind null root viewsImported from Marvisak/VIctory. Originally posted by matheusfrta on 2026-11-25T01:19:58Z.
Rebased onto
mainand integratedcount_bufinto 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
clippysteps passed, andcargo test --workspacefailed on the twovictory-shader::emit::synthetic_testshardware-adapter tests (gathers_at_a_level_match_the_hardwareandpermutes_read_the_lane_named_and_zero_from_lanes_left_out) on the GitHub runner, which are unrelated tovictory-gpu.Imported from Marvisak/VIctory. Originally posted by Mericas77 on 2026-11-25T08:31:04Z.
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 returningNone, the null fallback only covers thestage.root_cbvs / root_srvs / root_uavsloop. Sinced71c388, root SRVs and UAVs in programs that don't use title memory no longer go through that loop (it only holdsVIEW_STRIDESfor them now, see theemitmodule notes, "Root SRVs and root UAVs"). They go through the user-data entries instead, and both of those paths drop the whole draw/dispatch whenfindfails:ROOT_VIEW_OFFSETentry:crate::shadow::find(address, 1)->None => return false(draw.rs#L617-L627)ROOT_SRV_VIEW/ROOT_UAV_VIEWentries:self.root_view(...)->None => return false(draw.rs#L629-L634), becauseState::root_viewdoescrate::shadow::find(address, 1)?(draw.rs#L779)On the base,
find(0, 1)falls through toloose()and returns a 4 MiB copy of[0, 4 MiB)(its refresh just fails inReadProcessMemory), 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, whenaddress == 0, hand out a raw view ofnull_root_view()/null_root_uav()(cached inroot_slotslike the others) with offset 0, and make theROOT_VIEW_OFFSETbranch return 0 for address 0 instead ofreturn false. The page-table path (L603, title-memory programs) already just skips a failedfind, so it seems fine as is.Happy to test a rebased version on an RTX 4070 (NVIDIA) if useful.
AI-assisted review, read against
586d7daand current main (940d32f).Imported from Marvisak/VIctory. Originally posted by matheusfrta on 2026-11-25T10:50:50Z.
@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.
[PR #583] fix(gpu): respect indirect count buffer and bind null root viewsto [PR #583] fix(gpu): handle null root views in user data and resolve shadow conflict (#583)[PR #583] fix(gpu): handle null root views in user data and resolve shadow conflict (#583)to [PR #583] fix(gpu): respect indirect count buffer and bind null root viewsImported from Marvisak/VIctory. Originally posted by matheusfrta on 2026-11-25T14:26:01Z.
@Mericas77 Rebased onto current
main(keeping the write-marks changes indraw.rsandshadow.rs) and fixed the gap you spotted:State::root_viewnow caches and binds a null raw view with offset0for null (0) or unset root SRVs/UAVs instead of dropping the draw/dispatch (clearing any stale mark entry on UAV slots).ROOT_VIEW_OFFSETnow returns0for null/unset root views instead of returningfalse.shadow::find(0, _)and null/unset root views inState::root_view.CI is green and
victory-gpuclippy + 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.Imported from Marvisak/VIctory. Originally posted by Mericas77 on 2026-11-25T15:04:05Z.
Thanks, the rebased version (
f99ec1b) looks right to me:ROOT_VIEW_OFFSETnow gives 0 andState::root_viewbinds 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, againstmainat940d32f:940d32ff99ec1bdraw::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.descriptor::host::tests::dynamic_slots_are_held_until_released(descriptor heap cap,NumDescriptors >= HEAP_VIEWS) andmemory::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)
Imported from Marvisak/VIctory. Originally posted by matheusfrta on 2026-11-25T23:18:25Z.
Rebased onto
main(adaptedcount_bufinindirect::boundas read-only SRVt1alongside the new per-list argument buffer, and keptshadow.page_range/not_rundiagnostics inState::root_view).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.