startup: lower v_pack_b32_f16 with op_sel and neg/abs in gfx2hlsl #2467
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2475"
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 denn0x on 2026-11-25T17:48:08Z.
What
tools/startup/gfx2hlsl.pyhad no handler forv_pack_b32_f16, so a stage that uses it was refused.It now lowers
D[15:0] = S0.f16, D[31:16] = S1.f16(AMD RDNA 2 ISA, VOP3V_PACK_B32_F16):op_sel[i]selects the high half of source i. LLVM 15 declares the instructionVOP3_OPSEL.pixel_aotlowers this instruction. No binary16 denormal flush and no NaN quieting is modelled. This is an assumption; it was not measured.u()would give as the binary32 word, so constants are refused.The instruction was refused before, so no stage that already translated changes. The cache revision stays as it is.
Test
tests/startup_gfx2hlsl_pack_b32_f16_check.py(new). It is registered in CMake asstartup_gfx2hlsl_pack_b32_f16, in the Python CI list and in AGENTS.md.The fixture is synthetic VOP3 words, and the check asserts the decoder's printed op_sel and modifier forms. For every op_sel[0..1] × abs × neg combination, the emitted expression is evaluated in Python over sample register pairs. The result is compared with a bit reference written in the test (2304 cases). An SGPR source is checked as well.
1.0, the inline integer1.op_v_pack_b32_f16the instruction is refused, as onmain.On
main, the check fails withgfx2hlsl.Unsupported: v_pack_b32_f16. The emitted expression form compiles with dxc 1.8.2502cs_6_0.tests/startup_gfx2hlsl_*_check.py,tests/startup_image_*_check.py(except the device-onlystartup_image_get_lod_view_check.py, which needs a device),startup_translator_check.py,startup_flat_param_check.py,startup_inline_sampler_check.pyandstartup_compute_request_offline_check.pypass.allbuilds (Ninja Release, MSVC Build Tools 18, Windows 10.0.26300). Device-free, so there were no GPU runs and no capability skips.Refs #1723
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:41:20Z.
Review: COMMENTED
Review of head
b340d16(gfx2hlsl lowering ofv_pack_b32_f16, 5 files). This PR does not claim startup progress, so no game result is needed. Merge is a decision for @R0Y00 (see the open point below).Code (
tools/startup/gfx2hlsl.py,op_v_pack_b32_f16)low16_only. This matches the stated semantics.Unsupportedbefore, so no stage that already translated changes. The unchanged cache revision is consistent with that.Test (
tests/startup_gfx2hlsl_pack_b32_f16_check.py)windows.yml, and AGENTS.md. The PR's own Linux CI run executed it (ok, 2304 cases), so the changed workflow line is exercised.cs_6_0. There is no WARP readback. The expression is plain integer shifts, masks and xor, so the risk is low, but the rule is not met as written. Whether to accept or ask for a WARP case is your call.Mutations I ran locally (each made the check fail; then reverted)
>> 16changed to>> 15: AssertionError onop_sel:[1,0,0].^ 0x8000uchanged to^ 0x4000u: AssertionError on-v1.Duplicates and siblings
gh pr list --state all --search v_pack_b32_f16: only #1001 and #1013 (both merged, pixel_aot side). No open PR covers the gfx2hlsl lowering. No other open or merged PR covers this slice.FETCH_*-style sibling table is involved. The PR body cites #1723, and the PR does not depend on another PR.Windows results
b340d16: Windows build/test pass, Linux Python checks pass, gfx1013 fixtures pass; two jobs skipped.Commands run locally (Linux worktree at the head SHA)
python3 -B tests/startup_gfx2hlsl_pack_b32_f16_check.py: passgit diff --check origin/main...HEAD: cleanpython3 tests/docs_links_check.py: passpython3 tests/bidi_controls_check.py: passNo Windows VM was used, no
update-branch, no merge action.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T18:01:38Z.
Seven mutations on the handler body, all caught — including the abs/neg order the docstring calls out
Baseline:
pack_b32_f16: 2304 (op_sel, abs, neg, value) cases match the reference; SGPR source accepted; swapped halves and neg-before-abs caught; destination op_sel, clamp and constants refused; refused without the handler, exit 0, and the wholestartup_gfx2hlsl_*family passes.op_v_pack_b32_f16& 0x7fffu→& 0xffffu^ 0x8000udroppedop_selbit accepted (sel[2]check removed)op_selignored (all three selection bits forced to 1)The fourth row is the one that matters most and the one I expected to survive: applying
negfirst andabssecond is a plausible transcription of "neg and abs act on bit 15", and it is wrong — the mask would clear the sign bit that the xor just set, so-|x|would come out as|x|. Your fixture kills it, which means theabs first, then negsentence in the docstring is actually pinned rather than merely stated.One thing worth knowing about the fixture's own strength
2304 casesis the full cross product of (op_sel, abs, neg) — 2³ selection × 2² modifiers × 16 half patterns? Whatever the exact factorisation, the count is high enough that the four bit-level mutations above cannot pass by luck, and I would leave the size alone even though it costs runtime, because this is the only place in the tree that models the f16 sign bit.Two small suggestions
half = '(%s >> 16)' % self.u(tok)forsel[i]butself.u(tok, low16_only=True)otherwise — the asymmetry is correct (the high half needs the whole word, the low half does not), but it reads like an inconsistency. A one-word comment there would save the next reader a minute.modsloop accepts exactly oneop_sel:[a,b,c]token and refuses anything else — that is right for VOP3A, and it means anop_selon a_e64form with a different spelling is a refusal rather than a silent default. Worth one line in the docstring, since the pattern is stricter than it looks.The docstring's honesty about what is not modelled — binary16 denormal flush, NaN quieting, "an assumption, not measured" — is exactly what a reader needs to decide whether this lowering applies to their shader.
AI-assisted; the seven mutations were run locally on Windows 11 build 26300.9974.
Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-25T18:02:50Z.
Thanks for the mutation run. I took both suggestions in a comments-only commit: there is now a note on why the high half reads the whole word and the low half only bits 15:0, and the docstring says that any modifier other than the one
op_sel:[a,b,c]spelling is refused. The check still reports 2304 cases.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T19:06:45Z.
Review: COMMENTED
Review of head
b340d16c(against current main).What is good:
op_v_pack_b32_f16(tools/startup/gfx2hlsl.py): op_sel, abs-then-neg on bit 15, low half reads only bits 15:0, constants and dst op_sel/clamp refused. Matches the ISA text in the docstring.v_pack_b32_f16in gfx2hlsl. The registrations (CMake,windows.ymllist, AGENTS.md) are consistent.Blocking, missing test type:
tests/startup_gfx2hlsl_pack_b32_f16_check.py). It never compiles the HLSL or runs it on D3D12 WARP. A shader/math lowering needs a real WARP draw with GPU readback compared to a CPU reference. Sibling checks already do it with the sharedstartup_gfx2hlsl_lane_aluhelpers (check_draw,draw <dxc> <offscreen_check> <warp|hardware>; seetests/startup_gfx2hlsl_cvt_pk_u8_check.py,startup_gfx2hlsl_mul_hi_check.py).uintshift/precedence, howu(..., low16_only=True)is emitted, or^ 0x8000utyping. All of these are only seen by dxc plus the GPU result.lane_alufamily (anops/draw/mutationsentry forv_pack_b32_f16, with the op_sel x abs x neg sets as draw inputs, two mutations such as swapped halves and neg before abs), or add adrawmode to this check. Keep the current 2304-case Python reference as a cheap Linux check.Commands run locally:
python3 -B tests/startup_gfx2hlsl_pack_b32_f16_check.py(pass); one mutation (halves swapped in the handler) made it fail as expected;python3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py,git diff --check origin/main...HEAD(OK). No Win2025 run: stopped at review, and the branch is 24 behind main (needs update-branch before merge).Not merged for now.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T23:26:30Z.
Review: COMMENTED
Review of head
3d5bb508against origin/main (comment review).Checked:
op_v_pack_b32_f16: op_sel selects the high half per source, abs is applied before neg on bit 15, the low half reads only bits 15:0, the high half reads the whole word. Constants, destination op_sel, clamp and unknown modifiers are refused. No sibling handler or table is left out; no other open PR covers this slice (#1001 and #1013 are the mergedpixel_aotlowering it mirrors).startup_gfx2hlsl_pack_b32_f16_{warp,hardware}tests add a real D3D12 draw with readback. CMake, the Python CI list and AGENTS.md are all registered.Commands run locally on a worktree at the exact head:
python3 -B tests/startup_gfx2hlsl_pack_b32_f16_check.py: passes.python3 tests/docs_links_check.py: ok.python3 tests/bidi_controls_check.py: ok.git diff --check origin/main...HEAD: clean.0x4000, inverting the op_sel choice.Not verified here: the D3D12 draw tests (no Windows run in this review). The only workflow change is one added line in the Python CI list.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T23:23:34Z.
I added the independent D3D12 draw requested in review and resolved the adjacent CMake registrations against current main. On
3d5bb508,ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_(pack_b32_f16($|_)|cvt_pk_int16_controls$|cvt_off_f32_i4_controls$)' -Vpassed 5/5, zero skips. WARP and RTX 4060 Laptop matched the four packed integer words under FXC and DXC. Removing negation changes the expected words and fails the readback on both. This validates the desktop lowering and bit-preservation controls. The updated head is ready for the required CI.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T23:29:48Z.
Win2025 WARP receipt for head
729eb037after updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
729eb0379dad7e51d2b8d19420c8840adc1c28e8:--preset dev):cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2):0.47s(configure1.78s)ctest --preset dev -R '^startup_gfx2hlsl_pack_b32_f16($|_warp$)' --parallel 6 --no-tests=error --output-on-failure): 2/2 passed (0.63s:startup_gfx2hlsl_pack_b32_f160.14s,startup_gfx2hlsl_pack_b32_f16_warp0.52s)/O2(--preset release):cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2):0.90s(configure1.81s)ctest --preset release -R '^startup_gfx2hlsl_pack_b32_f16($|_warp$)' --parallel 6 --no-tests=error --output-on-failure): 2/2 passed (0.59s:startup_gfx2hlsl_pack_b32_f160.14s,startup_gfx2hlsl_pack_b32_f16_warp0.48s)tests/mesh_heap_sampler_check.pyok (0.6s),tests/startup_buffer_address_check.pyok (0.4s),tests/startup_buffer_format_word3_table_check.pyok (0.1s),tests/startup_compute_request_offline_check.pyok (0.5s),tests/startup_compute_store_format_xyzw_check.pyok (0.3s),tests/startup_compute_translate_check.pyok (0.2s),tests/startup_flat_param_check.pyok (0.1s),tests/startup_gfx2hlsl_add_sub_co_check.pyok (0.1s),tests/startup_gfx2hlsl_add_sub_co_ci_check.pyok (0.1s),tests/startup_gfx2hlsl_bit_alu_check.pyok (0.7s),tests/startup_gfx2hlsl_capture_check.pyok (0.9s),tests/startup_gfx2hlsl_cmp16_check.pyok (0.3s),tests/startup_gfx2hlsl_compare_dst_check.pyok (0.1s),tests/startup_gfx2hlsl_compute_check.pyok (0.3s),tests/startup_gfx2hlsl_cselect_mask_check.pyok (0.1s),tests/startup_gfx2hlsl_cvt_alu_check.pyok (0.2s),tests/startup_gfx2hlsl_cvt_off_f32_i4_check.pyok (0.2s),tests/startup_gfx2hlsl_cvt_pk_int16_check.pyok (0.2s),tests/startup_gfx2hlsl_f32_lg_check.pyok (1.1s),tests/startup_gfx2hlsl_f32_nan_check.pyok (4.2s),tests/startup_gfx2hlsl_fma_mix_check.pyok (0.1s),tests/startup_gfx2hlsl_getpc_refusal_check.pyok (0.1s),tests/startup_gfx2hlsl_handler_arity_check.pyok (0.1s),tests/startup_gfx2hlsl_image_arity_check.pyok (0.1s),tests/startup_gfx2hlsl_image_get_lod_check.pyok (0.1s),tests/startup_gfx2hlsl_int_med3_check.pyok (0.1s),tests/startup_gfx2hlsl_interp_p2_hi_check.pyok (0.2s),tests/startup_gfx2hlsl_join_symbols_check.pyok (0.2s),tests/startup_gfx2hlsl_loop_constants_check.pyok (0.1s),tests/startup_gfx2hlsl_mask_overwrite_check.pyok (0.1s),tests/startup_gfx2hlsl_operand_count_check.pyok (0.3s),tests/startup_gfx2hlsl_pack_absdiff_check.pyok (2.2s),tests/startup_gfx2hlsl_readfirstlane_recompute_check.pyok (0.1s),tests/startup_gfx2hlsl_readfirstlane_uniform_check.pyok (0.1s),tests/startup_gfx2hlsl_refusals_check.pyok (0.5s),tests/startup_gfx2hlsl_root_check.pyok (0.7s),tests/startup_gfx2hlsl_sad_check.pyok (0.3s),tests/startup_gfx2hlsl_saveexec_same_reg_check.pyok (0.1s),tests/startup_gfx2hlsl_scalar_arity_check.pyok (0.2s),tests/startup_gfx2hlsl_scalar_brev_fold_check.pyok (0.1s),tests/startup_gfx2hlsl_scalar_m0_check.pyok (0.1s),tests/startup_gfx2hlsl_scalar_table_arity_check.pyok (0.2s),tests/startup_gfx2hlsl_sdwa_cvt_check.pyok (0.2s),tests/startup_gfx2hlsl_sgpr_spill_check.pyok (0.1s),tests/startup_gfx2hlsl_shift64_check.pyok (0.2s),tests/startup_gfx2hlsl_sload_const_offset_check.pyok (0.1s),tests/startup_gfx2hlsl_smem_offset_check.pyok (0.1s),tests/startup_gfx2hlsl_sop2_complement_check.pyok (4.9s),tests/startup_gfx2hlsl_sopk_accum_check.pyok (0.8s),tests/startup_gfx2hlsl_sopk_signext_check.pyok (0.1s),tests/startup_gfx2hlsl_swap_check.pyok (0.2s),tests/startup_gfx2hlsl_vopc_sdwa_check.pyok (3.8s),tests/startup_gfx2hlsl_waitcnt_depctr_check.pyok (0.1s),tests/startup_gfx2hlsl_watch_check.pyok (2.3s),tests/startup_image_2d_array_check.pyok (0.1s),tests/startup_image_3d_check.pyok (0.1s),tests/startup_image_gather_lz_check.pyok (0.5s),tests/startup_image_load_d16_check.pyok (0.8s),tests/startup_image_sample_a16_check.pyok (0.2s),tests/startup_image_sample_b_check.pyok (0.2s),tests/startup_image_sample_c_check.pyok (0.2s),tests/startup_image_sample_l_check.pyok (0.2s),tests/startup_image_sample_lod_check.pyok (0.5s),tests/startup_inline_sampler_check.pyok (0.1s),tests/startup_mesh57_skeleton_check.pyok (0.4s),tests/startup_run_ps1_check.pyok (8.5s),tests/startup_run_sh_check.pyskipped (0.1s),tests/startup_sampler_heap_check.pyok (0.1s),tests/startup_shader_cache_rekey_check.pyok (1.5s),tests/startup_smem_address_check.pyok (0.1s),tests/startup_stream_fetch_check.pyok (0.2s),tests/startup_stream_interface_check.pyok (0.2s),tests/startup_translator_check.pyok (0.3s)sccache: 6/8 hits; wall55.2sAI-assisted; commands listed were executed locally.