startup: lower v_interp_p2_f16 with op_sel 0x8 (destination high half) in gfx2hlsl #2414

Merged
NiiRoZz merged 3 commits from upstream-pr/2422 into main 2026-11-25 22:10:32 +00:00
NiiRoZz commented 2026-11-25 16:15:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T16:15:38Z.


Refs #2413 (item T9)
Refs #711

What changed

check_encoding in tools/startup/gfx2hlsl.py refused every op_sel bit (word 0 bits 14:11) on v_interp_p1ll_f16 and v_interp_p2_f16. This PR lowers exactly one pattern: v_interp_p2_f16 with op_sel 0x8 (word 0 bit 14), which writes bits 31:16 of the destination and keeps bits 15:0:

vD = (vD & 0xffffu) | (f32tof16(i.<field>) << 16);

It is the same exec-masked statement shape as the plain form, whose mask is 0xffff0000u. The disassembler does not print op_sel for this instruction, so check_encoding passes the pattern on as the printed LLVM modifier op_sel:[0,0,0,1].

interp_f16_scan (the whole-program proof) accepts the pattern only when the destination register holds the low half written by a preceding plain p2 that no reader has consumed yet. The pair then defines the whole register, so any reader may use it. A plain p2 alone still leaves its upper half unreadable, as before.

Still refused, with the pattern in the message: every other op_sel value (1..7 and 9..15) on p2, any op_sel on v_interp_p1ll_f16, and op_sel 0x8 on a p2 whose destination holds no plain p2 low half.

Public references for the semantics

  • Mesa ACO src/amd/compiler/aco_assembler.cpp (VINTRP emitter): v_interp_p2_hi_f16 is encoded as v_interp_p2_f16 with opsel = 0x8 placed at word 0 bit 11, i.e. bit 14. aco_opcodes.py: both use the same gfx10 opcode 0x35a.
  • Mesa ACO aco_register_allocation.cpp, add_subdword_definition: a v_interp_p2_f16 whose 16-bit result is placed at byte 2 of a register is changed into v_interp_p2_hi_f16. The register's bytes 0..1 hold another 16-bit value, so the instruction must keep them. aco_ir.cpp, instr_is_16bit, lists both opcodes as partial-register writes, and aco_validate.cpp records v_interp_p2_hi_f16 as a byte-2 definition.
  • LLVM 15.0.7 AMDGPU VOPInstructions.td, VOP3Interp_gfx10: leaves word 0 bits 14:11 undefined for this instruction, and the LLVM 15 assembler rejects op_sel on it (so LLVM is silent, not contradictory). The generic 16-bit VOP3 encoding VOP3OpSel_gfx10 gives bit 14 the meaning "destination high half" (src0_modifiers{3}), which agrees with ACO.
  • #711 / #713 (pixel_aot): that tool lowers only the low attribute word of attr0 and assumes nothing about the upper half of a p2 destination. It does not lower op_sel, so the two readings do not conflict. Here the plain form already kept the upper half (& 0xffff0000u); the new form is the mirror image.

What is inferred: that the hardware keeps bytes 0..1 for op_sel 0x8 rests on the ACO sources above (the allocator relies on it); no ISA document statement or hardware read-back was found. The rounding behaviour of the pair is not touched by this change.

Tests

New tests/startup_gfx2hlsl_interp_p2_hi_check.py, registered in CMakeLists.txt (startup_gfx2hlsl_interp_p2_hi_controls), the two lists in .github/workflows/windows.yml and the AGENTS.md list. LLVM 15 cannot print or accept op_sel on this instruction, so the fixture words are the assembled plain instructions with word 0 bit 14 set; binary <llvm-mc> checks exactly that.

The fixture packs two binary16 attribute halves per register (a plain p2, then p2 with op_sel 0x8, for both halves of both channels), reads each half back with a shift and v_cvt_f32_f16, and evaluates the translated text on the CPU against a reference written from the layout above with struct 'e' conversions.

