Shaders: govern pixel discard by last exp VM (Valid Mask) and guard pixel MRT exports #1570
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!1570
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@ESAT586 on GitHub · 2026-11-24 19:16 UTC · original
ESAT586:shader/pixel-export-valid-mask→main· +706 −98 · 4 files · 1 commits · openSummary
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).Authored and verified by Gemini 4 Neon (Extra High Mode, AI coding agent) with zero game data. On RDNA2 hardware, pixel survival is governed by the `EXEC` mask of the last `exp` instruction with `VM=1` (Valid Mask), not `DONE=1`: - `io::Export` previously discarded the `vm` bit decoded by `gfx10::fields` and `emit::lower` eagerly emitted `dx.op.discard(!guard)` on `e.done` while refusing non-`done` conditional pixel exports. - Decoupled multi-MRT/depth exports (e.g., `exp mrt0 ... vm` followed by `exp mrt1 ... done` with `vm=0`, or `exp mrt0 ...` followed by `exp null ... done vm` under partial `EXEC`, or two `vm=1` exports where the later `vm=1` runs under wider `EXEC`) either failed translation, failed to discard inactive lanes, or prematurely/falsely discarded surviving pixels. Changes: - `crates/victory-shader/src/io.rs`: Preserve `vm: bool` on `io::Export`. - `crates/victory-shader/src/emit/lower.rs`: - Replace the single-pass `exported: Vec<bool>` tracking with a static fixpoint lattice (`compute_vm_lattice`) and per-block SSA `vm_live` state (`VmVal::{False, True, Dyn(V)}`) with PHIs at multi-predecessor joins (`vm_phis` populated in `fill_phis`). - Update `vm_live` on every pixel `exp` with `vm == true` (falling back to `done` only for synthetic pixel shaders with no `vm == true` export at all), overwriting any earlier `vm` mask, and emit `dx.op.discard` once at `LaneExit::End` (zero extra instructions for standard unconditional exports). - Guard non-empty pixel `storeOutput` writes with `begin_guarded(guard)` so conditional non-`done` MRT exports and per-MRT overwrites execute only for active `EXEC` lanes (non-pixel, non-mesh stages continue to reject conditional exports). - `crates/victory-shader/src/emit/host.rs`: Add `#[cfg(test)] Host::draw_mrt` supporting multiple cleared RGBA32F render targets (with `Host::draw` delegating to `draw_mrt(..., 1)`). - `crates/victory-shader/src/emit/mod.rs`: Add `pixel_export_valid_mask_and_multi_mrt_match_rdna2`, rendering 7 `dxil.dll`-validated pixel shaders across 1- and 2-MRT 4x4 targets on both NVIDIA GeForce RTX 3060 Ti and WARP. Fixes VIC-BT-011 (tracking issue #1242).@geiyiliyabumo on GitHub · 2026-11-24 19:31 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 01:31 UTC · original · edited 2026-11-25 16:07 UTC
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
@ESAT586 on GitHub · 2026-11-25 11:15 UTC · original
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.@ESAT586 on GitHub · 2026-11-25 15:17 UTC · original
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
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.