Shaders: trace multi-term, scaled, masked, and phi-joined addresses in resource tracking #645
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/645"
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 nathanbzrr on 2026-11-24T06:06:16Z.
Summary
Fixes five resource-address tracking failures in
crates/victory-shader/src/resource.rsand adds SSA-dominance-safe relative offset lowering incrates/victory-shader/src/emit/lower.rsblocking compute, raytracing/BVH, and multi-term buffer shaders:RootType::Constantsdword 0 was treated as a pointer base wheneverparam_ofsaw dword0, colliding with real base pointers ("an address not from a root parameter","an offset from a root parameter", or"an address from a root parameter that is no address").(base + row) + col, orbase + dynplussoffset/vaddr) discardedbase.s_addk_i32,s_lshl{1..4}_add_u32,v_lshl_add_u32,v_add3_u32,v_add_nc_i32, subtractions on the minuend, aligned constants_or_b32/v_or_b32, and address-localv_mov_b32->v_readfirstlane_b32/v_readlane_b32) were untraced.v_add_co_ci_u32(want, 0, _), skipped table dynamic carries (high == None), and did not strip VA-preservingandmasks (mask & 0xFF == 0xFF).if/else) and loop-carried induction pointerPhis failed immediately with"an address from a phi".Changes (
crates/victory-shader/src/resource.rs,emit/lower.rs,emit/valu_tests.rs)RelOffset { value, base, extra_dynamic }toAddress(keepingAddress: Copyand keepingdynamicpopulated for downstream readers such astranslate.rs).sum_valuetoTable,ResourceHeap,SamplerHeap, andDescriptor.Phibase validation (requiring at least one non-cyclic edge and a matchingbaseacross all non-cyclic edges), multi-term retention (multi: bool), and all listed GFX10 address ops without double-countings.offsetorextra_dynamic.high_half,carried(Term, Term), andSource::Builtmask stripping (set_bits) to acceptv_add_co_ci_u32,Term::Const(0)table carries, VA masks, and high-half phis.address_offsetandrel_offsetinemit/lower.rswith per-call local caching for non-phi expressions and globaladdr_phiscaching resolved infill_phisto preserve DXIL SSA dominance across blocks, wired intoflat(),code_smem(), andbuilt_offset().resource.rsand 3 end-to-end DXIL + D3D12 GPU/WARP compute dispatch tests (root_srv_*) inemit/valu_tests.rs.Verification
Isolated verification on branch
shader/resource-address-tracing(499bd98):rustfmt --edition 2024 --config skip_children=true --check crates/victory-shader/src/resource.rs crates/victory-shader/src/emit/lower.rs crates/victory-shader/src/emit/valu_tests.rs(passed)cargo test -p victory-shader -- --test-threads=1(77 passed, 0 failed, 0 ignored)VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-shader root_srv_ -- --test-threads=1(3 passed, 0 failed, 0 ignored, 74 filtered out)cargo clippy -p victory-shader --all-targets(0 warnings)cargo xtask policy(151 files ok)No game files. AI-assisted; reviewed and verified with the tests above.
Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T06:15:37Z.
Review: APPROVED
Tested on Windows 11 with Rust 1.98.1 (x86_64-pc-windows-msvc).
oot_constants_dword0_is_offset_not_base, scaled_subtracted_add3_addk_and_aligned_or_addresses, high_half_carry_va_mask_and_table_carry, and phi_joined_and_loop_carried_addresses) passed.
oot_srv_s_lshl2_add_u32_with_root_constant_dword0,
oot_srv_two_term_v_add_co_and_v_lshl_add,
oot_srv_loop_carried_pointer_induction_phi) passed.
Imported from Marvisak/VIctory. Originally posted by xiao47576-glitch on 2026-11-24T07:49:56Z.
I tested PR #645 (
499bd98) againstmain(d2a4bae) on Windows Server 2025 using D3D12 WARP. Main rejected a root SRV plus a byte offset from the first root-constant dword. On this PR, both operand orders read the expected values at offsets 0, 4, 48, and 112 bytes, plus a fixed 12-byte load offset.I found one carry case the tracker still accepts:
Here
s[4:5]holds the root SRV address ands10is the byte offset. When the offset is zero, the comparison sets SCC to 1 even though the low add produced no carry. The tracker also accepts a high add with immediate 1 and a signed low add.Download the tested source patch
With the patch applied, the tracker rejected all three cases. All 12 valid WARP reads returned the expected values, and all 78 shader tests passed. Only the valid reads were dispatched on WARP. The effect on the opening cutscene in #255 is still untested. AI-assisted.
Imported from Marvisak/VIctory. Originally posted by TrashTalker3460 on 2026-11-24T08:13:51Z.
Offline translation and validation of
499bd98againstmainatd2a4bae: +32 programs validate, 0 regressions.Setup:
shaders.rpfplus its executable and 16 DLLs: 26,148 programs.victory translate --validate --list, validated with DXC 1.9 (1.9.2609.5).mainplus #235 for the Linux build, and a local hook that runsdxvoff Windows; neither touches translation.What changed:
main, not with this PR): 0.resources: an address from a phi(Defect E).resources: an address not from a root parameter.an address not from a root parametertoemit: a descriptor read only as data. It was refused onmaintoo, so this isn't a regression.an address from a phi. All 4 are in the same shader group and fail at nearly the same offset (0x508/0x510), so they are likely one pattern the phi tracing doesn't yet accept.Caveat: these numbers are from
mainatd2a4bae.mainhas moved since (nowdd273df).crates/victory-shader/src/emit/valu_tests.rsconflicts with #140 (v_cmp_class_f16), which first appears at merge80c0d12.main. I can rerun after a rebase.Imported from Marvisak/VIctory. Originally posted by slint6614-dev on 2026-11-24T09:24:29Z.
Measured on the full retail shader pack (26,503 containers) with
victory translate --validate --pipelines(pipelines created on an AMD RX 9070, Windows 11, dxil.dll from SDK 10.0.26100). Counts are emitted / validated / pipelines. This PR conflicts with current main (lower.rs), so it was measured on its own base, against main1f858b0before #612 (VS/PS 12272 / 12172, CS 1693 / 1670, MS 8191 / 8129).CS 1721 / 1698 (+28 validated): "resources: an address from a phi" 28 → 4 and "an address not from a root parameter" 73 → 64. VS/PS +4 validated, MS unchanged.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T10:19:52Z.
Review: COMMENTED
Conflicts with current main (
ffe310e) —resource.rs(+1326/-96) andlower.rs(+593) are both hot after the recent shader merges; needs a rebase before anything else.I can't responsibly approve a 2329-line tracer rework on a conflicted base without running it, and the merged tree is exactly where the five "Defect A-E" fixes interact with #566's waterfall changes. The structure (SSA-dominance-safe relative offsets, multi-term/scaled/masked/phi-joined address tracing) sounds like the right direction for the resource-tracking failures, and the +295 lines in
valu_tests.rssuggest host coverage on Windows.After a rebase I'll run
cargo test -p victory-shader --lockedon macOS and do a full pass on the tracer invariants (thesumscache from #139 and the dominance reasoning are the parts most likely to interact badly with other in-flight PRs).Imported from Marvisak/VIctory. Originally posted by pablogonz12 on 2026-11-24T16:20:43Z.
Measured on Linux (RX 9070 XT, RADV/Mesa 26.3.1, GE-Proton11-14, vkd3d-proton master), head
499bd98merged onto a tree that already carries other merged fixes (its offline base is 692 of 751 of the world shader set, not main's number):victory translateof the 751-program world set: 692 -> 700; all 700 pass dxil-spirv andspirv-val --target-env vulkan1.3and build a RADV pipeline.cargo test -p victory-shader --lib: 122 pass, 1 known pre-existing failure, 1 ignored; no new failures.cargo xwin clippy --workspace --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.Not tested: in-game on this branch; native Windows.
Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-24T21:55:25Z.
Rebased onto
origin/main(ffe310e) at6817902and addressed the scalar-carry review finding.@catminou4 @xiao47576-glitch
Rebase integration (
ffe310e)#566waterfall tracking/lowering incrates/victory-shader/src/resource.rsandcrates/victory-shader/src/emit/lower.rs, preserving the 4-argumentresource::track(..., st)signature (#801).#612'sread_phisworklist inemit/lower.rs(fill_phis) alongsidepending_addr_phis.#140(v_cmp_class_f16_matches_rdna2) and wrappedrun_root_srv_caseswithONE_AT_A_TIME.lock()(#433) incrates/victory-shader/src/emit/valu_tests.rs.Soundness fix (
s_addc_u32/s_subb_u32carry)crates/victory-shader/src/resource.rssos_addc_u32ands_subb_u32require:Term::Const(c) if c == 0, rejecting non-zero immediates), andsccvalue traceable to a matchings_add_u32on the corresponding low-half value (including loop-carriedphiinduction chains), rejecting clobberedsccproducers (s_cmp_eq_u32,s_add_i32, or unrelateds_add_u32).resource::tests::scalar_carry_requires_matching_add_u32_scc_and_zero_const.Verification (
6817902)rustfmt --edition 2024 --check crates/victory-shader/src/emit/valu_tests.rs: clean (resource.rsandemit/lower.rsonly retain pre-existing upstream formatting diffs onorigin/main).cargo clippy --workspace --all-targets --locked -- -D warnings: clean.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.cargo test --workspace --locked:351 passed; 0 failed; 6 ignored(victory-shader:129 passed; 0 failed; 1 ignored;xtask:4 passed).VICTORY_WARP=1 cargo test -p victory-shader --locked -- root_srv:3 passed; 0 failed.Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-24T22:03:22Z.
Closing this PR as superseded by recent
main(70564ae):27c3dc9(Shaders and GPU: title memory at raw addresses through a page table, decision 0005) and0f63757(GPU: root views of programs that use title memory go through the page table) now intercept the data-computed address failure classes inTracer::address()(including"an address from a phi","an address with two computed terms","an address with an untracked high half","an address not from a root parameter", and"an address from a root parameter that is no address") and route them through theMEMORYpage table, alongsideUSER_DATAhandling for spilled compute root parameters.27c3dc9~2,388-line tracer rework would conflict with decision 0005 and0f63757's root-view page-table aliasing model; any remaining descriptor-heap address edge cases can be targeted cleanly in a focused follow-up PR onmain.Thanks @catminou4 and @xiao47576-glitch for the detailed reviews!
Pull request closed