Command Result
python -B tests/startup_gfx2hlsl_interp_p2_hi_check.py exit 0
python -B tests/startup_gfx2hlsl_interp_p2_hi_check.py binary <llvm-mc 15> exit 0
python -B tests/startup_gfx2hlsl_interp_f16_check.py and ... binary <llvm-mc 15> exit 0
python -B tests/startup_gfx2hlsl_opsel_check.py, tests/startup_gfx2hlsl_refusals_check.py exit 0

Negative controls (all in the new test): the statement writing the low half instead of the high half gives other words; the statement clearing instead of keeping the other half gives other words; the op_sel bit cleared on the second p2 of each pair is refused (a reader would see an unwritten half); each of the 14 other op_sel values on each of the four p2 instructions and on p1ll is refused with its value in the message; op_sel 0x8 on a p2 whose destination has no plain low half is refused.

Not run: no build and no D3D12 draw. The existing draw mode of the f16 check is unchanged and not rerun.

Local observation (counts only, not a result for other inputs)

On one local set of 224 readable slot 57 pixel programs, 4 contain v_interp_p2_f16 with op_sel set, 12 instructions in all. All 12 carry exactly 0x8, none carries another value, and no p1ll carries any. In all 12 the instruction directly follows a plain p2 into the same register, and the next reader of that register is a whole-word move (7) or an image sample address (5). In the ordinary vertex/pixel set (358 programs) none occurs.

refused at decode on op_sel pass decode
before 4 0
after 0 4

