startup: lower v_mul_i32_i24 and v_mad_i32_i24 in gfx2hlsl #2402
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2410"
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 R0D4X on 2026-11-25T15:38:38Z.
Summary
v_mul_i32_i24in both VOP2_e32and VOP3A_e64encodings, andv_mad_i32_i24VOP3A) intools/startup/gfx2hlsl.py, completing the signed counterparts tov_mul_u32_u24andv_mad_u32_u24inVEC_U.asuint(asint({0} << 8) >> 8) * asuint(asint({1} << 8) >> 8)[+{2}]) matchingtools/pixel_aot.py, with no new helper inPipeline.common().clamp,mul:2,div:2,op_sel,-v,|v|) and wrong operand counts.tests/startup_gfx2hlsl_mul_mad_i24_check.pycovering CPU evaluation across 256x4 (v_mul_i32_i24) and 384x4 (v_mad_i32_i24) edge cases (24-bit sign boundaries, upper-byte noise, 32-bit wraparound), unsigned-24-bit mutation controls,exec-masked emission, modifier/arity refusals,binary <llvm-mc>round-trip checks, and FXCps_5_1+ DXCps_6_0WARP/hardware draws.startup_gfx2hlsl_mul_mad_i24_{controls,warp,hardware}inCMakeLists.txtand wiretests/startup_gfx2hlsl_mul_mad_i24_check.pyintopixel-binaryandpython-linuxin.github/workflows/windows.yml.Verification
7092683a(upstream/main)05cbd7c710.0.26300.9974), MSVC19.44.35230, Windows SDK10.0.26100.0, FXC + DXC1.9.2602.17Microsoft Basic Render Driver(1414:008c), driver10.0.26100.9818, D3D12 debug layer enabledNVIDIA GeForce RTX 5080(10de:2c02), driver32.0.16.2124, D3D12 debug layer enabledCommands and Observed Results
docs_links_check.py: 19 files / 464 links;bidi_controls_check.py: 1723 files;startup_tools_lint: passed).mul_unsigned24,mad_unsigned24,mad_drop_addend) caught (rc=1) and reverted cleanly.dev: 4 passed, 0 skipped, 0 failed (debug_errors=0 debug_warnings=0on WARP and RTX 5080 for both FXCps_5_1and DXCps_6_0, including unsigned-24-bit GPU mutation controls).release: 3 passed, 0 skipped, 0 failed (4.22 s, RTX 5080 3.09 s).tests/startup_gfx2hlsl_mul_mad_i24_check.py binary llvm-mc-15was not run locally (llvm-mcis not installed on this Windows host); fixture words were cross-checked againsttools/disasm_rdna2.py/gfx2hlsl.decode()and are exercised by the Ubuntupixel-binaryCI job.v_mul_i32_i24/v_mad_i32_i24lowering and desktop GPU execution in isolation; they do not establish full-game startup.Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-25T16:04:25Z.
APPROVED: Lowering v_mul_i32_i24 and v_mad_i32_i24 in gfx2hlsl.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-25T16:15:24Z.
Review: COMMENTED
Review of head
05cbd7c7(base7092683a). It adds an AMD hardware run and thellvm-mcround-trip the PR body notes as not run locally.Result: no P1 or P2 findings. Two observations and a nit.
What I checked
tools/startup/gfx2hlsl.py: the twoVEC_Uentries sign-extend bits 23:0 of each source (<< 8, then an arithmetic>> 8onint) and multiply asuint, which wraps to the low 32 bits of the signed product. Forv_mad_i32_i24they add the full 32-bitS2with wraparound. That matches the ISA definition. The expression shape matches the unsigned siblings andtools/pixel_aot.py.warp/hardwaredraws in the same shape as the neighbouringshift64entries. The workflow adds thebinary llvm-mc-15entry and the Python-job line, with the\continuations intact.Commands executed (Windows 11 build 26300)
binary, llvm-mc 15.0.7fixture words match llvm-mcps_5_1and DXC 1.8.2502.11ps_6_001fffffe,01800000,ff800000,00000000and02000003,81800000,ff7fffff,7e000000)offscreen_checkwas a Release build at the base commit.My own mutation: replacing the
v_mul_i32_i24expression with a full 32-bit signed multiply,asuint(asint({0}) * asint({1})), makes the controls fail:emitted expressions match reference on 256 cases x 4 lanes: MISMATCH, exit 1. Reverted.Observations, not blocking
SDWA forms of
v_mul_i32_i24are now lowered through the existing generic SDWA path, which neither the PR body nor its tests mention. With llvm-mc-assembled words:src0_sel:BYTE_0emitsasuint(asint(((v0 >> 0u) & 0xffu) << 8) >> 8) * ...;dst_sel:WORD_1 dst_unused:UNUSED_PRESERVEemits the preserved-low-word merge.The semantics compose correctly: the selection zero-extends, or sign-extends under
sext(), to 32 bits before the 24-bit read. A single SDWA case would pin that: for examplesrc0_sel:WORD_1on a high word with bit 15 set, plain (positive) and undersext()(negative). Alternatively the body could say that SDWA comes through the generic path and is covered elsewhere.DPP:
quad_permreaches the generic DPP path, which needs a straight-line pixel stage, androw_shlis refused.clampis refused on both ops. Inline constants, literals and SGPR sources lower correctly, for example1.0is read as integer bits0x3f800000.Nit
DRAW['v_mul_i32_i24'], the commentINT24_MIN * INT24_MIN = 0 (mod 2^32) -> wait: 2^46 mod 2^32 = 0reads like a leftover note. That lane also gives00000000under the unsigned-24 mutation (2^46 mod 2^32 = 0 either way), so the "Set 0 separates signed 24-bit from unsigned 24-bit on every lane" comment doesn't hold for lane 3 of the multiply. The other draw sets cover the difference, so it's only wording.Title and body are neutral. The change is original in-repo work.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T16:59:05Z.
Five mutations, all caught — including the two I expected to be equivalent
Baseline on this branch:
tests/startup_gfx2hlsl_mul_mad_i24_check.py→ six… oklines, exit 0.v_mul_i32_i24: drop the sign extension (asuint({0}) * asuint({1}))v_mul_i32_i24: one shift short (asint(x << 8)without>> 8)v_mad_i32_i24: drop the+ {2}addend{0} & 0xffffffu)<< 8) >> 8→<< 7) >> 7The last two are the ones worth noting.
& 0xffffffuis the natural "simplification" of the sign extension and it is wrong in exactly the way that matters (a negative i24 becomes a large positive), and a shift pair of 7 is off by one byte but still symmetric — a fixture that only tried values below0x7fwould pass both.Independent check of the lowering itself
asuint(asint(x << 8) >> 8)is the 24-bit sign extension everyone writes and nobody verifies, so I evaluated it againstsext24on the values that matter:So the idiom is right for
v_mul_i32_i24's two sources. Thev_mad_i32_i24addend is not sign-extended in the ISA either (only the two multiplicands are i24), and the text adds{2}as a full dword — worth one comment in the table, because a reader will assume all three operands are narrowed.One thing I would pin
The check refuses modifiers and wrong operand counts, and covers the arithmetic — but
v_mul_i32_i24also exists asv_mul_u32_u24andv_mad_u32_u24in the same encoding family. If those stay unlowered, the refusal has to name them rather than fall through to the generic unknown-op message, otherwise a title that uses the unsigned form reads as "instruction not supported at all" in the census instead of "this form not lowered yet". If they are already refused by name, ignore this.What the PR gets right
The table entry is one line and the two instructions share their shape with the existing
v_mul_lo_u32neighbour, so there is nothing to review in the lowering beyond the shift idiom; the value is in the fixture, and the fixture is what this branch adds — including the "exec-maskedv_mad_i32_i24guards assignment" case, which is the one I would not have thought to write.AI-assisted; the five mutations and the sign-extension check were run locally on Windows 11 build 26300.9974.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T19:24:53Z.
Review: COMMENTED
Review of head
05cbd7c7.No blocking findings.
What I checked:
tools/startup/gfx2hlsl.py: thev_mul_i32_i24andv_mad_i32_i24entries sign-extend the low 24 bits with the UB-free shift pair, then multiply (and add src2 for mad). This matches the signed semantics and the existing unsigned siblings inVEC_U.gfx2hlsl.py(#1596 is the computev_mad_i32_i24lowering, a separate path).windows.ymlwiring is consistent with the neighbouringshift64entries.windows.ymlchange is two list entries only; the PR's own CI run exercised them and is green.Commands run locally (Linux, worktree at the PR head):
python3 -B tests/startup_gfx2hlsl_mul_mad_i24_check.py-> passpython3 tests/docs_links_check.py-> passpython3 tests/bidi_controls_check.py-> passgit diff --check origin/main...HEAD-> cleanv_mad_i32_i24changed to the unsigned 24-bit mask -> test fails (384 cases x 4 lanes mismatch)v_mul_i32_i24changed to a plain 32-bit multiply -> test fails (256 cases x 4 lanes mismatch)Note: the branch is 60 commits behind main, so a Windows run on an updated head is still needed before merge.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T19:36:51Z.
Win2025 WARP receipt for head
43c2faf6after updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
43c2faf624c0d834222dc00e3bce3e61d92513f6:--preset dev):cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim -- -j 2):1.37s(configure3.59s)ctest --preset dev -R 'startup_gfx2hlsl_mul_mad_i24_(controls|warp)' --parallel 2 --no-tests=error --output-on-failure): 2/2 passed (2.49s:startup_gfx2hlsl_mul_mad_i24_controls0.27s,startup_gfx2hlsl_mul_mad_i24_warp2.25s)/O2(--preset release):cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim -- -j 2):2.51s(configure3.91s)ctest --preset release -R 'startup_gfx2hlsl_mul_mad_i24_(controls|warp)' --parallel 2 --no-tests=error --output-on-failure): 2/2 passed (2.04s:startup_gfx2hlsl_mul_mad_i24_controls0.17s,startup_gfx2hlsl_mul_mad_i24_warp1.86s)tests/mesh_heap_sampler_check.pyok (0.9s),tests/startup_buffer_address_check.pyok (0.5s),tests/startup_compute_request_offline_check.pyok (0.6s),tests/startup_compute_translate_check.pyok (0.3s),tests/startup_flat_param_check.pyok (0.1s),tests/startup_gfx2hlsl_add_sub_co_check.pyok (0.2s),tests/startup_gfx2hlsl_add_sub_co_ci_check.pyok (0.2s),tests/startup_gfx2hlsl_bit_alu_check.pyok (1.0s),tests/startup_gfx2hlsl_capture_check.pyok (1.2s),tests/startup_gfx2hlsl_cmp16_check.pyok (0.3s),tests/startup_gfx2hlsl_compare_dst_check.pyok (0.1s),tests/startup_gfx2hlsl_compute_check.pyok (0.5s),tests/startup_gfx2hlsl_cselect_mask_check.pyok (0.1s),tests/startup_gfx2hlsl_cvt_alu_check.pyok (0.2s),tests/startup_gfx2hlsl_f32_lg_check.pyok (1.7s),tests/startup_gfx2hlsl_f32_nan_check.pyok (7.7s),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.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.4s),tests/startup_gfx2hlsl_readfirstlane_recompute_check.pyok (0.1s),tests/startup_gfx2hlsl_readfirstlane_uniform_check.pyok (0.2s),tests/startup_gfx2hlsl_refusals_check.pyok (0.6s),tests/startup_gfx2hlsl_root_check.pyok (0.9s),tests/startup_gfx2hlsl_saveexec_same_reg_check.pyok (0.1s),tests/startup_gfx2hlsl_scalar_arity_check.pyok (0.3s),tests/startup_gfx2hlsl_scalar_brev_fold_check.pyok (0.1s),tests/startup_gfx2hlsl_scalar_m0_check.pyok (0.1s),tests/startup_gfx2hlsl_sdwa_cvt_check.pyok (0.4s),tests/startup_gfx2hlsl_sgpr_spill_check.pyok (0.1s),tests/startup_gfx2hlsl_shift64_check.pyok (0.2s),tests/startup_gfx2hlsl_smem_offset_check.pyok (0.1s),tests/startup_gfx2hlsl_sop2_complement_check.pyok (9.2s),tests/startup_gfx2hlsl_sopk_accum_check.pyok (1.3s),tests/startup_gfx2hlsl_sopk_signext_check.pyok (0.2s),tests/startup_gfx2hlsl_swap_check.pyok (0.4s),tests/startup_gfx2hlsl_vopc_sdwa_check.pyok (7.1s),tests/startup_gfx2hlsl_waitcnt_depctr_check.pyok (0.1s),tests/startup_gfx2hlsl_watch_check.pyok (2.9s),tests/startup_image_2d_array_check.pyok (0.2s),tests/startup_image_3d_check.pyok (0.2s),tests/startup_image_gather_lz_check.pyok (0.9s),tests/startup_image_load_d16_check.pyok (1.4s),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.3s),tests/startup_image_sample_l_check.pyok (0.4s),tests/startup_image_sample_lod_check.pyok (1.1s),tests/startup_inline_sampler_check.pyok (0.3s),tests/startup_mesh57_skeleton_check.pyok (0.3s),tests/startup_run_ps1_check.pyok (19.8s),tests/startup_run_sh_check.pyFAIL (0.2s),tests/startup_sampler_heap_check.pyok (0.2s),tests/startup_smem_address_check.pyok (0.2s),tests/startup_stream_fetch_check.pyok (0.3s),tests/startup_stream_interface_check.pyok (0.5s),tests/startup_translator_check.pyok (0.8s)sccache: 60/485 hits; wall90.8sAI-assisted; commands listed were executed locally.