startup: carry the undefined upper half through v_mov / v_cndmask copies and read VOP3 modifiers in the f16 interpolation scan #2784

Closed
tedin7 wants to merge 5 commits from upstream-pr/2792 into main
tedin7 commented 2026-11-26 09:40:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T09:40:06Z.


Part of #1723

What this unblocks: pixel programs that copy a plain v_interp_p2_f16 result with v_mov_b32 / v_cndmask_b32 before reading it as a binary16 low half (for example through v_fma_mix_f32) no longer stop at "reads the upper 16 bits"; and a read of such a result through a VOP3 source modifier (-v4, |v4|) is now flagged instead of slipping past the scan.

Stacked on #2789 (this branch contains its commits until that merges; the new work is the last commit). Does not touch #2789's low-half v_fma_mix_f32 rule.

Source: AMD "RDNA 2" Instruction Set Architecture reference guide, VINTRP instruction V_INTERP_P2_F16 (a plain form writes only the low 16 bits of its destination), VOP3P V_FMA_MIX_F32 (op_sel_hi marks a binary16 source, op_sel picks its half), VOP1 V_MOV_B32 and VOP2 V_CNDMASK_B32 (32-bit register copies).

What changed (Stage.interp_f16_scan in tools/startup/gfx2hlsl.py)

  • A plain whole-register copy (v_mov_b32, or v_cndmask_b32 with both value sources plain VGPRs, no modifiers) of a register whose upper half is undefined is no longer a read of that half: it hands the undefined-upper-half state on to its destination. The half is still checked where it is observed (an export, a shift, a binary32 v_fma_mix, an op_sel pick of the upper half all stay refused on the copy).
  • The destination of v_mov_b32, v_cndmask_b32 and v_fma_mix_f32 (which rewrites all 32 bits) is no longer counted as a read of its old undefined half. It still counts for the pending / stale v_interp_p1ll_f16 result checks, so overwriting a pending result is refused with the same message as before.
  • The scan's register lookup now strips a VOP3 source modifier. Before, v_mul_f32_e64 v8, -v4, 1.0 or |v4| on a plain p2 result named no register, so the read of the undefined upper half was never flagged and the program translated.

What stays refused: any other reader of an undefined upper half, an op_sel upper-half pick, a binary32 source, a copy read through an export or shift, and every other v_interp_p1ll_f16 / v_interp_p2_f16 form that was refused before.

Tests (startup_gfx2hlsl_interp_f16_check.py, llvm-mc-verified words in binary mode)

  • Accepted: a v_mov_b32 copy and a v_cndmask_b32 copy of a plain p2 result read through v_fma_mix_f32 as a low half; both evaluate to the same words as the direct low-half read. The draw mode also draws the v_mov_b32 copy on D3D12 and compares it with the ISA arithmetic (binary16 low half squared), with a wrong-reference control that must fail.
  • Refused: the copy exported, the copy shifted, a negated read and an absolute-value read of a p2 result.
  • Mutations tried, each caught by the check: the modifier strip removed (negated read translated), copies no longer tolerated (accepted case refused), a copy that does not carry the state (copy exported translated).

Verification:

python3 -B tests/startup_gfx2hlsl_interp_f16_check.py                      rc=0
python3 -B tests/startup_gfx2hlsl_interp_f16_check.py binary llvm-mc-19    fixture words match llvm-mc
python3 -B tests/startup_gfx2hlsl_interp_p2_hi_check.py                    rc=0
python3 -B tests/startup_gfx2hlsl_fma_mix_check.py                         rc=0
python3 -B tests/startup_gfx2hlsl_f16_alu_check.py                         rc=0
remote_pycheck.sh <worktree> --compare origin/main                         0 differ

Win2025 WARP dev+release: pending Stage-2.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6623794930 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2792). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T09:40:06Z. --- Part of #1723 What this unblocks: pixel programs that copy a plain `v_interp_p2_f16` result with `v_mov_b32` / `v_cndmask_b32` before reading it as a binary16 low half (for example through `v_fma_mix_f32`) no longer stop at "reads the upper 16 bits"; and a read of such a result through a VOP3 source modifier (`-v4`, `|v4|`) is now flagged instead of slipping past the scan. Stacked on #2789 (this branch contains its commits until that merges; the new work is the last commit). Does not touch #2789's low-half `v_fma_mix_f32` rule. Source: AMD "RDNA 2" Instruction Set Architecture reference guide, VINTRP instruction V_INTERP_P2_F16 (a plain form writes only the low 16 bits of its destination), VOP3P V_FMA_MIX_F32 (`op_sel_hi` marks a binary16 source, `op_sel` picks its half), VOP1 V_MOV_B32 and VOP2 V_CNDMASK_B32 (32-bit register copies). What changed (`Stage.interp_f16_scan` in `tools/startup/gfx2hlsl.py`) - A plain whole-register copy (`v_mov_b32`, or `v_cndmask_b32` with both value sources plain VGPRs, no modifiers) of a register whose upper half is undefined is no longer a read of that half: it hands the undefined-upper-half state on to its destination. The half is still checked where it is observed (an export, a shift, a binary32 `v_fma_mix`, an `op_sel` pick of the upper half all stay refused on the copy). - The destination of `v_mov_b32`, `v_cndmask_b32` and `v_fma_mix_f32` (which rewrites all 32 bits) is no longer counted as a read of its old undefined half. It still counts for the pending / stale `v_interp_p1ll_f16` result checks, so overwriting a pending result is refused with the same message as before. - The scan's register lookup now strips a VOP3 source modifier. Before, `v_mul_f32_e64 v8, -v4, 1.0` or `|v4|` on a plain p2 result named no register, so the read of the undefined upper half was never flagged and the program translated. What stays refused: any other reader of an undefined upper half, an `op_sel` upper-half pick, a binary32 source, a copy read through an export or shift, and every other `v_interp_p1ll_f16` / `v_interp_p2_f16` form that was refused before. Tests (`startup_gfx2hlsl_interp_f16_check.py`, llvm-mc-verified words in `binary` mode) - Accepted: a `v_mov_b32` copy and a `v_cndmask_b32` copy of a plain p2 result read through `v_fma_mix_f32` as a low half; both evaluate to the same words as the direct low-half read. The `draw` mode also draws the `v_mov_b32` copy on D3D12 and compares it with the ISA arithmetic (binary16 low half squared), with a wrong-reference control that must fail. - Refused: the copy exported, the copy shifted, a negated read and an absolute-value read of a p2 result. - Mutations tried, each caught by the check: the modifier strip removed (negated read translated), copies no longer tolerated (accepted case refused), a copy that does not carry the state (copy exported translated). Verification: ``` python3 -B tests/startup_gfx2hlsl_interp_f16_check.py rc=0 python3 -B tests/startup_gfx2hlsl_interp_f16_check.py binary llvm-mc-19 fixture words match llvm-mc python3 -B tests/startup_gfx2hlsl_interp_p2_hi_check.py rc=0 python3 -B tests/startup_gfx2hlsl_fma_mix_check.py rc=0 python3 -B tests/startup_gfx2hlsl_f16_alu_check.py rc=0 remote_pycheck.sh <worktree> --compare origin/main 0 differ ``` Win2025 WARP dev+release: pending Stage-2. AI-assisted; commands listed were executed locally.
RavenCurseBurg commented 2026-11-26 10:04:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-26T09:56:19Z.


