Skip to content

shader: lower s_pack_ll_b32_b16, s_pack_lh_b32_b16 and s_absdiff_i32 in gfx2hlsl (continues #2086, Part of #1723) - #2512

Merged
tedin7 merged 5 commits into
R0Y00:mainfrom
Leyukaka:s-pack-absdiff
Nov 25, 2026
Merged

tedin7 merged 5 commits into
R0Y00:mainfrom
Leyukaka:s-pack-absdiff

Conversation

@Leyukaka

Copy link
Copy Markdown
Contributor

Continues #2086 by @tedin7 (paused to keep the Windows test queue short; takeover note). Part of #1723.

The first two commits are tedin7's, rebased on main 851a140 with his authorship:

  • s_pack_ll_b32_b16 and s_pack_lh_b32_b16 join the existing s_pack_hh_b32_b16 lowering. SCC is unchanged.
  • s_absdiff_i32: D = |wrap32(S0 - S1)| (INT_MIN stays INT_MIN), SCC = D != 0.
  • A lane-mask operand or a descriptor source is refused for all four. For the pack forms, the descriptor message is "on descriptor data". For s_absdiff_i32 it is "scc from descriptor data", since its SCC would be left stale.

Rebase. The cherry-pick of the two commits onto adf4e3b conflicted with main's scc_effect lines in Stage.scalar. I resolved it as #2086's own merge commit does. The normalized diff is identical to #2086's. Rebasing onto 851a140 was clean: #2459's lane_complement is only true for the complement forms, so pack and absdiff are still refused on lane masks.

Two commits of mine on top

  • The integer evaluator in startup_gfx2hlsl_bit_alu_check.py now asserts that abs gets a signed value. HLSL abs of a uint is the identity, so an s_absdiff_i32 lowering without asint used to pass.
  • The new check is listed in the Linux CI Python list and in AGENTS.md, next to startup_gfx2hlsl_sop2_complement_check.py, whose helpers it imports.

Why now. In a local first-refusal census of captured start-up requests at main dbab543, s_pack_ll_b32_b16 is the first refusal for 59 requests. The inputs are private; these are counts only.

Tests. Run on Windows 11 with Python 3.14 at this branch's head, all passing:

  • tests/startup_gfx2hlsl_pack_absdiff_check.py;
  • startup_gfx2hlsl_bit_alu_check.py;
  • startup_gfx2hlsl_sop2_complement_check.py;
  • startup_gfx2hlsl_scalar_arity_check.py;
  • startup_gfx2hlsl_operand_count_check.py.

Mutation checks, run by hand. startup_gfx2hlsl_pack_absdiff_check.py fails on each:

  • s_pack_ll shifting S1 by 8;
  • s_pack_lh with its sources swapped;
  • s_absdiff_i32 without its SCC;
  • a compare-first s_absdiff_i32;
  • the descriptor-source refusal removed for s_absdiff_i32;
  • s_absdiff_i32 without asint (caught by the new evaluator assertion).

No GPU run: the check evaluates the emitted lines with the integer evaluator.

AI-assisted.

tedin7 and others added 4 commits November 25, 2026 20:10
…in gfx2hlsl

Part of R0Y00#1723. s_absdiff_i32 subtracts the smaller signed source from the larger, so an overflowing difference wraps like the hardware. SCC is unchanged by the pack forms and is result != 0 for s_absdiff_i32.
…uator

HLSL abs of a uint is the identity, so an s_absdiff_i32 lowering that
dropped asint would still have passed the evaluator. Assert that abs gets a
signed value.

AI-assisted.
…ython checks

Add it to the Linux CI Python list and the AGENTS.md list next to
startup_gfx2hlsl_sop2_complement_check, whose helpers it imports.

AI-assisted.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head e2b7dca against origin/main (8 behind, mergeable).

Code: looks correct.

  • s_pack_ll_b32_b16, s_pack_lh_b32_b16: expressions match the ISA meaning, SCC untouched.
  • s_absdiff_i32: asuint(abs(asint(a - b))) keeps the wrapped INT_MIN case, SCC = D != 0.
  • Lane-mask and descriptor sources are refused for all four forms (no stale SCC).
  • No other open or merged PR covers this slice (only the paused #2086, which this continues).

Missing before merge: a real D3D12 WARP readback test.
tests/startup_gfx2hlsl_pack_absdiff_check.py runs the emitted lines on a Python integer evaluator. That is a good model check, but it does not compile the HLSL or run it on a GPU. For a shader/math lowering we need a WARP GPU readback compared with a CPU reference. Please extend an existing WARP suite with these three ops over the edge values (include 0x80000000 - 1 and a == b for absdiff, and the << 16 / & 0xffff0000 edges for the packs).

Commands run (Linux, in a clean worktree of this head)

  • python3 tests/startup_gfx2hlsl_pack_absdiff_check.py -> ok
  • python3 tests/docs_links_check.py -> ok; python3 tests/bidi_controls_check.py -> ok; git diff --check origin/main...HEAD -> clean
  • Mutations, each makes the new test fail: dropping asint in absdiff (evaluator assert), dropping the absdiff SCC (s_absdiff_i32 value and SCC), changing << 16 to << 15 in pack_ll (s_pack_ll_b32_b16 value and SCC).
  • No Windows run was done by this review.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Win2025 WARP receipt for head 79927a5 after updating with main.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 79927a57f5a3261c332cca062974a0755c874844:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim -- -j 2): 0.74s (configure 2.86s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim -- -j 2): 1.83s (configure 2.91s)
  • Windows Python checks: tests/mesh_heap_sampler_check.py ok (0.9s), tests/startup_buffer_address_check.py ok (0.6s), tests/startup_compute_request_offline_check.py ok (0.6s), tests/startup_compute_translate_check.py ok (0.3s), tests/startup_flat_param_check.py ok (0.1s), tests/startup_gfx2hlsl_add_sub_co_check.py ok (0.2s), tests/startup_gfx2hlsl_add_sub_co_ci_check.py ok (0.2s), tests/startup_gfx2hlsl_bit_alu_check.py ok (1.1s), tests/startup_gfx2hlsl_capture_check.py ok (1.4s), tests/startup_gfx2hlsl_cmp16_check.py ok (0.3s), tests/startup_gfx2hlsl_compare_dst_check.py ok (0.1s), tests/startup_gfx2hlsl_compute_check.py ok (0.5s), tests/startup_gfx2hlsl_cselect_mask_check.py ok (0.1s), tests/startup_gfx2hlsl_cvt_alu_check.py ok (0.2s), tests/startup_gfx2hlsl_f32_lg_check.py ok (1.9s), tests/startup_gfx2hlsl_f32_nan_check.py ok (8.0s), tests/startup_gfx2hlsl_getpc_refusal_check.py ok (0.1s), tests/startup_gfx2hlsl_handler_arity_check.py ok (0.2s), tests/startup_gfx2hlsl_image_arity_check.py ok (0.1s), tests/startup_gfx2hlsl_image_get_lod_check.py ok (0.1s), tests/startup_gfx2hlsl_int_med3_check.py ok (0.1s), tests/startup_gfx2hlsl_join_symbols_check.py ok (0.3s), tests/startup_gfx2hlsl_loop_constants_check.py ok (0.1s), tests/startup_gfx2hlsl_mad_check.py ok (0.2s), tests/startup_gfx2hlsl_mask_overwrite_check.py ok (0.1s), tests/startup_gfx2hlsl_operand_count_check.py ok (0.4s), tests/startup_gfx2hlsl_pack_absdiff_check.py ok (4.3s), tests/startup_gfx2hlsl_readfirstlane_recompute_check.py ok (0.2s), tests/startup_gfx2hlsl_readfirstlane_uniform_check.py ok (0.2s), tests/startup_gfx2hlsl_refusals_check.py ok (0.7s), tests/startup_gfx2hlsl_root_check.py ok (1.1s), tests/startup_gfx2hlsl_saveexec_same_reg_check.py ok (0.2s), tests/startup_gfx2hlsl_scalar_arity_check.py ok (0.3s), tests/startup_gfx2hlsl_scalar_brev_fold_check.py ok (0.2s), tests/startup_gfx2hlsl_scalar_m0_check.py ok (0.1s), tests/startup_gfx2hlsl_sdwa_cvt_check.py ok (0.4s), tests/startup_gfx2hlsl_sgpr_spill_check.py ok (0.2s), tests/startup_gfx2hlsl_shift64_check.py ok (0.2s), tests/startup_gfx2hlsl_smem_offset_check.py ok (0.1s), tests/startup_gfx2hlsl_sop2_complement_check.py ok (11.2s), tests/startup_gfx2hlsl_sopk_accum_check.py ok (1.5s), tests/startup_gfx2hlsl_sopk_signext_check.py ok (0.2s), tests/startup_gfx2hlsl_swap_check.py ok (0.4s), tests/startup_gfx2hlsl_vopc_sdwa_check.py ok (8.2s), tests/startup_gfx2hlsl_waitcnt_depctr_check.py ok (0.1s), tests/startup_gfx2hlsl_watch_check.py ok (3.2s), tests/startup_image_2d_array_check.py ok (0.3s), tests/startup_image_3d_check.py ok (0.1s), tests/startup_image_gather_lz_check.py ok (1.0s), tests/startup_image_load_d16_check.py ok (1.6s), tests/startup_image_sample_a16_check.py ok (0.3s), tests/startup_image_sample_b_check.py ok (0.2s), tests/startup_image_sample_c_check.py ok (0.3s), tests/startup_image_sample_l_check.py ok (0.3s), tests/startup_image_sample_lod_check.py ok (1.0s), tests/startup_inline_sampler_check.py ok (0.3s), tests/startup_mesh57_skeleton_check.py ok (0.3s), tests/startup_run_ps1_check.py ok (18.0s), tests/startup_run_sh_check.py FAIL (0.2s), tests/startup_sampler_heap_check.py ok (0.2s), tests/startup_smem_address_check.py ok (0.1s), tests/startup_stream_fetch_check.py ok (0.3s), tests/startup_stream_interface_check.py ok (0.3s), tests/startup_translator_check.py ok (0.6s)
  • sccache: 6/271 hits; wall 94.2s

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Win2025 WARP receipt for head 79927a5 after updating with main (focused run on the PR test and sibling gfx2hlsl checks).

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 79927a57f5a3261c332cca062974a0755c874844:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim -- -j 2): 1.07s (configure 3.14s)
    • Test (ctest --preset dev -R 'startup_gfx2hlsl_(pack_absdiff|bit_alu|sop2_complement)' --parallel 2 --no-tests=error --output-on-failure): 5/5 passed (14.49s: startup_gfx2hlsl_bit_alu_warp 7.07s, startup_gfx2hlsl_sop2_complement 9.23s, startup_gfx2hlsl_bit_alu_controls 0.89s, startup_gfx2hlsl_pack_absdiff 3.58s, startup_gfx2hlsl_bit_alu_hardware 7.26s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim -- -j 2): 14.50s (configure 2.59s)
    • Test (ctest --preset release -R 'startup_gfx2hlsl_(pack_absdiff|bit_alu|sop2_complement)' --parallel 2 --no-tests=error --output-on-failure): 5/5 passed (15.25s: startup_gfx2hlsl_bit_alu_hardware 6.79s, startup_gfx2hlsl_bit_alu_warp 6.80s, startup_gfx2hlsl_bit_alu_controls 1.12s, startup_gfx2hlsl_pack_absdiff 3.81s, startup_gfx2hlsl_sop2_complement 8.32s)
  • Windows Python checks: tests/mesh_heap_sampler_check.py ok (1.0s), tests/startup_buffer_address_check.py ok (0.6s), tests/startup_compute_request_offline_check.py ok (0.6s), tests/startup_compute_translate_check.py ok (0.3s), tests/startup_flat_param_check.py ok (0.1s), tests/startup_gfx2hlsl_add_sub_co_check.py ok (0.1s), tests/startup_gfx2hlsl_add_sub_co_ci_check.py ok (0.2s), tests/startup_gfx2hlsl_bit_alu_check.py ok (0.9s), tests/startup_gfx2hlsl_capture_check.py ok (1.3s), tests/startup_gfx2hlsl_cmp16_check.py ok (0.3s), tests/startup_gfx2hlsl_compare_dst_check.py ok (0.1s), tests/startup_gfx2hlsl_compute_check.py ok (0.5s), tests/startup_gfx2hlsl_cselect_mask_check.py ok (0.1s), tests/startup_gfx2hlsl_cvt_alu_check.py ok (0.1s), tests/startup_gfx2hlsl_f32_lg_check.py ok (1.6s), tests/startup_gfx2hlsl_f32_nan_check.py ok (11.6s), tests/startup_gfx2hlsl_getpc_refusal_check.py ok (1.0s), tests/startup_gfx2hlsl_handler_arity_check.py ok (0.8s), tests/startup_gfx2hlsl_image_arity_check.py ok (0.6s), tests/startup_gfx2hlsl_image_get_lod_check.py ok (0.5s), tests/startup_gfx2hlsl_int_med3_check.py ok (0.6s), tests/startup_gfx2hlsl_join_symbols_check.py ok (0.6s), tests/startup_gfx2hlsl_loop_constants_check.py ok (0.9s), tests/startup_gfx2hlsl_mad_check.py ok (0.5s), tests/startup_gfx2hlsl_mask_overwrite_check.py ok (1.3s), tests/startup_gfx2hlsl_operand_count_check.py ok (2.0s), tests/startup_gfx2hlsl_pack_absdiff_check.py ok (6.8s), tests/startup_gfx2hlsl_readfirstlane_recompute_check.py ok (2.6s), tests/startup_gfx2hlsl_readfirstlane_uniform_check.py ok (4.6s), tests/startup_gfx2hlsl_refusals_check.py ok (2.4s), tests/startup_gfx2hlsl_root_check.py ok (1.3s), tests/startup_gfx2hlsl_saveexec_same_reg_check.py ok (0.2s), tests/startup_gfx2hlsl_scalar_arity_check.py ok (0.3s), tests/startup_gfx2hlsl_scalar_brev_fold_check.py ok (0.2s), tests/startup_gfx2hlsl_scalar_m0_check.py ok (0.2s), tests/startup_gfx2hlsl_sdwa_cvt_check.py ok (0.5s), tests/startup_gfx2hlsl_sgpr_spill_check.py ok (0.2s), tests/startup_gfx2hlsl_shift64_check.py ok (0.2s), tests/startup_gfx2hlsl_smem_offset_check.py ok (0.1s), tests/startup_gfx2hlsl_sop2_complement_check.py ok (9.1s), tests/startup_gfx2hlsl_sopk_accum_check.py ok (1.1s), tests/startup_gfx2hlsl_sopk_signext_check.py ok (0.2s), tests/startup_gfx2hlsl_swap_check.py ok (0.4s), tests/startup_gfx2hlsl_vopc_sdwa_check.py ok (5.8s), tests/startup_gfx2hlsl_waitcnt_depctr_check.py ok (0.1s), tests/startup_gfx2hlsl_watch_check.py ok (2.5s), tests/startup_image_2d_array_check.py ok (0.2s), tests/startup_image_3d_check.py ok (0.1s), tests/startup_image_gather_lz_check.py ok (0.6s), tests/startup_image_load_d16_check.py ok (1.0s), tests/startup_image_sample_a16_check.py ok (0.2s), tests/startup_image_sample_b_check.py ok (0.2s), tests/startup_image_sample_c_check.py ok (0.3s), tests/startup_image_sample_l_check.py ok (0.2s), tests/startup_image_sample_lod_check.py ok (0.7s), tests/startup_inline_sampler_check.py ok (0.2s), tests/startup_mesh57_skeleton_check.py ok (0.2s), tests/startup_run_ps1_check.py ok (13.0s), tests/startup_run_sh_check.py FAIL (0.1s), tests/startup_sampler_heap_check.py ok (0.1s), tests/startup_smem_address_check.py ok (0.1s), tests/startup_stream_fetch_check.py ok (0.3s), tests/startup_stream_interface_check.py ok (0.3s), tests/startup_translator_check.py ok (0.6s)
  • sccache: -44/-1153 hits; wall 130.5s

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 merged commit 82bb67e into R0Y00:main Nov 25, 2026
5 checks passed
@Leyukaka

Copy link
Copy Markdown
Contributor Author

@tedin7, thanks for merging. The WARP and hardware readback you asked for is in follow-up #2523 (35/35 cases on WARP and on an RTX 5080; each of five mutations of the lowering fails both).

AI-assisted.

tedin7 added a commit that referenced this pull request Nov 25, 2026
…hardware (#2523)

Review request on #2512: compile the HLSL that gfx2hlsl emits for each op
into one cs_6_0 shader with DXC and run it through offscreen_check
--raw-uav-dump. The sources are loaded from the UAV fill pattern and XORed,
so DXC cannot fold them; D and, for s_absdiff_i32, SCC are stored and
compared with the integer references. Cases: absdiff (0x80000000, 1) and
its reverse, (0x7fffffff, 0x80000000) and its reverse, equal sources, 0 and
0xffffffff; packs with the <<16 and 0xffff0000 edges, both orders. The
operand region must come back unchanged. Registered as
startup_gfx2hlsl_pack_absdiff_dispatch_warp and _hardware (skip 77).

AI-assisted.

Co-authored-by: tedin7 <110300616+tedin7@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants