Repository navigation
shader: lower s_cmov_b32, s_cmov_b64 and s_cmovk_i32 in the direct compute path - #3071
Conversation
|
Thanks for this. The lowering reads cleanly: operands are read before the writes, the immediate is sign-extended I ran
All five still pass
Smaller points:
This comment was AI-assisted. |
…mpute path Lower SOP1 s_cmov_b32/s_cmov_b64 and SOPK s_cmovk_i32 in the direct compute path: D = SCC ? S0 : D with SCC unchanged, sign-extended 16-bit immediate for s_cmovk_i32, aligned SGPR pair or VCC for s_cmov_b64, and old destination read via operand32 so symbolic-descriptor destinations are refused. Unlike tools/startup/gfx2hlsl.py scalar_cmov (which refuses vcc and lane-mask operands and takes only an SGPR pair as the s_cmov_b64 source), the direct path accepts vcc as s_cmov_b64 destination, wave32 vcc_lo/vcc_hi on the 32-bit forms, and inline integer or zero-extended 32-bit literal sources on s_cmov_b64. Also mark all three instructions in reads_scc in uses_scc_after() and clear s_cmovk_i32 state in transfer(), with IR-level evaluation (native_salu_cmov_ir) and compile controls (native_salu_cmov_controls). Fixes R0Y00#3070 AI-assisted.
2b6e66b to
9ec0c0a
Compare
|
@JohnConnorNPC Thank you for the detailed review and for testing those broken lowerings! Addressed all points in rebased commit
Verification on Windows 10.0.26100 ( AI-assisted. |
pigalot
left a comment
There was a problem hiding this comment.
I reviewed 9ec0c0a6 merged into main 2e74b778 (tree 44389212, clean merge). This includes the hardware run JohnConnorNPC asked for in option 2.
What I traced.
- Every operand is read before either write, so
s_cmov_b64with overlapping source and destination is safe. - The 32-bit forms accept wave32
vcc_hi(107) as destination and source.s_cmov_b64acceptsvcc(106) or an even SGPR pair, and takes inline or literal sources throughpair_high(). s_cmovk_i32sign-extends viaint16_t, ass_movk_i32does.transfer()now clearss_cmovk_i32destinations along withs_movk's neighbours.
What I ran. I built compile_dxil native_store_replay native_compute_ir_dump in dev and release, then ran:
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^native_salu_cmov_'
- 3/3 passed in each preset.
native_salu_cmov_hardwareran and passed: all 24 cases reportresult words, preserved SCC and guards matched. That covers 12 forms × SCC 0/1, including wave32vcc_hisource and destination,vccas destination,-1234and the0x80000001literal.
Mutants (in src/gfx1013_direct_compute.inl, rebuilt each time):
| mutant | _ir |
_hardware |
|---|---|---|
32-bit select inverted (select(cond, old_lo, next)) |
fails | fails |
s_cmov_b64 keeps the old high word |
fails at ('cmov64 pair SCC=1', (0, 2309737967, 3735928559), (2309737967, 19088743)) |
fails |
_controls passes in both cases, as expected for a compile-only check. Restored, all pass, and git diff --check is clean.
Still unmeasured: whether gfx1013 zero- or sign-extends a 32-bit literal in s_cmov_b64. The hardware run shows only that the lowering matches the PR's reference, which follows pair_high() (zero-extension). Settling it needs RDNA 2 hardware or an ISA statement.
Verdict: approve on 9ec0c0a6.
Environment: NVIDIA GeForce RTX 5090 (wave 32..32, SM 6.8), driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10.
CI: Build and test on Windows passes on 9ec0c0a6. There are no review threads.
This reply was AI-assisted.
Lowers
s_cmov_b32,s_cmov_b64(SOP1) ands_cmovk_i32(SOPK) in the direct C++ compute path (src/gfx1013_direct_compute.inl), addsreads_scctracking inuses_scc_after(), and clears constant/symbolic state ons_cmovk_i32intransfer()(src/gfx1013_compute_native.cpp).Differences vs
tools/startup/gfx2hlsl.pyscalar_cmovgfx2hlsl.pyrefusesvccand lane-mask operands and accepts only an aligned SGPR pair fors_cmov_b64S0.vccass_cmov_b64destination, wave32vcc_lo/vcc_hion the 32-bit forms, and inline integers (-16..64, sign-extended) or 32-bit literals (pair_high()zero-extension) ons_cmov_b64.Verification
Measured on Windows 10.0.26100 (
devpreset) onupstream/main429f11d5+ this commit:ctest --preset dev --no-tests=error -R '^native_salu_cmov_' -V:native_salu_cmov_ir(passed): dumps DXIL IR vianative_compute_ir_dumpfor all 24 cases (SCC=0andSCC=1across 12 forms including wave32vcc_hidst/src,vccdst,-1234,0x7FFF,-1, and0x80000001), evaluates lane 0 to verifyD = SCC ? S0 : D, preservedSCC, untouched neighbors, and sign-extended-1234(4294966062vs64302); verifies thetransfer()s_cmovk_i32baseline + exact-pc+0x10refusal and 11 destination/source refusals (including 3 no-epilogue symbolic-descriptor dst cases at exact pc+0x20).native_salu_cmov_controls(passed): compiles all 12 accepted forms viacompile_dxil, verifies thetransfer()baseline + all 12 exact-pc/diagnostic refusals, and checks 5 reference mutants.native_salu_cmov_hardware(skipped, exit77): Quadro M1000M does not support shader model 6.6 with wave32, so GPU readback (including the unmeasured0x80000001literal high word) is not measured on hardware here.ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure: 47/47 passed.python -B tests/docs_links_check.py: passed (102 Markdown files, 590 links).ignores_scc,inverted_select,writes_nothing,zero_ext_cmovk,keeps_old_high_word, and droppings_cmovk_i32fromtransfer()) each failednative_salu_cmov_ir.Fixes #3070
AI-assisted.