I will verify the conditional-copy case with two distinct half values, both condition outcomes and an aliased destination. I will assemble the pixel programs, check the low-half readback on D3D12, and check that reading the copied upper half is still diagnosed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7188679741 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2792#issuecomment-7188679741). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-26T09:56:19Z. --- I will verify the conditional-copy case with two distinct half values, both condition outcomes and an aliased destination. I will assemble the pixel programs, check the low-half readback on D3D12, and check that reading the copied upper half is still diagnosed.
upstream-sync closed this pull request 2026-11-26 11:02:50 +00:00
tedin7 commented 2026-11-26 11:02:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T10:12:58Z.


Withdrawn: shader translation is moving to the native C++ frontend (see #870), so we are not continuing this change to the Python translator. The branch stays available if any part is useful later. Thank you to everyone who reviewed and tested it.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7189063854 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2792#issuecomment-7189063854). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T10:12:58Z. --- Withdrawn: shader translation is moving to the native C++ frontend (see #870), so we are not continuing this change to the Python translator. The branch stays available if any part is useful later. Thank you to everyone who reviewed and tested it.
RavenCurseBurg commented 2026-11-26 11:02:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-26T10:32:37Z.


Closing out my earlier test claim with fixtures the native frontend can reuse. On withdrawn head 92f8ee9f I assembled 24 gfx1013 pixel programs, varying the two conditional-copy inputs, their order, whether the destination aliases either source, and both outcomes of a comparison against an interpolated 0.5. Twelve cases mix a fully defined register and an interpolated register whose upper half is undefined.

WARP, Intel UHD 770 and RTX 4060 each passed 24/24 DXC SM 6.0 draws. Each reversed-arm reference failed. Replacing the low-half consumer with a shift reading the upper half was refused in all 24 cases. The selected channel was 1.5, −2.0 or 0.5, while the other channels stayed at 0.5, 0.5 and 3.0.

Reproducible guest assembly generator, CPU reference and draw checks. From that revision:

python tests/verify_interp_conditional_copy.py <clang> <llvm-objcopy> <dxc> <offscreen_check> warp

For a physical run, use hardware with XBOX2WINDOWS_ADAPTER=Intel or NVIDIA. Windows 11 26100.9711, WARP 10.0.26100.9711, Intel 32.0.101.5973, NVIDIA 32.0.15.9579, debug layer unavailable. AI-assisted with Codex.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7189505064 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2792#issuecomment-7189505064). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-26T10:32:37Z. --- Closing out my earlier test claim with fixtures the native frontend can reuse. On withdrawn head `92f8ee9f` I assembled 24 gfx1013 pixel programs, varying the two conditional-copy inputs, their order, whether the destination aliases either source, and both outcomes of a comparison against an interpolated 0.5. Twelve cases mix a fully defined register and an interpolated register whose upper half is undefined. WARP, Intel UHD 770 and RTX 4060 each passed **24/24** DXC SM 6.0 draws. Each reversed-arm reference failed. Replacing the low-half consumer with a shift reading the upper half was refused in all 24 cases. The selected channel was 1.5, −2.0 or 0.5, while the other channels stayed at 0.5, 0.5 and 3.0. [Reproducible guest assembly generator, CPU reference and draw checks](https://github.com/RavenCurseBurg/Xbox2Windows/blob/11c4950fe4545c3869a866502589a25aefd54443/tests/verify_interp_conditional_copy.py). From that revision: ```text python tests/verify_interp_conditional_copy.py <clang> <llvm-objcopy> <dxc> <offscreen_check> warp ``` For a physical run, use `hardware` with `XBOX2WINDOWS_ADAPTER=Intel` or `NVIDIA`. Windows 11 26100.9711, WARP 10.0.26100.9711, Intel 32.0.101.5973, NVIDIA 32.0.15.9579, debug layer unavailable. AI-assisted with Codex.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2784
No description provided.