Skip to content
Merged
1 change: 1 addition & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ jobs:
tests/startup_compute_lds_b64_check.py \
tests/startup_compute_translate_check.py \
tests/startup_gfx2hlsl_swap_check.py \
tests/startup_gfx2hlsl_fma_mix_check.py \
tests/startup_gfx2hlsl_shift64_check.py \
tests/startup_gfx2hlsl_mul_mad_i24_check.py \
tests/startup_gfx2hlsl_vopc_sdwa_check.py \
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ python3 -m venv out/pe-env
./out/pe-env/bin/python -B tests/startup_compute_image_store_d16_check.py
./out/pe-env/bin/python -B tests/startup_compute_translate_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_swap_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_fma_mix_check.py
./out/pe-env/bin/python -B tests/startup_image_2d_array_check.py
./out/pe-env/bin/python -B tests/startup_image_sample_a16_check.py
./out/pe-env/bin/python -B tests/startup_image_load_d16_check.py
Expand Down
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3059,6 +3059,9 @@ if(EXISTS "${INTAKE_PYTHON}")
# them as an index error before it checked the count.
add_test(NAME startup_gfx2hlsl_image_arity COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_image_arity_check.py")
# gfx2hlsl lowers v_fma_mix_f32 and selects binary16 source halves on all three mixed-precision FMAs.
add_test(NAME startup_gfx2hlsl_fma_mix COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_fma_mix_check.py")
# VOP1/VOP2 sub-dword addressing (SDWA) in the translator (#1141), checked against the pixel AOT
# lowering of the same selections.
add_test(NAME startup_gfx2hlsl_sdwa COMMAND "${INTAKE_PYTHON}" -B
Expand Down Expand Up @@ -3161,6 +3164,11 @@ if(EXISTS "${INTAKE_PYTHON}")
# gfx2hlsl run-time sampler heap indexing (#1143): translation controls, then a desktop draw with
# DXC ps_6_0 and, when the Windows SDK's FXC is found, the ps_5_1 the startup tools compile with.
find_program(STARTUP_FXC fxc HINTS "${DXC_BIN_DIR}")
if(STARTUP_FXC)
# The v_fma_mix* translations from startup_gfx2hlsl_fma_mix, compiled for ps_5_1.
add_test(NAME startup_gfx2hlsl_fma_mix_fxc COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_fma_mix_check.py" fxc "${STARTUP_FXC}")
endif()
# gfx2hlsl conversion operations: translation controls, then a draw of the translated pairs with
# reference words and one mutated lowering per operation (v_cvt_f16_f32 through DXC only).
# Compute translator: integer inequality lane guards.
Expand Down Expand Up @@ -3487,6 +3495,15 @@ if(EXISTS "${INTAKE_PYTHON}")
set_tests_properties(startup_gfx2hlsl_mad_dispatch_${adapter} startup_gfx2hlsl_mad_preserve_${adapter}
PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
endforeach()
# gfx2hlsl v_fma_mix*: every translated form dispatched against a CPU reference that decodes the VOP3P
# word itself, plus a control that drops the high-half shift.
foreach(adapter IN ITEMS warp hardware)
add_test(NAME startup_gfx2hlsl_fma_mix_dispatch_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_fma_mix_check.py" dispatch "${DXC_EXECUTABLE}"
"$<TARGET_FILE:offscreen_check>" ${adapter})
set_tests_properties(startup_gfx2hlsl_fma_mix_dispatch_${adapter}
PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
endforeach()
# gfx2hlsl compute stage: entry registers, numthreads and the offen buffer store, dispatched on a plain device (#1412).
add_test(NAME startup_gfx2hlsl_compute_controls COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_compute_check.py")
Expand Down
29 changes: 29 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -14299,6 +14299,35 @@ The binary32 table (`VEC_F`) applies the same operand-count rule. Before this ch

`tests/startup_gfx2hlsl_swap_check.py` (`startup_gfx2hlsl_swap`) decodes the documented VOP1 words, evaluates the translated text of seven programs on the CPU against a plain exchange of two list entries, and checks the refusals. Two mutations (write before read, only one destination written) are loaded from the translator source and must fail the fixtures. `python -B tests/startup_gfx2hlsl_swap_check.py binary llvm-mc-15` also reassembles the source lines. This is translation only; no draw was run.

## Startup translator: v_fma_mix_f32

`tools/startup/gfx2hlsl.py` now lowers `v_fma_mix_f32` (VOP3P, opcode 0x20), which it used to refuse. It shares one handler with `v_fma_mixlo_f16` and `v_fma_mixhi_f16`. Each source is read as LLVM 15 selects it (`SelectVOP3PMadMixModsImpl`): `op_sel_hi` set means a binary16 source, and `op_sel` then picks its high half. abs and then neg apply after widening. The binary32 result is written to the whole VGPR, with optional `clamp`.

The shared handler now also:

- reads the high half of a binary16 source with `op_sel` (previously refused on all three forms);
- accepts `-` and `|...|` on binary16 register sources;
- still refuses `op_sel` on a binary32 source, including a negated inline zero (it was refused on every source before);
- refuses any other modifier it does not model (previously ignored);
- reads only bits 15:0 of a low-half binary16 source, so a register left with undefined upper bits by an odd-dmask D16 `image_load` stays usable there; a high-half read is still refused for such a register;
- reads a literal on a binary16 source through the selected half, so `0x40003c00` gives 1.0 from the low half and 2.0 from the high half;
- accepts inline `0.5` on a low-half binary16 source and refuses the high half of an inline constant and every other inline float there. Before, `mixlo`/`mixhi` passed the binary32 bits of an inline float such as `1.0` through `f16tof32`, which reads 0;
- reads a negated inline zero (`-0`) as `-0.0` on any source, so a `-0` product stays `-0`;
- emits neg on a negative inline float (printed `--0.5`) as `(-(-0.5))`. Before, `(--0.5)` was an HLSL decrement and did not compile;
- refuses a binary32 source printed as a negative integer or literal (`-1`, `-17`, `-0x…`). The decoder prints neg on inline 1..64 or on a literal that way, and reading it as an integer loses the sign-bit flip: neg on inline 1 is `0x80000001`, not `0xffffffff`. Inline `-1` prints the same text as neg on inline 1, so it is refused too until the decoder resolves the operand from the encoding, as it does for `v_cndmask_b32_e64` (#1932).

`tests/startup_gfx2hlsl_fma_mix_check.py` (`startup_gfx2hlsl_fma_mix`) builds VOP3P words from the decoder layout. It first checks that its encoder reproduces two `llvm-mc`-assembled words already pinned in `tests/rdna2_tools_check.py`. It then checks the decoded text and pins the translation of seventeen forms. They include a register with undefined upper bits read through its low half, both halves of one literal, and inline `0.5` on a low half. Two controls check that flipping `op_sel` and `op_sel_hi` changes the output, a third checks that an unnegated literal still translates, and eleven forms must be refused. On the translator before this change the check fails at the first form.

With `fxc <path>`, the check also compiles all seventeen translated lines for ps_5_1, the profile the startup tools use. CMake registers that mode as `startup_gfx2hlsl_fma_mix_fxc` when it finds FXC. As a control, putting back the earlier `(--0.5)` text makes FXC fail with error X3025. The refusal census was not re-measured.

With `dispatch <dxc> <offscreen_check> warp|hardware`, all seventeen translated lines run in one DXC cs_6_0 thread. CMake registers this as `startup_gfx2hlsl_fma_mix_dispatch_warp` and `_hardware`. Each case loads its register words through the raw UAV fill pattern, so the compiler cannot fold them, runs the line and stores the destination. The check compares each word with a CPU reference that decodes the VOP3P word itself, without the decoder or the translator. The reference applies the LLVM 15 reading: binary16 if `op_sel_hi`, high half if `op_sel`, abs then neg, clamp. Inputs have short mantissas, so a fused and an unfused multiply-add give the same word; this check does not separate the two. A control drops the high-half shift from the emitted lines. Its readback must then follow a reference with `op_sel` cleared, and must differ from the correct result in at least one case. It differs in 3 of 4: the `-0` case has a zero product, so the half it reads does not show.

Measured at `741ff02c` plus the dispatch mode, `dev` preset, Windows 11 26300.9974. On WARP (Microsoft Basic Render Driver, 1414:008c) and on an NVIDIA GeForce RTX 4090 (10de:2684, driver 32.0.16.1088), 17 of 17 words matched the reference, and the control read the low half in all 4 high-half cases. Neither run reported a capability skip. The fixture does not report D3D12 debug-layer status.

```powershell
ctest --preset dev --no-tests=error -j1 -R '^startup_gfx2hlsl_fma_mix(_fxc|_dispatch_(warp|hardware))?$' -V
```

## Non-fused multiply-add in the startup translator

The gfx1013 `v_mad_f32`, `v_mac_f32`, `v_madmk_f32`, `v_madak_f32` and
Expand Down
Loading
Loading