fix(gpu): bind bounded single-descriptor tables for root SRVs and UAVs #3337
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3337"
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 legayclightning22 on 2026-11-26T18:58:31Z.
Summary
Binds bounded single-descriptor tables for root SRVs and UAVs in
victory-gpu(crates/victory-gpu/src/draw.rsandcrates/victory-gpu/src/pipeline/host.rs), with aVICTORY_ROOT_SRV_DIRECTopt-out for direct root binding.Changes
crates/victory-gpu/src/draw.rsandcrates/victory-gpu/src/pipeline/host.rsto use bounded single-descriptor tables[cite: 18].VICTORY_ROOT_SRV_DIRECTopt-out support and unit tests covering bounded root views and environment override behavior[cite: 18].Verification
cargo test -p victory-gpu --lib[cite: 18]cargo clippy --locked -p victory-gpu --all-targets -- -D warnings[cite: 18]cargo xtask policy[cite: 18]Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T19:09:12Z.
Review: APPROVED
LGTM — verified on RTX 5090 (Windows / D3D12) against
origin/main(63bcca4).cargo test -p victory-gpu --lib pipeline::host:: -- --test-threads=1: 7 passed, 0 failed (root_srv_direct_only_for_one,root_srv_direct_opt_out_keeps_raw_addresses,root_srvs_and_uavs_are_bounded_one_descriptor_tables).cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20 passed, 0 failed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T19:16:39Z.
WARP/CPU verification of head
8dd2ca97(claim: #1633)Environment: Windows 11, WARP only (
VICTORY_WARP=1,VICTORY_D3D12_WARP=1),dxil.dllfrom Windows SDK 10.0.26100.0 (VICTORY_DXIL), no physical GPU, no game files.-j 4,--locked, separate target dir. Control:origin/main@63bcca43. Merge:git merge-treeagainst currentorigin/mainis clean (head is 1 commit ahead, 0 behind).63bcca438dd2ca97cargo test -p victory-gpucargo clippy -p victory-gpu --all-targets -- -D warningsxtask policyNew tests all pass on WARP:
root_srvs_and_uavs_are_bounded_one_descriptor_tables,root_srv_direct_opt_out_keeps_raw_addresses,root_srv_direct_only_for_one. They are absent on control (added by this PR); I did not separately demonstrate them failing without the fix. Synthetic/unit tests only; no real-title rendering was checked.AI disclosure: run by Claude Code (Claude Sonnet 5.5), coordinated by Antigravity.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T20:58:41Z.
Review: CHANGES_REQUESTED
Converting raw root SRVs/UAVs to bounded single-descriptor tables is a solid goal, and
pipeline/host.rscleanly switchesroot_srvs/root_uavstoD3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLEwith theVICTORY_ROOT_SRV_DIRECT=1opt-out. However, there is a silent data-corruption bug inState::root_tablewhenever a title binds a root SRV or root UAV at a non-zero offset inside a buffer.Blocking issue:
State::root_tablediscards the byte offset (crates/victory-gpu/src/draw.rs:1064, 1080-1092)In
crates/victory-gpu/src/draw.rs:root_view_slotcreates the raw view atfirst = 0(shadow.start) and caches it per(key, copy, uav):root_tablethen callsroot_view_slotand discards the returnedoffset(address - shadow.start):Reusing a
first = 0view only works for theis_root_viewuser-data path (victory-shader/src/emit/lower.rs:1695-1733,!self.root_memory), where the shader receivesoffsetin aROOT_VIEW_OFFSETuser-data dword and adds it to every byte address. For shaders that populatestage.root_srvs/stage.root_uavs(victory-shader/src/emit/lower.rs:5447-5459,root_memory == true),root_view_offset()returnsNone(lower.rs:1724): the shader indexes directly from byte0of the bound resource, relying on the binding itself to start ataddress(asSet*RootShaderResourceView/Set*RootUnorderedAccessView(param, shadow.gpu(address))did onmain).As a result, any root SRV/UAV bound at
address > shadow.start:shadow.start + 0instead ofaddress— which is either unrefreshed zeros (becauseroot_view_slotat line 1046 only refreshes[address..shadow.end]) or stale/unrelated data at offset0.shadow.start + 0instead ofaddress, silently corrupting the start of the buffer (outside the declaredgpu_writes(list, address, ...)range) while leavingaddressuntouched.1 << 27dwords) raw-view cap inHostHeap::raw_view_atifaddressis more than 512 MiB into a large buffer.Live GPU reproduction (RTX 5090 & WARP,
VICTORY_D3D12_DEBUG=1)Dispatching a compute shader (
ByteAddressBuffer : register(t0, space1)->RWByteAddressBuffer : register(u1, space1), copying dword 0) withsrc[0x0] = 0xDEADBEEF,src[0x100] = 0xCAFEBABE, binding root SRV atsrc + 0x100and root UAV atdst + 0x200:main/VICTORY_ROOT_SRV_DIRECT=1):dst[0x0] = 0x00000000,dst[0x200] = 0xcafebabe(RTX 5090 & WARP).root_table(coldsrc[0]):dst[0x0] = 0x00000000,dst[0x200] = 0x00000000(reads unrefreshed zeros atsrc[0]; RTX 5090 & WARP).root_table(warmsrc[0]):dst[0x0] = 0xdeadbeef,dst[0x200] = 0x00000000(reads wrong data fromsrc[0]and writes it todst[0]instead ofdst[0x200]; RTX 5090 & WARP).Note that the new test assertion in
draw.rs:2784only checksstate.root_table(...) == heap_host.gpu(index)without actually dispatching a shader through the table at a non-zero offset.Suggested fix
root_tablecreate (and cache separately, keyed by(key, copy, offset, uav)or(key, address, uav)) a bounded raw view starting atfirst = offsetwithbytes = shadow.left(address) & !3(requiringoffsetto be 4-byte aligned, and passingshadow.mark_entry(address)tohost.set_markfor UAVs), rather than reusingroot_view_slot'sfirst = 0descriptor.root_tableon both a root SRV and a root UAV at non-zero offsets within their buffers, plus an out-of-bounds read pastshadow.left(address)returning0.Imported from Marvisak/VIctory. Originally posted by legayclightning22 on 2026-11-26T22:06:25Z.
Great catch—pushed
30beed1updatingState::root_tableto create and cache its own bounded raw view keyed by(heap, copy, offset, uav)starting atfirst = offsetwithbytes = shadow.left(address) & !3(requiring 4-byte alignment and callingshadow.mark_entry(address)for UAVs) instead of reusingroot_view_slot'sfirst = 0descriptor. Addeddraw::tests::root_table_srv_uav_nonzero_offset_boundedexercising non-zero root SRV/UAV offsets and out-of-bounds reads returning0, and re-verifieddraw::tests,clippy --all-features -- -D warnings, andcargo xtask policy.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T22:44:15Z.
Review: CHANGES_REQUESTED
Thanks for fixing the
root_tablenon-zero offset handling (draw.rs:1130) and addingroot_table_srv_uav_nonzero_offset_bounded. However, testing the updated head (30beed1f) end-to-end throughState::bindon both RTX 5090 and WARP reproduced a blocking double-offset (2 * offset) silent data corruption bug for root SRVs/UAVs bound at non-zero offsets.Blocking issue:
ROOT_VIEW_OFFSETinState::bindstill addss.offset(address)on top ofFirstElement = offset / 4State::root_view_slot(crates/victory-gpu/src/draw.rs:1069-1074), the descriptor now bakesoffsetintoFirstElement = offset / 4:State::bind(crates/victory-gpu/src/draw.rs:779-793) was not updated and still emits the full shadow buffer byte offset forvictory_shader::emit::ROOT_VIEW_OFFSET:ROOT_VIEW_OFFSETto every byte offset when accessingROOT_SRV_VIEW/ROOT_UAV_VIEW(crates/victory-shader/src/emit/mod.rs:33-47), any root SRV or UAV at a non-zero offset within its shadow buffer appliesoffsettwice (FirstElement * 4 + ROOT_VIEW_OFFSET = 2 * offset):2 * offsetinstead ofoffset(or silently read0when2 * offset >= left).2 * offset(clobbering neighboring data or silently dropping out-of-bounds writes, and marking the wrong 64 KiB write-mark page when(address & 0xFFFF) + offset >= 65536).Live hardware & WARP repro (
VICTORY_D3D12_DEBUG=1)Lowered a minimal RDNA2 compute shader with
victory_shader::emit::emit_with(..., Options { view_marks: true })that copies dword 0 from root SRV slot 0 to root UAV slot 1, and dispatched it throughState::bindwith:src[0x000] = 0xDEADBEEF,src[0x100] = 0xCAFEBABE,src[0x200] = 0xBAD00200src + 0x100, root UAV slot 1 bound atdst + 0x200Observed results on both RTX 5090 and WARP (
--features diagnostics,VICTORY_D3D12_DEBUG=1):main(63bcca43):host[0x200] = 0xcafebabe,host[0x400] = 0x00000000,title[0x200] = 0xcafebabe,title[0x400] = 0x00000000(correct).#3337(30beed1f):host[0x200] = 0x00000000,host[0x400] = 0xbad00200,title[0x200] = 0x00000000,title[0x400] = 0xbad00200(readsrc[0x200]instead ofsrc[0x100], leftdst[0x200]untouched, and overwrotedst[0x400]).offset & 3, i.e.,0for 4-byte-aligned addresses — or usingself.root_view's returned offset directly) atcrates/victory-gpu/src/draw.rs:787immediately restoreshost[0x200] = 0xcafebabe,host[0x400] = 0x00000000,title[0x200] = 0xcafebabe,title[0x400] = 0x00000000on both RTX 5090 and WARP with 0 Debug Layer errors.Additional note
root_slotsby(key, copy, offset, uav)(draw.rs:1027) allocates a new dynamic descriptor slot for each distinct non-zero offset into the same shadow buffer (e.g., transient ring buffers), whereasmainreused a single slot per(key, copy, uav)by passingoffsetviaROOT_VIEW_OFFSET. Worth verifying whether per-offset descriptor caching is necessary forROOT_SRV_VIEW/ROOT_UAV_VIEW(or whether keeping the existingoffset = 0descriptor +ROOT_VIEW_OFFSETforroot_view_slotand only boundingroot_table/raw_view_atis simpler and avoids dynamic slot pressure). Also please add an end-to-endState::bindregression test covering non-zero root SRV/UAV offsets.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T01:12:11Z.
Review: APPROVED
The double-offset issue from the previous review is fixed cleanly:
root_view_slotnow keepsFirstElement = 0(keyed on(key, copy, 0, uav)) for theROOT_SRV_VIEW/ROOT_UAV_VIEW+ROOT_VIEW_OFFSETpath, whileroot_tablecreates a separate bounded single-descriptor view starting atoffset(keyed on(key, copy, offset, uav)) for root SRV/UAV descriptor tables, rejecting non-4-byte-aligned offsets cleanly.Verified on
b6550abe4cd730d2b60bb83926396ffffc3fbae5:cargo xtask policyandcargo clippy --tests -p victory-gpu(default and--features diagnostics,-D warnings) pass cleanly.draw::tests(22/22, includingroot_table_srv_uav_nonzero_offset_boundedandbind_root_srv_uav_nonzero_offsets) andpipeline::host::tests(7/7) pass on both RTX 5090 and WARP withVICTORY_D3D12_DEBUG=1.State::bind->Dispatchon both RTX 5090 and WARP (VICTORY_D3D12_DEBUG=1) with no title heap bound (memory_heap = true), non-zero offsets (src + 0x100->dst + 0x200), 10x repeated binds reusing the 2 cached dynamic slots, unaligned offset (+0x102) rejection, and both default bounded tables andVICTORY_ROOT_SRV_DIRECT=1: exact results and zero D3D12 debug layer messages.(Note: the single CI failure on
b6550abewas an unrelated timing flake inframe::tests::waits_end_on_ticks_and_count_frames— 235/236victory-gputests including alldraw::testspassed.)Imported from Marvisak/VIctory. Originally posted by legayclightning22 on 2026-11-27T01:52:23Z.
Pushed
<NEW_SHA>serializing the new non-zero offset compute dispatch tests with the existingdraw.rsdispatch lock soframe::tests::waits_end_on_ticks_and_count_framespasses reliably under parallelcargo test. Re-verified full parallelvictory-gpulib tests,clippy --all-features -- -D warnings, andcargo xtask policy.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.