Repository navigation
GPU: copy unaligned buffer SRVs into element-aligned scratch memory - #986
CitizenCinema wants to merge 1 commit into
Conversation
Placed structured buffer SRVs sub-allocated inside a larger title buffer can land at shadow offsets not divisible by StructureByteStride (e.g. offset % 56 != 0 in GTA VI hit detection). buffer_srv() rejected these views, leaving null_buffer_view (zeros) in the host descriptor slot. Detect unaligned buffer SRVs, promote their descriptor table to fresh dynamic slots, copy their bytes at submission into an element-aligned upload scratch slice, and bind an SRV with FirstElement = at / element.
|
A guest command-list readback isolates #986’s staging behavior on RTX 4090 under Wine/vkd3d-proton 3.2. Two dispatches used the same table for a two-record, 56-byte-stride structured SRV. The fixture checked that only one dynamic slot was allocated. After closing the list and before submitting it, the CPU changed fields in both records. GPU readback then matched the new field pairs This verifies submission-time staging of CPU-written records. A GPU producer earlier in the same submission remains a separate case. The reported 8m19s title result used #986 together with #984, so the title effect of the staging change alone remains open. |
A structured buffer SRV placed inside a larger title buffer can start off an element of its host copy (offset % stride != 0); FirstElement cannot address it, so the view was left null and read zeros (upstream traced a 4.8 s DEVICE_HUNG to it). Such a view's table goes to fresh dynamic slots, its elements are copied at submission into upload scratch memory aligned to the element, and the slot views that. shortcut: copied from title memory, so GPU writes earlier in the same submission are not seen. From upstream PR Marvisak#986 (d8d7c2c), hand-ported. Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
|
The same placed views also come as unordered views, of 44-byte elements: in a 10-minute world run on an RTX 4070, 315 such ranges, all left null on main. #1019 handles both kinds with one copy per view range (an unordered view's writes go back through the copy-back), in case that saves duplicate work on the follow-up you mention. |
|
Verified on Windows 10 + RTX 3080 — this stack (with #1260 and #1267) eliminated the world device removal and took the world from ~1 fps to ~20 fps. Setup: Win10 21H2 19044.7846, RTX 3080 10 GB, driver 621.24 (32.0.16.2124), Ryzen 9 7900X, 32 GB. Build: main
This matches the GTT-fill mechanism described here: the unaligned SRV scratch copy storm (#1260) and the re-copied 174 MB heap union (#1267) were both the frame-rate cost and the timed removal. With them gone the world runs continuously until I closed it (the exit was a teardown segfault, not a GPU fault). Cross-ref: #1260 (one aligned copy per range per list), #1267 (each declared byte copied once per submission). The three together are what produced the result; I can't isolate each one's share from this run, but the combined effect is unambiguous. AI use: Qwen Code (underlying model name not disclosed by the tool) built the stack, ran the title, extracted the counts and drafted this comment at the user's request. |
|
I compared three diagnostics builds on WARP with D3D12 debug, GPU-based validation and DRED enabled, using the same title and scripted Player input. Clean ffe310e logged 13 occurrences of validation ID 940 across four pixel shaders (heap index 0, expected Texture2D, actual Texture1D). This PR alone at d8d7c2c logged zero. Adding #1260 and #1267 also logged zero. All three runs still reached device removal 0x887A0005. The three pixel pipelines we tracked were present in submission summaries on both patched runs. These are log occurrences from one run per build. A separate targeted experiment on #568 helps explain the difference for pixel 280967ad158cee0b. Its placed structured SRV at table slot 1, byte offset 0 has a 304-byte stride. Three observed shadow offsets had remainders of 112, 208 and 208 bytes; host view creation fell back to null in all three cases. Giving only that shader an aligned, submission-populated copy removed its ID 940 messages in a repeat while other pixel shaders continued reporting them. This supports the SRV fix for this path; the later WARP removal remains open. |
|
Automated triage for the maintainers. Closing because this change is already in Unaligned structured SRVs get an own copy in main (shadow::for_view / exact, held by the slot, commit 86a5ed6); the per-draw scratch copy here was the costlier variant (#1260 measured 35 GB of copies). If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution. |
Root cause
Titles sub-allocate placed structured buffer SRVs at 16-byte-aligned addresses inside much larger shared title buffers (e.g., 182 MB transient ring buffers). Because a D3D12
D3D12_BUFFER_SRVaddresses elements viaFirstElementin multiples ofStructureByteStride,descriptor/host.rs::buffer_srv()cannot point directly into the shared shadow buffer whenshadow.offset(address) % element != 0.Previously,
buffer_srv()logged once ("buffer view not on an element of its host copy") and returnedNone, causingnull_for()to write anull_buffer_view(all zeros) into the host descriptor slot. In GTA VI'svfx_proj_decal_hit_detection(eeed82b877b44b5f), bufferB(112 B,StructureByteStride = 56) landed at shadow offsets withoffset % 56 != 0(24/48), soBsilently read all zeros (base = 0), pointingAinto the overlapping descriptor heap (0x45495676tags) and causing a ~4.8 sDXGI_ERROR_DEVICE_HUNGTDR even for element 0 (u6 = 0).Fix
HostList::scratch_aligned(len, align)incrates/victory-gpu/src/host.rs(sharingscratch_inwithscratch()while preserving 256-byte alignment for CBVs).unaligned_srv(&View)andHostHeap::srv_at()incrates/victory-gpu/src/descriptor/host.rsto detectView::Shader/View::Placedbuffer SRVs whose shadow offset is not divisible by their element stride, clampingNumElementsto the buffer's declared length.draw.rs::tables()to promote descriptor tables containing an unaligned buffer SRV intofreshdynamic slots (keeping scratch buffer lifetimes tied to the command list, matchingView::Constant), defer-copy their bytes into element-aligned scratch memory at submission, and bind an SRV withFirstElement = at / align.unaligned_buffer_srv_is_detectedincrates/victory-gpu/src/descriptor/host.rs.Verification
cargo test -p victory-gpu: 51 passed, 0 failed (includingunaligned_buffer_srv_is_detected) andcargo test -p victory-shader: 120 passed, 0 failed.StructuredBufferlowering fix (fix/structured-buffer-flat-offset), GTA VI ran live on RTX 5090 for 8m19s with noVICTORY_SKIP_PIPELINES: 0 slow submissions, 0 GPU hangs, 0"buffer view not on an element of its host copy"SRV warnings, steady 2.0–2.2 fps (eeed82b877b44b5frunning cleanly every frame past frame 1114; stopped cleanly by hand).element = 44) are left for a separate follow-up.