startup: lower SDWA output modifiers on float-result conversions #2055
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2062"
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 consolelogkyo on 2026-11-24T23:47:35Z.
Summary
Lowers output modifiers (
clamp,mul:2,mul:4,div:2) on SDWA forms of the float-result conversions (VEC_U_TO_F:v_cvt_f32_u32,v_cvt_f32_i32,v_cvt_f32_ubyte0..3,v_cvt_f32_f16) intools/startup/gfx2hlsl.py(Part of #2023, item E).Semantics & Implementation
In GFX10
VOP_SDWA(VOP_SDWA9Aein LLVMllvm/lib/Target/AMDGPU/VOPInstructions.tdandSIDefines.h;S_000504_*in Mesasrc/amd/common/sid.handSDWA_Instructioninsrc/amd/compiler/aco_assembler.cpp), control wordw1carriesdst_sel([10:8]),dst_unused([12:11]),clamp([13]),omod([15:14]:0none,1mul:2,2mul:4,3div:2),src0_sel([18:16]), andsrc0_sext([19]).For float-result conversions (
VEC_U_TO_F), the hardware pipeline order is:src0_sel(zero-extended, or sign-extended to 32 bits undersext(...)) and convert to IEEE binary32float.omodscaling (* 2.0,* 4.0, or* 0.5).clamp(saturateto[0.0, 1.0]) afteromod, even though disassembly printsclampbeforemul:2/mul:4/div:2.floatas a 32-bit word (U(...)/asuint(...)) and place its low8/16/32bits intodst_selaccording todst_unused(UNUSED_PADorUNUSED_PRESERVE).Stage.f_mods()is factored out ofStage.set_vf()so VOP3 and SDWA share one implementation ofomod+clampordering. Without output modifiers, the emitted HLSL text is unchanged. Because these SDWA output-modifier forms previously raisedUnsupported(writing.failrather than a manifest or.cso), existing shader caches hold no stale entries for them and the startup cache revision stays unchanged.Refusal Boundaries Preserved
VEC_U(v_cvt_f16_f32_sdwa,v_cvt_u32_f32_sdwa,v_add_nc_u32_sdwa, etc.) keep refusingclampandomod.VEC_FSDWA operations (v_rcp_f32_sdwa,v_add_f32_sdwa, etc.) remain refused.neg/absmodifiers onv_cvt_f32_f16_sdwaanddst_unused:UNUSED_SEXTremain refused.Verification
tests/startup_gfx2hlsl_sdwa_cvt_check.py):uint/int/ IEEE-754 binary32 evaluator across2,376combinations (7VEC_U_TO_Fconversions x4omodmodes x2clampstates x sub-dword source/destination selections xsextx test bit patterns) against an independent RDNA 2 ISA reference, plus refusal checks and a live monkeypatch negative control.python-linuxCI job andAGENTS.md.startup_gfx2hlsl_sdwa_cvt_warp&startup_gfx2hlsl_sdwa_cvt_hardware):06cdc47d, Windows 11 26H2 (build26300.9974), D3D12 debug layer enabled (debug_errors=0 debug_warnings=0), compiled with both FXC (ps_5_1) and DXC (ps_6_0), across:1414:008c, driver10.0.26100.9818)1002:7550, driver32.0.32029.2010)1,024exported 32-bit words (256pixels x4channels coveringv_cvt_f32_u32_sdwa ... mul:2,v_cvt_f32_u32_sdwa ... clamp div:2,v_cvt_f32_i32_sdwa ... sext(...) mul:4, andv_cvt_f32_f16_sdwa ... clamp div:2 dst_sel:WORD_0 dst_unused:UNUSED_PRESERVE) match the ISA reference, while all5mutated HLSL negative controls fail against the reference and match their own models.tests/startup_gfx2hlsl_*_check.py,tests/startup_translator_check.py, andctest --preset prpass.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T00:04:32Z.
Ran the draw check on both adapters here; three production mutations, caught on each backend
dxcand a builtoffscreen_checkexist on this machine, so the draw half of this PR is executable:and
hardware:Windows 11 build 26300.9974, DXC 10.0.26100.0, debug layer enabled.
Your negative controls are the right shape — and they are not the same as mutating the production code
The check mutates its own model and confirms the reference catches each variant (
early clamp before div:2,dropped mul:4,dropped div:2 on f16,dropped WORD_0 dst_sel). That proves the comparison is sensitive. It does not prove the translator is connected to it, so I mutatedtools/startup/gfx2hlsl.pyand let the draw run decide:float_result = base in VEC_U_TO_F→True(integer forms get the float output modifiers)dst_seldropped from the accepted SDWA keysAll three fail through the pixel comparison, not a compile error, on both backends.
The third is the one I would keep: silently ignoring an unknown modifier is the failure mode where the shader still runs and still produces a colour,
so nothing but a value comparison can see it.
What I could not check
dst_unused UNUSED_SEXTbeing refused is stated as "no lowering"; a draw fixture cannot reach a refusal, so it stays a comment. If the refusal ismeant to be pinned, it belongs in the form check beside the other
Unsupportedrows.Notes
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T00:12:30Z.
I verified the source-built 16 by 16 draw on WARP and RTX 4060 Laptop, with both FXC and DXC and no debug errors or warnings. Each of the five mutations differed from the reference and matched its mutated model. I pushed a documentation fix to make clear that existing integer and uint-result SDWA forms continue to work without output modifiers.
precise, so RDNA 1 drops the sign of a -0 product (startup_gfx2hlsl_fma_mix_dispatch_hardware) #2721