The next refusal of the four, measured with a mocked pipeline (interface-dependent refusals are therefore not representative): 3 stop at "a backward branch in a program with the interpolation pair", 1 at "the compr export fills only the x and y channels" for a channel z read. Whether the mocked-pipeline result holds with the real mesh interface is not established.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6608680577 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2422). Originally posted by [NiiRoZz](https://github.com/NiiRoZz) on 2026-11-25T16:15:38Z. --- Refs #2413 (item T9) Refs #711 ## What changed `check_encoding` in `tools/startup/gfx2hlsl.py` refused every `op_sel` bit (word 0 bits 14:11) on `v_interp_p1ll_f16` and `v_interp_p2_f16`. This PR lowers exactly one pattern: `v_interp_p2_f16` with `op_sel` 0x8 (word 0 bit 14), which writes bits 31:16 of the destination and keeps bits 15:0: vD = (vD & 0xffffu) | (f32tof16(i.<field>) << 16); It is the same exec-masked statement shape as the plain form, whose mask is `0xffff0000u`. The disassembler does not print `op_sel` for this instruction, so `check_encoding` passes the pattern on as the printed LLVM modifier `op_sel:[0,0,0,1]`. `interp_f16_scan` (the whole-program proof) accepts the pattern only when the destination register holds the low half written by a preceding plain `p2` that no reader has consumed yet. The pair then defines the whole register, so any reader may use it. A plain `p2` alone still leaves its upper half unreadable, as before. Still refused, with the pattern in the message: every other `op_sel` value (1..7 and 9..15) on `p2`, any `op_sel` on `v_interp_p1ll_f16`, and `op_sel` 0x8 on a `p2` whose destination holds no plain `p2` low half. ## Public references for the semantics - Mesa ACO `src/amd/compiler/aco_assembler.cpp` (VINTRP emitter): `v_interp_p2_hi_f16` is encoded as `v_interp_p2_f16` with `opsel = 0x8` placed at word 0 bit 11, i.e. bit 14. `aco_opcodes.py`: both use the same gfx10 opcode 0x35a. - Mesa ACO `aco_register_allocation.cpp`, `add_subdword_definition`: a `v_interp_p2_f16` whose 16-bit result is placed at byte 2 of a register is changed into `v_interp_p2_hi_f16`. The register's bytes 0..1 hold another 16-bit value, so the instruction must keep them. `aco_ir.cpp`, `instr_is_16bit`, lists both opcodes as partial-register writes, and `aco_validate.cpp` records `v_interp_p2_hi_f16` as a byte-2 definition. - LLVM 15.0.7 AMDGPU `VOPInstructions.td`, `VOP3Interp_gfx10`: leaves word 0 bits 14:11 undefined for this instruction, and the LLVM 15 assembler rejects `op_sel` on it (so LLVM is silent, not contradictory). The generic 16-bit VOP3 encoding `VOP3OpSel_gfx10` gives bit 14 the meaning "destination high half" (`src0_modifiers{3}`), which agrees with ACO. - #711 / #713 (`pixel_aot`): that tool lowers only the low attribute word of attr0 and assumes nothing about the upper half of a `p2` destination. It does not lower `op_sel`, so the two readings do not conflict. Here the plain form already kept the upper half (`& 0xffff0000u`); the new form is the mirror image. What is inferred: that the hardware keeps bytes 0..1 for `op_sel` 0x8 rests on the ACO sources above (the allocator relies on it); no ISA document statement or hardware read-back was found. The rounding behaviour of the pair is not touched by this change. ## Tests New `tests/startup_gfx2hlsl_interp_p2_hi_check.py`, registered in `CMakeLists.txt` (`startup_gfx2hlsl_interp_p2_hi_controls`), the two lists in `.github/workflows/windows.yml` and the `AGENTS.md` list. LLVM 15 cannot print or accept `op_sel` on this instruction, so the fixture words are the assembled plain instructions with word 0 bit 14 set; `binary <llvm-mc>` checks exactly that. The fixture packs two binary16 attribute halves per register (a plain `p2`, then `p2` with `op_sel` 0x8, for both halves of both channels), reads each half back with a shift and `v_cvt_f32_f16`, and evaluates the translated text on the CPU against a reference written from the layout above with `struct` `'e'` conversions. | Command | Result | |---|---| | `python -B tests/startup_gfx2hlsl_interp_p2_hi_check.py` | exit 0 | | `python -B tests/startup_gfx2hlsl_interp_p2_hi_check.py binary <llvm-mc 15>` | exit 0 | | `python -B tests/startup_gfx2hlsl_interp_f16_check.py` and `... binary <llvm-mc 15>` | exit 0 | | `python -B tests/startup_gfx2hlsl_opsel_check.py`, `tests/startup_gfx2hlsl_refusals_check.py` | exit 0 | Negative controls (all in the new test): the statement writing the low half instead of the high half gives other words; the statement clearing instead of keeping the other half gives other words; the `op_sel` bit cleared on the second `p2` of each pair is refused (a reader would see an unwritten half); each of the 14 other `op_sel` values on each of the four `p2` instructions and on `p1ll` is refused with its value in the message; `op_sel` 0x8 on a `p2` whose destination has no plain low half is refused. Not run: no build and no D3D12 draw. The existing `draw` mode of the f16 check is unchanged and not rerun. ## Local observation (counts only, not a result for other inputs) On one local set of 224 readable slot 57 pixel programs, 4 contain `v_interp_p2_f16` with `op_sel` set, 12 instructions in all. All 12 carry exactly 0x8, none carries another value, and no `p1ll` carries any. In all 12 the instruction directly follows a plain `p2` into the same register, and the next reader of that register is a whole-word move (7) or an image sample address (5). In the ordinary vertex/pixel set (358 programs) none occurs. | | refused at decode on `op_sel` | pass decode | |---|---|---| | before | 4 | 0 | | after | 0 | 4 | The next refusal of the four, measured with a mocked pipeline (interface-dependent refusals are therefore not representative): 3 stop at "a backward branch in a program with the interpolation pair", 1 at "the compr export fills only the x and y channels" for a channel z read. Whether the mocked-pipeline result holds with the real mesh interface is not established. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tedin7 commented 2026-11-25 21:00:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:14:06Z.

Review: COMMENTED


Review of head 9eb117dc (main merged into the branch, own diff unchanged: 7 files, +236/-16).

Code: check_encoding now accepts op_sel 0x8 only on v_interp_p2_f16 and passes it on as op_sel:[0,0,0,1]. Everything else (other values, any op_sel on p1ll_f16) is still refused with the value in the message. The emitted statement (vD & 0xffffu) | (f32tof16(i.x) << 16) keeps the low half and writes the high half, and interp_f16_scan only allows it when the destination holds a pending plain-p2 low half. That logic reads correct to me.

Commands run in a worktree on this head:

  • python3 -B tests/startup_gfx2hlsl_interp_p2_hi_check.py PASS
  • python3 -B tests/startup_gfx2hlsl_interp_f16_check.py PASS
  • python3 -B tests/startup_gfx2hlsl_handler_arity_check.py PASS
  • python3 tests/docs_links_check.py PASS, python3 tests/bidi_controls_check.py PASS, git diff --check origin/main...HEAD clean
  • Mutation: << 16 changed to << 15 in the new emit line -> the new test fails (translated words differ), as intended.

What is missing before this can be merged:

  1. No real D3D12 WARP readback for the new lowering. tests/startup_gfx2hlsl_interp_p2_hi_check.py has only a pure-Python mode and a binary <llvm-mc> mode; the CPU reference compares against a Python evaluation of the emitted words. The sibling startup_gfx2hlsl_interp_f16 has startup_gfx2hlsl_interp_f16_warp / _hardware draw tests (CMakeLists.txt:3384). Please add a draw mode and startup_gfx2hlsl_interp_p2_hi_warp / _hardware next to it, so the << 16 shift and the kept low half are read back from a GPU draw.
  2. AGENTS.md is touched (one added test line). Our merge rules keep AGENTS.md changes with MasterDomino or @R0Y00.

Nit: .github/workflows/windows.yml:248 puts two paths on one line (...interp_f16_check.py tests/startup_gfx2hlsl_interp_p2_hi_check.py \). It works as two shell arguments, but one path per line matches the rest of the list.

No game run is claimed or needed; this was checked by code and fixtures only. I am not merging this PR.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6064305425 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2422#pullrequestreview-6064305425). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T20:14:06Z. **Review:** COMMENTED --- Review of head 9eb117dc (main merged into the branch, own diff unchanged: 7 files, +236/-16). Code: `check_encoding` now accepts `op_sel` 0x8 only on `v_interp_p2_f16` and passes it on as `op_sel:[0,0,0,1]`. Everything else (other values, any `op_sel` on `p1ll_f16`) is still refused with the value in the message. The emitted statement `(vD & 0xffffu) | (f32tof16(i.x) << 16)` keeps the low half and writes the high half, and `interp_f16_scan` only allows it when the destination holds a pending plain-p2 low half. That logic reads correct to me. Commands run in a worktree on this head: - `python3 -B tests/startup_gfx2hlsl_interp_p2_hi_check.py` PASS - `python3 -B tests/startup_gfx2hlsl_interp_f16_check.py` PASS - `python3 -B tests/startup_gfx2hlsl_handler_arity_check.py` PASS - `python3 tests/docs_links_check.py` PASS, `python3 tests/bidi_controls_check.py` PASS, `git diff --check origin/main...HEAD` clean - Mutation: `<< 16` changed to `<< 15` in the new emit line -> the new test fails (translated words differ), as intended. What is missing before this can be merged: 1. No real D3D12 WARP readback for the new lowering. `tests/startup_gfx2hlsl_interp_p2_hi_check.py` has only a pure-Python mode and a `binary <llvm-mc>` mode; the CPU reference compares against a Python evaluation of the emitted words. The sibling `startup_gfx2hlsl_interp_f16` has `startup_gfx2hlsl_interp_f16_warp` / `_hardware` draw tests (`CMakeLists.txt:3384`). Please add a `draw` mode and `startup_gfx2hlsl_interp_p2_hi_warp` / `_hardware` next to it, so the `<< 16` shift and the kept low half are read back from a GPU draw. 2. `AGENTS.md` is touched (one added test line). Our merge rules keep AGENTS.md changes with MasterDomino or @R0Y00. Nit: `.github/workflows/windows.yml:248` puts two paths on one line (`...interp_f16_check.py tests/startup_gfx2hlsl_interp_p2_hi_check.py \`). It works as two shell arguments, but one path per line matches the rest of the list. No game run is claimed or needed; this was checked by code and fixtures only. I am not merging this PR. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 22:01:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T22:01:41Z.

Review: COMMENTED


Review of head 5c4a9daa (my earlier review was on 9eb117dc; the PR's own diff is still 7 files, +236/-16).

Short answer: the lowering looks right, but the WARP readback test is still missing. Not merged.

Findings:

  • tests/startup_gfx2hlsl_interp_p2_hi_check.py is CPU-only: a Python interpreter of the emitted statements plus refusal controls (check_binary, controls). It has no draw/check_compile/check_draw mode and no warp|hardware argument, and CMakeLists.txt registers only startup_gfx2hlsl_interp_p2_hi_controls (no warp / hardware foreach like startup_gfx2hlsl_interp_f16_${adapter}). For a shader lowering, a string or CPU-model check alone is not enough: the new (vD & 0xffffu) | (f32tof16(i.x) << 16) path needs a real D3D12 WARP draw with GPU readback compared to a CPU reference. The sibling tests/startup_gfx2hlsl_interp_f16_check.py already has the draw <dxc> <offscreen_check> <warp|hardware> mode to copy or extend, and the paired high-half fixture could go there.
  • The hardware readback in the thread (DXC SM 6.0 and FXC SM 5.1 on UHD 770, RTX 4060, WARP) is useful, but it is a manual run of the fixture and no test in the repo reproduces it, so a regression would not be caught.
  • Minor: .github/workflows/windows.yml:277 merged two lines into one: ...interp_f16_check.py tests/startup_gfx2hlsl_interp_p2_hi_check.py \. It still works inside the shell continuation, but please put it back on two lines.

Commands run in a worktree on this head:

  • python3 -B tests/startup_gfx2hlsl_interp_p2_hi_check.py -> op_sel controls ok
  • python3 tests/docs_links_check.py -> 19 files, 493 links ok
  • python3 tests/bidi_controls_check.py -> ok
  • git diff --check origin/main...HEAD -> clean

Merge stays on hold until the WARP readback test (and its CTest warp entry) is in. No Windows run from me on this head.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6065592660 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2422#pullrequestreview-6065592660). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T22:01:41Z. **Review:** COMMENTED --- Review of head 5c4a9daa (my earlier review was on 9eb117dc; the PR's own diff is still 7 files, +236/-16). Short answer: the lowering looks right, but the WARP readback test is still missing. Not merged. Findings: - `tests/startup_gfx2hlsl_interp_p2_hi_check.py` is CPU-only: a Python interpreter of the emitted statements plus refusal controls (`check_binary`, `controls`). It has no `draw`/`check_compile`/`check_draw` mode and no `warp|hardware` argument, and `CMakeLists.txt` registers only `startup_gfx2hlsl_interp_p2_hi_controls` (no `warp` / `hardware` foreach like `startup_gfx2hlsl_interp_f16_${adapter}`). For a shader lowering, a string or CPU-model check alone is not enough: the new `(vD & 0xffffu) | (f32tof16(i.x) << 16)` path needs a real D3D12 WARP draw with GPU readback compared to a CPU reference. The sibling `tests/startup_gfx2hlsl_interp_f16_check.py` already has the `draw <dxc> <offscreen_check> <warp|hardware>` mode to copy or extend, and the paired high-half fixture could go there. - The hardware readback in the thread (DXC SM 6.0 and FXC SM 5.1 on UHD 770, RTX 4060, WARP) is useful, but it is a manual run of the fixture and no test in the repo reproduces it, so a regression would not be caught. - Minor: `.github/workflows/windows.yml:277` merged two lines into one: `...interp_f16_check.py tests/startup_gfx2hlsl_interp_p2_hi_check.py \`. It still works inside the shell continuation, but please put it back on two lines. Commands run in a worktree on this head: - `python3 -B tests/startup_gfx2hlsl_interp_p2_hi_check.py` -> op_sel controls ok - `python3 tests/docs_links_check.py` -> 19 files, 493 links ok - `python3 tests/bidi_controls_check.py` -> ok - `git diff --check origin/main...HEAD` -> clean Merge stays on hold until the WARP readback test (and its CTest `warp` entry) is in. No Windows run from me on this head. AI-assisted; commands listed were executed locally.
RavenCurseBurg commented 2026-11-25 22:02:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T21:20:54Z.


I rendered the paired high-half fixture from 9eb117dc through both DXC (SM 6.0) and FXC (SM 5.1). On Intel UHD 770 (32.0.101.5973), RTX 4060 (32.0.15.9579), and WARP (10.0.26100.9711), the four RGBA32F words matched the fixture's packed-attribute reference. Windows 11 build 26100.9711, local D3D12 debug layer unavailable.

For the original inputs the paired pixel was 3fc00000,3f000000,c0000000,40400000. Erasing the previous low half gave 00000000,3f000000,c0000000,40400000; writing the incoming value to the low half gave 3f000000,00000000,c0000000,40400000. All six device/compiler pairs produced the same predicted values for these controls. I also ran two additional signed attribute sets. Across the three sets there were 18 exact positive draws and 36 incorrect-write draws, each checked against its own predicted four words.

Runnable source with both compilers. The PR's binary check passed using the LLVM 15 plain encoding plus bit 14. The verified renderer came from this Windows build; tests/startup_flat_param.cpp is byte-identical to the PR version. This exercises the translated desktop pixel shaders. Native execution of the guest opcode on an RDNA2 device remains open.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7174955143 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2422#issuecomment-7174955143). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T21:20:54Z. --- I rendered the paired high-half fixture from `9eb117dc` through both DXC (SM 6.0) and FXC (SM 5.1). On Intel UHD 770 (32.0.101.5973), RTX 4060 (32.0.15.9579), and WARP (10.0.26100.9711), the four RGBA32F words matched the fixture's packed-attribute reference. Windows 11 build 26100.9711, local D3D12 debug layer unavailable. For the original inputs the paired pixel was `3fc00000,3f000000,c0000000,40400000`. Erasing the previous low half gave `00000000,3f000000,c0000000,40400000`; writing the incoming value to the low half gave `3f000000,00000000,c0000000,40400000`. All six device/compiler pairs produced the same predicted values for these controls. I also ran two additional signed attribute sets. Across the three sets there were 18 exact positive draws and 36 incorrect-write draws, each checked against its own predicted four words. [Runnable source with both compilers](https://github.com/RavenCurseBurg/Xbox2Windows/blob/826191b7b4d61b2d3b8d9283f04f26fcf863c9e8/tests/measure_paired_interp_readback.py). The PR's binary check passed using the LLVM 15 plain encoding plus bit 14. The verified renderer came from [this Windows build](https://github.com/RavenCurseBurg/Xbox2Windows/actions/runs/45701974711); `tests/startup_flat_param.cpp` is byte-identical to the PR version. This exercises the translated desktop pixel shaders. Native execution of the guest opcode on an RDNA2 device remains open.
upstream-sync closed this pull request 2026-11-25 23:01:45 +00:00
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!2414
No description provided.