startup: lower v_interp_p2_f16 with op_sel 0x8 (destination high half) in gfx2hlsl #2414
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2422"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T16:15:38Z.
Refs #2413 (item T9)
Refs #711
What changed
check_encodingintools/startup/gfx2hlsl.pyrefused everyop_selbit (word 0 bits 14:11) onv_interp_p1ll_f16andv_interp_p2_f16. This PR lowers exactly one pattern:v_interp_p2_f16withop_sel0x8 (word 0 bit 14), which writes bits 31:16 of the destination and keeps bits 15:0:It is the same exec-masked statement shape as the plain form, whose mask is
0xffff0000u. The disassembler does not printop_selfor this instruction, socheck_encodingpasses the pattern on as the printed LLVM modifierop_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 plainp2that no reader has consumed yet. The pair then defines the whole register, so any reader may use it. A plainp2alone still leaves its upper half unreadable, as before.Still refused, with the pattern in the message: every other
op_selvalue (1..7 and 9..15) onp2, anyop_selonv_interp_p1ll_f16, andop_sel0x8 on ap2whose destination holds no plainp2low half.Public references for the semantics
src/amd/compiler/aco_assembler.cpp(VINTRP emitter):v_interp_p2_hi_f16is encoded asv_interp_p2_f16withopsel = 0x8placed at word 0 bit 11, i.e. bit 14.aco_opcodes.py: both use the same gfx10 opcode 0x35a.aco_register_allocation.cpp,add_subdword_definition: av_interp_p2_f16whose 16-bit result is placed at byte 2 of a register is changed intov_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, andaco_validate.cpprecordsv_interp_p2_hi_f16as a byte-2 definition.VOPInstructions.td,VOP3Interp_gfx10: leaves word 0 bits 14:11 undefined for this instruction, and the LLVM 15 assembler rejectsop_selon it (so LLVM is silent, not contradictory). The generic 16-bit VOP3 encodingVOP3OpSel_gfx10gives bit 14 the meaning "destination high half" (src0_modifiers{3}), which agrees with ACO.pixel_aot): that tool lowers only the low attribute word of attr0 and assumes nothing about the upper half of ap2destination. It does not lowerop_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_sel0x8 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 inCMakeLists.txt(startup_gfx2hlsl_interp_p2_hi_controls), the two lists in.github/workflows/windows.ymland theAGENTS.mdlist. LLVM 15 cannot print or acceptop_selon 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, thenp2withop_sel0x8, for both halves of both channels), reads each half back with a shift andv_cvt_f32_f16, and evaluates the translated text on the CPU against a reference written from the layout above withstruct'e'conversions.python -B tests/startup_gfx2hlsl_interp_p2_hi_check.pypython -B tests/startup_gfx2hlsl_interp_p2_hi_check.py binary <llvm-mc 15>python -B tests/startup_gfx2hlsl_interp_f16_check.pyand... binary <llvm-mc 15>python -B tests/startup_gfx2hlsl_opsel_check.py,tests/startup_gfx2hlsl_refusals_check.pyNegative 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_selbit cleared on the secondp2of each pair is refused (a reader would see an unwritten half); each of the 14 otherop_selvalues on each of the fourp2instructions and onp1llis refused with its value in the message;op_sel0x8 on ap2whose destination has no plain low half is refused.Not run: no build and no D3D12 draw. The existing
drawmode 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_f16withop_selset, 12 instructions in all. All 12 carry exactly 0x8, none carries another value, and nop1llcarries any. In all 12 the instruction directly follows a plainp2into 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.op_selThe 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
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_encodingnow acceptsop_sel0x8 only onv_interp_p2_f16and passes it on asop_sel:[0,0,0,1]. Everything else (other values, anyop_selonp1ll_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, andinterp_f16_scanonly 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.pyPASSpython3 -B tests/startup_gfx2hlsl_interp_f16_check.pyPASSpython3 -B tests/startup_gfx2hlsl_handler_arity_check.pyPASSpython3 tests/docs_links_check.pyPASS,python3 tests/bidi_controls_check.pyPASS,git diff --check origin/main...HEADclean<< 16changed to<< 15in the new emit line -> the new test fails (translated words differ), as intended.What is missing before this can be merged:
tests/startup_gfx2hlsl_interp_p2_hi_check.pyhas only a pure-Python mode and abinary <llvm-mc>mode; the CPU reference compares against a Python evaluation of the emitted words. The siblingstartup_gfx2hlsl_interp_f16hasstartup_gfx2hlsl_interp_f16_warp/_hardwaredraw tests (CMakeLists.txt:3384). Please add adrawmode andstartup_gfx2hlsl_interp_p2_hi_warp/_hardwarenext to it, so the<< 16shift and the kept low half are read back from a GPU draw.AGENTS.mdis touched (one added test line). Our merge rules keep AGENTS.md changes with MasterDomino or @R0Y00.Nit:
.github/workflows/windows.yml:248puts 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.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T22:01:41Z.
Review: COMMENTED
Review of head
5c4a9daa(my earlier review was on9eb117dc; 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.pyis CPU-only: a Python interpreter of the emitted statements plus refusal controls (check_binary,controls). It has nodraw/check_compile/check_drawmode and nowarp|hardwareargument, andCMakeLists.txtregisters onlystartup_gfx2hlsl_interp_p2_hi_controls(nowarp/hardwareforeach likestartup_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 siblingtests/startup_gfx2hlsl_interp_f16_check.pyalready has thedraw <dxc> <offscreen_check> <warp|hardware>mode to copy or extend, and the paired high-half fixture could go there..github/workflows/windows.yml:277merged 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 okpython3 tests/docs_links_check.py-> 19 files, 493 links okpython3 tests/bidi_controls_check.py-> okgit diff --check origin/main...HEAD-> cleanMerge stays on hold until the WARP readback test (and its CTest
warpentry) is in. No Windows run from me on this head.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T21:20:54Z.
I rendered the paired high-half fixture from
9eb117dcthrough 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 gave00000000,3f000000,c0000000,40400000; writing the incoming value to the low half gave3f000000,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.cppis 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.