Shaders: govern pixel discard by last exp VM (Valid Mask) and guard pixel MRT exports #1569
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1570"
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 ESAT586 on 2026-11-24T19:16:30Z.
Summary
Fixes VIC-BT-011 from #1242: propagates the RDNA2
EXPVM(Valid Mask) bit fromgfx10::fieldsthroughio::Exportintoemit::lower, governs pixel shaderdx.op.discardby theEXECmask of the lastexp ... vmexecuted on each path, and allows guarded per-MRT pixel exports.(Note on related open PRs: #655 guards conditional non-final exports and #1473 tracks
doneexport state across mixed joins, but neither propagatesExport::vmor decouplesVMfromDONE/ last-VM-wins pixel survival.)Root Cause
crates/victory-shader/src/gfx10/fields.rsalready decodedvm: bit(w0, 12)onFields::Exp, butcrates/victory-shader/src/io.rsdiscardedvm(..) when constructingio::Export.crates/victory-shader/src/emit/lower.rseagerly emitteddx.op.discard(!guard)ate.donewhile rejecting conditional non-donepixel exports (Err("a conditional export")) and tracking only a single-passexported: Vec<bool>fore.done.expwithVM=1, notDONE=1:exp mrt0 ... vm(partialEXEC) followed byexp mrt1 ... done(vm=0, fullEXEC) must still discard the lanes that were inactive atexp mrt0 ... vm.exp mrt0 ... vm(fullEXEC) followed byexp mrt1 ... done(vm=0, partialEXEC) must not discard the lanes that were inactive atexp mrt1.exp mrt0(fullEXEC) followed byexp null ... done vm(partialEXEC) must keep active lanes alive with theirMRT0color while discarding inactive lanes.vm=1exports where the second runs under widerEXECmust let the latervm=1overwrite the earlier valid mask (impossible if an irreversibledx.op.discardfired eagerly at the first export).Changes
crates/victory-shader/src/io.rs: Addedpub vm: booltoExportand populated it fromFields::Exp::vm.crates/victory-shader/src/emit/lower.rs:exported: Vec<bool>withcompute_vm_lattice()(static fixpoint over reachable blocks) + per-block SSAvm_live: VmVal(False,True,Dyn(V)) +vm_phispopulated infill_phis().vm_liveon every pixelexpwithvm == true(falling back todoneonly if a pixel shader has novm == trueexport at all), emittingdx.op.discardonce atLaneExit::End(zero extra DXIL instructions or PHIs for standard unconditional single-export shaders).storeOutputwrites inbegin_guarded(guard)/end_guarded()so conditional non-doneMRT writes and per-MRT overwrites execute only for activeEXEClanes (non-pixel, non-mesh stages still reject conditional exports).crates/victory-shader/src/emit/host.rs: Added#[cfg(test)] Host::draw_mrtsupporting cleared multi-MRT RGBA32F render targets and readback (withHost::drawdelegating todraw_mrt(..., 1)).crates/victory-shader/src/emit/mod.rs: Addedpixel_export_valid_mask_and_multi_mrt_match_rdna2, validating all 7 shaders withdxil.dlland rasterizing fullscreen triangles into 1- and 2-MRT4x4RGBA32F targets on both hardware GPU and WARP:exp mrt0 vm(partialx < 2) → restoreEXEC→exp mrt1 done(vm=0, fullEXEC): right half discarded on both MRTs.exp mrt0 vm(fullEXEC) → narrowEXEC→exp mrt1 done(vm=0, partialx < 2): all pixels survive (MRT0 = REDeverywhere, leftMRT1 = BLUE).exp mrt0(fullEXEC) →exp null done vm(partialx < 2): left survives withMRT0 = RED, right discarded.vm=1exports (exp mrt0 vmpartial →exp mrt1 done vmfull): lastvm=1wins, all pixels survive (MRT1 = BLUEeverywhere).exp mrt0 REDfull →exp mrt0 GREENpartial →exp mrt1 BLUE done vmfull):MRT0isGREENon left /REDon right,MRT1isBLUEeverywhere.s_cbranch_execzskippingexp mrt0 done vmto shareds_endpgm): left survives, right discarded viavm_livePHI.v_cmpx_lt_f32+s_cbranch_execnz→exp null done vmunderEXEC=0): left survives, right discarded.Verification
Ran locally on Windows 11 with NVIDIA GeForce RTX 3060 Ti, Microsoft WARP, and
dxil.dll:cargo test -p victory-shader --locked— 121 passed, 0 failed (including all 7 rasterized pixel readback cases on both RTX 3060 Ti and WARP, all validated bydxil.dll)cargo clippy --workspace --all-targets --locked -- -D warnings— passcargo clippy --workspace --all-targets --all-features --locked -- -D warnings— passcargo xtask policy— 154 files okRelated to #1242 (
VIC-BT-011).Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T19:20:47Z.
Review: APPROVED
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (
ffe310e),cargo test -p victory-shader --locked→ 96. Execution/valu tests are#[cfg(all(test, windows))]and were not run here.Pixel survival governed by the last
exp ... vm(Valid Mask) instead of onlydone: theVmLatfixpoint (Unreached/Const/Varying) classifiesvm_liveat each block entry, single-predecessor varying chains forward without a phi, multi-pred joins get an i1 phi filled infill_phis, andtracks_vmfalls back todonesemantics when no export sets VM. Conservative and loop-safe (fixpoint, not single RPO pass).host.rs::draw_mrtgeneralizes the test draw to N render targets for the MRT test. The valu testpixel_export_valid_mask_and_multi_mrt_match_rdna2covers it on hardware+WARP (Windows-only here).Note: this rewrites the same
exportedtracking that #1473 (also approved by me) extends — they touch the same hunks, so whichever lands second will need a rebase.Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T19:31:54Z.
Verified commit
2f88983on Windows 11 / AMD Radeon RX 9060 XT (RDNA4,gfx1200, SM 6.6) + WARP:cargo test -p victory-shader --lib: 121 passed, 0 failed, 1 ignored (including the new pixelexpVM / MRT export lowering and host execution tests).AI-assisted; synthetic tests only, no game files.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:31:03Z.
Automated triage for the maintainers.
This pull request no longer merges cleanly into
main(conflicts incrates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the currentmain. The earlier verdict (needs-work) was for an older state ofmain.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-25T11:15:33Z.
Rebased onto \main\ (\
940d32f) at $sha. Generalized \main's \discarded_at_done\ guard to \discarded_by_vm\ + \overwrites_unconditional_export\ so conditional pixel exports that would leave surviving lanes without a store for an output target stay refused (\n_export_before_a_discarding_done_export_stores_unguarded\ passes), while VM-discarded and overwriting conditional MRT exports work cleanly with zero undefined outputs. Verified on RTX 3060 Ti + WARP: \emit::tests\ 17/17 passed, strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-25T15:17:34Z.
Per the triage note on evidence for the
EXPVM(Valid Mask) bit:EXPmicrocode format,VMbit [12]):VM(Valid Mask): when set to 1, theEXECmask is sent as the pixel export's valid mask, and pixel shader survival tracks the valid mask sent withVM=1.DONE(bit [11]): marks the last export of a given type (color/MRT, pos, param).VMandDONEare independent control bits in theEXPencoding (bit 12 vs bit 11), a shader can carryVM=1on a non-DONEexport (or clear lanes viaEXECbefore a subsequentVM=1export), so tracking pixel survival viaVM=1rather than solelyDONE=1matches the RDNA2 ISA semantics.Happy to split the guarded MRT store (
begin_guarded) piece out if you prefer theDONE-based model in #1473, or keep both together here if you pick this line.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.