Shaders: accept loaded buffer descriptors rewritten with base intact (#815) #2386
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2388"
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-25T12:30:28Z.
Summary
Allows non-format 4-dword
V#buffer descriptors (Fields::BufferandFields::Smem) whose stride, record-count, or flag fields were rewritten in place via pure SCC-free scalar ALU afters_load_*to resolve toSource::Loaded, provided the 48-bit virtual base address (w0andw1[15:0]) is provably preserved (andw1is untouched whenidxen = true).In the native compute pipeline measurements on
mainreported in #815 (#issuecomment-7160878577world-run breakdown),"a descriptor changed after loading"is the single largest refusal reason (316 distinct compute programs), where the shader compiler converts structured buffer descriptors to raw views or adjusts record counts/flags with scalar ALU sequences outsidemade_raw's single 6-instruction FidelityFX pattern.Soundness Guards
Fields::SmemandFields::Bufferwith!inst.name().contains("format") && dwords == 4(threaded throughclassify,phi,select,per_lane,lane_select, andlane_phi). 8-dwordT#image descriptors, 4-dwordS#samplers, and formattedtbuffer_*_format_*/buffer_*_format_*accesses remain rejected if modified.w0(BASE_ADDRESS[31:0]) must be the unmodifiedValueinst.writes[first].1of thes_load_*.Fields::SmemorFields::Buffer { idxen: false, .. }),preserves_low16provesw1retains bits[15:0](BASE_ADDRESS[47:32]) ofinst.writes[first + 1].1(e.g.s_and_b32withmask & 0xFFFF == 0xFFFF,s_or_b32/s_xor_b32/s_andn2_b32withlow16_is_zero,s_bitset0/1_b32on bit>= 16).Fields::Buffer { idxen: true, .. }),w1must equalinst.writes[first + 1].1unchanged soSTRIDE(w1[29:16]) andSWIZZLE_ENABLEmatch the host view.w1,w2, andw3must derive via pure SCC-free scalar ALU exclusively from constants andinst.writes[first..first + 4]of that descriptor's load (rejecting cross-descriptor dwords from widers_load_dwordx8/x16loads or external SGPRs).Verification
resource::tests::rewritten_loaded_buffer_descriptors_keep_base_and_reject_unsafe_edits: covers valid MUBUF, SMEM,idxenw2/w3, andphi-joined rewrites, and verifies refusals for modifiedw0, modifiedw1[15:0], modifiedw1stride withidxen = true,tbuffer_load_format_x, cross-descriptors_load_dwordx8mixing, and rewritten 4-dword samplers.emit::valu_tests::rewritten_loaded_buffer_descriptor_executes_on_gpu_and_warp: validates DXIL withdxil.dlland executes on both hardware GPU andWARP.cargo clippy -p victory-shader --lib --tests --all-features --locked -- -D warnings&cargo xtask policypass.Refs #815
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T12:41:46Z.
Review: APPROVED
Tested locally: merged into main
940d32f69b,cargo test -p victory-shader --lockedon macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — loaded buffer descriptors rewritten with base accepted.Imported from Marvisak/VIctory. Originally posted by welisonzika14-jpg on 2026-11-25T13:08:06Z.
First run on NVIDIA hardware here, as far as I can see. RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head
a276e8bmerged ontomain940d32f,cargo test -p victory-gpu -p victory-shader --lib --no-fail-fast.The PR's new test(s) pass on this card:
emit::valu_tests::rewritten_loaded_buffer_descriptor_executes_on_gpu_and_warp,resource::tests::rewritten_loaded_buffer_descriptors_keep_base_and_reject_unsafe_edits. The rest is the same asmainon this card: the 5 known NVIDIA failures from #1744 (2 view heap cap tests invictory-gpu, 3 invictory-shader), nothing new.One run, unit tests only, title not run.
Written with AI help (Claude/Kiro); the numbers are from runs on my machine.
Imported from Marvisak/VIctory. Originally posted by RomainKH on 2026-11-25T14:26:23Z.
Review: COMMENTED
I read the tracing change and ran a probe on the head (
a276e8b) on macOS arm64, CPU tracking only (cargo test -p victory-shader --lib).derived_from_loadaccepts any SCC-free rewrite of dword 3, and of dword 1 above bit 15, as the loaded descriptor. Some of those bits change the addresses a MUBUF access reaches. The access then goes through the host view made from the descriptor in memory, which still has the old bits.Here are four rewrites that
mainrefuses witha descriptor changed after loadingand that this head returns asSource::Loaded. Each comes after the test'ss_load_dwordx4 s[8:11]and beforebuffer_store_dwordx4 v[0:3], v7, s[8:11], 0 offen:s_or_b32 s11, s11, 0x00800000ADD_TID_ENABLEs_or_b32 s11, s11, 0x00600000INDEX_STRIDEs_or_b32 s9, s9, 0x80000000SWIZZLE_ENABLEs_min_u32 s10, s10, 16NUM_RECORDSI don't know whether any of the 316 programs does this. The patterns the PR targets (stride cleared, records scaled,
OOB_SELECTset) don't. Still, the first three now translate into a wrong access wheremainrefuses by name.A narrow fix: require dword 1 bit 31 and dword 3 bits 23:21 to come through from the load unchanged, as
preserves_low16already does for the base. For example, generalise it to a mask, with0x8000_FFFFon dword 1 and0x00E0_0000on dword 3. The record count could then get a// shortcut:note saying the host view's bound is the one in memory.The probe below passes on
mainand fails on this head (accepted [880bff0b, 00800000]), so it can go intoresource::testsas is:Unrelated to the above: this head merges cleanly with #2324, #2046, #2078 and #2342 together on top of
main940d32f.cargo test -p victory-shader --lockedon that merge: 158 passed, 0 failed, 2 ignored (macOS, so the Windows-only GPU checks did not run).AI-assisted (Claude Code); the results are from runs on my machine.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T15:56:02Z.
Thanks @RomainKH — great catch on the MUBUF addressing bits! Rebased onto
da82e444and updated in4e642d2e:preserves_low16topreserves_bits(mask)/bits_zero(mask).Mubuf { idxen: false },w1now requires0x8000_FFFF(SWIZZLE_ENABLEbit 31 plus base bits15:0) andw3requires0x00E0_0000(ADD_TID_ENABLEbit 23 andINDEX_STRIDEbits22:21) unchanged from the load;Mubuf { idxen: true }keeps all ofw1unchanged plus0x00E0_0000onw3;Smemkeeps0x0000_FFFFonw1.// shortcut:note onw2(NUM_RECORDS) and includedrewrites_that_change_addressing_are_refusedinresource::tests(withCo-authored-bycredit).Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T16:03:12Z.
Automated triage for the maintainers.
Needs work.
Tracer::rewritten_bufferincrates/victory-shader/src/resource.rslets a loaded 4-dword non-format buffer descriptor resolve toSource::Loadedafter scalar-ALU rewrites ofw1tow3. The conditions are that the base (w0,w1[15:0]) and the addressing bits (SWIZZLE_ENABLE,ADD_TID_ENABLE/INDEX_STRIDE) are provably kept (preserves_bits/bits_zero), and that every word comes only from that load's four dwords (derived_from_load). The rebase onto67e8ae1(d135178) has dropped the unrelated rustfmt hunks, so the diff now shows only the change and its tests. CI (check): passing.What still blocks it is evidence for the semantics. By the PR's own
// shortcut:note, a rewrittenNUM_RECORDS(w2) is ignored: the host view keeps the bound of the descriptor in memory. For unindexed access, a rewritten stride is ignored too. That is safe only if the title's rewrites never shrink the range or rely on the new bound. Otherwise reads the console would clamp to zero go past the intended range on the host.On your reply: understood that you have no shader corpus. Either of these would move it forward:
translate --validatecount before and after this PR, with which rewrite patterns occur (opcode sequences or counts only, no shader data).w2, or a rewritten stride on unindexed access, is still refused. Then only the rewrites whose effect the host view really reproduces are accepted, and the shortcut goes away.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T16:51:31Z.
Rebased onto
67e8ae14(d135178f) and stripped the unrelatedrustfmthunks fromcrates/victory-shader/src/resource.rs(track,phi, etc.) andcrates/victory-shader/src/emit/valu_tests.rsso the diff contains only the descriptor rewrite change and its tests.Regarding the offline
translate --validatecount and opcode breakdown on the 316 programs from #815: I do not have the title shader packs locally (all testing here uses synthetic shaders only), so I cannot run that corpus measurement myself — if a tester with the #815 shader set can run before/aftertranslate --validateand share the rewrite counts/patterns, I am happy to tighten or adjust the guard accordingly.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T03:06:02Z.
Thanks for the detailed review. I agree that keeping the 48-bit base intact is not sufficient when lowering through the original loaded host view: changes to
NUM_RECORDS(w2),STRIDE(w1[29:16]), orOOB_SELECT(w3[29:28]) can alter guest bounds or addressing semantics relative to the unmodified host descriptor. Since all of the positive rewrite cases in this PR rely on those fields and there is no demonstrated hint-only shader case here, I'm closing this PR and will revisit if we have a specific title rewrite with proven bounds equivalence or explicit lowered bounds checks.Pull request closed