shader: lower uniform VCC branches and shared-target nested SAVEEXEC in mesh SAVEEXEC then arms (Part of #3703) #3797
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3797"
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 R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-01T23:03:58Z.
Part of #3703.
Lowers the unclaimed SAVEEXEC
then-arm patterns opened on #3703 insrc/gfx1013_direct_mesh.inl:Summary
thenarm:s_and_b64 vcc, exec, sN/s_and_b64 vcc, sN, exec(and wave32s_and_b32 vcc_lo, exec_lo, sN) immediately followed by a forwards_cbranch_vccnzors_cbranch_vccztargeting within thethenarm or its exit.Symbol::Type::uniform_maskormask_uniformcoveringlane_active) so per-lane branching agrees with hardware's wave-widevcc != 0test; lane-varyingv_cmp_*masks remain refused.(s_and, s_cbranch_vcc*)pair, records the jump inscalar_branchso VCC branches over nestedSAVEEXECregions remain refused (mesh scalar branch crosses a nested SAVEEXEC region), updatesSCCto match(exec & sN) != 0, clearsvcc(106,107),vcc_words, andvcc_nonempty(both at the test and inscalar_clobbersat the join) so stale whole-wave VCC state can never leak across theSAVEEXEC, and merges register state through the existing PHI machinery.masked_vccstrictly to activeSAVEEXECdiamonds (saveexec_shapes.count(branch->start)).s_and_saveexec_b64+s_cbranch_execzinside athenarm to target the enclosing arm's exit only when the enclosing arm restores its savedEXECdirectly (s_mov_b64 exec, sOuter).elseinverses (s_andn2_b64/s_xor_b64) and non-direct parent restores remain refused with explicit diagnostics (nested mesh SAVEEXEC cannot share exit with an enclosing inverse/nested mesh SAVEEXEC cannot share exit without a direct parent restore) because skipping the inner restore would route inactive inner lanes into the outerelsearm.#3782:SAVEEXECregions, saved-mask clobbers, and arbitraryEXECwrites remain strictly refused.#3782edit thethen-arm scan and add a second visit of the join address (shared_exithere vschain_closedin#3782), so whichever lands second will merge those two checks cleanly.Verification (source-built fixtures only)
Environment: Windows 11 (
26200.9974), MSVC19.44, Ninja, Windows SDK10.0.26100.0DXC, rebased ontoorigin/main(b7d61632, C++20 //W4).dev):ctest --preset dev --no-tests=error -R 'native_direct_mesh|native_direct_container' -V— 2/2 passed (native_direct_container14.20 s,native_direct_meshpassed; zero new/W4warnings).release):ctest --preset release --no-tests=error -R 'native_direct_mesh|native_direct_container' -V— 2/2 passed (native_direct_container11.55 s,native_direct_mesh11.72 s; total 23.48 s).git diff --check origin/main..HEADclean.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T02:29:08Z.
Review: COMMENTED
Reviewed
5655b237by reading the diff; not built or run.Verdict: comment. The uniform VCC branch is sound: inside a then arm EXEC is nonempty, so on a proven uniform mask
(exec & sN) != 0equals the lane's own bit, and the shared-exit child is limited to a parent that restores withs_mov_b64at its alternate. No MUST, but the VCC path skips one of the arm's existing guards.scalar_branch. The scancontinues past thes_cbranch_vcc*(gfx1013_direct_mesh.inl:583-586) before theop.branch()bookkeeping at:609-612, somesh scalar branch crosses a nested SAVEEXEC region(:622) no longer applies to it. An arm with a VCC branch over a whole nesteds_and_saveexec_b64, a CMPX region or a shared-exit child now passes the scan. The SAVEEXEC lowering'sforward.upper_boundcheck only refuses an edge that lands inside the child, not one that jumps over it. No case covers that combination. Either record the jump inscalar_branch, or add a case where a VCC branch jumps over a nested SAVEEXEC and check its joins.masked_vccalso lifts theallocatedandlane_elserefusals (:1410). No case has a VCC branch after the GS_ALLOC_REQ send or in an arm with a lane-split else. A positive case for each, or keeping those two refused, would pin it.\t/\rescapes ate letters: "then" shows as a tab plus "hen", "release" as "elease". It also says it doesn't overlap #3782, which edits the same then-arm scan and conflicts textually with this head. Both add a second visit of the join address, hereshared_exitand therechain_closed, so whichever lands second can merge the two.saveexec-nested-shared-inverseis refused asthen arm lacks an EXECZ skip. A message naming the inverse would say why.joins_skip_endchanged from!shape.resettoshape.join==exec_skip->end. For existing shapes this is the same value: a reset sits before its boundary, and a reset-less top-level join is the skip end.vcc_wordsthatsaveexec-vcc-stale-branch-after-joinpins.s_cbranchreached first, and a lane-varying mask are each refused.Tests:
checked_vcc_skip(vccnz, vccz, reverse operands, scalar compare, wave32), the local diamond and the then-exit case check the edge phis and the final select.saveexec-nested-shared-exitreuseschecked_nested, and the refusals cover each match condition. CI rannative_direct_meshin theprpreset at this head, green.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T02:41:30Z.
#3782 is now on main. Please rebase the shared SAVEEXEC scan and join handling on it and cover the reviewer's VCC-jumps-over-nested-SAVEEXEC case on the rebased head, or keep that combination refused.
Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T02:47:44Z.
@lukaslw-lab Thanks for the thorough review! Rebased onto
origin/main(b7d61632->7585f6b2) and addressed every item:scalar_branchfor VCC tests): Recordedjump.pcinscalar_branchinsideif (vcc_test)invalidate_saveexecso VCC branches over a nesteds_and_saveexec_b64(including shared-exit children) remain refused withmesh scalar branch crosses a nested SAVEEXEC region. Addedsaveexec-vcc-crosses-nestedandsaveexec-vcc-crosses-shared-nestednegative controls.allocatedandbranch->lane_else): Tightenedmasked_vccto explicitly requiresaveexec_shapes.count(branch->start)(so it can never apply to a non-SAVEEXECv_cmpx/gatherlane_elsediamond). Note thatsaveexec_skipalready places its block afterGS_ALLOC_REQ(program[:3], soallocated == true), andsaveexec-vccnz-then-exitalready runs insidesaveexec_open(..., [0x7e020284])(branch->lane_else != 0). Added two extra positive cases to pin the remaining matrix explicitly:saveexec-vccnz-paired-else(interior VCC skip inside a paired-EXECZif/elseSAVEEXEC afterGS_ALLOC_REQ, verifying both the interior scalar PHI and outerthen/elsePHI) andsaveexec-vccnz-pre-alloc(same skip beforeGS_ALLOC_REQ,allocated == false).\t/\rmangling, and updated the note on#3782interaction.match_saveexecintonested mesh SAVEEXEC cannot share exit with an enclosing inverseandnested mesh SAVEEXEC cannot share exit without a direct parent restore, updatingsaveexec-nested-shared-inverseandsaveexec-nested-escaping-thenand addingsaveexec-nested-shared-gapplussaveexec-nested-escaping-past-inverse.Re-verified on Windows 11 (
26200.9974), MSVC19.44, Windows SDK10.0.26100.0:dev):native_direct_container+native_direct_mesh— 2/2 passed.release):native_direct_container+native_direct_mesh— 2/2 passed (23.48 s).Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T02:58:52Z.
Review: APPROVED
Re-reviewed
a358540e(rebased on main7069dfea, with #3782) by reading the diff; not built or run.Verdict: approve. Both SHOULDs are closed, and the rebase merges the two join paths cleanly. No MUST, no open points.
scalar_branch(gfx1013_direct_mesh.inl:659), socrosses a nested SAVEEXEC regioncovers it again.saveexec-vcc-crosses-nestedand-crosses-shared-nestedpin both child forms.saveexec_skipalready runs after GS_ALLOC_REQ, andlane_elseis the paired arm'selse_begin, sosaveexec-vccnz-then-exitalready covered both.-paired-elseand-pre-allocnow name them explicitly. The newsaveexec_shapes.count(branch->start)term also keepsmasked_vccoff non-SAVEEXEC diamonds.shared_exit(:967) replaces #3782'schain_closed. It is!reset && !else_begin, which only the two shared-exit forms produce: a CMPX chain, and a nested SAVEEXEC whose EXECZ lands on the parent restore. Paired, if-only and top-level skip-end shapes all carry a reset or an else arm, so they do not revisit the join. The refusal message still names the form.:500-503) are reached only when the target is the boundary. Top-level skips at the boundary keep the oldlacks an EXECZ skip.Tests: the new crossing, gap, escaping-past-inverse, paired-else and pre-alloc cases each reach the changed lines. CI ran
native_direct_meshin theprpreset. At the time of this review the Windows job was still running at this head, and the gfx1013 job was green.