shader: lower 24-bit multiply, xnor, alignbit and alignbyte in gfx2hlsl (Part of #1723) #2070
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2077"
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 tedin7 on 2026-11-25T00:03:15Z.
Part of #1723
What this unblocks: startup pixel/vertex shaders that use 24-bit integer multiplies,
v_xnor_b32or the bit/byte funnel shifts now translate to HLSL instead of being refused.Adds to
tools/startup/gfx2hlsl.py:v_mul_i32_i24,v_mul_hi_i32_i24,v_mul_hi_u32_u24,v_mad_i32_i24,v_xnor_b32,v_alignbit_b32,v_alignbyte_b32. None were onorigin/mainor in an open PR. The hi forms stay inside 32-bit integers by splitting each 24-bit field into two 12-bit halves, and the funnel shifts guard the shift-by-32 case.New test
tests/startup_gfx2hlsl_mul24_align_check.py(registered asstartup_gfx2hlsl_mul24_aligninCMakeLists.txt): translates each instruction with the real translator, evaluates the emitted HLSL on the CPU and compares with an unbounded-integer reference.Verification:
python3 -B tests/startup_gfx2hlsl_mul24_align_check.pyonorigin/main: exit 1 (Unsupported: v_mul_i32_i24).python3 -B tests/startup_gfx2hlsl_bit_alu_check.py,startup_gfx2hlsl_op_refusals_check.py,startup_gfx2hlsl_operand_count_check.py,startup_gfx2hlsl_refusals_check.py: all exit 0.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:07:44Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
54c215a788ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:03:29Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
54c215aℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:07:44Z.
Code review location:
tools/startup/gfx2hlsl.py; line 1907This adds support for
v_alignbit_b32and the signed/high 24-bit multiplies, butdocs/experiments.md:11586still explicitly lists those operations as not lowered. Contributors consulting the capability documentation therefore receive an incorrect support boundary. The rootAGENTS.mdrequires updating the relevant README row or experiment documentation when a public capability changes; update that section with the newly supported forms and the CPU-only reproduction command.AGENTS.md reference: AGENTS.md:L211-L212
Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:03:46Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:03:46Z.
Code review location:
tools/startup/gfx2hlsl.py; line 1907Fixed in f2222c75 (rebased on current main, pending push to this branch). New section in docs/experiments.md lists the seven lowered forms, refusals, the CPU check and the WARP/hardware draw runs (hardware reported separately), and the check is added to AGENTS.md and the CI list.
AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_mul24_align_check.py, startup_gfx2hlsl_bit_alu_check.py, startup_translator_check.py, docs_links_check.py.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-25T02:38:25Z.
I ran this on a real AMD card (RX 9070 XT, driver 32.0.32029.2010), which is the first GPU run of
startup_gfx2hlsl_mul24_align_draw_check.py— the PR body says the Win2025 GPU draw was not run.dxc: the whole draw passes on hardware. fxc: it fails on
v_mul_hi_u32_u24, identically on WARP, so the adapter is not involved:The three ops that come before it in the same loop —
v_mul_i32_i24,v_mad_i32_i24,v_mul_hi_i32_i24— pass under the same fxc.The artifact: compiling the emitted pixel shader with
fxc /T ps_5_1givesNo
dcl_inputat all: the whole expression is folded to a constant, and the shader reads nothing. Its signed twin declares its inputs (dcl_input_ps constant v3.xyzw,v4.xyzw) and computes. With/Odthe unsigned one also produces the expected code (dcl_input_ps constant v3.xyzw,v4.xyzw, thenishl/ushr), so this is the optimizer, not the emission — and dxc emits correct code from the same source.Two things I tried before writing this, both still fold to zero under fxc: replacing the overflowing
(v0 << 8) >> 20top with the equivalent(v0 >> 12) & 0xfff, andumulhi(which does not exist in HLSL —error X3004: undeclared identifier, my mistake).What I think it means: the startup path compiles its shaders with fxc (
find_fxcingfx2hlsl.py), so an op that fxc folds to zero is silently wrong there even though the CPU check and the dxc draw are green. Either restructuring the unsigned form, or marking the op as not fxc-safe with a pointer to this, seems worth it before merge.Limits: one fxc build (10.0.26100.0, Windows SDK), AMD RDNA2 only, no NVIDIA card here, so I can't say whether the same fold appears elsewhere — and I have not isolated which sub-expression triggers it.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-25T10:18:30Z.
startup_gfx2hlsl_mul24_align_warpfails on WARP at headd9214336, with the all-zero readback that thepatrickworld reported earlier in this thread. The failure comes from the fxc branch. The dxc branch passes on this head on WARP when run alone.Command
Observed (two runs, same result)
The fxc ops
v_mul_i32_i24,v_mad_i32_i24andv_mul_hi_i32_i24pass. Then:dxc branch, run alone on the same head and adapter
The
fxcargument ofstartup_gfx2hlsl_mul24_align_draw_check.pyis optional (check_draw(dxc, renderer, adapter, fxc=None)). I ran the command of the ctest test without it:Result: exit code 0. The log has 21
dxclines: 3 chunks each forv_mul_i32_i24,v_mad_i32_i24,v_mul_hi_i32_i24,v_mul_hi_u32_u24,v_xnor_b32,v_alignbit_b32andv_alignbyte_b32.v_mul_hi_u32_u24passes under dxc on WARP, withdebug_errors=0 debug_warnings=0.Measured
check_draw()runs all ops with fxc first, and the assertion stops the test. That log has 0dxcresult lines.fxc /T ps_5_1disassembly earlier in this thread shows the shader folded tomov o0.xyzw, l(0,0,0,0). I did not repeat it on this head.5c8e82d7("fix: read the unsigned 24-bit fields with a shift pair so FXC keeps the high product"). The fxc readback ofv_mul_hi_u32_u24is still zero here..github/workflows/windows.ymlat this head:pull_requestthe job runsctest --preset pr --no-tests=error ...(line 334). Theprpreset does not selectstartup_gfx2hlsl_mul24_align*. The Windows CI run on this head lists 31 tests and none is mul24.main, the job runsctest --preset dev --no-tests=error --parallel 4 -E '_hardware$' ...(line 339). The namestartup_gfx2hlsl_mul24_align_warpdoes not end in_hardware, so this selection includes it.startup_gfx2hlsl_mul24_align(non-draw) passes.Environment: Windows 11 build 26300;
fxc.exe10.0.26100.9457 (SDK 10.0.26100.0);dxc1.9.2602.17; WARP "Microsoft Basic Render Driver" 1414:008c, driver 10.0.26100.9818; D3D12 debug layer enabled,debug_errors=0 debug_warnings=0; Debug build. No hardware run in this comment.Suggestion
Run the DXC branch even when the fxc branch fails, then report both results at the end. This does not change the pass criteria. It makes the fxc-only failure visible in a single run.
Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-25T10:27:32Z.
Hardware result for head
d9214336, on an RTX 3070 Ti (10de:2482, driver 32.0.16.2101, Windows 11 build 26300.9974, fxc 10.0.26100.9457, dxc 1.9.2602.17, debug layer enabled, 0 capability skips (77)). It matches the WARP result in my earlier comment.AssertionError: fxc v_mul_hi_u32_u24 ...withstartup_flat_param mismatch expected=00003fff,00004000,0000ffff,00003fff actual=00000000,00000000,00000000,00000000. The FXC ops before it (v_mul_i32_i24,v_mad_i32_i24,v_mul_hi_i32_i24) pass.fxcargument) printed 21dxcresult lines, 3 per op for all 7 ops, with no traceback, exit code 0. All 21 draws reportdebug_errors=0 debug_warnings=0.Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-25T11:02:28Z.
Two corrections to the "Limits" paragraph of my comment above.
I wrote "AMD RDNA2 only". The card is an RX 9070 XT, RDNA4 (
gfx1201) — RDNA2 is the ISA I quote for the comparison rules, not the hardware I ran on. Sloppy, and wrong in the one paragraph where precision matters."no NVIDIA card here, so I can't say whether the same fold appears elsewhere" no longer holds: Makto94 reproduced the same fold on an RTX 3070 Ti, same op, same four zeros, with the neighbouring ops passing. So this is not an AMD artefact, and the fxc optimiser is the common factor.
What still stands: one fxc build (10.0.26100.0), and I have not isolated which sub-expression makes the optimiser fold the expression to zero.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:08:09Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:04:24Z.
@Makto94 thank you for the WARP and hardware runs and for the line-by-line CI analysis; the failure was real. Pushed
ca819bf7.v_mul_hi_u32_u24is now refused (Unsupported, VOP2 and_e64) instead of being translated into the zeros FXC produced. Three unsigned variants all folded to zero under FXCps_5_1; DXC kept them. A lowering FXC keeps can replace the refusal later. The reason is written next to the table intools/startup/gfx2hlsl.pyand in a new section ofdocs/experiments.md.startup_gfx2hlsl_mul24_align_check.pynow asserts both refusals; the draw check covers the six translated instructions and runs both compilers before it fails, as you suggested.Verification (Windows Server 2025 build 26100, MSVC 14.44.35207, D3D12 WARP), commit
ca819bf7:python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 2077 --force --targets offscreen_check --regex '^startup_gfx2hlsl_mul24_align'startup_gfx2hlsl_mul24_align,_warpand_hardware3/3 passed in each. On that machine the_hardwaretest ran on the Microsoft Basic Render Driver, so it is not a physical GPU result.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-25T11:11:28Z.
I ran the hardware test on
ca819bf7, as you asked..\tools\dev.ps1; ctest --preset dev --no-tests=error -j1 -R '^startup_gfx2hlsl_mul24_align_hardware$' -Vpasses. The log has 18fxcand 18dxcresult lines, 3 for each of the six ops (v_mul_i32_i24,v_mad_i32_i24,v_mul_hi_i32_i24,v_xnor_b32,v_alignbit_b32,v_alignbyte_b32). Nodebug_errors=line has a non-zero value in either log, and there are no skips (77). Serial run on an idle machine..\tools\dev.ps1; ctest --preset dev --no-tests=error -j1 -R '^startup_gfx2hlsl_mul24_align($|_warp$)' -Vgives100% tests passed, 0 tests failed out of 2.startup_gfx2hlsl_mul24_alignprintsv_mul_hi_u32_u24: refused okandv_mul_hi_u32_u24_e64: refused ok.10de:2482), driver 32.0.16.2101; WARP (Microsoft Basic Render Driver,1414:008c), driver 10.0.26100.9818; Windows 11 build 26300.9974, Debug build, D3D12 debug layer enabled, fxc 10.0.26100.9457, dxc 1.9.2602.17. The binaries were built atd9214336; between that commit andca819bf7only Python files and docs change.Some FXC data, in case it helps a later lowering of
v_mul_hi_u32_u24. The pixel shader comes from the check at450326ef, where FXC still read zeros on WARP and on the RTX; atca819bf7the op is no longer generated. Command:fxc /nologo /T ps_5_1 /E main /Fc out.asm ps.hlsl. Each variant changes only theo.mrt0line (and the output type for the uint4 rows).mov o0.xyzw, l(0,0,0,0)F(v12)..F(v15)(generated)F(v0 >> 9)F(v0 >> 8)uint4(v0 >> 9, ...)uint4(v12, v13, v14, v15)/Gismov [precise] o0.xyzw, l(0,0,0,0))docs/experiments.mdatca819bf7says: "Three variants (an unsigned shift pair, a shift and a mask, and the signed shift pair with a mask) all folded to zero under FXC". Measured here:F(v0 >> 9)folds with no product in it, and the same generated arithmetic with a uint4 output is kept.My hypothesis, not tested further: below 0x00800000 the word read as a float is denormal, and FXC seems to zero a float output whose provable range lies entirely under that value. At runtime small words survive: on the RTX at
ca819bf7, FXCv_mul_hi_i32_i24reads back00003fff,00004000,00000000,ffffc000and passes.Limits: one fxc version only, and the variants were compiled, not drawn.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:08:09Z.
Code review location:
tools/startup/gfx2hlsl.py; line 1907Addressed at
ca819bf796: docs/experiments.md now has a "Startup 24-bit multiplies, v_xnor_b32 and the funnel shifts" section listing the translated forms, the refused v_mul_hi_u32_u24, and the reproduction commands (python3 -B tests/startup_gfx2hlsl_mul24_align_check.py,ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_mul24_align$' -V). The stale "not lowered" wording no longer matches the file.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:05:42Z.
@Makto94 thank you for the hardware run and the FXC table. Your denormal reading fits the data, and I took it.
v_mul_hi_u32_u24refusal stays. Its result is at most0xffff, so as a float output word it is always a binary32 denormal. FXC folds a float output whose provable range is under0x00800000, so any lowering of this op would read zeros on the float path.docs/experiments.mdand the comment next to the table intools/startup/gfx2hlsl.pyno longer say "three unsigned variants folded". They now give the cause (denormal float output), yourF(v0 >> 9)/F(v0 >> 8)/uint4results, and say the variants were compiled, not drawn, on one FXC version.startup_gfx2hlsl_mul24_alignalready asserts both refusals.Committed as
438079bf(docs and a comment only).Commands run locally:
python3 -B tests/startup_gfx2hlsl_mul24_align_check.py(bothv_mul_hi_u32_u24spellings printrefused ok)Not re-run: Win2025 WARP and hardware (no executable change since the last passing run).
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:52:09Z.
Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is.
We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T23:08:55Z.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
8c3de91b5bd12a9ed4a6d908ea8e9ca903318a47:--preset dev):cmake --build --preset dev --target offscreen_check -- -j 2):23.83s(configure1.94s)ctest --preset dev -R 'startup_gfx2hlsl_(mul24_align|mul_mad_i24)' --parallel 4 --no-tests=error --output-on-failure): 6/6 passed (4.15s:startup_gfx2hlsl_mul_mad_i24_controls0.25s,startup_gfx2hlsl_mul24_align0.38s,startup_gfx2hlsl_mul_mad_i24_warp1.59s,startup_gfx2hlsl_mul_mad_i24_hardware1.49s,startup_gfx2hlsl_mul24_align_hardware4.01s,startup_gfx2hlsl_mul24_align_warp4.02s)/O2(--preset release):cmake --build --preset release --target offscreen_check -- -j 2):44.59s(configure2.34s)ctest --preset release -R 'startup_gfx2hlsl_(mul24_align|mul_mad_i24)' --parallel 4 --no-tests=error --output-on-failure): 6/6 passed (4.35s:startup_gfx2hlsl_mul_mad_i24_controls0.25s,startup_gfx2hlsl_mul24_align0.34s,startup_gfx2hlsl_mul_mad_i24_warp1.62s,startup_gfx2hlsl_mul_mad_i24_hardware1.61s,startup_gfx2hlsl_mul24_align_warp4.20s,startup_gfx2hlsl_mul24_align_hardware4.21s)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.4s),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.6s),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.3s),tests/startup_gfx2hlsl_f32_lg_check.pyok (1.1s),tests/startup_gfx2hlsl_f32_nan_check.pyok (4.3s),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.2s),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.6s),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 (5.0s),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.9s),tests/startup_gfx2hlsl_waitcnt_depctr_check.pyok (0.1s),tests/startup_gfx2hlsl_watch_check.pyok (2.4s),tests/startup_image_2d_array_check.pyok (0.2s),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.9s),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.7s),tests/startup_run_sh_check.pyskipped (0.1s),tests/startup_sampler_heap_check.pyok (0.1s),tests/startup_shader_cache_rekey_check.pyok (1.6s),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.4s)sccache: 2/10 hits; wall131.3sAI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T23:09:00Z.
@MasterDomino #2077 is ready for review/merge.
origin/main(no force-push). The Linux checkstartup_gfx2hlsl_mul_mad_i24_check.pyfailed because this PR re-registeredv_mul_i32_i24/v_mad_i32_i24with different text than main's, which broke that test's mutation control. I dropped the two duplicate entries so main's lowering stays; the new mul24/alignbit lowerings are unchanged.8c3de91b5bd12a9ed4a6d908ea8e9ca903318a47. CI is green on this head.startup_gfx2hlsl_mul24_align_warpandstartup_gfx2hlsl_mul_mad_i24_warp) is in the comment above.AI-assisted; commands listed were executed locally.