Skip to content

shader: per-lane v_cmp_* and v_cndmask_b32 in compute_store_aot - #2175

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
henriazz10:shader/compute-vcmp-select
Nov 25, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
henriazz10:shader/compute-vcmp-select

Conversation

@henriazz10

Copy link
Copy Markdown
Contributor

Change

Refs #721. This is the general per-lane v_cmp_* + v_cndmask_b32 slice for compute_store_aot (gfx1013), claimed in #721 (comment). It touches only tools/compute_store_aot.py, tests/compute_store_check.py, CMakeLists.txt, and docs/experiments.md (plus updated expected rejection diagnostics in tests/compute_alu_cmp_ne_check.py and tests/compute_lane_mask_check.py where previously unsupported v_cmp_*/v_cndmask_b32 forms are now parsed and refused downstream).

Accepted forms (66 total: 64 compare forms + 2 select forms)

  • Unsigned 32-bit integer compares (16 forms): v_cmp_{f,lt,eq,le,gt,ne,ge,t}_u32_e32 (into vcc_lo) and v_cmp_{f,lt,eq,le,gt,ne,ge,t}_u32_e64 (into vcc_lo or s0..s105), comparing uint words.
  • Signed 32-bit integer compares (16 forms): v_cmp_{f,lt,eq,le,gt,ne,ge,t}_i32_e32 (into vcc_lo) and v_cmp_{f,lt,eq,le,gt,ne,ge,t}_i32_e64 (into vcc_lo or s0..s105), comparing asint(...).
  • Binary32 float compares (32 forms): v_cmp_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg,ngt,nle,neq,nlt,tru}_f32_e32 (into vcc_lo) and v_cmp_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg,ngt,nle,neq,nlt,tru}_f32_e64 (into vcc_lo or s0..s105), comparing asfloat(...) with explicit isnan(...) checks for all ordered and unordered IEEE NaN predicates.
  • Per-lane select (2 forms): v_cndmask_b32_e32 vD, S0, vS1, vcc_lo and v_cndmask_b32_e64 vD, S0, S1, (vcc_lo|sN), lowering to (cond ? S1 : S0) when the mask holds a ("cond", ...) (wave-size independent because only the same lane reads its bit).

Existing lane guards (s_and_saveexec_b32 on uniform v_cmp_*), constant-mask v_cndmask_b32_e64, and vcc_carry/vcc_borrow keep their current behavior. Any write to vcc_lo invalidates the other VCC-derived states.

Refused (one control each)

  • f32 source modifiers (-v1, |v1|);
  • clamp, SDWA (_sdwa), and DPP (_dpp) spellings;
  • a cond SGPR read by a scalar ALU instruction (s_add_u32) or used as a branch condition (s_cbranch_scc0);
  • s_and_saveexec_b32 on a cond built from loaded (v1) or ALU (v4) data;
  • a _ci carry-in from a cond (vcc_lo or s4);
  • a stale cond after another vcc_lo write (v_add_co_u32).

Verification

Commit e3e132b1, on shader/compute-vcmp-select from e3e39c43. Windows 11 build 26300, VS 2019 Build Tools 16.11 (MSVC 14.29), DXC (Windows SDK 10.0.26100.0), Python 3.12, debug layer enabled.

python -B -c "import sys; sys.path.insert(0, 'tests'); import compute_store_check; compute_store_check.controls()"
python -B tests/compute_store_check.py draw-vcmp-select <dxc> <offscreen_check> warp
python -B tests/compute_store_check.py draw-vcmp-select <dxc> <offscreen_check> hardware
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py
git diff --check HEAD~1
Backend Adapter / driver Result
WARP Microsoft Basic Render Driver 10.0.26100.9818 exit 0, 12 dispatches × compared_words=320 mismatches=0, debug_errors=0 debug_warnings=0
hardware NVIDIA GeForce RTX 5080, 32.0.16.1692 exit 0, 12 dispatches × compared_words=320 mismatches=0, debug_errors=0 debug_warnings=0

The LLVM 15 round trip in Docker (x2w-llvm15) exited 0 (binary_exit=0):

docker run --rm -v "C:\Proyectos\Xbox2Windows\wt-vcmp:/src" x2w-llvm15 bash -c 'cp -r /src /w && cd /w && python3 -B tests/compute_store_check.py binary llvm-mc-15 llvm-objcopy-15 /usr/lib/x86_64-linux-gnu/libLLVM-15.so.1; echo binary_exit=$?'

vcmp_select_binary() disassembles all 12 assembled programs and checks identical v_cmp_* / v_cndmask_b32_* lines and identical aot.lower() output.

Negative control. With tools/compute_store_aot.py from origin/main, vcmp_select_controls() fails with ValueError: Unverified lane guard compare.

Evidence

  • Independent Python model & fixture: 12 64-thread gfx1013 dispatches (buffer_store_dwordx4, 256 output words + 64 SENTINEL words each = 3,840 words total) covering all 32 predicates (8 u32 + 8 i32 + 16 f32) across equal values, 0x7fffffff vs 0x80000000, 0 vs 0xffffffff, denormal raw words (0x00000001 vs 0x80000001), ±0, NaN on either or both sides, ±inf, and memory-loaded/tid inputs.
  • Reference controls (each failing at its stated word):
    • lt and gt swapped: word 1;
    • signed used for unsigned: word 1;
    • ordered (lt) used for unordered (nge): word 5;
    • select operands swapped: word 0;
    • sentinel past group: word 256.
  • Recompiled-HLSL mutations (each failing on the device):
    • < for <= on u32;
    • asint dropped on i32;
    • isnan replaced by isinf on unordered f32.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs (docs/experiments.md).
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the change and ran the checks; Claude Code reviewed it.

🤖 Generated with Claude Code

Refs R0Y00#721

Written with Gemini 4 Hydrogen (Antigravity CLI), reviewed by Claude.

@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 e3e132b14446805dde968785324446bc0e641625: 0 P1, 0 P2.

Logic check against RDNA2 VOPC/VOP2 semantics:

  • Integer predicates (f/lt/eq/le/gt/ne/ge/t, u32 and i32 via asint) are correct.
  • f32 predicates follow the IEEE rule. The ordered forms are false on NaN. The n* forms are true on NaN, and nge, nlg, ngt, nle, nlt and neq are the exact complements of their ordered partners. lg is ordered !=.
  • v_cndmask_b32 takes a per-lane cond from VCC or an SGPR pair. The constant-mask path keeps the existing single-wave limit.
  • vcc_cond is cleared by the carry/borrow writers and merged at the guard end, so a stale condition is not reused.
  • No sibling PR covers the same slice. #2020 is the unrelated f16 class op.

Commands run locally (Linux):

  • python3 -B tests/compute_store_check.py controls and the lane_mask and cmp_ne controls: the self-controls ran with no failure.
  • python3 tests/docs_links_check.py: PASS (401 links).
  • python3 tests/bidi_controls_check.py: PASS.
  • git diff --check origin/main...HEAD: clean.
  • Mutation: in FLOAT_COMPARE_PREDICATES, nge was changed to the ordered form. The controls failed with an AssertionError. I reverted it afterwards.

Windows Server 2025 (WARP and hardware):

  • python3 x2w_pipe.py win2025 2175 --scope direct --targets offscreen_check --regex 'compute_store_aot_vcmp_select|compute_lane_mask|compute_alu_cmp_ne|compute_store_aot_(bfe|draw)'
  • Debug: 5/5 passed.
  • Release /O2: 5/5 passed.
  • This includes compute_store_aot_vcmp_select_warp and compute_store_aot_vcmp_select_hardware, which compare GPU readback against the independent Python model.

GitHub CI Build and test on Windows: SUCCESS.

AI-assisted; commands listed were executed locally.

@legacy-code-archaeologist

Copy link
Copy Markdown
Contributor

Ran head e3e132b1 on three adapters. All pass. Windows 11 build 26100, debug layer unavailable.

Test Adapter Driver Result
compute_store_aot_vcmp_select_warp Microsoft Basic Render Driver 10.0.26100.8972 pass, 12/12 dispatches with compared_words=320 mismatches=0
compute_store_aot_vcmp_select_hardware (XBOX2WINDOWS_ADAPTER=Quadro) NVIDIA Quadro M1000M (Maxwell) 32.0.15.7371 pass, same
compute_store_aot_vcmp_select_hardware (XBOX2WINDOWS_ADAPTER=Intel) Intel HD Graphics 530 (Gen9) 31.0.101.2111 pass, same

AI-assisted.

@stan495 stan495 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verified head e3e132b1 on Windows x64 (dev preset, MSVC 19.44.35228.0, SDK/DXC 10.0.26100.0):

  • cmake --build --preset dev --target offscreen_check -> succeeded
  • ctest --preset dev --no-tests=error -R '^compute_store_aot_vcmp_select_' -V -> 2/2 passed (compute_store_aot_vcmp_select_hardware, compute_store_aot_vcmp_select_warp)
    • Hardware: AMD Radeon RX 7900 XTX (vendor=1002 device=744c, driver 32.0.32029.2010)
    • WARP: Microsoft Basic Render Driver (vendor=1414 device=008c, driver 10.0.26100.9818)

Verdict: Approved at e3e132b1.

@R0Y00
R0Y00 merged commit 9f749a9 into R0Y00:main Nov 25, 2026
5 checks passed
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.

5 participants