Shaders: split flat byte-offset accesses to structured buffers #984
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!984
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-984"
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:40 UTC · original
CitizenCinema:fix/structured-buffer-flat-offset→main· +275 −6 · 2 files · 1 commits · openRoot cause
Table-bound
StructuredBuffer/RWStructuredBufferdescriptors carryStructureByteStridein the host descriptor heap, andUsedResource.striderecords that stride (>= 4, multiple of 4; rawByteAddressBufferrecordsstride = 1).Previously,
lower.rsonly checkedUsedResource.stridefor indexed (idxen) buffer operations. Flat byte-offset accesses—scalars_buffer_load_dword*insmem()and non-idxenbuffer_load/buffer_store/buffer_atomicinbuffer()—always annotated the handle asByteAddressBuffer((11, 0)) and passed the flat byte offset as the index argument.On NVIDIA D3D12 (tested on RTX 5090), reading a
StructuredBuffer<stride>heap descriptor through aByteAddressBufferhandle bounds-checks any byte offset>= strideto0. In GTA VI'svfx_proj_decal_hit_detection(CS_ComputeHitDetectionSkinnedResults,eeed82b877b44b5f), bufferB(s1+0) is aStructuredBuffer<56>read withs_buffer_load_dword: record 1 (byte_offset = 80 >= 56) returnedbase = 0, causing the shader to readA + 0(which overlaps VIctory's descriptor heap0x45495676view tags), hit the loop abortretbefore a workgroup barrier, and trigger a ~4.9 sDXGI_ERROR_DEVICE_HUNGTDR.Fix
structured_stride(used)incrates/victory-shader/src/emit/lower.rsmatching table-bound resources (RootType::Table) withstride >= 4 && stride % 4 == 0(root descriptors have no D3D12 descriptor stride and stay raw(11, 0)).smem()(handling bothResourceType::SrvandResourceType::Uav) andbuffer()(index == Noneloads, stores, and atomics) to annotate structured handles as(12 | uav, stride)and split each flat byte address into(addr / stride, addr % stride)(one dword at a time for multi-dword loads/stores so cross-element accesses stay in-bounds).structured_buffer_flat_byte_offset_loads_reach_elements_past_the_firstincrates/victory-shader/src/emit/valu_tests.rsverifyings_buffer_load_dwordand flatbuffer_load_dword offenacross elements 0, 1, and 2 of aStructuredBuffer<56>.Verification
cargo test -p victory-shader: 121 passed, 0 failed (including the new regression test on both RTX 5090 hardware and WARP) andcargo test -p victory-gpu: 50 passed, 0 failed.eeed82b877b44b5fwithBbound asStructuredBuffer<56>andA + 0populated with0x45495676tags: previously hungu6 = 1in 4896 ms (DEVICE_HUNG); after fix, bothu6 = 0(61.5 ms) andu6 = 1(52.2 ms) succeed.shaders.rpf(translate --validate --pipelines --list): 21,973 emitted, 21,645 RTX 5090 PSOs created, 0 new DXIL validator errors.fix/unaligned-buffer-srv), GTA VI ran live on RTX 5090 for 8m19s with noVICTORY_SKIP_PIPELINES(0 slow submissions, 0 GPU hangs,eeed82b877b44b5fexecuting cleanly acrossu6 = 0andu6 = 1every frame).@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
5011645:cargo test -p victory-shaderpasses, 121 passed / 0 failed. Workspace baseline on main (ffe310e) was green on the same machine (342 passed).Tested with AI assistance (Claude).
@R0D4X on GitHub · 2026-11-24 15:17 UTC · original
RTX 5080 (Blackwell, Wave32) A/B Verification of #984 + #986 + #452 (+ #946, #948, #688)
Environment:
min=32, max=32), Windows 11mainffe310ecargo build --profile diag -p victory --features diagnosticsVICTORY_D3D12_DRED=1,VICTORY_D3D12_DEBUG=1,VICTORY_LOG=victory_gpu=info, scripted menu entry (VICTORY_KEYS), noVICTORY_SKIP_WAVE64, noVICTORY_SHADER_LOOP_LIMIToverride1.0.2.1(no game assets or dumps attached)Runs:
ffe310e+#439,#578,#334,#492,#646,#635,#987,#669#984,#986,#452,#946,#948,#688#984,#986,#452,#946,#948,#688)0x887A0006) at 152.1 sop 6):dispatch 12x1x1 [compute eeed82b877b44b5f](4293 ms)eeed82b877b44b5fbound & ran cleanly from frame 1542 onward)slow host submission(>250 ms)849–901 msevery world frame, containingcompute 9146291b38ea9ce1)45–980 ms(frequent500–980 msspikes)116–139 mssteady0.7–1.6 fps1.4–1.6 fps(CPU-bound bypreparing~235 ms +copying back~243–356 ms)0(only the 4 startup probes: 1M view heap cap +B5G5R5A1/B4G4R4A4)0dropped=256(n=178)dropped=512(n=254, even with#688reclaiming finished lists)Takeaways:
#984+#986eliminate the deterministiceeed82b877b44b5fTDR hang on RTX 5080 (Wave32) without needingVICTORY_SKIP_WAVE64.#452eliminates all 27 recurring ~850–900 ms GPU stalls (9146291b38ea9ce1), dropping peak world GPU time from ~980 ms to116–139 ms.#986+#688/#747(#949): On NVIDIA's 1M capped shader-visible view heap (MIN_DYNAMIC = 65,536), promoting unaligned SRV tables tofreshdynamic slots in#986pushed dynamic slot drops from256to512(n=254) even with#688active — reinforcing the need for#949.#578) and untranslated lighting/BVH shaders (#995,#704,#710,#979).@SantannaCarlos on GitHub · 2026-11-24 15:50 UTC · original
In-game data for this PR on an RTX 4070 (Windows 11): diagnostics build, Series X mode,
VICTORY_SHADER_LOOP_LIMIT=64, DRED, Enter-only input to the world, runs of 10 minutes. Every tree ismainffe310e+ #493 + #439 (with #223, #233, #320) + #116 and a local tracing patch; the rows add:eeed82b877b44b5f; DRED stops atcommand 6 of 11, the second of its two dispatches in that list617aba9, #876, this PR85d813c, #876, this PR, #68885d813c, #876, this PR, #949So 2 of 2 hung in that dispatch without this PR and 3 of 3 ran to the time limit with it, which fits your reading of the second dispatch. Caveat: between the two groups #1019 also went from its first commit to its full head (which adds unordered views off an element), so this is not an A/B of this PR alone.
@alessiodeia on GitHub · 2026-11-24 15:56 UTC · original
RTX 2070 SUPER (Turing, Wave32), driver 617.42, Windows 11: this PR +
CitizenCinema:fix/unaligned-buffer-srvclears theeeed82b877b44b5fhang, and a scalar-only control still hangs.Diag build, Series X mode,
VICTORY_D3D12_DRED=1, default loop limit, Enter-only scripted input into the world, 30-minute runs. Common tree:mainffe310e+ #493 + #587 + #282 + #876 + #67 + #490 + #464 +alessiodeia:fix/reuse-aligned-cbv-tables(#840) +alessiodeia:perf/fast-texture-content-hash(#916).s_buffer_load_dword*on a table SRV with a used stride ≥ 4 (multiple of 4) annotatedStructuredBuffer<stride>, address split into(addr & ~3) / stride,% stride; no vectoroffenchange, no unaligned-SRV changecommand 4 of 9 (op 6),dispatch 12x1x1 [compute eeed82b877b44b5f]5011645+fix/unaligned-buffer-srvatd8d7c2cSo on this card the scalar split alone is not enough. The flat vector-load part of this PR, the unaligned-view companion, or both are needed. Two details from the hung runs:
Format 0, NumElements 1, StructureByteStride 56), so the structured annotation matches the descriptor here.0x70008, an offset into the 182,452,224-byte SRV ats0+304. The title has no CPU mapping at that offset, so its contents are whatever the host copy holds there.Synthetic check of the underlying mismatch on the same GPU: a raw
rawBufferLoadthrough aStructuredBuffer<56>descriptor at byte 80 returned dword 40 on NVIDIA and dword 20 on WARP.No game data attached. AI-assisted (Claude Code).
@adamdotpy on GitHub · 2026-11-24 16:47 UTC · original
Reviewed on Windows 11 / Rust 1.98.1,
5011645on currentmain(ffe310e, merges as it stands), isolated target dir. Verified:cargo test -p victory-shader --lib121 passed / 1 ignored including the newstructured_buffer_flat_byte_offset_loads_reach_elements_past_the_first(run on the hardware GPU here, underONE_AT_A_TIME— good, that lock is the one #383 missed); clippy--all-targets --all-features --locked -D warningsclean;cargo build --release -p victorybuilds.The test pins the bug, red and green. With
lower.rsreverted tomainand the test kept, it fails on hardware:i.e. the flat byte-offset load at byte 24 of a 56-byte-stride structured buffer read a dword out of element 0 instead of element 0's later bytes — exactly "elements past the first are dropped". With the branch's lowering it passes. The test is also the right shape: the same dword read two ways (indexed
s_buffer_load_dwordand flatbuffer_load_dword offen) and asserted equal, so it is a differential test, not a golden value.What I checked in the lowering, and it held.
structured_stridegates onroot == Table && stride >= 4 && stride % 4 == 0, so root descriptors (no host stride) and raw views (stride = 1) stay on the old raw path, as the comment says. The structured annotation(12 | uav, stride)is the same props pair the already-existing indexed path uses (lower.rs:6317-area), so loads, stores and atomics now agree on one annotation instead of two. The(index, offset)split isUDiv/URemby a constant stride, and the operand order[h, idx, eoff, mask, al]matches the indexed path's[index, off, iu]shape with the samemask = 1,align = 4. All four flat paths are covered —buffer_load(the f32 loop), atomics, and both store paths — and each is guarded by!typed && index.is_none(), so typed and indexed accesses are untouched.Two things worth a second look, neither blocking.
4while the element offset is nowURem(a, stride)— fine for dword-sized flat accesses, but a flat byte or short access (buffer_load_ubyte/_ushortwith a non-4-alignedaddr) would hand the validator an offset the structured annotation may reject. If the title only ever does dword-aligned flat accesses to structured buffers, theal = 4is right and a comment saying so would settle it; if not, the alignment should come from the access width.UDiv/URemby the stride are emitted per access; for a loop of flat loads that is a divide per element where the console's raw view does none. With the stride a compile-time constant the backend usually turns it into a multiply-shift, so I do not expect this to show up, but it is the one place this PR adds work per element, and aVICTORY_GPU_TIMINGrun on the world would be the way to confirm it costs nothing.Bottom line: the defect is real, the test proves it both ways, and the lowering is consistent with the indexed path it mirrors. The only open question is the alignment assumption for sub-dword flat accesses.
@jeremygold02 on GitHub · 2026-11-24 18:04 UTC · original
I found a scalar vertex-buffer case worth covering alongside the structured-host-view compute test. On a physical RTX 5070, a draw-side observer matched the active vertex shader by its guest container and inspected its selected graphics root table (slot 0, offset 0). The title supplied a buffer SRV with
DXGI_FORMAT_R32_TYPELESS, RAW set, 32 elements andStructureByteStride = 0. The same shader's native table metadata says stride 64. This was observed on a local baseline that renders the account picker.Offline replay of that exact shader on
ffe310ebproduced 16 raw byte-addressed scalar reads. Replay on this PR at50116450produced a structured handle with stride 64 and 16 index/offset splits. Both passed the Windows SDK DXIL validator. Comparing the emitted vertex programs, the values from these reads feed all four position output components. #995 at78c8078aalso produced the structured version for this shader.This provides a concrete input for the raw-host-view concern in #437. For a synthetic regression test, the observed combination is a 64-byte guest stride with a 32-DWORD raw host SRV. The descriptor observation and translation comparison are verified; the effect on the picture has not yet been isolated in a run where only this lowering differs.
@clypeal6 on GitHub · 2026-11-24 19:02 UTC · original
Independent confirmation of this root cause from a second shader and GPU.
Hardware: RTX 4070 Laptop GPU, Windows 11, title v1.0.2.1, Series X mode.
The shader: compute
42683eebec081520. It reads its loop bounds withs_buffer_load_dwordx4from a 16-byteStructuredBuffer(s1+0). Title and host copies both hold[1024, 512, 2560, 1440]. On NVIDIA the raw read returns 0 past the first dword, so the shader divides by zero and its loops run toLOOP_LIMIT.In game:
VICTORY_GPU_TIMING=1timed it at 1.5–1.7 s per 128×64 dispatch, andDEVICE_HUNG(0x887A0006) followed after 2–10 minutes in the world.Our fix: we made the same change independently. Unindexed
s_buffer_load,buffer_load,buffer_storeandbuffer_atomicuse(12 | uav, stride)and(byte / stride, byte % stride)when the stride is above 4. With the default loop limit:42683eebec081520per dispatchYour version restricts the change to table-bound resources and also covers stride 4, which is more careful than ours. We'd suggest #984 over a second PR.
A GPU test that reproduces it, in case it helps. It runs a scalar load of dword 3 from a 16-byte structured element:
View::Buffer { stride: Stride::Structured(16) }, withs_buffer_load_dwordx4 s[12:15], s[4:7], 0, then dword 3 stored from every lane.It's at clypeal6/VIctory, branch
fix/structured-buffer-reads, inwaterfall_tests.rs:a_scalar_load_reads_a_structured_buffer_element_whole. You're welcome to take it.Related:
VICTORY_SHADER_LOOP_LIMIT=32because "translated loops were almost endless". This bug is very likely the reason for that.AI-assisted (Claude Code). Measured on our own copy of the game. No game data shared.
@ -6401,1 +6470,4 @@}if !typed&& index.is_none()&& let Some(stride) = structured_stride(used)@Rezwo on GitHub · 2026-11-24 19:41 UTC · original
Could we verify that all descriptor choices have the same layout before using this stride? For merged sources,
used_kind()takes the first alternative's metadata, whilehandle()selects the actual descriptor at runtime. If a flat load can select between stride 56 and stride 32, byte offset 80 becomes(1, 24)with the first stride even when the second view is selected; that view needs(2, 16).Either reject differing layouts during lowering or use each choice's own layout. A two-descriptor regression would cover this; the current stride-56 test already covers reads past the first element. This is from source inspection, not a game repro.
@Marvisak on GitHub · 2026-11-25 00:31 UTC · original
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-shader/src/emit/lower.rs,crates/victory-shader/src/emit/valu_tests.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
@ -6401,1 +6470,4 @@}if !typed&& index.is_none()&& let Some(stride) = structured_stride(used)@Rezwo on GitHub · 2026-11-25 06:21 UTC · original
Follow-up: reproduced on unchanged PR head
501164509d220fd643300e080b8e68bb498ce562, Windows / RTX 2080 Ti, with a synthetic one-thread shader; no game files.The shader selects between table-bound structured SRVs (strides 56 and 32) via a runtime root constant, then reads byte offset 80 through scalar
s_buffer_load_dwordand flat vectorbuffer_load_dword offen.0x00000000for both reads instead of0xb000141b. Original test passes, added test fails, exit 101.Each scenario started with
cargo clean -p victory-shader, then:This is a test-only patch, not a compiler fix or an in-game diagnosis. Apply against this head with
git -c core.autocrlf=false apply. Expected patched file SHA-256:1eccfc898b3b6a207e74ea2955f59a268dfabfde183de04a4a61bde543f356af.AI-assisted (OpenAI Codex); measurements executed locally.
Synthetic regression patch
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.