From 72603d64725194c8168b3806d0f8df72e9f19317 Mon Sep 17 00:00:00 2001 From: triggered02 <153171514+triggered02@users.noreply.github.com> Date: Wed, 25 Nov 2026 21:44:10 +0530 Subject: [PATCH] startup: refuse modifiers on modifier-free handlers Fixes #1771. --- CMakeLists.txt | 3 + docs/experiments.md | 14 ++ tests/startup_gfx2hlsl_modifier_free_check.py | 179 ++++++++++++++++++ ...up_gfx2hlsl_readfirstlane_uniform_check.py | 6 +- tools/startup/gfx2hlsl.py | 12 ++ 5 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 tests/startup_gfx2hlsl_modifier_free_check.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c19656804..f19a4b3c93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3041,6 +3041,9 @@ if(EXISTS "${INTAKE_PYTHON}") # lowering of the same selections. add_test(NAME startup_gfx2hlsl_sdwa COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_sdwa_check.py") + # Handlers that do not model a modifier they can receive refuse it (#1771). + add_test(NAME startup_gfx2hlsl_modifier_free COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_modifier_free_check.py") # image_sample_c_lz with sampler word 2 bits 28-30 set (#1723). add_test(NAME startup_gfx2hlsl_sample_c_lz_mip COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_sample_c_lz_mip_check.py") diff --git a/docs/experiments.md b/docs/experiments.md index 6a206cc2dc..b52acf34c6 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -15108,3 +15108,17 @@ Building on #2443 (Slice 1), `X2W_D3D12_RELEASE_RETIRED=1` extends desktop objec ```powershell ctest --preset dev --no-tests=error -R '^startup_resource_(retire|budget)' -V ``` + +## Refusing unmodelled modifiers in the startup translator + +Several `Stage` instruction handlers accepted a `mods` list without reading it, so an encoding modifier such as +`clamp`, `omod` (`mul:2`), or `op_sel` on `v_mov_b32`, `v_cvt_pkrtz_f16_f32`, or `v_interp_mov_f32` was silently +dropped from the emitted HLSL (#1771). `MODIFIER_FREE_HANDLERS` declares these five handlers (`op_v_mov_b32`, +`op_v_cvt_pkrtz_f16_f32`, `op_v_interp_p1_f32`, `op_v_interp_p2_f32`, and `op_v_interp_mov_f32`), and `Stage.one` +refuses any non-empty `mods` list before dispatching to them. Scalar-ALU handlers are omitted because their encodings +have no modifier field. Separately, `op_v_interp_p1_f32` and `op_v_interp_p2_f32` refuse `abs`/`neg` modifiers (`|...|` +or `-...`) printed on the ignored data-source operand (`ops[1]`). + +```powershell +ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_modifier_free$' -V +``` diff --git a/tests/startup_gfx2hlsl_modifier_free_check.py b/tests/startup_gfx2hlsl_modifier_free_check.py new file mode 100644 index 0000000000..e18d4c1d16 --- /dev/null +++ b/tests/startup_gfx2hlsl_modifier_free_check.py @@ -0,0 +1,179 @@ +"""Handlers whose lowering does not model a modifier they can receive (issue #1771). + +usage: startup_gfx2hlsl_modifier_free_check.py + +Several handlers take the modifier list and never read it, so a modifier their encoding can carry was dropped +from the emitted HLSL - the same class as the `op_sel`/`clamp` cases fixed one at a time earlier +(`set_vf`, `op_v_cndmask_b32`, `compare`). The dispatch now refuses a modifier for the handlers declared in +`MODIFIER_FREE_HANDLERS`, before the handler can ignore it. + +The instruction bytes are **constructed here** from the field layout the checked-in decoder reads +(`tools/disasm_rdna2.py`): VOP1/VOP2-as-VOP3 use prefix `0b110101` with opcode `0x180 + n` / `0x100 + n`, +modifiers at `w0[15]` (clamp), `w0[14:11]` (op_sel) and `w1[28:27]` (omod); VOP3A uses the opcode in `w0[25:16]`. +""" +import os +import struct +import sys + +here = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.join(here, '..', 'tools')) +sys.path.insert(0, os.path.join(here, '..', 'tools', 'startup')) +import gfx2hlsl as G # noqa: E402 + +failures = [] + + +def check(label, condition, detail=''): + print(f"{label}: {'ok' if condition else 'MISMATCH'}") + if not condition: + failures.append(label) + if detail: + print(' ' + detail) + + +VOP1_E64_BASE = 0x180 +VOP2_E64_BASE = 0x100 +VOP1_MOV_B32 = 0x01 +VOP2_CVT_PKRTZ_F16_F32 = 0x2F +VOP3A_INTERP_P1 = 0x200 +VOP3A_INTERP_P2 = 0x201 +VOP3A_INTERP_MOV = 0x202 +V1, V2, V3 = 0x101, 0x102, 0x103 + + +def _word0(opcode, vdst, *, clamp=0, op_sel=(0, 0, 0, 0)): + w0 = (0b110101 << 26) | ((opcode & 0x3FF) << 16) | ((clamp & 1) << 15) | (vdst & 0xFF) + for i, bit in enumerate(op_sel): + w0 |= (bit & 1) << (11 + i) + return w0 + + +def encode_vop1(op, vdst, src0, *, clamp=0): + return struct.pack('