Shaders: lower indexed buffer accesses with used-resource stride 0 as raw #2359
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!2359
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2359/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?
@fuzeofficlal on GitHub · 2026-11-25 11:44 UTC · original
fuzeofficlal:fix/shader-stride-zero-indexed-buffer-1482→main· +297 −3 · 2 files · 1 commits · closed without mergingPart of #1482 (Rule 3, reported by @studiostephe).
Summary
Lower::buffer(crates/victory-shader/src/emit/lower.rs), dropindex(index = None) whenused.is_some_and(|u| u.stride == 0) && !typed && format.is_none()so indexedbuffer_load*,buffer_store*, andbuffer_atomic_*instructions on raw buffers route through the existing raw-view(11 | u, 0)path at byte offsetoffinstead of failing with"a structured buffer of unknown stride". Strides1..=3remain refused.UsedResource.stride == 0innative.rsand hardware semanticsFSSM(DXILcontainers,native.rs:654):UsedResource.strideis read directly fromle32(e, 12)of the 20-byteusedentry: structured buffers carry their element byte stride (>= 4), root views carry1, and raw buffers (ByteAddressBuffer/RWByteAddressBuffer) carry0— the same conventionLower::descriptor_data(lower.rs:4088-4110) already relies on. (UnlikeSource::Built, aRootType::Tableload's descriptor dword 1 sits in the title's heap at draw time rather than in shader code, andHostHeap'sVIEW_STRIDEStable stores4for raw buffers and reserves0for non-buffers.)FSPX(ACCCcontainers,native.rs:530):0x41records store view dimension at+12rather than stride, sofspx_programsetsstride: 0; FidelityFX upscaler shaders build raw descriptors (made_raw) and address buffers viaoffenbyte offsets.MUBUFaddressing (inst_offset + soffset + (offen ? voffset : 0) + (idxen ? vindex * V#.STRIDE : 0)) with raw-bufferOOB_SELECT = 3,V#.STRIDE == 0contributesvindex * 0 == 0to the byte address and checksbyte_offset + payload_bytes <= NUM_RECORDS, matchingindex = None.Verification
emit::stride_tests::indexed_buffer_accesses_with_stride_zero_lower_as_raw_while_one_to_three_refuse: verifiesstride = 0andstride = 4lower and validate viadxil.dllacrossload,store, andatomic, whilestride = 1, 2, 3still returnUnsupported("a structured buffer of unknown stride").emit::stride_tests::stride_zero_indexed_load_store_and_atomic_address_as_raw_buffers: end-to-end Wave32 compute readback (vindex = lane + 1withidxenacross load, store, andglcatomic add) on NVIDIA GeForce RTX 5090 and D3D12 WARP.cargo clippy -p victory-shader --all-targets --locked -- -D warningsandcargo xtask policy: passed.@steven-seagull27 on GitHub · 2026-11-25 13:35 UTC · original
Both supplied tests passed on
4e14e76on an RTX 5080 (621.40) and built-in Microsoft WARP (10.0.26100.10068). I extended the existing Wave32 test to give the load, atomic and two stores distinct scalar byte offsets of 12, 8, 4 and 8. This checks that dropping a zero-stride index still preserves the scalar offset on all three kinds of access.Each adapter matched 68/68 values with the original offsets and 72/72 with the new offsets. The shifted load returned 1004–1035, the atomic returned every previous value from 0 to 31, only counter word 3 reached 32, and all four untouched output words stayed zero. Both cases use the same fixture.
Test-only commit
356decfAI-assisted with Codex. Synthetic compute readbacks.
@Marvisak on GitHub · 2026-11-25 18:27 UTC · original
Automated triage for the maintainers.
In
Lower::buffer(crates/victory-shader/src/emit/lower.rs), an indexed MUBUF access is now lowered as raw (index dropped) whenever the used-resource entry hasstride == 0. Before, it was refused as "a structured buffer of unknown stride". The address formula cited,vindex * V#.STRIDE, is right per the public RDNA2 ISA. The change, though, keys on the metadata stride (UsedResource.stride), not the descriptor's stride, and two things are not shown:native.rs,fspx_programsetsstride: 0for every resource, because that record carries no stride. With this change, an FSPX structured buffer accessed withidxenwould silently get the wrong addresses (index dropped) instead of being refused. Please exclude FSPX programs, or show that they never useidxenon buffers.The added tests are synthetic and confirm the chosen lowering. They do not show what the console does. With the FSPX case handled and that evidence given, this would be a reasonable fix.
CI: passing.
Generated by Claude Code
@fuzeofficlal on GitHub · 2026-11-25 19:37 UTC · original
Thanks for the detailed triage! Both points are completely fair:
fspx_programsetsstride: 0for all resources regardless of whether a buffer is structured, so keying onUsedResource.stride == 0without excluding FSPX would silently misaddress indexed FSPX structured buffers.UsedResource.stride == 0metadata always corresponds toV#.STRIDE == 0in the runtime descriptors (vs. missing metadata where droppingvindexwould be wrong).Closing this PR rather than leaving an unverified metadata-to-descriptor assumption in the review queue.
Pull request closed