Shaders: handle redundant partial descriptor writes and lane-preserving VGPR moves (#750) #1229
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!1229
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1229/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?
@Ctrl-Alt-Haze on GitHub · 2026-11-24 16:35 UTC · original
Ctrl-Alt-Haze:fix/resource-vgpr-descriptors→main· +2381 −101 · 3 files · 2 commits · closed without mergingSummary
Addresses #750 (
joined_descriptor_redundant_partial_write) and extendsvictory-shaderresource tracking for"a descriptor read from the first lane of computed VGPRs".(Note: #1182 also addresses #750 for plain
v_mov_b32; this PR covers both #750 and the broader computed-VGPR move/extract/select family described below.)Changes
crates/victory-shader/src/structure.rs:Bools::var_booland non-mutatingBools::meet_with_facts(meet_facts_in) to enforce equivalence/complement groups overAtom::Lanes and check leaf consistency without cloning or mutatingBools.crates/victory-shader/src/resource.rs:feasible,canon_cmp,cmp_leaf_okwith 1D integer constant bounds) acrossruns,lane_phi,lane_select,waterfall, andlane_value_equals.lane_value_in,redundant_write,lane_value_equals,split_term): when a guardedlane_copyorv_cndmask_b32failsruns(site, known), keeps the prior register value iffoldand the written value provably evaluate to the same 32-bit word on every feasible active lane inknownwherereach[site.0]andguardhold.lane_copy(guarded by!clamp && omod == 0) for sound lane-preserving moves, selects, and 32/64-bit word extracts (v_mov_b32incl.DWORDSDWA,v_swap_b32, identityv_or_b32/v_and_b32/v_xor_b32/v_add_*/v_sub*/v_lshlrev_b32/v_lshrrev_b32/v_ashrrev_i32/v_mul_lo_u32/v_min_*/v_max_*/v_bfi_b32,v_perm_b32,v_alignbit_b32/v_alignbyte_b32, 64-bit 0/32-bit word shifts, and constant-mask / equal-operandv_cndmask_b32with!self.p.wave64guard on 32-bitu32::MAXliterals).lane_select(same_maskand single-feasible-branchv_cndmask_b32) andwaterfall(usinglane_value(..., &loop_known)).resource::tests, including #750 image & sampler reproducers, swapped/negated compares, lane-preserving moves/extracts, and negative soundness controls (non-identity writes, widened masks, flipped arms, non-identity ALU/perm/shifts, guardedv_swap_b32, mixedlane_selectmasks, and Wave64 literalu32::MAXmask refusal).crates/victory-shader/src/emit/waterfall_tests.rs:lanes_sample_texture_after_redundant_partial_write,lanes_sample_joined_sampler_after_redundant_partial_write,lanes_sample_after_vgpr_swap_and_word_extract) validated withdxil.dlland executed on RTX 5070 Ti + WARP.Verification
32.0.16.2135), WARP (VICTORY_WARP=1), Windows SDK10.0.26100.0dxil.dll, Rust1.98.1, baseffe310eb.cargo xtask policy:154 files okcargo clippy --workspace --all-targets --locked -- -D warnings(default &--all-features): passedcargo test --workspace --locked:352 passed, 0 failed, 6 ignored(victory-shader130/1 ign)cargo test -p victory-shader --features host --locked(RTX 5070 Ti + WARP):130 passed, 0 failed, 1 ignoredVICTORY_WARP=1 cargo test -p victory-shader --features host --locked(WARP):130 passed, 0 failed, 1 ignoredcargo test -p victory-gpu --features diagnostics --locked&VICTORY_D3D12_WARP=1:53 passed, 0 failed, 1 ignoredeachrustfmt --edition 2024 --checkon modified files: zero diffs on added/modified lines (waterfall_tests.rscompletely clean).AI use: Written and verified locally with an AI coding swarm (
gemini-4-hydrogen-high), then independently audited and tested on RTX 5070 Ti + WARP.@pablogonz12 on GitHub · 2026-11-24 17:27 UTC · original
Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main
ffe310eplus #1017 (main's host build fails without it:E0425 host_resource), then the four-stage offline check over 768 programs (751-program world dump + 52-program BVH capture, 35 duplicate containers skipped).No program gained or lost and the failure table is identical to the base, reason for reason: nothing in this capture reaches the class you handle, so this is a no-regression result only (same 10 SPIR-V validation failures as the base).
Not tested: in-game.
@Zipettte on GitHub · 2026-11-24 17:59 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 7b4cb23:
cargo test -p victory-shaderpasses, 130 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@Ctrl-Alt-Haze on GitHub · 2026-11-24 18:21 UTC · original
@pablogonz12 Thank you for running the 768-program Linux/RADV (
dxil-spirv/spirv-val) check and confirming zero regressions on this branch!@Ctrl-Alt-Haze on GitHub · 2026-11-24 18:28 UTC · original
@Zipettte Thanks for verifying
7b4cb23on the AMD Radeon RX 7700 XT!@SantannaCarlos on GitHub · 2026-11-24 18:43 UTC · original
Scope of the PR, as described: handle redundant partial descriptor writes (#750) and lane-preserving VGPR moves/extracts/selects (
v_mov_b32,v_swap_b32, identityv_perm_b32/v_alignbit_b32, 64-bit shifts by 32, same-operandv_cndmask_b32…) in front of a waterfallv_readfirstlane_b32, so that fewer programs stop with "a descriptor read from the first lane of computed VGPRs".Measurement (title data, local; counts only)
main(ffe310e) + #1229 (7b4cb23),victory translate --validate --liston the 38 containers that stop with that reason onmain: 38 of 38 still stop with the same reason, at the same instruction.shaders.rpfwith and without #1229: identical totals, 0 programs gained, 0 lost; the 39 programs with this reason (38 containers; mostly foliage mesh programs) are the same programs at the same offsets.cargo test -p victory-shader -- --test-threads=1, 175 passed), and nothing regresses in the counts. So the PR looks safe, but it does not reach the pattern these programs use.The pattern that stays out (instructions only)
One representative program; the others share the shape:
v_cmp_eq_u32 s[6:7], vX, sYthens_and_saveexec_b64 s[64:65], s[6:7](then arm),s_andn2_b64 exec, s[64:65], exec+s_cbranch_execz <join>(else arm), ands_mov_b64 exec, s[64:65]at the join.v79..v82. Those registers keep values computed before the split (abuffer_load_dwordx3and float math such asv_sub_f32/v_mul_legacy_f32).s_load_dwordx4 s[8:11], s[24:25], <imm>(a sampler from a descriptor table, uniform), thenv_mov_b32 v79..v82, s8..s11.v_readfirstlane_b32 s28..s31 ← v79..v82, twov_cmp_eq_u64,s_and_saveexec_b64,image_sample_lz …, s[28:31],s_xor_b64 exec, exec, …,s_cbranch_execnzback to the loop head.Where the tracker stops (confirmed by instrumenting
per_lanelocally): the four words reachper_laneas the then-arm values:v_sub_f32,v_mul_legacy_f32and twobuffer_load_dwordx3results, defined before the split.lane_select/lane_phido not resolve the join, and the refusal names the first varying word, an arithmetic instruction, hence "computed VGPRs". It is not the loop-head phi and not a move the PR handles: thev_movcopies are on the other arm of a per-lane join.So the descriptor is "uniform sampler in the else lanes, non-descriptor data in the then lanes". The console runs the waterfall over both kinds of lanes (sampling with whatever the then lanes hold). Whether the then lanes' results are dead is not proven here: the sample's result is used afterwards under the full mask, and I did not follow it further.
Suggestion for the PR (or a follow-up)
Loaded) and whose other side is not a descriptor only when the join's condition is the same mask that later selects which lanes use the sample's result. Then the lanes holding computed data never consume what they sample, and the descriptor side can be used for the waterfall. This needs a mask-liveness check from the join to the uses of the sample's result; without it the case should keep refusing, since we have not shown that the then lanes' results are dead.v_movon one arm, untouched VGPRs on the other, waterfall after the join) would pin the case.Counts and instruction shapes only; no title bytes. Instrumentation was local and is not part of any branch.
@Ctrl-Alt-Haze on GitHub · 2026-11-24 19:29 UTC · original
@SantannaCarlos Thank you so much for testing
#1229againstshaders.rpfand pinning down the exact 4-step foliage mesh pattern!I've pushed
f55ba49to implement your exact suggestion soundly:What changed (
crates/victory-shader/src/resource.rs,emit/waterfall_tests.rs)site: Sitethroughdescriptor/classify/phi/select/per_lane/lane_select/lane_phi.Tracer::uses) and a strict forward per-lane deadness proof (Tracer::dead_for_bad_lanes):siteis a pure VGPR-producingImageorBufferread (stores, atomics, LDS,tfe/lwe, SGPR/SCC writes stay refused).(Value, Known)forward throughPhis (enforcing loop invariance viabool_born_beforeon backedges so waterfall loop-header phis preservingsite'sdstare handled soundly),v_cndmask_b32mask narrowing (Wave32 & Wave64 viaStructured::mask_bits),v_swap_b32, and pure per-lane VALU ops (tracking partial-destination overwrites includingsdwa,*_f16/*_u16/*_i16/*_b16,v_cvt_f16_f32,v_fma_mix*_f16, and_d16buffer loads).lane_phi/lane_select, when one arm resolves to a valid descriptorSourceand the other arm fails, accepts the descriptor side only whendead_for_bad_lanesproves the failing arm's lanes never consumesite's output; otherwise it keeps refusing with"a descriptor read from the first lane of computed VGPRs".lanes_sample_joined_sampler_with_dead_non_descriptor_armvalidated bydxil.dlland executed on RTX 5070 Ti + WARP.Re-verified on
f55ba49cargo xtask policy:154 files okcargo clippy --workspace --all-targets --locked -- -D warnings(default &--all-features): passcargo test --workspace --locked: pass (victory-shader135/0/1 ign)cargo test -p victory-shader --features host --locked(RTX 5070 Ti &VICTORY_WARP=1):135 passed, 0 failed, 1 ignoredeachcargo test -p victory-gpu --features diagnostics --locked(RTX 5070 Ti &VICTORY_D3D12_WARP=1):53 passed, 0 failed, 1 ignoredeachIf you get a chance to re-run
victory translate --validate --liston those 38 containers withf55ba49, I'd love to hear how many clear!AI-assisted fix (
gemini-4-hydrogen-high), independently audited and tested on RTX 5070 Ti + WARP; no game data.@SantannaCarlos on GitHub · 2026-11-24 20:21 UTC · original
Thanks for implementing the dead-lane rule in
f55ba49. Measured again the same way (title data, local; counts only):ffe310e) + #1229 atf55ba49: 38 of 38 still stop with the same reason, at the same instruction.shaders.rpf, integration stack with and withoutf55ba49: identical totals (VS+PS 12231 emitted / 12155 validated, CS 1480/1445, MS 8214/8152). 0 programs gained, 0 lost; dxil.dll validator failures unchanged (234 → 234). The 39 programs with this reason are the same programs at the same offsets.cargo test -p victory-shader -- --test-threads=1passes on the PR alone (135 passed, including the four new foliage-shaped tests) and merged into our stack (180 passed), on an RTX 4070.Why the rule does not fire on the title's programs. The synthetic shader matches the shape up to the waterfall: per-lane if/else, a uniform sampler loaded and copied by
v_movon one arm, computed VGPRs left on the other, a full-mask waterfall after the join. The difference is what happens to the sample's result.v_mul_legacy_f32under the full mask, then severalv_fmac_f32/v_fma_mix_f32accumulations, still under the full mask.v_cndmask_b32and no guarded consumer separates the then-arm lanes again.What remains is a question of intent, not of tracking:
Either way, in our measurement the PR changes nothing for the title's programs and regresses nothing (same totals, no validator changes).
Counts and instruction shapes only; no title bytes.
@Ctrl-Alt-Haze on GitHub · 2026-11-24 20:29 UTC · original
Thanks @SantannaCarlos for re-testing
f55ba49on RTX 4070 (135standalone /180in the stacked build, 0 regressions) and confirming why those remaining 38 containers stop at that point (full-maskv_mul_legacy_f32/v_fmac_f32/v_fma_mix_f32consumers without re-masking).We'll keep Option 1 — keeping the strictly sound dead-lane proof rule as-is rather than substituting a fallback descriptor on potentially live non-descriptor lanes — unless the maintainers explicitly prefer adding an opt-in/logged fallback shortcut (Option 2).
@Ctrl-Alt-Haze on GitHub · 2026-11-24 22:00 UTC · original
Rebased onto upstream
main(70564ae) atda25359(mergedself::meetpruning from70564aeintofeasiblealongside bothspilled/spill_atanduses).Verified locally on Windows 11 x64 / NVIDIA GeForce RTX 5070 Ti + WARP:
cargo xtask policy: passed (174 files ok)cargo clippy --workspace --all-targets --locked -- -D warnings(default &--all-features): passed--locked -- --test-threads=1):victory1 passed,victory-core11 passed,victory-formats23 passed / 4 ignored,victory-game15 passed,victory-loader25 passed (22 unit + 2load_probe+ 1title_dlls),victory-pipeline4 passed,victory-hle99 passed (97 unit + 1fidelityfx+ 1no_dll_planting),victory-pe7 passed,xtask4 passed;victory-gpu76 passed / 2 pre-existing70564aefailures (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views) / 1 ignoredcargo test -p victory-shader --features host --locked(hardware):221 passed; 3 failed; 2 ignored(the 3 failures are pre-existing on cleanupstream/main70564aeon RTX 5070 Ti:stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,synthetic_tests::gathers_at_a_level_match_the_hardware)VICTORY_WARP=1 cargo test -p victory-shader --features host --locked:222 passed; 2 failed; 2 ignored(pre-existinggathers_at_a_level_match_the_hardware+permutes_read_the_lane_named_and_zero_from_lanes_left_outwhich skips underVICTORY_WARP=1and passed on RTX hardware)@Marvisak on GitHub · 2026-11-25 00:35 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.rebased, but still 2,130 lines rewriting main's lane-value tracking for #750 and 'first lane of computed VGPRs', classes main brought to 0 on the title's programs; no count of programs it adds on main.
If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed