GPU: copy unaligned buffer SRVs into element-aligned scratch memory #986
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!986
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/986/head"
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?
@CitizenCinema on GitHub · 2026-11-24 14:41 UTC · original
CitizenCinema:fix/unaligned-buffer-srv→main· +149 −11 · 3 files · 1 commits · closed without mergingRoot 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.@Zipettte on GitHub · 2026-11-24 14:54 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
d8d7c2c:cargo test -p victory-gpupasses, 51 passed / 0 failed. Workspace baseline on main (ffe310e) was green on the same machine (342 passed).Tested with AI assistance (Claude).
@MichaelSmithAI on GitHub · 2026-11-24 14:53 UTC · original · edited 2026-11-24 14:57 UTC
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
[17, 31]and[41, 59]. The control passed on the author revision and on our gstack + #986 build. On the matchedffe310ebaseline, the same view allocated zero staged slots. The fixture stopped at that assertion before queue submission, so there is no baseline GPU readback.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.
@SantannaCarlos on GitHub · 2026-11-24 15:07 UTC · original
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.
@justlovett0 on GitHub · 2026-11-24 17:32 UTC · original
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
ffe310e+ #175 + #994 + #302 + #193 + #704 + #309 + #1067 + #953 + this PR + #1260 + #1267 + #1254, release+diagnostics. Retail GTA VI 1.0.2.1, Series X.VICTORY_DEBUG_PS=1 VICTORY_SHOW_TARGET=2560x1440-f28-3.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.
@alladeen321123 on GitHub · 2026-11-24 17:51 UTC · original
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
ffe310elogged 13 occurrences of validation ID 940 across four pixel shaders (heap index 0, expected Texture2D, actual Texture1D). This PR alone atd8d7c2clogged 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.
@Marvisak on GitHub · 2026-11-25 00:29 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.Unaligned structured SRVs get an own copy in main (shadow::for_view / exact, held by the slot, commit
86a5ed6b); 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.
Pull request closed