shader: lower gfx1013 binary16 v_cmp and v_cmp_class_f16 in pixel_aot #606
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/612"
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 Neoplayer on 2026-11-22T15:50:01Z.
Change
Lower all 34 gfx1013 binary16 comparison and classification instruction forms (
17 VOPC_e32+17 VOP3_e64) intools/pixel_aot.py, synchronizetools/scan_unsupported_shaders.py, and add binary + DXC/WARP draw tests and negative controls intests/pixel_aot_check.pyandtests/form_coverage_check.py:tools/pixel_aot.py:class16(uint bits)inPREAMBLE(modeling all 10 IEEE binary16SIInstrFlags::ClassFlagsbits on bits[15:0]: signaling NaN, quiet NaN,-inf,-normal,-denormal,-0,+0,+denormal,+normal,+inf), and fix the missing opening parenthesis inclass32(if (magnitude != 0u)).f16_cmp_operand()supporting binary16 inline constants (INLINE_F16), integer inline patterns, 16-bit literals (rejecting> 0xffff), SGPR/VGPR sources, and VOP3_e64-onlyabs/negmodifiers (for_e32, modifiers raiseValueError("Input modifiers require VOP3 encoding")).lower()branches forv_cmp_class_f16(_e32|_e64)?and all 16v_cmp_<COMPARE>_f16(_e32|_e64)?predicates.tools/scan_unsupported_shaders.py:v_cmp_class_f16/v_cmp_<op>_f16(with optional_e32) and modifiedv_cmp_class_f16_e64/v_cmp_<op>_f16_e64(-,|...|,abs(...)) inSUPPORTED_INSTRUCTIONS_REGEX.tests/pixel_aot_check.py&tests/form_coverage_check.py:F16_COMPARE_SETS,f16_compares(),f16_compares_reference(), andcheck_f16_compare_draws()covering dirty high halfwords,±0.0,±denorm(0x0001/0x8001),±inf, quiet/signaling NaNs, inline constants (-4.0..4.0,0.15915494/0x3118, integer1/-1),_e64input modifiers, andR32G32B32A32_UINT(integer_rt=True) expectations plus wrong-bit and shader-mutation controls (lt -> leswap, dropped-on_e64, dropped-onv_cmp_class_f16_e64).(uncompressed_export(f16_compares()), translate_int)incheck_binary(), update rejected neighbor controls tov_cmp_class_f64_e32/v_cmp_lt_f64_e64, and updatetests/form_coverage_check.py(len(compare_forms) == 90).Verification
Commit under test:
857b893on macOS arm64 with Homebrew LLVM 15.0.7 (-mcpu=gfx1013) and Python 3.12.13:FORM_COVERAGE_RECORD=/tmp/x2w_f16_cov.txt python3 -B tests/pixel_aot_check.py binary llvm-mc llvm-objcopy libLLVM-15.dylib: exit0; recorded all 34 binary16 compare/class forms (17_e32+17_e64).python3 -Bsimulation executing emitted HLSL (widen16,class16,main) againstf16_compares_reference()across all 14F16_COMPARE_SETS:All 14 sets match emitted HLSL bit-for-bit!and all 3 shader mutations caught.LLVM_LIB=libLLVM-15.dylib LLVM_MC=llvm-mc LLVM_OBJCOPY=llvm-objcopy python3 -B tests/rdna2_tools_check.py:Ran 50 tests in 0.492s—OK(0 skips).python3 -B tests/form_coverage_check.py:form coverage checks passed.compute_store_check.py binary,depth_mask_check.py binary,mesh_*_check.py binary,sampled_coverage_check.py binary,ffx_dispatch_aot_check.py,awc_metadata_check.py,bc7_*,bcpack_check.py,bidi_controls_check.py,dependency_paths_check.py,docs_links_check.py,dxcontainer_part_offsets_check.py,dxil_retarget_check.py,gpu_report_format_check.py,layout_chunks_check.py,pso_readiness_check.py,resource_ranges_check.py,resource_root_check.py,script_state_check.py,sgd5_effects_check.py,shader_probe_check.py,xmem_attribute_scan_check.py,intake/paths_check.py): exit0.git diff --check: exit0.MSVC, D3D12, DXC, and WARP runtime execution (
pixel_aot_warp/check_f16_compare_draws) were not run on this macOS host and will be exercised by Windows CI.Evidence and follow-up
All fixtures are source-built synthetic sequences verified with LLVM 15.0.7
-mcpu=gfx1013.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by MarlomMedeiros on 2026-11-22T17:47:38Z.
Review: COMMENTED
Community review + independent run on a second adapter, since the PR notes MSVC/D3D12/DXC/WARP were not exercised on the authoring macOS host.
Environment
857b893on basee3946ddctest --preset dev --no-tests=error -R '^pixel_aot_predicate_rounding_(warp|hardware)$' -V: both passeddebug_errors=0 debug_warnings=0on every drawtests/pixel_aot_check.pycontrols,tests/form_coverage_check.py, and the LLVM 15.0.7 binary round-trip (binarymode) all pass on this commitThe f16 compare draw runs inside
pixel_aot_predicate_rounding_*throughcheck_f16_compare_draws: all 14F16_COMPARE_SETScases passed pixel-exact on the integer readback on both adapters, the 4 corrupted-reference controls reportedpixel_mismatch, and all 3 shader mutants (e32 predicate flip, e64 dropped neg, class dropped neg) were detected on both backends.Review notes
v_cmp_*_f32/v_cmp_class_f32arms faithfully: sameLANE_MASKdestination handling, same("condition", ...)tuple shape, samemask != "entry"and pending-load guards, modifiers gated to_e64throughf16_cmp_operand,widen16/vop3p_f16_word/INLINE_F16reused rather than duplicated.class16decomposes the f16 15:0 bits correctly: sNaN/qNaN split on the quiet bit, inf at 0x7c00, normal from 0x0400, denormal and zero below, sign folding the negative classes. The reference test asserts the raw 0x7f800000-emptiness invariant per set.clamp/op_selsuffixes,v_cmpxvariants, mid-program and pending-load placements, plus a modifier-on-the-class-mask case that correctly routes throughint_operandinstead.> 0x3ff) is accepted and emits dead bits, same as thev_cmp_class_f32arm. Not a defect, just parity.("condition", ...)tupless_and_saveexec_b64consumes, so they would be able to open masked regions automatically once both land. Inside a region thev_cmpdeny prefix still rejects them, which is the intended behavior. No conflict, just a free capability.e3946dd, 15+ commits behind currentmain(8f57366). The cmp arm chain has moved since, so a rebase may hit minor textual conflicts inlower().No blockers found.
Imported from R0Y00/Xbox2Windows. Originally posted by descent81 on 2026-11-22T15:58:12Z.
Independent Windows GPU run on
857b89304ce46daea5618c2ca9a2ba1af2996546. Windows build 26300.9974, Windows SDK 10.0.26100.0 DXC 1.8.2502.11. RTX 4060 driver 32.0.16.1088 and WARP 10.0.26100.9818. D3D12 debug layer enabled.WARP passed (7.49 s), including the four wrong-reference cases and three shader mutations. RTX 4060 failed (4.36 s) at the ninth positive FP16 input (
F16_COMPARE_SETS[8], batch case 12). The other 13 positive draws and all four wrong-reference checks reported the expected statuses. The fixture raises at the batch status check, before reaching the three shader mutations on hardware.At pixel (0, 0), channel 1 expected
0x0000ff00and read0x0002ff00. The only differing bit is 17, produced byv_cmp_le_f16_e64 vcc_lo, -|s44|, 2.0. Heres44is0x00007e00(quiet NaN). The generated comparison is(-abs(widen16(asuint(params[0].w)))) <= widen16(16384u), and the reference expects false.I reran that case alone twice per backend: the original shader failed both times on RTX 4060 and passed both times on WARP. In a local HLSL-only diagnostic I guarded just that comparison with
(asuint(params[0].w) & 0x7fffu) <= 0x7c00u. Both backends then passed both runs. All isolated runs reported zero debug errors and warnings. This localizes the observed difference to the ordered NaN comparison in this case; I did not establish which compilation stage introduces it or test the guard as a general fix.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by MarlomMedeiros on 2026-11-22T17:56:39Z.
AI-assisted: yes. All reported checks ran locally on the adapter and driver listed.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-22T18:00:36Z.
@Neoplayer Independent AMD (RDNA4) result on
857b893. Measurements only, no code change.Environment
debug_layer=unavailable(Tools.Graphics.DirectXisNotPresenthere)857b893, base7b55abcd.Commands
Observed
21 tests, 21 passed, 0 failed, 0 skipped (113.36 s):
rdna2_tools_check, ten_hardwaresuites (pixel_aot,buffer_color,u32_from_f32,attribute,three_way,predicate_rounding,blend_scalar,e64,integer_nc,rndne) and their ten_warpcounterparts. This tree has nopixel_aot_bfmentry yet, hence 21 rather than 23.Main draw suite:
pixels=4096and one atpixels=64, every onemax_absolute_error=0(4 channels per pixel).max_absolute_error=0.Why this is worth measuring on this adapter
Two things here are vendor-sensitive by nature:
class16helper models all ten IEEE binary16 class bits. A wrong classification would show as a mismatched pixel, not a compile error. None appeared across 16,384 channels per draw on both backends.class32fix — you add the missing opening parenthesis (if (magnitude != 0u)) to a helper that all existing pixel suites already use. The other nine hardware suites in this run still pass with the corrected preamble, so the fix does not perturb the 32-bit classification path that was already in use.Limit
The negative controls are in
tests/pixel_aot_check.py, and the CTest entries above exercise the draw path. I did not run the standalonebinarymode, which needs LLVM with gfx1013 support — not installed on this machine. So this run confirms the draws and the registered tool check, not the assembly-level controls.AI-assisted; runs executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by rwZephyr on 2026-11-22T18:16:53Z.
Independent RTX 3060 Ti result on
857b89304ce46daea5618c2ca9a2ba1af2996546. I checked whether the RTX 4060’s FP16 NaN comparison mismatch also occurs on Ampere, using the PR’s synthetic fixture.Windows 10 22H2 build
19045.6466, MSVC19.44.35230, Windows SDK10.0.26100.0, DXC1.8.2502.11. D3D12 debug layer unavailable on both backends. The Debug build used a static CRT (/MTd).10de:2414), driver576.02(32.0.15.7602via DXGI). At pixel(0, 0), channel 1 ofF16_COMPARE_SETS[8](batch case 12) expected0x0000ff00and read0x0002ff00. Only bit 17 differed. The other 13 positive FP16 cases and all four wrong-reference controls behaved as expected. Two isolated--check-pixel-caseruns reproduced the same mismatch.1414:008c), driver10.0.19041.5794. Two isolated runs of case 8 also matched all 4,096 pixels exactly.The same shader program was rejected during translation at the branch point
e3946ddand target base7b55abc, both atv_cmp_f_f16_e32. The base comparison therefore ended before GPU readback.AI-assisted. All reported runs were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Neoplayer on 2026-11-22T18:21:40Z.
Thanks for the independent runs. The RTX 4060 and RTX 3060 Ti failure on
F16_COMPARE_SETS[8](-|s44| <= 2.0withs44a quiet NaN, bit 17) is real; it is a float NaN comparison folded differently by the NVIDIA compiler, as the diagnostic showed.Fix in
32dd77b(rebased onto719552e): every ordering-dependentv_cmp_*_f16predicate (lt eq le gt lg ge o uand then*forms) is now guarded bynum16(bits), which decides "not a NaN" from the binary16 encoding ((bits & 0x7fff) <= 0x7c00) withabs/negapplied to the bits, instead of relying on float NaN semantics.fandtruare unchanged.Run on macOS arm64 (LLVM 15.0.7) after the rebase:
pixel_aot_check.py binaryexit 0,form_coverage_check.pypassed,rdna2_tools_check.py50 tests OK,git diff --checkclean. I have no NVIDIA hardware, so the draw suites were not run locally; could someone re-run^pixel_aot_predicate_rounding_(hardware|warp)$on the RTX cards?AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by rwZephyr on 2026-11-22T18:44:22Z.
RTX 3060 Ti retest on Windows 10 22H2 build
19045.6466, NVIDIA621.24(32.0.16.2124via DXGI, adapter10de:2414), MSVC19.44.35230, SDK10.0.26100.0, and DXC1.8.2502.11. The D3D12 debug layer was unavailable on both backends.857b89304ce46daea5618c2ca9a2ba1af2996546still failed on 621.24. At pixel(0, 0), channel 1 ofF16_COMPARE_SETS[8]expected0x0000ff00and read0x0002ff00. Fixed head32dd77be451198a5b2337c65ff669c6678d81b37passed the full test.6b33fbf) reproduced the mismatch twice. The fixed translator matched all 4,096 pixels twice.10.0.19041.5794) passed on both full checkouts. Skipped: zero CTest skips.AI-assisted. All reported runs were executed locally.