diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index b7a494ddaa..e27d2d079e 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -117,6 +117,7 @@ jobs: (["tests/startup_image_load_d16_check.py", "binary", "llvm-mc-15"], {}), (["tests/startup_image_load_d16_check.py", "decode", "libLLVM-15.so.1"], {}), (["tests/startup_flat_param_check.py", "binary", "llvm-mc-15"], {}), + (["tests/startup_gfx2hlsl_float_transcendental_check.py", "binary", "llvm-mc-15"], {}), (["tests/startup_gfx2hlsl_bit_alu_check.py", "binary", "llvm-mc-15"], {}), (["tests/startup_gfx2hlsl_interp_f16_check.py", "binary", "llvm-mc-15"], {}), (["tests/startup_gfx2hlsl_interp_p2_hi_check.py", "binary", "llvm-mc-15"], {}), @@ -288,6 +289,7 @@ jobs: tests/startup_run_ps1_check.py \ tests/startup_run_sh_check.py \ tests/startup_flat_param_check.py \ + tests/startup_gfx2hlsl_float_transcendental_check.py \ tests/startup_ps_input_scan_check.py \ tests/startup_packed_position_provenance_check.py \ tests/startup_build_rev_check.py \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b9ba48969..ae009bcdc0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4131,6 +4131,17 @@ if(EXISTS "${INTAKE_PYTHON}") "$" ${adapter} $<$:${STARTUP_FXC}>) set_tests_properties(startup_inline_sampler_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) endforeach() + # gfx2hlsl binary32 reciprocal, roots, exp2 and log2 (VEC_F) on exact inputs: translation controls, then a + # draw of the translated pairs with reference words and one mutated lowering per operation. + add_test(NAME startup_gfx2hlsl_float_transcendental_controls COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_float_transcendental_check.py") + foreach(adapter IN ITEMS warp hardware) + add_test(NAME startup_gfx2hlsl_float_transcendental_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_float_transcendental_check.py" draw "${DXC_EXECUTABLE}" + "$" ${adapter} $<$:${STARTUP_FXC}>) + set_tests_properties(startup_gfx2hlsl_float_transcendental_${adapter} PROPERTIES TIMEOUT 300 + SKIP_RETURN_CODE 77) + endforeach() add_test(NAME startup_gfx2hlsl_scalar_shift64_bfe_controls COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_scalar_shift64_bfe_check.py") add_test(NAME startup_gfx2hlsl_scalar_m0_controls COMMAND "${INTAKE_PYTHON}" -B diff --git a/docs/experiments.md b/docs/experiments.md index 97c7fad37a..1578349127 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -15757,6 +15757,19 @@ The [MASM fixture](../tests/cpu/vex_parity.asm) and [differential check](../test ctest --preset release --no-tests=error -R '^cpu_aot_vex_parity$' -V ``` +## Startup translator: reciprocal, roots, exp2 and log2 + +The `VEC_F` table of `tools/startup/gfx2hlsl.py` lowers six operations to HLSL with no check that ran them before: `v_rcp_f32` and `v_rcp_iflag_f32` to `1.0 / x`, `v_sqrt_f32` to `sqrt`, `v_rsq_f32` to `rsqrt`, `v_exp_f32` to `exp2` and `v_log_f32` to `log2`. `tests/startup_gfx2hlsl_float_transcendental_check.py` draws them with the shared runner `tests/startup_gfx2hlsl_lane_alu.py`. Each draw applies one operation per lane on flat inputs, alternates the `_e32` and `_e64` spellings, and compares the four result words exactly. + +Every input is a power of two, or 0 and 9 for the square root, so every result is exact. The check therefore tests which function each operation is lowered to and the base 2 of `v_exp_f32` and `v_log_f32`. It does not test how many ulps an adapter's approximation may be off. + +Each operation has a wrong lowering whose first draw must read its own mutated words: +- `2.0 / x` for the reciprocals; +- sqrt and rsqrt exchanged; +- the exponent off by one; +- the logarithm plus one. + +On WARP 10.0.26100.9818 and on an AMD Radeon RX 6600 (driver 32.0.21045.29003), all 24 draws matched through FXC `ps_5_1` and DXC `ps_6_0`, and all 12 mutated draws read their mutated words. `v_sin_f32` and `v_cos_f32` are not covered: their results at the few exact points depend on the approximation. Tests: `startup_gfx2hlsl_float_transcendental_controls`, `startup_gfx2hlsl_float_transcendental_warp` and `startup_gfx2hlsl_float_transcendental_hardware`. ### gfx1013 pixel DPP16 quad broadcast The pixel translator lowers `quad_perm:[k,k,k,k]` (k = 0 to 3) with full `row_mask` and `bank_mask` on `v_mov_b32` and the VOP1/VOP2 float, integer and integer-to-float forms to `QuadReadLaneAt(value, k)`. The four lanes of a pixel quad are one 2 x 2 block (lane = x & 1 | (y & 1) << 1). It is accepted in the entry straight-line prefix of a pixel stage that ran `s_wqm_b64 exec, exec` (or `s_wqm_b32 exec_lo, exec_lo`) with EXEC unchanged since: the entry EXEC can leave out lanes of a partly covered quad, and the guest would then read an inactive source lane while `QuadReadLaneAt` returns a helper lane's value. A later uniform loop or forward branch elsewhere in the same stage does not drop that proof (the M200-01/003 shape). Without the proof the instruction is refused, as are a broadcast after a branch target, after EXEC changed, or with divergent EXEC before the broadcast, swaps, pair broadcasts, row shifts, mirrors, DPP8, partial masks, `bound_ctrl:0`, non-VGPR sources and vertex stages. `fi:1` is accepted with the proof and changes nothing, since no source lane is disabled. A stage that holds a quad read compiles as `ps_6_0` with DXC (`X2W_DXC`, the Windows Kits `bin` folder or `PATH`), and its vertex stage as `vs_6_0`. diff --git a/tests/startup_gfx2hlsl_float_transcendental_check.py b/tests/startup_gfx2hlsl_float_transcendental_check.py new file mode 100644 index 0000000000..adc1b5bc26 --- /dev/null +++ b/tests/startup_gfx2hlsl_float_transcendental_check.py @@ -0,0 +1,84 @@ +"""Binary32 reciprocal, root, exponential and logarithm of tools/startup/gfx2hlsl.py (its VEC_F table). + + (no arguments) translation controls, pure Python + binary reassemble the pixel bodies and compare them with the recorded words + draw [fxc] + draw one pixel per four input sets and compare the four result words + +Covers v_rcp_f32, v_rcp_iflag_f32, v_sqrt_f32, v_rsq_f32, v_exp_f32 and v_log_f32, which no check ran before. They +lower to 1.0 / x, sqrt, rsqrt, exp2 and log2. The fixture and runner are startup_gfx2hlsl_lane_alu.py: one operation +per lane, alternating the e32 and e64 spellings, on flat parameters the compilers cannot fold. The references follow +the AMD RDNA 2 ISA reference (v_exp_f32 and v_log_f32 are base 2). Every input is a power of two, or 0 and 9 for the +square root, so every result is exact and the comparison does not depend on how many ulps an adapter's +approximation may be off: it checks which function each operation is lowered to, not its precision. +""" +import math +import struct +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +from startup_gfx2hlsl_lane_alu import main, words # noqa: E402 + + +def f(value): + return struct.unpack('