Shaders: accept loaded buffer descriptors rewritten with base intact (#815) #2388
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!2388
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2388/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 12:30 UTC · original
fuzeofficlal:fix/shader-rewritten-buffer-descriptors-815→main· +540 −11 · 2 files · 1 commits · closed without mergingSummary
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
@welisonzika14-jpg on GitHub · 2026-11-25 13:08 UTC · original
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.
@fuzeofficlal on GitHub · 2026-11-25 15:56 UTC · original
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).@Marvisak on GitHub · 2026-11-25 16:03 UTC · original · edited 2026-11-25 18:45 UTC
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
@fuzeofficlal on GitHub · 2026-11-25 16:51 UTC · original
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.@fuzeofficlal on GitHub · 2026-11-26 03:06 UTC · original
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