Shaders: lower indexed buffer accesses with used-resource stride 0 as raw #2357
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2359"
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 Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T11:44:25Z.
Part 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.Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T11:55:43Z.
Review: APPROVED
Static review and local verification of
4e14e76:emit::stride_tests::indexed_buffer_accesses_with_stride_zero_lower_as_raw_while_one_to_three_refuse(passed)cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warningscargo xtask policy: 182 files okApproving.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T11:56:18Z.
Review: APPROVED
Tested locally: merged into main
940d32f69b,cargo test -p victory-shader --lockedon macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — indexed buffer accesses lowered with used-resource strides.upstream-sync referenced this pull request2026-11-25 13:02:56 +00:00
Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-25T13:35:00Z.
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.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T18:27:58Z.
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
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T19:37:44Z.
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