GPU: typed buffer views off their host copy's elements read a copy of their own #230
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/230"
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 DexNom/VIctory. Originally posted by murillojndem on 2026-11-29T20:46:37Z.
A typed buffer view of a title buffer that lies inside a larger host copy (
crate::shadow) cannot always be expressed there: Direct3D begins a typed view atFirstElementtimes the element size of the buffer it views. When the title buffer begins at an offset in the copy that is not a multiple of the element size,rebase_srvreturnsSrvError::Alignmentandbuffer_srvleaves the slot null, so shaders read zeros through the view.In runs of the user's on an RX 7900 XT (logs of 2026-11-29), the real cases were R32G32B32_FLOAT views (format 6) of 40 to 50 elements in a copy of 182,452,224 bytes, 8 bytes past an element (for example
offset=22205600, 44 elements:12-byte SRV could not address the first whole element in its host buffer). The doubling log counted 16 distinct ones in four minutes with ray tracing on, and 2 to 8 in runs with it off. The other buffer views those logs left null had addresses from 0x7 to 0xb or no elements.Change:
own_copy_srv(descriptor/host.rs): such a typed view (not raw, not structured, its bytes beginning on a dword of the copy, at most 64 KiB) is made at element 0 of a buffer of its own in the card's memory, which holds the view's bytes. One own copy serves every slot that shows the same bytes of the same copy: the title slot and the dynamic slots of each table made afresh with it.OwnCopieskeys them by (source copy, first byte, bytes) and counts the slots that show each. A slot that shows another resource gives it up (HostHeap::keep_sparse, and the texture-pressure branch ofHostHeap::release, which takes slots' resources itself), and so does each slot of a heap that is dropped. The last one removes it. All own copies together take at most 16 MiB of the card's memory, counted in the 64 KiB each buffer takes (so at most 256); past that, views are left null as before (logged once). The buffer is made outside the registry's lock.record_feedsinhost.rs), after the CPU refreshes of the submission and the card's prelude (card_before, an earlierExecuteCommandLists). The prelude is the first command list of itsExecuteCommandLists, so both buffers start in the common state; the copies promote them, and explicit transitions put them back in it (the source once, and not at all for an upload-heap source) for the lists that follow, which read the own copies as views.Weak): one whose source the host let go of is no longer filled, andbuffer_owner_currentno longer treats its slots as current, so they are made again from the new owner, as a slot on another copy is today. A slot that shows an own copy of the current owner is current, so it is not made again at every pass.VICTORY_OWN_COPIES=0leaves such views null, as before.What a shader reads through such a view: the copy's bytes as the submission finds them, after its refreshes, which is what a view made on the copy reads of bytes the title wrote on the CPU. What earlier lists of the same submission write into those bytes it reads from the next submission on; on the console the view reads them at once. So bytes the card rewrites each frame are a frame late, and if the title rewrites a range with other data each frame, the view shows the previous data where main showed zeros. The views in the logs above kept their addresses (16 in four minutes), which points to the first case, but I could not tell which draws read them. That case is not rare upstream: Marvisak/VIctory#1405 counted 1,938 ranges written by shaders within the submission that read them in a 10-minute run on an RTX 4070, about ten a frame.
Upstream (Marvisak/VIctory) tried this three ways, none merged:
None of them is in this repository. This change takes the direction of #1019 for typed shader views, filling the own copy on the card from the buffer's copy instead of from title memory, so it also shows what earlier submissions' shaders wrote before their copy-back lands. Reading within a submission would need buffer states tracked across the submission's lists, which this repository does not have either.
Tests:
descriptor::host::tests::a_shader_reads_the_title_bytes_of_a_typed_view_off_the_elements_of_its_copy: a compute shader reads two R32G32B32_FLOAT views through heap slots whose title buffers begin 260 and 812 bytes into one copy (8 past an element each), 40 and 16 elements, and writes them out; it gets the title's floats. Two own copies are filled from one source.a_typed_view_off_the_elements_of_its_copy_reads_an_own_copy_until_an_owner_places_it_on_onereplacesnull_typed_srv_rebinds_when_a_new_owner_places_it_on_an_element: the slot shows an own copy filled from byte 256 of the outer copy and is current; a copy of the title buffer itself takes the slot (the own copy goes); the own copy comes back when that copy goes, and goes with the heap.slots_that_show_one_view_share_its_own_copy_while_any_shows_it: a title slot and two dynamic slots share one own copy (3 slots); a slot made again with the same view leaves 3; a release under texture pressure gives two back; a null view in the last one removes it.an_own_copy_holds_the_elements_of_the_view_inside_the_host_copy: the range, including the view from the log above, the cut at the copy's end, the dword rule and the 64 KiB limit.victory-gpu --lib: 222 passed, 0 failed, 4 ignored on WARP, with and withoutVICTORY_RELAY=1, and on the RX 7900 XT (main: 219, 0, 4); 242, 0, 4 in a diagnostics build withVICTORY_D3D12_DEBUG=1on WARP. WithVICTORY_RELAY=1,resource::tests::buffer_data_reaches_the_host_texturesometimes fails on this branch and on main alike (on main, 2 of 3 runs of it alone).-D warnings, with and without--all-features, andcargo xtask policypass. The touched files are not rustfmt-formatted on main (1,156 rustfmt differences in victory-gpu there, 1,180 here); the new code follows the style around it.Limits:
HEAP_VIEWS_ELSEWHERE(diagnostics) counts the slots that show an own copy among those showing another buffer than their range finds. Leaving them out would touch a line #95 reworks.Generated with Claude Code
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.