shader: lower v_mad_u64_u32 and v_mad_i64_i32 in gfx2hlsl (Part of #1723) #2040
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2047"
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-24T23:37:52Z.
Part of #1723
What this unblocks: shaders that use 64-bit multiply-add (
v_mad_u64_u32,v_mad_i64_i32) now translate ingfx2hlsl.pyinstead of being refused.D = S0 * S1 + S2modulo 2^64 into av[d:d+1]pair using 16-bit partial products (no 64-bit HLSL type).vcc,vcc_loor one SGPR (tracked as a lane mask, sov_cndmask_b32can read it).nulldestination (its carry-out is not established); other forms, modifiers and wrong operand shapes are refused.pixel_aotlowering (#1278).Verification: (local Linux run; Win2025 not run for this pure-Python change)
python3 -I -B tests/startup_gfx2hlsl_mad64_check.py: pass (700 inputs per form against a 64-bit Python reference, carry mask, overlap, 7 refusals).origin/maingfx2hlsl.py: fails (mulhi32 missing).startup_gfx2hlsl_shift64_check.py,_bit_alu_check.py,_op_refusals_check.py,_operand_count_check.py,_mad_check.py: pass.startup_gfx2hlsl_mad64inCMakeLists.txt.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:43:36Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
e6e8f6b571ℹ️ 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 tedin7 on 2026-11-25T00:58:09Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:38:05Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
e6e8f6bℹ️ 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 ChazY11 on 2026-11-24T23:45:36Z.
Ran it, broke the helpers six ways — all caught — and checked the arithmetic against exact 64-bit values
mulhi32dropsmid >> 16mulhi32buildsmidwithoutp00 >> 16mad64u:c0 = lo < pl→lo <= plmad64u:hi = hs + c0→hi = hsmad64u: the carry-outzonly looks aths < phmad64idrops one sign-correction termThe second one is the one I expected to survive: dropping
p00 >> 16frommidchanges the high product only when a low-word product carries intothe middle term, which needs operands above
0xffffin a specific pattern. It is caught.The arithmetic, against a reference that uses real 64-bit integers
I transcribed
mulhi32,mad64uandmad64iand compared the resulting 64-bit value witha * b + (chi:clo)computed exactly, for both theunsigned and the signed reading of the two 32-bit factors:
and the lane-mask carry-out on its own:
That last check is the one I would keep if you only kept one:
zis assembled from two comparisons (hs < phandhi < hs), and asingle-comparison version is exactly mutation five — which survives a text comparison but not a value comparison.
The
mulhi32decomposition, written outa*b = p11·2^32 + (p01 + p10)·2^16 + p00, so the high word isp11 + (p01 >> 16) + (p10 >> 16) + carry-out-of-mid, wheremid = (p00 >> 16) + (p01 & 0xffff) + (p10 & 0xffff). All four terms are needed and all four are pinned by the mutations above. This is worth asentence in the helper comment: a reader who knows the identity will check it in ten seconds, and one who does not will assume
p00only affectspl.Two design choices I would like stated in the description
nullis accepted. That is an honest refusal, and it is the right call — but it meansv_mad_i64_i32with a real lane mask is still a refusal after this PR, so the PR does not "unblock signed 64-bit carry chains". The title says"lower
v_mad_u64_u32andv_mad_i64_i32", which reads as both being complete.mad64ireturnsz = 0urather than omitting it. Given the caller never reads it in the signed path, that is fine; a comment saying so wouldstop someone from "fixing" it later.
What I could not check
No shader compiled or run — the checks above evaluate the emitted expressions in Python. The claim that this matches the
pixel_aotlowering from#1278 is a comparison I did not make; if the two emit different expressions for the same instruction, that is the thing a reviewer cannot see from
either file alone.
Notes
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:43:36Z.
Code review location:
tools/startup/gfx2hlsl.py; line 1597If MAD64 reads
vcc_loor an SGPR previously written as a compare/carry mask,u()supplies the per-lane 0/1 projection rather than the architectural 32-bit mask. For example, on a fully active wave32,v_mad_u64_u32 v[12:13], s60, 1, 1, -1followed byv_mad_u64_u32 v[14:15], vcc_lo, s60, 1, 0is accepted here and computesv14 = 1, although the architecturals60contains0xffffffffand the correct result isv14 = 0xffffffff. Reject VCC and SGPRs inself.masksas integer inputs, including either SGPR word of S2, unless the full mask is reconstructed; otherwise this newly supported form silently miscompiles.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:58:09Z.
Code review location:
tools/startup/gfx2hlsl.py; line 1597Fixed in
b9a3844d. MAD64 now refuses VCC and any SGPR tracked as a lane mask (including either word of S2) as an integer input, so the s60 example is rejected instead of miscompiled. Added refusal cases plus a control showing a non-mask scalar is still accepted. Ran: python3 tests/startup_gfx2hlsl_mad64_check.py and all tests/startup_gfx2hlsl_*_check.py locally, all pass.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-25T10:43:24Z.
First hardware run reported in this thread:
startup_gfx2hlsl_mad64_hardwarepasses on headce9b7342with both FXC and DXC.Environment: NVIDIA GeForce RTX 3070 Ti (
10de:2482), driver 32.0.16.2101, Windows 11 build 26300.9974, Debug build, fxc 10.0.26100.9457, dxc 1.9.2602.17, D3D12 debug layer enabled, hardware run serial on an idle machine, 0 capability skips (77). The log has 18fxclines and 18dxclines (16 draw rows, 8u64and 8i64, and 2 "mutation: fails as expected" rows per compiler), anddebug_errors=0 debug_warnings=0on all 36 runs.Same head, WARP and CPU checks:
100% tests passed, 0 tests failed out of 2(startup_gfx2hlsl_mad64,startup_gfx2hlsl_mad64_warp); the WARP test has 18fxclines, 18dxclines anddebug_errors=0 debug_warnings=0on all 36 runs.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:54:42Z.
Thank you @ChazY11 for the six-mutation run with exact 64-bit checks, and @Makto94 for the RTX 3070 Ti run at
ce9b7342(startup_gfx2hlsl_mad64_hardwarepassed with FXC and DXC, CPU and WARP 2/2). Recorded as extra evidence for this PR.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-25T13:00:37Z.
Run at head
ce9b7342, on the AMD adapter (adapter=AMD Radeon RX 9070 XT), backendhardware, both compilers.16 readbacks per compiler — eight
u64and eighti64draws — all matching their references, plus one mutation run per family per compiler that reads its mutated words. Nothing divergent: the 64-bit multiply-add lands on the right words underfxc(ps_5_1) and underdxc(ps_6_0).AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:45:12Z.
Thank you @thepatrickworld for the AMD Radeon RX 9070 XT run.
startup_gfx2hlsl_mad64_hardwareat headce9b7342on thehardwarebackend: 16 readbacks per compiler (eightu64, eighti64) match their references under bothfxc(ps_5_1) anddxc(ps_6_0), and the mutation runs fail as expected. No divergence.What it means for the PR: this is a third independent hardware result (after the RTX 3070 Ti run and the earlier mutation run), and the first on an AMD adapter. No code change needed.
Note: the current head is
50051c12. It differs fromce9b7342by a merge oforigin/maininto the branch. The merge pulls in other, unrelatedgfx2hlsl.pychanges from main; the mad64 helpers andtests/startup_gfx2hlsl_mad64_check.pyare not touched by it.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:50:57Z.
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-26T00:40:33Z.
@MasterDomino #2047 is ready for review/merge.
What changed since the last head:
main(oneCMakeLists.txtconflict, both sides kept).v_mad_u64_u32is now tracked as varying (per-lane), not uniform. New check instartup_gfx2hlsl_mad64_check.pyfails on the old code and passes now.startup_gfx2hlsl_mad64_check.py(controls andbinary) is now registered in.github/workflows/windows.yml.Head:
9bd7e5d894037ac0e7e8dfb7f2be1396398d0bba. CI is green on this head.Verification (Windows Server 2025 Build 26100, MSVC 14.44.35207, D3D12 WARP, exact head above):
x2w_pipe.py win2025 2047 --wait 7200 --keep-release: dev + release PASS.x2w_pipe.py win2025 2047 --wait 7200 --keep-release --targets offscreen_check --regex '^startup_gfx2hlsl_mad64': dev and release both runstartup_gfx2hlsl_mad64(pure-Python 64-bit reference),startup_gfx2hlsl_mad64_warp(D3D12 WARP draw readback vs CPU reference) andstartup_gfx2hlsl_mad64_hardware; 3/3 passed in each preset.python3 -I -B tests/startup_gfx2hlsl_mad64_check.pypass.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-26T01:11:46Z.
Fresh hardware run at the current head. The AMD run I posted in this thread was at
ce9b7342, and this head changes behaviour (thev_mad_u64_u32carry-out mask is varying now), so that one does not cover it.Environment, read on the machine: Windows 11 25H2, build
26200.9974, MSVC tools14.44.35207, AMD Radeon RX 9070 XT (1002:7550, driver32.0.32029.2010),devpreset, head9bd7e5d8.All three filtered tests report
Passed; the output contains no skipped or failed entry. A verbose run of the hardware test alone (separate invocation:1/1 ... Passed 11.89 sec) confirms the adapter it actually drew on, and the raw readback words:Sixteen draw readbacks per compiler under
fxcanddxc(32), each matching its reference; plus four mutation readbacks, one per form per compiler, for 36 in all — and those four fail as they must.Only the AMD adapter appears in this run (
vendor=1002 device=7550, driver32.0.32029.2010). The RTX numbers in this thread are not from here.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:29:38Z.
@thepatrickworld thank you for the fresh AMD Radeon RX 9070 XT run at
9bd7e5d8: 3/3startup_gfx2hlsl_mad64*passed, 32 draw readbacks plus 4 mutation readbacks matched. No defect there, so no code change for it.That head had a merge conflict with
mainin.github/workflows/windows.yml(both sides added a test to the lists). I mergedorigin/mainand kept both sides: new head5a6dad42, no force-push, CI green (Linux checks, gfx1013 fixtures, Windows build and test).@MasterDomino #2047 is ready for review/merge at
5a6dad42.Verification, all executed locally:
git merge origin/main, thenpython3 -B tests/startup_gfx2hlsl_mad64_check.pyandpython3 -B tests/startup_gfx2hlsl_mul_hi_i32_check.py: ok.5a6dad42: PASS on the second run. The first run failed only intests/startup_run_ps1_check.py(an 80-column wrap of a PowerShell warning, a load-dependent check onmain, not this change), so I re-ran once.--targets offscreen_check --regex '^startup_gfx2hlsl_(mad64|mul_hi_i32)'), receipt below.AI-assisted; commands listed were executed locally.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
5a6dad42af4e6f546ea3b97536da1727096a4104:--preset dev):cmake --build --preset dev --target offscreen_check -- -j 2):1.91s(configure0.00s)ctest --preset dev -R '^startup_gfx2hlsl_(mad64|mul_hi_i32)' --parallel 2 --no-tests=error --output-on-failure): 6/6 passed (6.20s:startup_gfx2hlsl_mad640.52s,startup_gfx2hlsl_mad64_warp4.98s,startup_gfx2hlsl_mad64_hardware4.31s,startup_gfx2hlsl_mul_hi_i32_controls0.17s,startup_gfx2hlsl_mul_hi_i32_warp1.00s,startup_gfx2hlsl_mul_hi_i32_hardware0.91s)/O2(--preset release):cmake --build --preset release --target offscreen_check -- -j 2):6.21s(configure0.00s)ctest --preset release -R '^startup_gfx2hlsl_(mad64|mul_hi_i32)' --parallel 2 --no-tests=error --output-on-failure): 6/6 passed (4.86s:startup_gfx2hlsl_mad640.49s,startup_gfx2hlsl_mad64_warp3.40s,startup_gfx2hlsl_mul_hi_i32_controls0.18s,startup_gfx2hlsl_mad64_hardware3.43s,startup_gfx2hlsl_mul_hi_i32_warp0.84s,startup_gfx2hlsl_mul_hi_i32_hardware0.82s)tests/mesh_heap_sampler_check.pyok (1.1s),tests/startup_buffer_address_check.pyok (0.7s),tests/startup_buffer_format_word3_table_check.pyok (0.1s),tests/startup_compute_request_offline_check.pyok (0.8s),tests/startup_compute_store_format_xyzw_check.pyok (0.3s),tests/startup_compute_translate_check.pyok (0.3s),tests/startup_flat_param_check.pyok (0.2s),tests/startup_gfx2hlsl_add_sub_co_check.pyok (0.1s),tests/startup_gfx2hlsl_add_sub_co_ci_check.pyok (0.2s),tests/startup_gfx2hlsl_bit_alu_check.pyok (0.9s),tests/startup_gfx2hlsl_capture_check.pyok (1.3s),tests/startup_gfx2hlsl_cmp16_check.pyok (0.3s),tests/startup_gfx2hlsl_cmp_class_f16_sdwa_check.pyok (47.4s),tests/startup_gfx2hlsl_compare_dst_check.pyok (0.2s),tests/startup_gfx2hlsl_compute_check.pyok (0.8s),tests/startup_gfx2hlsl_cselect_mask_check.pyok (0.2s),tests/startup_gfx2hlsl_cvt_alu_check.pyok (0.3s),tests/startup_gfx2hlsl_cvt_off_f32_i4_check.pyok (0.4s),tests/startup_gfx2hlsl_cvt_pk_int16_check.pyok (0.6s),tests/startup_gfx2hlsl_f32_lg_check.pyok (2.5s),tests/startup_gfx2hlsl_f32_nan_check.pyok (9.5s),tests/startup_gfx2hlsl_fma_mix_check.pyok (0.2s),tests/startup_gfx2hlsl_getpc_refusal_check.pyok (0.2s),tests/startup_gfx2hlsl_handler_arity_check.pyok (0.2s),tests/startup_gfx2hlsl_heap_record_check.pyok (0.3s),tests/startup_gfx2hlsl_image_arity_check.pyok (0.2s),tests/startup_gfx2hlsl_image_get_lod_check.pyok (0.3s),tests/startup_gfx2hlsl_int_med3_check.pyok (0.2s),tests/startup_gfx2hlsl_interp_p2_hi_check.pyok (0.4s),tests/startup_gfx2hlsl_join_symbols_check.pyok (0.3s),tests/startup_gfx2hlsl_loop_constants_check.pyok (0.2s),tests/startup_gfx2hlsl_mask_data_check.pyok (0.2s),tests/startup_gfx2hlsl_mask_overwrite_check.pyok (0.2s),tests/startup_gfx2hlsl_operand_count_check.pyok (0.6s),tests/startup_gfx2hlsl_pack_absdiff_check.pyok (4.9s),tests/startup_gfx2hlsl_pack_b32_f16_check.pyok (0.3s),tests/startup_gfx2hlsl_readfirstlane_recompute_check.pyok (0.2s),tests/startup_gfx2hlsl_readfirstlane_uniform_check.pyok (0.2s),tests/startup_gfx2hlsl_refusals_check.pyok (0.9s),tests/startup_gfx2hlsl_root_check.pyok (1.1s),tests/startup_gfx2hlsl_s_abs_check.pyok (0.1s),tests/startup_gfx2hlsl_s_bitset_check.pyok (0.2s),tests/startup_gfx2hlsl_s_ff0_check.pyok (0.1s),tests/startup_gfx2hlsl_s_ff1_check.pyok (0.2s),tests/startup_gfx2hlsl_s_flbit_check.pyok (0.2s),tests/startup_gfx2hlsl_s_quadmask_check.pyok (0.2s),tests/startup_gfx2hlsl_sad_check.pyok (0.6s),tests/startup_gfx2hlsl_saveexec_same_reg_check.pyok (0.2s),tests/startup_gfx2hlsl_scalar_arity_check.pyok (0.4s),tests/startup_gfx2hlsl_scalar_brev_fold_check.pyok (0.3s),tests/startup_gfx2hlsl_scalar_m0_check.pyok (0.3s),tests/startup_gfx2hlsl_scalar_null_check.pyok (0.3s),tests/startup_gfx2hlsl_scalar_table_arity_check.pyok (0.4s),tests/startup_gfx2hlsl_sdwa_cndmask_check.pyok (0.2s),tests/startup_gfx2hlsl_sdwa_cvt_check.pyok (0.4s),tests/startup_gfx2hlsl_sgpr_spill_check.pyok (0.2s),tests/startup_gfx2hlsl_shift64_check.pyok (0.3s),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 (8.0s),tests/startup_gfx2hlsl_sopk_accum_check.pyok (1.1s),tests/startup_gfx2hlsl_sopk_signext_check.pyok (0.2s),tests/startup_gfx2hlsl_spill_branches_check.pyok (1.0s),tests/startup_gfx2hlsl_swap_check.pyok (0.3s),tests/startup_gfx2hlsl_vopc_sdwa_check.pyok (4.6s),tests/startup_gfx2hlsl_waitcnt_depctr_check.pyok (0.1s),tests/startup_gfx2hlsl_watch_check.pyok (2.5s),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.6s),tests/startup_image_load_d16_check.pyok (1.0s),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.6s),tests/startup_inline_sampler_check.pyok (0.2s),tests/startup_mesh57_depth_only_check.pyok (0.2s),tests/startup_mesh57_lane_spill_check.pyok (0.2s),tests/startup_mesh57_loop_check.pyok (0.2s),tests/startup_mesh57_loop_refusal_check.pyok (0.2s),tests/startup_mesh57_skeleton_check.pyok (1.4s),tests/startup_run_ps1_check.pyok (11.6s),tests/startup_run_sh_check.pyskipped (0.1s),tests/startup_sampler_heap_check.pyok (0.1s),tests/startup_shader_cache_rekey_check.pyok (2.3s),tests/startup_smem_address_check.pyok (0.2s),tests/startup_stream_fetch_check.pyok (0.2s),tests/startup_stream_interface_check.pyok (0.3s),tests/startup_translator_check.pyok (0.5s)sccache: 182/209 hits; wall143.2sImported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T05:47:28Z.
Review: APPROVED
Reviewed the 32-bit partial products, signed high-word correction and unsigned 64-bit carry. With main
1ec01d70combined, the Python controls and the FXC/DXC draw suite passed on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 on Windows 11 build 26200. The carry/limb mutation read back the expected wrong words. Signed carry remains refused except when discarded.