From ba96084da489d1f4b690320af348df2ecd1a219a Mon Sep 17 00:00:00 2001 From: Roland Edi Date: Mon, 30 Nov 2026 03:31:50 +0000 Subject: [PATCH 1/7] tests: restore green main after the SDWA and UAV merges --- docs/experiments/direct-sdwa-profiles.md | 7 ++++--- tests/native_cvt_f16_i16_check.py | 3 ++- tests/native_sdwa_profiles_check.py | 3 ++- tools/startup/gfx2hlsl.py | 14 ++++++++++++++ tools/startup/triage_run.py | 1 + 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/docs/experiments/direct-sdwa-profiles.md b/docs/experiments/direct-sdwa-profiles.md index 0190cfb3f9..09d6097443 100644 --- a/docs/experiments/direct-sdwa-profiles.md +++ b/docs/experiments/direct-sdwa-profiles.md @@ -33,8 +33,9 @@ SDWA validation is per operand, mirroring `place_subword` destination placement; no modifier or subword selection is silently ignored. -Still refused in SDWA: `v_sin_f16`/`v_cos_f16` (no direct lowering), -`v_fmac_f32`/`v_fmac_f16` and the rest of `VOP2_SDWA_UNSUPPORTED_OPS`, +The SDWA forms of `v_sin_f16`/`v_cos_f16` are covered by the separate +`native_sin_cos_f16` suite. Still refused in SDWA: `v_fmac_f32`/`v_fmac_f16` +and the rest of `VOP2_SDWA_UNSUPPORTED_OPS`, 64-bit `_f64`/`_b64` forms, and VOP3-only ops (`v_fma_f16`, `v_min3_f16`, `v_med3_f16`, `v_cvt_pknorm_*`). @@ -56,7 +57,7 @@ a second and third program (12, 28 and 6 slots, each under the 32-slot hardware layout) with an independent Python/ISA reference model, plus 15 refusal controls: disallowed VOP2 SDWA ops, float/int modifier violations, omod/clamp on integer destinations, invalid 16-bit destination selection and -unused mode, a byte source pick, literal 255, and `v_sin_f16`. The new +unused mode, a byte source pick, and literal 255. The new profiles also pin the `v_frexp_*_f32` SDWA source pick (a WORD_1 pick reads only the high half, so the picked value is a subnormal) and destination placement (a WORD destination keeps only the result's low half, with the diff --git a/tests/native_cvt_f16_i16_check.py b/tests/native_cvt_f16_i16_check.py index e92cc74afb..dc61801ef5 100644 --- a/tests/native_cvt_f16_i16_check.py +++ b/tests/native_cvt_f16_i16_check.py @@ -209,7 +209,8 @@ def refusal_programs(): programs = [] for op, (vop1_op, vop3_op, _, to_f16) in OPS.items(): programs.append(([vop1(vop1_op, 3, 250), 0xFF00B101, 0xBF810000], 'unsupported DPP arithmetic')) - programs.append(([vop1(vop1_op, 3, 249), 0x06060601, 0xBF810000], 'unimplemented direct SDWA operand profile')) + programs.append(([vop1(vop1_op, 3, 249), 0x06060601, 0xBF810000], + 'unsupported SDWA destination modifier')) programs.append((vop3_unary(vop3_op, 3, 257, omod=1) + [0xBF810000], f'unsupported {op} clamp or omod')) programs.append((vop3_unary(vop3_op, 3, 257, op_sel=1) + [0xBF810000], f'unsupported {op} high-half op_sel')) programs.append((vop3_unary(vop3_op, 3, 257, op_sel=8) + [0xBF810000], f'unsupported {op} high-half op_sel')) diff --git a/tests/native_sdwa_profiles_check.py b/tests/native_sdwa_profiles_check.py index 2e114e4aa2..9437c26be1 100644 --- a/tests/native_sdwa_profiles_check.py +++ b/tests/native_sdwa_profiles_check.py @@ -478,7 +478,8 @@ def refusal_cases(): (sdwa_instruction(profile("v_floor_f16", 0x5B, True, 0, src0=DWORD | 0x80, dst=WORD_0), reg0=255), "literal is unavailable in SDWA"), (sdwa_instruction(profile("v_fmac_f32", 0x2B, False, 0, 0)), SDWA_REFUSAL), - (sdwa_instruction(profile("v_sin_f16", 0x60, True, 0)), SDWA_REFUSAL), + # v_sin_f16/v_cos_f16 are admitted by the SDWA path since #3300; the + # separate native_sin_cos_f16 suite pins their positive forms. ) diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index 0c8bdee786..dbf459541a 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -14081,6 +14081,20 @@ def stage_ok(s): fail_name = base_name + '.fail' fail_entry = files.get(fail_name) recheck = lost and (manifest_entry is not None) + + # A watch pass sees a request written after it started even when an + # earlier pass already recorded its failure. Keep that failure + # unchanged: retrying it every second would rewrite .fail and + # make its mtime look like new work. + if watch_since_ns is not None and fail_entry is not None and not recheck: + try: + fail_stat = fail_entry.stat() + if (fail_stat.st_mtime_ns > watch_since_ns and + fail_stat.st_mtime >= max(entry.stat().st_mtime, described or 0)): + continue + except OSError: + pass + if skip_failed and not recheck and fail_entry is not None: try: fail_mtime = fail_entry.stat().st_mtime diff --git a/tools/startup/triage_run.py b/tools/startup/triage_run.py index 4ee978ed53..e22aa9fb29 100644 --- a/tools/startup/triage_run.py +++ b/tools/startup/triage_run.py @@ -178,6 +178,7 @@ 'an output UAV covers only part of a copied placement', 'an output UAV has no supported byte interval', 'an output UAV interval crosses the end of its buffer', + 'an output UAV interval exceeds the D3D12 buffer view element limit', 'an output UAV interval is empty', 'an output UAV interval is not 16-byte aligned in its buffer', 'an output UAV interval is not whole dwords', From 8dfc23d77b96c9539ef74ea20b0f0ceeaedbc09b Mon Sep 17 00:00:00 2001 From: Roland Edi Date: Mon, 30 Nov 2026 03:28:54 +0000 Subject: [PATCH 2/7] gpu: sync both retire queues before the title settle case6 of startup_resource_retire_title releases the newer wrapper and calls settle() without waiting for the queues. Every release signals a release-time fence on each registered queue, and settle() only resubmits the drain list, so a fence that has not completed leaves both wrappers retained and the stage fails with retained=131072/2 against 65536/1. Sync the direct and gated queues before settle(), as #3457 did for startup_resource_retire. The expectation is unchanged. Refs #3507 --- tests/startup_resource_retire_title.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/startup_resource_retire_title.cpp b/tests/startup_resource_retire_title.cpp index 23c4f51952..e172024908 100644 --- a/tests/startup_resource_retire_title.cpp +++ b/tests/startup_resource_retire_title.cpp @@ -880,6 +880,9 @@ bool case6_written_generation_preserved(Context& c, void* title_mem) std::puts("FAIL: releasing the newer wrapper erased metadata used by the older wrapper's live SRV"); return false; } + // The release above signalled a release-time fence on every registered queue, and the drains never wait for the + // GPU: let both queues pass before settle(), as the other stages do (#3507). + if (!c.sync(c.direct) || !c.sync(c.gated)) return false; Tnew.freed = true; if (!c.settle("newer wrapper retired with older SRV live", "newer wrapper kept or older SRV retired")) return false; if (!x2w_d3d12_written_probe(title_mem, &generation, &bc7_width, nullptr) || generation != 2 || bc7_width != side) { From 949a63ff2ec06325458653c87eb0c37d283a7116 Mon Sep 17 00:00:00 2001 From: Roland Edi Date: Mon, 30 Nov 2026 03:53:09 +0000 Subject: [PATCH 3/7] shader: lower the exec-writing VOPC SDWA compares Lower the 62 v_cmpx_*_sdwa forms of gfx1013/rdna2 in the pixel translator, reusing the existing v_cmpx EXEC region opener. VOPC SDWA has no destination: the comparison writes EXEC, so the non-SDWA path is unchanged. Add draw-cmpx-sdwa (warp/hardware), the static controls and the coverage assertions, and teach the scanner the new spellings. Tests: draw-cmpx-sdwa warp/hardware, draw-cmpx-regions warp, draw-sdwa-cmp warp, form_coverage_check, rdna2_tools_check. Coverage: 62 of 62 forms in each reference; 1542/1968 gfx1013 and 1533/1863 gfx1030 in the 194-entry WARP replay. --- CMakeLists.txt | 5 + docs/experiments.md | 6 +- tests/form_coverage_check.py | 35 ++++++- tests/pixel_aot_check.py | 147 +++++++++++++++++++++++++++--- tests/rdna2_tools_check.py | 30 ++++-- tools/pixel_aot.py | 100 +++++++++++++++----- tools/scan_unsupported_shaders.py | 20 ++++ 7 files changed, 302 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5da721cd70..900c79cd1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11153,6 +11153,11 @@ if(EXISTS "${INTAKE_PYTHON}") "$" ${adapter}) set_tests_properties(pixel_aot_cmpx_e64_${adapter} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77 ENVIRONMENT "FORM_COVERAGE_RECORD=${CMAKE_BINARY_DIR}/form_coverage/pixel_aot_cmpx_e64_${adapter}.txt") + add_test(NAME pixel_aot_cmpx_sdwa_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/pixel_aot_check.py" draw-cmpx-sdwa "${DXC_EXECUTABLE}" + "$" ${adapter}) + set_tests_properties(pixel_aot_cmpx_sdwa_${adapter} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77 + ENVIRONMENT "FORM_COVERAGE_RECORD=${CMAKE_BINARY_DIR}/form_coverage/pixel_aot_cmpx_sdwa_${adapter}.txt") add_test(NAME pixel_aot_region_body_${adapter} COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/pixel_aot_check.py" draw-region-body "${DXC_EXECUTABLE}" "$" ${adapter}) diff --git a/docs/experiments.md b/docs/experiments.md index 1ff6eb7fe8..e83793ec84 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -8927,7 +8927,9 @@ Scalar ALU support also covers the 64-bit SOP1/SOP2 family (`s_cmov_b64`, `s_not The SDWA forms of the 16 `v_cmp_*_f32` predicates are lowered when both `src0_sel` and `src1_sel` are `DWORD`. With whole-dword selections they compare the operands exactly as the e32/e64 forms do; the translator emits identical HLSL for both, and a control asserts it. A byte or word selection would compare a zero-extended field as binary32 and is refused. The predicate draws are repeated with the SDWA compares for all four groups and the same five input pairs, including NaN on either side. A reference that inverts each group's unordered result must report a mismatch. -The 46 non-`v_cmpx` VOPC SDWA comparisons left by lot 1a are lowered: the 16 binary16 predicates and `v_cmp_class_f16_sdwa`, `v_cmp_class_f32_sdwa`, the 8 signed and 8 unsigned 32-bit predicates and the 6 signed and 6 unsigned 16-bit predicates. VOPC SDWA encodes only `src0_sel` and `src1_sel`; `llvm-mc` rejects `dst_sel`/`dst_unused` on these instructions, so the destination stays `vcc`/`vcc_lo` or one SGPR and the translator refuses an SGPR pair and the destination fields. Sources accept `BYTE_0..3`, `WORD_0..1` and `DWORD`, with `sext()` where LLVM prints it. The selection is zero-extended, or sign-extended under `sext()`, before the existing table applies: binary16 uses the low 16 bits through `widen16`/`num16`, the 16-bit integer forms take the low 16 bits, the 32-bit integer forms compare the selected word as signed or unsigned, and the class forms feed the selected bits to `class16` or `class32`. The comparison result is tracked in the same VCC/SGPR lane-mask state as the e32 and e64 forms, so `v_cndmask_b32` consumes it unchanged. The source-built fixture `tests/pixel_aot_check.py draw-sdwa-cmp` puts all 46 forms in one program, folds each predicate into two exported `R32G32B32A32_UINT` words, and repeats the rows with selections on every field. Its wrong references must each report `pixel_mismatch`: selections ignored (whole dwords), every field reversed (`BYTE_0`/`BYTE_3`, `BYTE_1`/`BYTE_2`, `WORD_0`/`WORD_1`), signedness inverted on the rows containing `0x8000`/`0xffff`, and zero extension in place of `sext()`. A second program writes two comparisons to `s52` and `vcc_lo` before consuming both; a reference that uses the second mask for both channels must mismatch. `tests/form_coverage_check.py` isolates this fixture's accepted words and asserts the 46 forms count in both `gfx1013.tsv` and `rdna2.tsv`, while the non-SDWA `v_cmp_*` neighbours and the `v_cmpx_*_sdwa` forms stay out. The same program is part of `check_binary`, so the LLVM 15 `Assemble and translate gfx1013 fixtures` job assembles, disassembles and re-translates it. On base `0aa6522c` the measurement moved from 1255/1968 to 1301/1968 on gfx1013 and from 1246/1863 to 1292/1863 on gfx1030, exactly 46 forms in each reference. The new tests passed on WARP and on `pixel_aot_sdwa_cmp_hardware` on an AMD Radeon RX 9060 XT (driver 32.0.32029.2010), Windows 11 build 10.0.26300.10075, in 1.10 s; the debug layer was unavailable. The separate `pixel_aot_comparisons_hardware` entry still fails on this adapter in its pre-existing strict binary32 subnormal comparison ([issue #958](https://github.com/R0Y00/Xbox2Windows/issues/958)); that failure is outside this lot and does not affect the SDWA draw. This measures translated fixtures, not console behavior or full title execution. Reproduce with `ctest --preset dev --no-tests=error -R '^pixel_aot_sdwa_cmp_' -V`; the full measurement is `ctest --preset dev --no-tests=error -R '^(pixel_aot_|compute_store_aot_)' -E '_hardware$' -j 1 --output-junit out/build/dev/out/wave1-sdwa-after.xml` followed by `python -B tools/form_coverage.py out/build/dev/out/wave1-sdwa-after.xml --records out/build/dev/form_coverage --json out/wave1-sdwa-after.json`. A supplemental per-predicate fixture (`tests/pixel_aot_check.py draw-sdwa-int-compare`, tests `pixel_aot_sdwa_int_compare_{warp,hardware}`) exercises all 16 32-bit integer SDWA comparisons across four 4-channel groups (`i32_lo`, `i32_hi`, `u32_lo`, `u32_hi`) with 41 targeted single-channel negative controls plus static refusal checks for `low16` sources, pending loads, masked regions, float modifiers, `clamp` and SGPR pair destinations. +The 46 non-`v_cmpx` VOPC SDWA comparisons left by lot 1a are lowered: the 16 binary16 predicates and `v_cmp_class_f16_sdwa`, `v_cmp_class_f32_sdwa`, the 8 signed and 8 unsigned 32-bit predicates and the 6 signed and 6 unsigned 16-bit predicates. VOPC SDWA encodes only `src0_sel` and `src1_sel`; `llvm-mc` rejects `dst_sel`/`dst_unused` on these instructions, so the destination stays `vcc`/`vcc_lo` or one SGPR and the translator refuses an SGPR pair and the destination fields. Sources accept `BYTE_0..3`, `WORD_0..1` and `DWORD`, with `sext()` where LLVM prints it. The selection is zero-extended, or sign-extended under `sext()`, before the existing table applies: binary16 uses the low 16 bits through `widen16`/`num16`, the 16-bit integer forms take the low 16 bits, the 32-bit integer forms compare the selected word as signed or unsigned, and the class forms feed the selected bits to `class16` or `class32`. The comparison result is tracked in the same VCC/SGPR lane-mask state as the e32 and e64 forms, so `v_cndmask_b32` consumes it unchanged. The source-built fixture `tests/pixel_aot_check.py draw-sdwa-cmp` puts all 46 forms in one program, folds each predicate into two exported `R32G32B32A32_UINT` words, and repeats the rows with selections on every field. Its wrong references must each report `pixel_mismatch`: selections ignored (whole dwords), every field reversed (`BYTE_0`/`BYTE_3`, `BYTE_1`/`BYTE_2`, `WORD_0`/`WORD_1`), signedness inverted on the rows containing `0x8000`/`0xffff`, and zero extension in place of `sext()`. A second program writes two comparisons to `s52` and `vcc_lo` before consuming both; a reference that uses the second mask for both channels must mismatch. `tests/form_coverage_check.py` isolates this fixture's accepted words and asserts the 46 forms count in both `gfx1013.tsv` and `rdna2.tsv`, while the non-SDWA `v_cmp_*` neighbours stay out (the exec-writing `v_cmpx_*_sdwa` forms follow in lot 1b). The same program is part of `check_binary`, so the LLVM 15 `Assemble and translate gfx1013 fixtures` job assembles, disassembles and re-translates it. On base `0aa6522c` the measurement moved from 1255/1968 to 1301/1968 on gfx1013 and from 1246/1863 to 1292/1863 on gfx1030, exactly 46 forms in each reference. The new tests passed on WARP and on `pixel_aot_sdwa_cmp_hardware` on an AMD Radeon RX 9060 XT (driver 32.0.32029.2010), Windows 11 build 10.0.26300.10075, in 1.10 s; the debug layer was unavailable. The separate `pixel_aot_comparisons_hardware` entry still fails on this adapter in its pre-existing strict binary32 subnormal comparison ([issue #958](https://github.com/R0Y00/Xbox2Windows/issues/958)); that failure is outside this lot and does not affect the SDWA draw. This measures translated fixtures, not console behavior or full title execution. Reproduce with `ctest --preset dev --no-tests=error -R '^pixel_aot_sdwa_cmp_' -V`; the full measurement is `ctest --preset dev --no-tests=error -R '^(pixel_aot_|compute_store_aot_)' -E '_hardware$' -j 1 --output-junit out/build/dev/out/wave1-sdwa-after.xml` followed by `python -B tools/form_coverage.py out/build/dev/out/wave1-sdwa-after.xml --records out/build/dev/form_coverage --json out/wave1-sdwa-after.json`. A supplemental per-predicate fixture (`tests/pixel_aot_check.py draw-sdwa-int-compare`, tests `pixel_aot_sdwa_int_compare_{warp,hardware}`) exercises all 16 32-bit integer SDWA comparisons across four 4-channel groups (`i32_lo`, `i32_hi`, `u32_lo`, `u32_hi`) with 41 targeted single-channel negative controls plus static refusal checks for `low16` sources, pending loads, masked regions, float modifiers, `clamp` and SGPR pair destinations. + +Lot 1b lowers the remaining 62 exec-writing VOPC SDWA comparisons: the 16 binary32 predicates (whole-dword selections only, as their `v_cmp` forms), the 16 binary16 predicates, `v_cmpx_class_f16` and `v_cmpx_class_f32`, the 8 signed and 8 unsigned 32-bit predicates and the 6 signed and 6 unsigned 16-bit predicates. VOPC SDWA prints no destination and encodes no `dst_sel`/`dst_unused`: the comparison writes EXEC, so each form reuses the existing `v_cmpx` region opener unchanged (the `s_mov_b64 s[a:b], exec` save, the entry-mask intersection, the SKIP/else handling and the two closes), and the non-SDWA path is untouched. Selections are the same `BYTE_0..3`, `WORD_0..1` and `DWORD` fields, zero-extended or sign-extended under `sext()`, applied before the e32 table. The fixture `draw-cmpx-sdwa` (`pixel_aot_cmpx_sdwa_{warp,hardware}`) opens one region per form and adds an exact power of two to one of three exported binary32 accumulators (24 bits per channel, so every partial sum is an exact integer below 2^24); its wrong references must each mismatch: selections ignored, every field reversed, signedness inverted, zero extension instead of `sext()`, and the region applied to every lane. Static controls refuse a missing or non-adjacent EXEC save, `dst_sel`/`dst_unused`, an SGPR pair in the source position, byte/word selections on an f32 predicate, and the nonexistent 64-bit SDWA exec writers. `tests/form_coverage_check.py` isolates this fixture's accepted words and asserts its 62 forms are exactly the SDWA `v_cmpx` family of both references, while the non-SDWA exec writers and the `v_cmp_*_sdwa` forms stay out. The same program is part of `check_binary`. The 194-entry WARP replay (`pixel_aot_`/`compute_store_aot_`, `_hardware` excluded) passes with no failure or skip and measures 1542/1968 on gfx1013 and 1533/1863 on gfx1030; removing the 62 forms of this lot leaves 1480/1968 and 1471/1863. The targeted WARP and hardware runs pass on the AMD Radeon RX 9060 XT (driver 32.0.32029.2010); `draw-cmpx-regions` and `draw-sdwa-cmp` also pass on both adapters. This measures translated fixtures, not console behavior or full title execution. Reproduce the target with `python -B tests/pixel_aot_check.py draw-cmpx-sdwa warp` (or `hardware`), `tests/pixel_aot_check.py draw-cmpx-regions`, `tests/pixel_aot_check.py draw-sdwa-cmp` and `python -B tests/form_coverage_check.py`; in a configured tree the CTest entry is `ctest --preset dev --no-tests=error -R '^pixel_aot_cmpx_sdwa_' -V`, and the full measurement is `ctest --preset dev --no-tests=error -R '^(pixel_aot_|compute_store_aot_)' -E '_hardware$' -j 1 --output-junit out/build/dev/out/wave1-cmpx-sdwa.xml` followed by `python -B tools/form_coverage.py out/build/dev/out/wave1-cmpx-sdwa.xml --records out/build/dev/form_coverage --json out/wave1-cmpx-sdwa.json`. In this worktree the CMake configure stops in the `opus` dependency (`LNK1104: m.lib`) before any target, so the 194-entry run replayed the main build's CTest command list with this tree's tests and the main build's `offscreen_check.exe`; the replay helper is untracked under `out/coverage-run/`. Binary32 floating-point vector comparisons (`v_cmp_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg,ngt,nle,neq,nlt,tru}_f32` in e32, e64, and whole-dword SDWA forms) evaluate the 16 IEEE-754 relations against scalar and vector operands, including subnormals, signed zeroes, infinities, and quiet/signaling NaNs. The e32 (VOPC) encoding requires destination `vcc` or `vcc_lo`; SGPR destinations (`s52`, `s[52:53]`) are accepted on suffix-less and explicit `_e64` (VOP3) encodings. Source modifiers (`neg`, `abs`) are accepted on e64 operands (`-s44`, `|v18|`, `-|s44|`), while `clamp` and `op_sel` remain rejected on comparisons. Rejection controls verify that untracked source registers, SGPR destinations on explicit e32, and sub-dword SDWA selections (`src0_sel:WORD_0`, `src1_sel:BYTE_2`) raise `ValueError`. The synthetic fixture `f32_compares()` verifies all 16 predicates across e32, e64, and whole-dword SDWA, validating them against an exact reference oracle (`f32_compares_reference()`). Mutating predicates or modifiers produces a mismatch. @@ -8973,7 +8975,7 @@ The SDWA forms of the exact arithmetic (`add`, `sub`, `subrev`, `mul`, `mul_lega The SDWA forms of the remaining unary binary32 operations (`v_exp_f32`, `v_log_f32`, `v_rcp_f32`, `v_rcp_iflag_f32`, `v_rsq_f32`, `v_sqrt_f32`, `v_sin_f32`, `v_cos_f32`, `v_rndne_f32` and `v_frexp_mant_f32`) go through the same path: each reuses its e32/e64 lowering unchanged, with `src0_sel:DWORD` only, and the result is placed with the SDWA move rules. The translator emits the same shader for the whole-dword SDWA spelling and the e32 spelling of each operation, and the controls assert that. A byte or word source, a `src1_sel`, a second operand, an output modifier, `UNUSED_SEXT` on a partial destination and `UNUSED_PRESERVE` over an untracked destination are refused for every one of the ten. Three programs are drawn with two constant rows each. D3D allows `exp2`, `log2`, a reciprocal, `rsqrt`, `sqrt`, `sin` and `cos` an error, so the first two programs choose inputs whose true result is an integer, add 0.5 and take the floor, which returns that integer for any result within 0.5 of it: exp of `-A`, log of `|B|`, rcp of C and rcp_iflag of `-|D|` give 8, 5, 8, -4 and then 16, 3, -2, -16; rsq of `|A|`, sqrt of B, sin of C and cos of `-D` (in revolutions) give 4, 7, 1, -1 and then 2, 3, -1, 1. That checks which operation ran and its source modifiers, not last-place accuracy. The third program is exact and is compared directly: `v_rndne_f32_sdwa` of the ties 2.5 and -3.5 (2 and -4), `v_frexp_mant_f32_sdwa` of `-B` with `clamp`, the low byte of a rounded tie kept in `BYTE_2` of 1.0 under `UNUSED_PRESERVE`, and the low byte of a significand padded into `BYTE_3`. 26 wrong references, each replacing one channel, must report `pixel_mismatch`: a neighbouring operation for each approximate one (natural exponential and logarithm, rsq for rcp, sqrt and rcp for rsq, rsq for sqrt, sin and cos swapped, radians for revolutions), a copied source, a dropped negation, ties rounded up or toward zero, a dropped clamp, padding for preserving, the neighbouring byte and an unplaced result. That is 32 draws from three compiles and three renderer launches. They run as their own tests, `pixel_aot_sdwa_unary_hardware` and `pixel_aot_sdwa_unary_warp` (`tests/pixel_aot_check.py draw-sdwa-unary`), with their own coverage record, and the LLVM 15 round trip covers the three programs. They passed on the NVIDIA GeForce RTX 3060 (driver 32.0.15.9636) and on WARP (Microsoft Basic Render Driver 10.0.19041.5794), Windows 10 (10.0.19045.6466), debug layer enabled with no errors or warnings. Not shown: last-place accuracy of the approximate operations on any adapter, a partial destination for an approximate result (its low bits have no single reference), inputs outside these rows (zero, negative arguments to log, rsq and sqrt, infinities, NaN, denormals), the integer-divide flag of `v_rcp_iflag_f32`, and what the console computes. -Signed and unsigned 16-bit integer comparisons (`v_cmp_{eq,ne,lt,le,gt,ge}_{i16,u16}` in e32 and e64 encodings) compare only the low 16 bits of each source: the lowering sign-extends them with `asint(x << 16) >> 16` or masks them with `& 0xffff`, and the result feeds `v_cndmask_b32` through the same tracked lane mask as the other comparisons. A source may be a register, an integer inline constant from -16 to 64 or a literal up to `0xffff`. LLVM prints a float inline constant on a 16-bit integer operand as its binary16 literal (`1.0` as `0x3c00`), so float tokens, wider literals, source modifiers, `clamp` and `op_sel` are refused. The exec-writing `v_cmpx_*` forms stay rejected outside the `v_cmpx` region openers described above, which admit the e32 integer forms (the f16 comparisons and `v_cmp_class_f16` are lowered by their own branches in `tools/pixel_aot.py`), and `tests/form_coverage_check.py` asserts that all 24 16-bit integer forms, the 32 32-bit integer forms, the 32 64-bit integer forms, and the 34 binary16 and 34 binary32 floating-point forms (156 compare forms in all) are counted while those neighbours are not. The binary fixtures cover the 24 forms, and the draws (`tests/pixel_aot_check.py draw-comparisons`) evaluate all six predicates per kind and encoding on six word pairs. Each word is a normal binary32 value whose upper half differs from the lower one where a 32-bit comparison would disagree, and the pairs include `0x8000` against 0, equal low halves, -1 against 1, `0x7fff` against `0x8000` and both ends of the inline-constant range. Three references must report a pixel mismatch: a signed shader against the unsigned reference, `eq` replaced by `ne`, and a 32-bit comparison against the 16-bit reference on equal low halves. +Signed and unsigned 16-bit integer comparisons (`v_cmp_{eq,ne,lt,le,gt,ge}_{i16,u16}` in e32 and e64 encodings) compare only the low 16 bits of each source: the lowering sign-extends them with `asint(x << 16) >> 16` or masks them with `& 0xffff`, and the result feeds `v_cndmask_b32` through the same tracked lane mask as the other comparisons. A source may be a register, an integer inline constant from -16 to 64 or a literal up to `0xffff`. LLVM prints a float inline constant on a 16-bit integer operand as its binary16 literal (`1.0` as `0x3c00`), so float tokens, wider literals, source modifiers, `clamp` and `op_sel` are refused. The exec-writing `v_cmpx_*` forms are admitted only by the `v_cmpx` region openers described above, which cover the e32 and e64 forms (the f16 comparisons and `v_cmp_class_f16` have their own branches in `tools/pixel_aot.py`) and, since lot 1b, the SDWA forms. `tests/form_coverage_check.py` asserts that all 24 16-bit integer forms, the 32 32-bit integer forms, the 32 64-bit integer forms, and the 34 binary16 and 34 binary32 floating-point forms (156 compare forms in all) are counted while the rejected non-SDWA neighbours are not; the 62 SDWA exec writers are counted separately by `check_cmpx_sdwa_coverage`. The binary fixtures cover the 24 forms, and the draws (`tests/pixel_aot_check.py draw-comparisons`) evaluate all six predicates per kind and encoding on six word pairs. Each word is a normal binary32 value whose upper half differs from the lower one where a 32-bit comparison would disagree, and the pairs include `0x8000` against 0, equal low halves, -1 against 1, `0x7fff` against `0x8000` and both ends of the inline-constant range. Three references must report a pixel mismatch: a signed shader against the unsigned reference, `eq` replaced by `ne`, and a 32-bit comparison against the 16-bit reference on equal low halves. Signed and unsigned 64-bit integer comparisons (`v_cmp_{f,lt,eq,le,gt,ne,ge,t}_{i64,u64}` in e32, suffix-less and e64 spellings, [#794](https://github.com/R0Y00/Xbox2Windows/issues/794)) compare two words per source, so the HLSL needs no 64-bit type. Without a suffix the encoding is chosen as LLVM 15 does: e32 when the destination is `vcc`/`vcc_lo` and src1 is a VGPR pair, e64 otherwise. The high words decide unless they are equal, and then the low words, which always compare unsigned. A signed comparison reads only the high word as `int`. Every word is read as raw bits with `asuint` (`asint` for a signed high word), bound to a local before the comparison, and no arithmetic touches a float view. The result is a tracked lane condition like the other comparisons, so `v_cndmask_b32` consumes it unchanged. A source is a VGPR pair `v[a:a+1]` with `a` from 0 to 254 whose two registers hold tracked numbers, an even-aligned SGPR pair, or an integer inline constant from -16 to 64 sign-extended to 64 bits (`-1` is all ones). On e32 (VOPC) the destination must be `vcc_lo` or `vcc` and src1 must be a VGPR pair, because LLVM 15 rejects an SGPR there. On e64 the destination is `vcc_lo`, `vcc`, an SGPR or an aligned SGPR pair, as for the narrower comparisons, and the wave64 spellings (`vcc`, `s[52:53]`) lower to the same HLSL as the wave32 ones. Refused with a message that names the cause: 32-bit literals, float and hex tokens, constants outside -16..64, register ranges other than a pair, untracked or pending sources, an SGPR destination or SGPR src1 on e32, and misaligned or out-of-range SGPR pairs. Source modifiers, `clamp`, `op_sel`, the `v_cmpx_*` forms, f64 and the unsupported predicates, and the DPP and SDWA forms are refused with the generic `Unsupported instruction` message, which does not name the cause. The 32-bit literal extension rule is not sourced, so literals stay outside this change; refusing float inline constants (LLVM accepts `1.0`) is the translator's choice. diff --git a/tests/form_coverage_check.py b/tests/form_coverage_check.py index e46a275565..73533b4874 100644 --- a/tests/form_coverage_check.py +++ b/tests/form_coverage_check.py @@ -479,7 +479,12 @@ def check_shader_records(): assert compare_forms <= covered, (name, sorted(compare_forms - covered)) assert not {form for _, form in covered} & (compare_neighbours | {f"{n}_e64" for n in compare_neighbours}) assert cmpx_forms <= reference and cmpx_forms <= covered, (name, sorted(cmpx_forms - covered)) - assert {form for _, form in covered if form.startswith("v_cmpx_")} == {form for _, form in cmpx_forms}, name + # The non-SDWA v_cmpx family is the 190 forms above; the 62 exec-writing SDWA forms are a separate + # family, checked by check_cmpx_sdwa_coverage and counted here from the same control run. + assert {form for _, form in covered + if form.startswith("v_cmpx_") and not form.endswith("_sdwa")} == {form for _, form in cmpx_forms}, name + assert {form for _, form in covered if form.startswith("v_cmpx_") and form.endswith("_sdwa")} == \ + {entry["form"] for entry in pixel.CMPX_SDWA_FORMS}, name # The scalar ALU fixture counts its SOP1, SOP2, SOPK and SOPC forms; the neighbours the controls # reject (s_addc_u32, s_cmp_lt_u64) stay out; s_getreg_b32 joined the accepted forms with the mode-register fixture. scalar = {"s_movk_i32", "s_cmovk_i32", "s_not_b32", "s_add_u32", "s_sub_u32", "s_add_i32", "s_sub_i32", @@ -1422,6 +1427,33 @@ def check_sdwa_cmp_coverage(): assert ("SDWA", "v_cmp_lt_f16_sdwa") not in fc.gfx_forms(stripped, reference), name +def check_cmpx_sdwa_coverage(): + """The 62 exec-writing VOPC SDWA comparisons are the complete SDWA v_cmpx family of both references, + counted from this fixture's accepted words. The non-SDWA exec writers and the v_cmp SDWA forms stay out.""" + import pixel_aot_check as pixel + wanted = {("SDWA", entry["form"]) for entry in pixel.CMPX_SDWA_FORMS} + assert len(wanted) == 62 + saved = set(pixel.ACCEPTED) + pixel.ACCEPTED.clear() + try: + pixel.translate(pixel.uncompressed_export(pixel.cmpx_sdwa_body())) + accepted = set(pixel.ACCEPTED) + finally: + pixel.ACCEPTED.clear() + pixel.ACCEPTED.update(saved) + assert not {form for form in accepted if form.startswith("v_cmp_")} + assert not {form for form in accepted if form.startswith("v_cmpx_") and not form.endswith("_sdwa")} + for name in ("gfx1013.tsv", "rdna2.tsv"): + reference = fc.load_reference(name) + family = {entry for entry in reference if entry[0] == "SDWA" and entry[1].startswith("v_cmpx_")} + assert family == wanted, (name, sorted(family ^ wanted)) + covered = fc.gfx_forms(accepted, reference) + assert wanted <= covered, (name, sorted(wanted - covered)) + # Control: removing one accepted SDWA word removes exactly that form from the count. + stripped = accepted - {"v_cmpx_lt_f16_sdwa"} + assert ("SDWA", "v_cmpx_lt_f16_sdwa") not in fc.gfx_forms(stripped, reference), name + + def check_dpp_f16_arith_round_forms(): """The 16 quad-local DPP16/DPP8 binary16 arithmetic and rounding forms count as covered once the translator accepts their fixtures; unlowered f16 DPP/SDWA neighbours stay uncovered.""" @@ -1722,6 +1754,7 @@ def check_f16_cvt_norm_forms(): check_swap_coverage() check_pk_fmac_coverage() check_sdwa_cmp_coverage() + check_cmpx_sdwa_coverage() check_sopk_wait_forms() check_s_version_form() check_parsing() diff --git a/tests/pixel_aot_check.py b/tests/pixel_aot_check.py index e5cc0628c3..3e4a3f37a9 100644 --- a/tests/pixel_aot_check.py +++ b/tests/pixel_aot_check.py @@ -4876,6 +4876,15 @@ def check_sdwa_predicate_draws(directory, compiler, renderer, backend): for entry in SDWA_CMP_FORMS) assert len(SDWA_CMP_FORMS) == 46 +# The 62 exec-writing VOPC SDWA comparisons of lot 1b: the same 46 forms as v_cmpx (no destination operand) +# plus the 16 binary32 predicates, which take whole-dword selections as their v_cmp forms do. +CMPX_SDWA_FORMS = (tuple({"form": f"v_cmpx_{op}_f32_sdwa", "kind": "f32", "op": op, + "sel0": "DWORD", "sel1": "DWORD", "sext0": False, "sext1": False} + for op in PREDICATES) + + tuple(dict(entry, form="v_cmpx_" + entry["form"][len("v_cmp_"):]) + for entry in SDWA_CMP_FORMS)) +assert len(CMPX_SDWA_FORMS) == 62 and len({entry["form"] for entry in CMPX_SDWA_FORMS}) == 62 + # Runtime words: s44 is A and s45/v18 is B. Their byte, word and dword fields disagree, and the signed # rows put 0x8000/0xffff in the selected halves so a signedness or selection error changes a bit. SDWA_CMP_WORDS = ( @@ -4924,8 +4933,7 @@ def f16_bits_value(bits): return struct.unpack(" and open the v_cmpx EXEC region that it masks.""" + lines.append(f" bool cmp{index} = {expr};") + for reg in pair: + scalar[reg] = ("exec_saved",) + vector.masked = True + scalar.masked = True + return {"save": pair, "cond": f"cmp{index}", "written": {}, "skip": None, "start": index, + "arm_start": index, "else": None, "then": {}, "else_written": {}, + "else_undefined": set(), "skipped": False, "scalar_written": set(), "scc_written": False, + "opener": "cmpx", "width": width, + "arm_outstanding": (set(pending), dict(sample_dest))} + + +def cmpx_save_pair(saved, region, mask, scalar): + """The pair and width of a v_cmpx EXEC save, refusing a missing save or a non-entry mask.""" + if (region is not None or mask != "entry" or saved is None + or [scalar.get(r) for r in saved[0]] != saved[2]): + raise ValueError("Unsupported v_cmpx execution mask save") + return saved[0], saved[1] # Binary32 arithmetic with SDWA forms on gfx1013 (docs/coverage/gfx1013.tsv): the exact operations, then the # remaining unary ones. Each reuses its e32/e64 entry in ALU unchanged. SDWA_ALU = ("add", "sub", "subrev", "mul", "mul_legacy", "max", "min", "floor", "ceil", "fract", "trunc", @@ -4328,18 +4363,7 @@ def match(pattern): fop, iop, kind, op16, kind16, cls, hop, hcls, f64op, enc, src0, src1 = m.groups() if op16 is not None: iop, kind = op16, kind16 - previous = instructions[i - 1] if i else "" - previous = previous[1] if isinstance(previous, tuple) else previous - saved = re.fullmatch(r"s_mov_b64 (s\[\d+:\d+\]), exec", previous) - pair = sgpr_pair(saved[1]) if saved else None - width, entry = 64, [("entry", 0), ("entry", 1)] - # A wave32 guest saves exec_lo, its whole EXEC, into one SGPR; the save branch already refused it - # without the wave32 profile. The region then closes and switches with the wave32 spellings. - if pair is None and guest_wave32 and (saved32 := re.fullmatch(r"s_mov_b32 (s\d+), exec_lo", previous)): - pair, width, entry = [saved32[1]], 32, [("entry", "w32")] - if (region is not None or mask != "entry" or pair is None - or [scalar.get(r) for r in pair] != entry): - raise ValueError("Unsupported v_cmpx execution mask save") + pair, width = cmpx_save_pair(cmpx_exec_save(instructions, i, guest_wave32), region, mask, scalar) # VOPC e32 encodes VSRC1 as a VGPR (a VGPR pair at 64 bits) and carries no source modifiers. wide = kind in ("i64", "u64") or f64op not in (None, "class") vsrc1 = r"v\[\d+:\d+\]" if wide else r"v\d+" @@ -4376,15 +4400,49 @@ def match(pattern): values = [read(t, scalar, vector, pending, sample_dest, signed=kind in ("i32", "i16")) for t in (src0, src1)] expr = INT_COMPARE[iop].format(*values) - lines.append(f" bool cmp{i} = {expr};") - for reg in pair: - scalar[reg] = ("exec_saved",) - region = {"save": pair, "cond": f"cmp{i}", "written": {}, "skip": None, "start": i, "arm_start": i, "else": None, "then": {}, "else_written": {}, - "else_undefined": set(), "skipped": False, - "scalar_written": set(), "scc_written": False, "opener": "cmpx", "width": width, - "arm_outstanding": (set(pending), dict(sample_dest))} - vector.masked = True - scalar.masked = True + region = open_cmpx_region(i, lines, expr, pair, width, pending, sample_dest, vector, scalar) + elif m := match(rf"v_cmpx_({'|'.join(COMPARE)})_f32_sdwa ([^,]+), ([^,]+)" + r" src0_sel:DWORD src1_sel:DWORD"): + # A VOPC SDWA compare that writes EXEC (issue #932). VOPC SDWA encodes only the two source + # selections and no destination: the comparison writes EXEC, which becomes the entry mask + # intersected with the predicate. With whole-dword selections the f32 form is the e32 one; + # byte and word selections would compare zero-extended fields as binary32 and are refused. + op, src0, src1 = m.groups() + pair, width = cmpx_save_pair(cmpx_exec_save(instructions, i, guest_wave32), region, mask, scalar) + tokens = [SDWA_NEG_DECIMAL.sub(r"-\1", token) for token in (src0, src1)] + expr = f32_comparison(op, tokens, scalar, vector, pending, sample_dest) + region = open_cmpx_region(i, lines, expr, pair, width, pending, sample_dest, vector, scalar) + elif m := match(rf"v_cmpx_((?:{'|'.join(COMPARE)})_f16|class_(?:f16|f32)" + rf"|(?:{'|'.join(INT_COMPARE)})_(?:i32|u32)" + rf"|(?:eq|ne|lt|le|gt|ge)_(?:i16|u16))_sdwa (.+)"): + # The remaining VOPC SDWA exec writers: every binary16 predicate and class test, the 32-bit + # signed and unsigned predicates and the six 16-bit relations, each applying its source + # selections before the e32 table. The region opens exactly as the non-SDWA v_cmpx path does. + form, rest = m.groups() + pair, width = cmpx_save_pair(cmpx_exec_save(instructions, i, guest_wave32), region, mask, scalar) + (src0, sel0, sext0), (src1, sel1, sext1) = sdwa_cmp_operands(rest) + if form.startswith("class_"): + kind = form[len("class_"):] + value = sdwa_cmp_bits(src0, sel0, sext0, scalar, vector, pending, sample_dest, + f16=kind == "f16") + classes = sdwa_cmp_bits(src1, sel1, sext1, scalar, vector, pending, sample_dest, f16=False) + expr = (f16_class_bits(value, classes) if kind == "f16" + else f"(class32(asfloat({value})) & {classes}) != 0u") + elif form.endswith("_f16"): + raw = [sdwa_cmp_bits(src0, sel0, sext0, scalar, vector, pending, sample_dest, f16=True), + sdwa_cmp_bits(src1, sel1, sext1, scalar, vector, pending, sample_dest, f16=True)] + expr = f16_comparison_bits(form[:-len("_f16")], raw) + else: + op, kind = form.rsplit("_", 1) + raw = [sdwa_cmp_bits(src0, sel0, sext0, scalar, vector, pending, sample_dest, f16=False), + sdwa_cmp_bits(src1, sel1, sext1, scalar, vector, pending, sample_dest, f16=False)] + if kind in ("i32", "u32"): + values = [f"asint({word})" if kind == "i32" else word for word in raw] + else: + values = [f"(asint({word} << 16) >> 16)" if kind == "i16" else f"({word} & 0xffffu)" + for word in raw] + expr = INT_COMPARE[op].format(*values) + region = open_cmpx_region(i, lines, expr, pair, width, pending, sample_dest, vector, scalar) elif m := S_CALL.fullmatch(line): # The inlined call (inline_calls): the pair receives the address after the call, an opaque value that # only the removed s_setpc_b64 consumed. Neither the callee nor the code after it may name either word. diff --git a/tools/scan_unsupported_shaders.py b/tools/scan_unsupported_shaders.py index 43ffd88784..6fc5cbc3dc 100644 --- a/tools/scan_unsupported_shaders.py +++ b/tools/scan_unsupported_shaders.py @@ -233,6 +233,18 @@ def lower_rejection_causes(results: list[dict]) -> dict: SUPPORTED_INSTRUCTIONS_REGEX.append( rf"v_cmp_(?:{cmp_ops})_f32_sdwa\s+{PIXEL_LANE_MASK},\s+[^,]+,\s+[^,]+\s+src0_sel:DWORD\s+src1_sel:DWORD" ) + # The exec-writing VOPC SDWA forms print no destination: the predicate writes EXEC. + SUPPORTED_INSTRUCTIONS_REGEX.append( + rf"v_cmpx_(?:{cmp_ops})_f32_sdwa\s+[^,]+,\s+[^,]+\s+src0_sel:DWORD\s+src1_sel:DWORD" + ) + SUPPORTED_INSTRUCTIONS_REGEX.append( + rf"v_cmpx_(?:{cmp_ops})_f16_sdwa\s+{SDWA_CMP_SOURCE},\s+{SDWA_CMP_SOURCE}" + rf"\s+src0_sel:{SDWA_SEL_PATTERN}\s+src1_sel:{SDWA_SEL_PATTERN}" + ) + SUPPORTED_INSTRUCTIONS_REGEX.append( + rf"v_cmpx_class_(?:f16|f32)_sdwa\s+{SDWA_CMP_SOURCE},\s+{SDWA_CMP_SOURCE}" + rf"\s+src0_sel:{SDWA_SEL_PATTERN}\s+src1_sel:{SDWA_SEL_PATTERN}" + ) SUPPORTED_INSTRUCTIONS_REGEX.append( rf"v_cmp_(?:{cmp_ops})_f16{PIXEL_VOPC_E32_DST},\s+{F16_PLAIN},\s+{F16_PLAIN}" ) @@ -257,10 +269,18 @@ def lower_rejection_causes(results: list[dict]) -> dict: rf"v_cmp_(?:{icmp_ops})_(?:i32|u32)_sdwa\s+{PIXEL_SDWA_DST},\s+{SDWA_CMP_SOURCE},\s+{SDWA_CMP_SOURCE}" rf"\s+src0_sel:{SDWA_SEL_PATTERN}\s+src1_sel:{SDWA_SEL_PATTERN}" ) + SUPPORTED_INSTRUCTIONS_REGEX.append( + rf"v_cmpx_(?:{icmp_ops})_(?:i32|u32)_sdwa\s+{SDWA_CMP_SOURCE},\s+{SDWA_CMP_SOURCE}" + rf"\s+src0_sel:{SDWA_SEL_PATTERN}\s+src1_sel:{SDWA_SEL_PATTERN}" + ) SUPPORTED_INSTRUCTIONS_REGEX.append( rf"v_cmp_(?:eq|ne|lt|le|gt|ge)_(?:i16|u16)_sdwa\s+{PIXEL_SDWA_DST},\s+{SDWA_CMP_SOURCE},\s+{SDWA_CMP_SOURCE}" rf"\s+src0_sel:{SDWA_SEL_PATTERN}\s+src1_sel:{SDWA_SEL_PATTERN}" ) + SUPPORTED_INSTRUCTIONS_REGEX.append( + rf"v_cmpx_(?:eq|ne|lt|le|gt|ge)_(?:i16|u16)_sdwa\s+{SDWA_CMP_SOURCE},\s+{SDWA_CMP_SOURCE}" + rf"\s+src0_sel:{SDWA_SEL_PATTERN}\s+src1_sel:{SDWA_SEL_PATTERN}" + ) # 64-bit comparisons are checked by supports_int64_compare() below: the pair and inline ranges are numeric. INT64_COMPARE_PATTERN = re.compile( rf"v_cmp_(?:{icmp_ops})_(?:i64|u64)(_e32|_e64)?\s+(vcc(?:_lo)?|s\d+|s\[\d+:\d+\]),\s+(\S+),\s+(\S+)" From 0f54799475cbbbe9087fb81cea8d31a2855fef75 Mon Sep 17 00:00:00 2001 From: Roland Edi Date: Mon, 30 Nov 2026 04:02:00 +0000 Subject: [PATCH 4/7] tests: put the cmpx SDWA addend in src0 --- tests/pixel_aot_check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pixel_aot_check.py b/tests/pixel_aot_check.py index 3e4a3f37a9..17db72a9b0 100644 --- a/tests/pixel_aot_check.py +++ b/tests/pixel_aot_check.py @@ -5189,7 +5189,7 @@ def cmpx_sdwa_body(): for index, entry in enumerate(CMPX_SDWA_FORMS): channel, bit = divmod(index, 24) body += [CMPX_SAVE, cmpx_sdwa_instruction(entry), - f"v_add_f32_e32 v{13 + channel}, v{13 + channel}, {(127 + bit) << 23:#x}", + f"v_add_f32_e32 v{13 + channel}, {(127 + bit) << 23:#x}, v{13 + channel}", CMPX_MOV_RESTORE] return body From 3600208e30f6bd3dba9651af246ddadafdc3cd01 Mon Sep 17 00:00:00 2001 From: Roland Edi Date: Mon, 30 Nov 2026 04:08:46 +0000 Subject: [PATCH 5/7] tests: define the cmpx SDWA addend outside the region --- tests/pixel_aot_check.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/pixel_aot_check.py b/tests/pixel_aot_check.py index 17db72a9b0..cfc57dc8a4 100644 --- a/tests/pixel_aot_check.py +++ b/tests/pixel_aot_check.py @@ -5188,8 +5188,9 @@ def cmpx_sdwa_body(): body += [f"v_mov_b32_e32 v{13 + channel}, 0" for channel in range(3)] for index, entry in enumerate(CMPX_SDWA_FORMS): channel, bit = divmod(index, 24) - body += [CMPX_SAVE, cmpx_sdwa_instruction(entry), - f"v_add_f32_e32 v{13 + channel}, {(127 + bit) << 23:#x}, v{13 + channel}", + body += [f"v_mov_b32_e32 v16, {(127 + bit) << 23:#x}", + CMPX_SAVE, cmpx_sdwa_instruction(entry), + f"v_add_f32_e32 v{13 + channel}, v{13 + channel}, v16", CMPX_MOV_RESTORE] return body From f83514b76b90535304694e85630e13e63684b21b Mon Sep 17 00:00:00 2001 From: Roland Edi Date: Mon, 30 Nov 2026 04:19:51 +0000 Subject: [PATCH 6/7] tests: keep the cmpx SDWA addends out of inline constants --- docs/experiments.md | 2 +- tests/pixel_aot_check.py | 32 +++++++++++++++++++------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/docs/experiments.md b/docs/experiments.md index e83793ec84..369e8c4fb7 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -8929,7 +8929,7 @@ The SDWA forms of the 16 `v_cmp_*_f32` predicates are lowered when both `src0_se The 46 non-`v_cmpx` VOPC SDWA comparisons left by lot 1a are lowered: the 16 binary16 predicates and `v_cmp_class_f16_sdwa`, `v_cmp_class_f32_sdwa`, the 8 signed and 8 unsigned 32-bit predicates and the 6 signed and 6 unsigned 16-bit predicates. VOPC SDWA encodes only `src0_sel` and `src1_sel`; `llvm-mc` rejects `dst_sel`/`dst_unused` on these instructions, so the destination stays `vcc`/`vcc_lo` or one SGPR and the translator refuses an SGPR pair and the destination fields. Sources accept `BYTE_0..3`, `WORD_0..1` and `DWORD`, with `sext()` where LLVM prints it. The selection is zero-extended, or sign-extended under `sext()`, before the existing table applies: binary16 uses the low 16 bits through `widen16`/`num16`, the 16-bit integer forms take the low 16 bits, the 32-bit integer forms compare the selected word as signed or unsigned, and the class forms feed the selected bits to `class16` or `class32`. The comparison result is tracked in the same VCC/SGPR lane-mask state as the e32 and e64 forms, so `v_cndmask_b32` consumes it unchanged. The source-built fixture `tests/pixel_aot_check.py draw-sdwa-cmp` puts all 46 forms in one program, folds each predicate into two exported `R32G32B32A32_UINT` words, and repeats the rows with selections on every field. Its wrong references must each report `pixel_mismatch`: selections ignored (whole dwords), every field reversed (`BYTE_0`/`BYTE_3`, `BYTE_1`/`BYTE_2`, `WORD_0`/`WORD_1`), signedness inverted on the rows containing `0x8000`/`0xffff`, and zero extension in place of `sext()`. A second program writes two comparisons to `s52` and `vcc_lo` before consuming both; a reference that uses the second mask for both channels must mismatch. `tests/form_coverage_check.py` isolates this fixture's accepted words and asserts the 46 forms count in both `gfx1013.tsv` and `rdna2.tsv`, while the non-SDWA `v_cmp_*` neighbours stay out (the exec-writing `v_cmpx_*_sdwa` forms follow in lot 1b). The same program is part of `check_binary`, so the LLVM 15 `Assemble and translate gfx1013 fixtures` job assembles, disassembles and re-translates it. On base `0aa6522c` the measurement moved from 1255/1968 to 1301/1968 on gfx1013 and from 1246/1863 to 1292/1863 on gfx1030, exactly 46 forms in each reference. The new tests passed on WARP and on `pixel_aot_sdwa_cmp_hardware` on an AMD Radeon RX 9060 XT (driver 32.0.32029.2010), Windows 11 build 10.0.26300.10075, in 1.10 s; the debug layer was unavailable. The separate `pixel_aot_comparisons_hardware` entry still fails on this adapter in its pre-existing strict binary32 subnormal comparison ([issue #958](https://github.com/R0Y00/Xbox2Windows/issues/958)); that failure is outside this lot and does not affect the SDWA draw. This measures translated fixtures, not console behavior or full title execution. Reproduce with `ctest --preset dev --no-tests=error -R '^pixel_aot_sdwa_cmp_' -V`; the full measurement is `ctest --preset dev --no-tests=error -R '^(pixel_aot_|compute_store_aot_)' -E '_hardware$' -j 1 --output-junit out/build/dev/out/wave1-sdwa-after.xml` followed by `python -B tools/form_coverage.py out/build/dev/out/wave1-sdwa-after.xml --records out/build/dev/form_coverage --json out/wave1-sdwa-after.json`. A supplemental per-predicate fixture (`tests/pixel_aot_check.py draw-sdwa-int-compare`, tests `pixel_aot_sdwa_int_compare_{warp,hardware}`) exercises all 16 32-bit integer SDWA comparisons across four 4-channel groups (`i32_lo`, `i32_hi`, `u32_lo`, `u32_hi`) with 41 targeted single-channel negative controls plus static refusal checks for `low16` sources, pending loads, masked regions, float modifiers, `clamp` and SGPR pair destinations. -Lot 1b lowers the remaining 62 exec-writing VOPC SDWA comparisons: the 16 binary32 predicates (whole-dword selections only, as their `v_cmp` forms), the 16 binary16 predicates, `v_cmpx_class_f16` and `v_cmpx_class_f32`, the 8 signed and 8 unsigned 32-bit predicates and the 6 signed and 6 unsigned 16-bit predicates. VOPC SDWA prints no destination and encodes no `dst_sel`/`dst_unused`: the comparison writes EXEC, so each form reuses the existing `v_cmpx` region opener unchanged (the `s_mov_b64 s[a:b], exec` save, the entry-mask intersection, the SKIP/else handling and the two closes), and the non-SDWA path is untouched. Selections are the same `BYTE_0..3`, `WORD_0..1` and `DWORD` fields, zero-extended or sign-extended under `sext()`, applied before the e32 table. The fixture `draw-cmpx-sdwa` (`pixel_aot_cmpx_sdwa_{warp,hardware}`) opens one region per form and adds an exact power of two to one of three exported binary32 accumulators (24 bits per channel, so every partial sum is an exact integer below 2^24); its wrong references must each mismatch: selections ignored, every field reversed, signedness inverted, zero extension instead of `sext()`, and the region applied to every lane. Static controls refuse a missing or non-adjacent EXEC save, `dst_sel`/`dst_unused`, an SGPR pair in the source position, byte/word selections on an f32 predicate, and the nonexistent 64-bit SDWA exec writers. `tests/form_coverage_check.py` isolates this fixture's accepted words and asserts its 62 forms are exactly the SDWA `v_cmpx` family of both references, while the non-SDWA exec writers and the `v_cmp_*_sdwa` forms stay out. The same program is part of `check_binary`. The 194-entry WARP replay (`pixel_aot_`/`compute_store_aot_`, `_hardware` excluded) passes with no failure or skip and measures 1542/1968 on gfx1013 and 1533/1863 on gfx1030; removing the 62 forms of this lot leaves 1480/1968 and 1471/1863. The targeted WARP and hardware runs pass on the AMD Radeon RX 9060 XT (driver 32.0.32029.2010); `draw-cmpx-regions` and `draw-sdwa-cmp` also pass on both adapters. This measures translated fixtures, not console behavior or full title execution. Reproduce the target with `python -B tests/pixel_aot_check.py draw-cmpx-sdwa warp` (or `hardware`), `tests/pixel_aot_check.py draw-cmpx-regions`, `tests/pixel_aot_check.py draw-sdwa-cmp` and `python -B tests/form_coverage_check.py`; in a configured tree the CTest entry is `ctest --preset dev --no-tests=error -R '^pixel_aot_cmpx_sdwa_' -V`, and the full measurement is `ctest --preset dev --no-tests=error -R '^(pixel_aot_|compute_store_aot_)' -E '_hardware$' -j 1 --output-junit out/build/dev/out/wave1-cmpx-sdwa.xml` followed by `python -B tools/form_coverage.py out/build/dev/out/wave1-cmpx-sdwa.xml --records out/build/dev/form_coverage --json out/wave1-cmpx-sdwa.json`. In this worktree the CMake configure stops in the `opus` dependency (`LNK1104: m.lib`) before any target, so the 194-entry run replayed the main build's CTest command list with this tree's tests and the main build's `offscreen_check.exe`; the replay helper is untracked under `out/coverage-run/`. +Lot 1b lowers the remaining 62 exec-writing VOPC SDWA comparisons: the 16 binary32 predicates (whole-dword selections only, as their `v_cmp` forms), the 16 binary16 predicates, `v_cmpx_class_f16` and `v_cmpx_class_f32`, the 8 signed and 8 unsigned 32-bit predicates and the 6 signed and 6 unsigned 16-bit predicates. VOPC SDWA prints no destination and encodes no `dst_sel`/`dst_unused`: the comparison writes EXEC, so each form reuses the existing `v_cmpx` region opener unchanged (the `s_mov_b64 s[a:b], exec` save, the entry-mask intersection, the SKIP/else handling and the two closes), and the non-SDWA path is untouched. Selections are the same `BYTE_0..3`, `WORD_0..1` and `DWORD` fields, zero-extended or sign-extended under `sext()`, applied before the e32 table. The fixture `draw-cmpx-sdwa` (`pixel_aot_cmpx_sdwa_{warp,hardware}`) opens one region per form and adds one of 2^8..2^23 to one of four exported binary32 accumulators (16 bits per channel; every partial sum is an exact integer below 2^24, and the constants avoid LLVM's float inline-constant spellings); its wrong references must each mismatch: selections ignored, every field reversed, signedness inverted, zero extension instead of `sext()`, and the region applied to every lane. Static controls refuse a missing or non-adjacent EXEC save, `dst_sel`/`dst_unused`, an SGPR pair in the source position, byte/word selections on an f32 predicate, and the nonexistent 64-bit SDWA exec writers. `tests/form_coverage_check.py` isolates this fixture's accepted words and asserts its 62 forms are exactly the SDWA `v_cmpx` family of both references, while the non-SDWA exec writers and the `v_cmp_*_sdwa` forms stay out. The same program is part of `check_binary`. The 194-entry WARP replay (`pixel_aot_`/`compute_store_aot_`, `_hardware` excluded) passes with no failure or skip and measures 1542/1968 on gfx1013 and 1533/1863 on gfx1030; removing the 62 forms of this lot leaves 1480/1968 and 1471/1863. The targeted WARP and hardware runs pass on the AMD Radeon RX 9060 XT (driver 32.0.32029.2010); `draw-cmpx-regions` and `draw-sdwa-cmp` also pass on both adapters. This measures translated fixtures, not console behavior or full title execution. Reproduce the target with `python -B tests/pixel_aot_check.py draw-cmpx-sdwa warp` (or `hardware`), `tests/pixel_aot_check.py draw-cmpx-regions`, `tests/pixel_aot_check.py draw-sdwa-cmp` and `python -B tests/form_coverage_check.py`; in a configured tree the CTest entry is `ctest --preset dev --no-tests=error -R '^pixel_aot_cmpx_sdwa_' -V`, and the full measurement is `ctest --preset dev --no-tests=error -R '^(pixel_aot_|compute_store_aot_)' -E '_hardware$' -j 1 --output-junit out/build/dev/out/wave1-cmpx-sdwa.xml` followed by `python -B tools/form_coverage.py out/build/dev/out/wave1-cmpx-sdwa.xml --records out/build/dev/form_coverage --json out/wave1-cmpx-sdwa.json`. In this worktree the CMake configure stops in the `opus` dependency (`LNK1104: m.lib`) before any target, so the 194-entry run replayed the main build's CTest command list with this tree's tests and the main build's `offscreen_check.exe`; the replay helper is untracked under `out/coverage-run/`. Binary32 floating-point vector comparisons (`v_cmp_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg,ngt,nle,neq,nlt,tru}_f32` in e32, e64, and whole-dword SDWA forms) evaluate the 16 IEEE-754 relations against scalar and vector operands, including subnormals, signed zeroes, infinities, and quiet/signaling NaNs. The e32 (VOPC) encoding requires destination `vcc` or `vcc_lo`; SGPR destinations (`s52`, `s[52:53]`) are accepted on suffix-less and explicit `_e64` (VOP3) encodings. Source modifiers (`neg`, `abs`) are accepted on e64 operands (`-s44`, `|v18|`, `-|s44|`), while `clamp` and `op_sel` remain rejected on comparisons. Rejection controls verify that untracked source registers, SGPR destinations on explicit e32, and sub-dword SDWA selections (`src0_sel:WORD_0`, `src1_sel:BYTE_2`) raise `ValueError`. The synthetic fixture `f32_compares()` verifies all 16 predicates across e32, e64, and whole-dword SDWA, validating them against an exact reference oracle (`f32_compares_reference()`). Mutating predicates or modifiers produces a mismatch. diff --git a/tests/pixel_aot_check.py b/tests/pixel_aot_check.py index cfc57dc8a4..02abc16815 100644 --- a/tests/pixel_aot_check.py +++ b/tests/pixel_aot_check.py @@ -5024,7 +5024,8 @@ def sdwa_cmp_expected_words(word0, word1, *, select=None, signed=None, sext=True for index, entry in enumerate(SDWA_CMP_FORMS): if sdwa_cmp_expected(entry, word0, word1, select=select, signed=signed, sext=sext): words[index // 32] |= 1 << (index % 32) - return tuple(words) + # Each addend is 2^(8 + bit), so the accumulator holds the bitmap shifted left by 8. + return tuple(word << 8 for word in words) def sdwa_cmp_destination_body(): @@ -5183,34 +5184,39 @@ def cmpx_sdwa_instruction(entry): def cmpx_sdwa_body(): - """All 62 forms, each folded into bit i of three exported binary32 words (24 bits per channel).""" + """All 62 forms, each folded into one bit of four exported binary32 words. + + The four accumulators carry bits 8..23 of each word, so every addend is an exact power of two + that LLVM prints as a hex literal (small values become float inline constants and would not + round-trip). Each word holds 16 bits; the fourth uses 14. + """ body = ["v_mov_b32_e32 v18, v12"] - body += [f"v_mov_b32_e32 v{13 + channel}, 0" for channel in range(3)] + body += [f"v_mov_b32_e32 v{12 + channel}, 0" for channel in range(4)] for index, entry in enumerate(CMPX_SDWA_FORMS): - channel, bit = divmod(index, 24) - body += [f"v_mov_b32_e32 v16, {(127 + bit) << 23:#x}", + channel, bit = divmod(index, 16) + body += [f"v_mov_b32_e32 v16, {(135 + bit) << 23:#x}", CMPX_SAVE, cmpx_sdwa_instruction(entry), - f"v_add_f32_e32 v{13 + channel}, v{13 + channel}, v16", + f"v_add_f32_e32 v{12 + channel}, v{12 + channel}, v16", CMPX_MOV_RESTORE] return body def cmpx_sdwa_expected_words(word0, word1, *, select=None, signed=None, sext=True, unmasked=False): - words = [0, 0, 0] + words = [0, 0, 0, 0] for index, entry in enumerate(CMPX_SDWA_FORMS): if unmasked or sdwa_cmp_expected(entry, word0, word1, select=select, signed=signed, sext=sext): - words[index // 24] |= 1 << (index % 24) - return tuple(words) + words[index // 16] |= 1 << (index % 16) + # Each addend is 2^(8 + bit), so the accumulator holds the bitmap shifted left by 8. + return tuple(word << 8 for word in words) def cmpx_sdwa_pixels(word0, **kwargs): pixels = [] for g in MASKED_RAMP: for r in MASKED_RAMP: - x = single(r / 255) - bits, = struct.unpack(" Date: Mon, 30 Nov 2026 04:33:49 +0000 Subject: [PATCH 7/7] tests: restore the lot 1a sdwa compare words --- tests/pixel_aot_check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pixel_aot_check.py b/tests/pixel_aot_check.py index 02abc16815..1180568f0d 100644 --- a/tests/pixel_aot_check.py +++ b/tests/pixel_aot_check.py @@ -5025,7 +5025,7 @@ def sdwa_cmp_expected_words(word0, word1, *, select=None, signed=None, sext=True if sdwa_cmp_expected(entry, word0, word1, select=select, signed=signed, sext=sext): words[index // 32] |= 1 << (index % 32) # Each addend is 2^(8 + bit), so the accumulator holds the bitmap shifted left by 8. - return tuple(word << 8 for word in words) + return tuple(words) def sdwa_cmp_destination_body():