shader: lower remaining SOP1 *_saveexec_* and *_wrexec_* ops in direct Compute DXIL #3297
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3297"
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 legacy-code-archaeologist on 2026-11-28T06:05:37Z.
Lowers the remaining 12 SOP1 EXEC-mask instructions (
*_saveexec_*and*_wrexec_*) in the direct Compute DXIL translator, alongside consistentuses_scc_after()andtransfer()tracking.Fixes #3296. Refs #2935.
Changes
src/gfx1013_compute_native.cpp(transfer()): Generalize the wave32 compute!graphics && !wave64EXEC-mask transfer rule to cover all*_saveexec_b32ands_andn1_wrexec_b32/s_andn2_wrexec_b32instructions, clearing symbolic provenance on bothi.dstand126(EXEC_LO).src/gfx1013_direct_compute.inl(uses_scc_after()): Adds_orn2_b64,s_nand_b64,s_nor_b64,s_xnor_b64,s_andn1_saveexec_b64,s_orn1_saveexec_b64, ands_andn1_wrexec_b64tomask_scc, and add all 9 newly lowered wave32 ops (s_xor_saveexec_b32,s_andn2_saveexec_b32,s_orn2_saveexec_b32,s_nand_saveexec_b32,s_nor_saveexec_b32,s_xnor_saveexec_b32,s_andn1_saveexec_b32,s_orn1_saveexec_b32,s_andn1_wrexec_b32) tooverwrites.src/gfx1013_direct_compute.inl(emit()):combine_scalar_maskhelper coveringand/or/xor,andn2/orn2(a op ~b),andn1/orn1(~a op b), andnand/nor/xnor(~(a op b)).s_andn1_saveexec_b64(0x37),s_orn1_saveexec_b64(0x38), ands_andn1_wrexec_b64(0x39) in the 64-bit mask path (s_andn1_wrexec_b64gated tocompute && wave64with even SGPR pair operands<= 104, matchings_andn2_wrexec_b64).*_saveexec_b32(0x3e..0x45) ands_andn1_wrexec_b32(0x46) undercompute && !wave64(dst <= 107, refusingdst > 107withunsupported wave32 SAVEEXEC destination), updatingdst(oldfor saveexec,maskfor wrexec),EXEC_LO, andSCC = (mask != 0).tests/native_saveexec_wrexec_check.py,tests/cmake/native_saveexec_wrexec.cmake,docs/experiments/native-saveexec-wrexec.md: Addir,controls, andhardwarechecks covering 19 wave32 cases, 9 wave64 cases (includingSCC=0,SCC=1, high-word-only non-zeroEXEC_HI,dst == srcaliasing,vcc_lo/exec_lo/inline/literal sources, partial waves), and 8 negative operand/mode refusals.Verification
All tests ran after the final edit on both
devandreleasepresets:ctest --preset dev --no-tests=error --output-on-failure -j 1 -V -R '^native_saveexec_wrexec_':native_saveexec_wrexec_ir: Passed (0.84s, evaluated IR for19wave32 +9wave64 cases +8refusals)native_saveexec_wrexec_controls: Passed (3.62s, compiled28wave32/wave64 cases +8refusals)native_saveexec_wrexec_hardware: Skipped (77) on localIntel(R) HD Graphics 530(driver=31.0.101.2111,requires shader model 6.6 with wave32; hardware execution unmeasured locally)ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^native_direct_container$'&-R '^(native_or_saveexec|native_wrexec64|native_salu_cmp64|native_s_not_b64_exec)_':native_direct_container(24.99s),native_s_not_b64_exec_controls,native_salu_cmp64_ir, andnative_salu_cmp64_controlsPassed;4hardware tests Skipped (77).ctest --preset release --no-tests=error --output-on-failure -j 1 -R '^(native_saveexec_wrexec_|native_or_saveexec_|native_wrexec64_|native_salu_cmp64_|native_s_not_b64_exec_|native_direct_container$)':6non-hardware tests Passed (31.88s),5hardware tests Skipped (77).python -B tests/docs_links_check.py: Passed (145Markdown files,663links).dev(native_saveexec_wrexec_ir):andn1/orn1operand swap (~rightinstead of~left): killed atw32_andn1_nznand/nor/xnor: killed atw32_nand_nzoldinstead ofmaskforwrexec: killed atw32_wr1_nz(
src/gfx1013_direct_compute.inlrestored cleanly andnative_saveexec_wrexec_irre-passed.)AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-28T06:27:56Z.
Independent Windows verification at
80c13cf5, parent17f112b2. Windows 11 26300.10075, MSVC 19.52.37029, Windows SDK 10.0.26100 DXC, RTX 4070 driver 32.0.16.2124, and app-local WARP 1.0.22.Debug and Release each passed 11/11. The RTX 4070 matched all 2,064 words per case across 19 wave32 and 9 wave64 replays, including aliasing, the high-word SCC cases, and the 128-thread dispatch. Both configurations passed the eight compiler refusals.
I also ran the 28 cases via
native_store_replay --direct-warp. Both configurations matched 27 cases. The 8-threadw32_andn1_zhad the same 45 wrong words in each, first at word 265 (69696969instead of000000a5). The fixture calculates its vector addresses before setting guest EXEC, so this case relies on the partial-wave entry ballot from #3160. Prependings_mov_b32 exec_lo, -1to that fixture before its first vector instruction restored all 2,064 words on WARP and preserved the RTX result. The explicit old EXEC used by the tested opcode remains0xa5.I separately checked the SCC liveness change in Release. A symbolic stride extraction from a UAV slot precedes each of the nine new wave32 forms, whose result is immediately observed by
s_cselect_b32. All 18 combinations compiled and matched both result words and every guard on both adapters without stride metadata. Omitting the EXEC instruction or making it readSRC_SCCcorrectly refused the live symbolic SCC.Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-28T06:31:38Z.
I reviewed the diff (not run). The new lowerings look right: operand order for the n1/n2 forms, saveexec versus wrexec, SCC from the new mask, and both EXEC words in wave64. The widened wave32 branch in
transfer()now also clearss[126]afters_andn2_wrexec_b32, whichmaindid not do.One soundness gap in the static analysis, which this PR inherits rather than introduces:
transfer()(src/gfx1013_compute_native.cpp), only the wave32*_saveexec_b32/*_wrexec_b32branch clearss[126]. The 64-bit*_saveexec_b64and*_wrexec_b64fall into the generic SOP1 branch, which clearsdstanddst + 1but leavess[126]ands[127]as they were.s_mov_b64 exec, <constant>and then a 64-bit saveexec or wrexec, the analysis still sees EXEC as that constant.s_mov_b32 sN, exec_locopies the stale constant into sN, and the constant-sampler path (sampler_index) would then fold it. I do not expect real shaders to do this, so it is a soundness gap rather than an observed miscompile.mainto the eight*_saveexec_b64formsmainlowers and tos_andn2_wrexec_b64(that one is mine, from #3247). This PR addss_andn1_saveexec_b64,s_orn1_saveexec_b64ands_andn1_wrexec_b64.s[126]ands[127]for every compute SOP1*_saveexec_b64/*_wrexec_b64intransfer()would close it. I'm happy to do that separately after this PR, since it also touches #3247's op.dst == execfor the saveexec forms.s_andn1_saveexec_b64 exec, s[22:23]then writes the saved EXEC and immediately overwrites it with the new mask. The wave32 forms added in this PR refuseexec_loas the destination. I have not checked what RDNA2 does with that encoding.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-28T06:44:44Z.
Thanks @RonLogic for running the independent Debug/Release verification on RTX 4070 + WARP (and confirming the symbolic SCC liveness test!), and @Leyukaka for the thorough diff review and noting the inherited 64-bit
transfer()EXEC symbol /dst == execitems (and #3247's wave64 wrexec). Happy to leave #3297 clean on80c13cf5since both points are pre-existing across the*_saveexec_b64/*_wrexec_b64family and #3297's wave32s_mov_b32 exec_lo, -1question on WARP isn't blocking, or let me know if a follow-up fixture/patch on this PR is preferred.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-28T06:45:21Z.
Thank you for this PR. I reviewed
80c13cf5merged locally into currentmain(cross build under Wine, not Windows).native_saveexec_wrexec_ir("19 wave32 and 9 wave64 cases, plus 8 refusals") andnative_saveexec_wrexec_controls("compiled 28 wave32/wave64 cases cleanly and verified 8 refusals") both pass there. Your operand-swap mutant turns the test red, and so does dropping the wave32 destination refusal.Could you remove one fixture dependency before merge? The 8-thread
w32_andn1_zcase relies on #3160's partial-wave entry ballot:build_wave32_programcomputes the vector addresses (v_lshlrev_b32 v8,v_add_nc_u32 v8,v_add_nc_u32 v1) before it sets guest EXEC withs_mov_b32 exec_lo, <old_exec>. So in a partial wave the store addresses depend on the EXEC the wave starts with.--direct-warprun in the earlier comment shows the effect:w32_andn1_zhad 45 wrong words, first at word 265 (69696969instead of000000a5). Prependings_mov_b32 exec_lo, -1before the first vector instruction restored all 2,064 words on WARP and kept the RTX result.0xa5) as it is, so the case still checks the same thing without relying on #3160.Could you add that line at the start of
build_wave32_program(build_wave64_programalready starts withs_mov_b64 exec, -1) and rerunnative_saveexec_wrexec_hardware, on WARP if you can?This comment was AI-assisted.