Skip to content

rdna2spirv: fix operand layout and carry mask for _co_ci_u32 SDWA/DPP - #3553

Open
Wasler wants to merge 2 commits into
ItsNotRexed:mainfrom
Wasler:fix/co-ci-sdwa-dpp
Open

Wasler wants to merge 2 commits into
ItsNotRexed:mainfrom
Wasler:fix/co-ci-sdwa-dpp

Conversation

@Wasler

@Wasler Wasler commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: SHADER-637 (claim in #3047, carried forward to #3381)

What and why

v_add_co_ci_u32, v_sub_co_ci_u32, and v_subrev_co_ci_u32 use the VOP2 5-operand carry layout [vdst, cd, src0, src1, cin] in _sdwa and _dpp encodings, placing the carry-out scalar mask destination (cd) at args[1] before src0 (args[2]), src1 (args[3]), and cin (args[4]).

Two translator bugs broke these six forms:

  • Operand indexing (Gen.insn / Gen.dpp_insn): Both hardcoded first = 1 (args[1]) as src0. Under _sdwa, src0_sel was applied to cd, src1_sel to src0, and src1 (including sext(src1)) received no selection. Under _dpp, reading args[1] (vcc_lo/vcc/SGPR mask) failed with Unsupported: mask destination and never shuffled src0 (for v_subrev_co_ci_u32_dpp as well, RDNA2 shuffles src0 at args[2] rather than src1).
  • DPP disabled-lane scalar carry mask (_co_ci_u32): When a lane is disabled by row_mask, bank_mask, or an out-of-row/fi:0 bound_ctrl:0 invalid source (self.dpp_guard), hardware keeps vdst[lane] and clears the scalar carry-out bit cd[lane] = 0 rather than writing carry-out from the fallback value or leaking prior cd bits.

Changes:

Tested

  • GPU (NVIDIA GeForce RTX 5060 Ti, driver 621.01, Windows 11 x64, LLVM 23.1.6, SPIRV-Tools 2026.4):
    • python -I scripts/run_gpu_tests.py --build runtime/build --llvm-mc llvm-mc.exe: 205/205 GPU test shaders translate and pass spirv-val (154/200 passed, 46 skipped, 0 failed — skipped are native-wave64/mesh/D3D12-harness fixtures unavailable on 32-wide Vulkan compute). Includes PASS cs_co_ci_sdwa_dpp 268374580 4294868992 8192 30583 65546 131066 6 43981 (no game shader corpus locally; before this fix, v_{add,sub,subrev}_co_ci_u32_dpp raised Unsupported: mask destination and _sdwa misapplied selects).
    • With LEONIDA_W64_EMULATE=1: PASS cs_dpp_w64 1 0 3 2 5 4 7 6 (1/1 passed); synthetic wave64 --wave64-emulate modules containing v_{add,sub,subrev}_co_ci_u32_{dpp,sdwa} assemble with spirv-as and pass spirv-val.
  • Differential & cross-lane fuzzers:
    • python -I tools/sdwa_diff.py --self-test -> passed
    • python -I tools/sdwa_diff.py --programs 1000 --seed 1 -> 940 pass, 0 mismatch, 60 skipped
    • python -I tools/sdwa_diff.py --ops v_add_co_ci_u32,v_sub_co_ci_u32,v_subrev_co_ci_u32 --programs 1000 --seed 7 -> 1000 pass, 0 mismatch, 0 skipped
    • python -I tools/crosslane_fuzz.py --no-maskdata --programs 50 --seed 1 --dpp -> wave32 native 20 match, 0 mismatch, 5 hyp_only; wave64 emulate 22 match, 0 mismatch, 3 hyp_only
  • CPU / CI suites:
    • python -m pytest tests/test_docs_design_rows.py tests/test_docs_links.py tests/test_docs_list_items.py tests/test_docs_repo_paths.py tests/test_text_write_line_endings.py tests/test_sdwa_diff.py tests/test_shader_checks.py tests/test_shader_diff.py tests/test_lane_masks.py tests/test_wave64_halves_fixtures.py -q -> 141 passed, 252 subtests passed
    • python -m pytest tests/test_translate.py -q -> 564 passed, 4 skipped
    • python -I tests/semantic/test_co_ci_sdwa_dpp.py -v -> 10/10 OK; python -I tests/semantic/test_carry_exec_mask.py -v -> 9/9 OK
    • All 333 files in tests/semantic/test_*.py (python -m unittest <stem>) -> 7332 tests, 0 failures
    • python -I tests/semantic/regen_fixtures.py --check, python -m compileall -q make_game.py tools tests, node --test tests/test_*.cjs (42/42) -> passed
  • Note: The dpp_guard scalar carry-out zeroing rule (cd[lane] = 0 on DPP-disabled lanes) follows the AMD RDNA2/RDNA3.5 ISA and was verified on NVIDIA Vulkan and CPU, not yet measured on physical RDNA2 hardware.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested 6ae5aff against the hardware. Measured on gfx1036 (RDNA2, driver 26.10.1, game MODE; integer ops) through raw hw_oracle kernels, one lane: v_add_co_ci_u32_sdwa, v_sub_co_ci_u32_sdwa and v_subrev_co_ci_u32_sdwa v8, vcc_lo, S0, S1, vcc_lo dst_sel:DWORD dst_unused:UNUSED_PAD with random src0_sel / src1_sel over BYTE_0..3, WORD_0, WORD_1, DWORD, sext() on either source in half the cases, random carry-in and edge-value operands: 300 cases. The hardware equals the formula (selected field, zero or sign extended, a + b + cin / a - b - cin / b - a - cin; carry-out in VCC bit 0): 300 of 300. I then ran the same 300 programs through this branch's translation (semantic interpreter): 300 of 300 identical to the hardware (word and carry bit), so the src0 / src1 selection and the carry layout of the SDWA forms are right.

DPP, measured only: v_add_co_ci_u32_dpp v8, vcc_lo, v1, v2, vcc_lo row_shr:1 [bound_ctrl:0] over 32 lanes with VCC seeded all ones and no carries in range: lanes 0 and 16 have no source (row_shr:1 reads outside the row). With bound_ctrl:0 they compute with a zero source (0x41 = 0 + 0x40 + carry-in); without it they keep the old vdst (0xdeadbeef) and VCC afterwards is 0x00000000 in both runs, i.e. the carry-out bit of a disabled lane is cleared, not left at the seeded 1, as the PR says. I did not run this PR's DPP translation, and the quad_perm / row_mask / bank_mask variants I tried did not assemble in that operand order, so those masks are not measured. The scripts are local, not pushed. AI-assisted.

@kacper-serewis kacper-serewis 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.

At 6ae5aff, 19 focused tests passed. Independent CPU interpretation checked destination and carry/borrow on 384 lanes across 12 listings. SDWA, quad_perm and row_shr with omitted bound_ctrl matched; six boundary-lane differences with explicit bound_ctrl:0 agree with the existing hardware review. This supports the operand-layout change and leaves the explicit-boundary semantics unresolved. AI-assisted synthetic CPU validation.

@evilclanker9000

Copy link
Copy Markdown
Contributor

Hardware data for the _dpp half, since the design row here says "not measured on physical RDNA2 hardware". Raw wave64 (and wave32 for the non-carry ops) kernels through tools/hw_oracle on a gfx1036 (Radeon iGPU, Ryzen 9 9950X3D):

  • Carry-out of unwritten lanes: confirmed. For v_add_co_ci_u32_dpp and v_sub_co_ci_u32_dpp the carry-out mask is rewritten whole; a lane that is off in EXEC, turned off by row_mask/bank_mask, or has an invalid source with bound_ctrl:0 gets 0 whatever the mask held, and bound_ctrl:1 computes with the selected operand = 0 (60 random programs and a 48-case table, all lanes).
  • v_subrev_co_ci_u32_dpp selects the other operand. With v_subrev_co_ci_u32_dpp v2, vcc, v3, v4, vcc row_shr:1 (v3 = 3·lane + 100, v4 = 5·lane + 1000, carry-in 0) lane 1 gives 0x381 = v4[lane 0] − v3[lane 1], not v4[lane 1] − v3[lane 0] = 0x389; with bound_ctrl:1 lane 0 gives 0xffffff9c = 0 − v3[0]. So the lane select and the bound zero land on the second source operand (args[3], the minuend), not on args[2]. v_add_co_ci_u32_dpp and v_sub_co_ci_u32_dpp select args[2] as this PR has it.

The same holds for the non-carry reversed integer ops (v_subrev_nc_u32, v_lshlrev_b32, v_lshrrev_b32, v_ashrrev_i32), which is #3672; the float v_subrev_f32/v_subrev_f16 select the first operand. Case 7 of cs_co_ci_sdwa_dpp (quad_perm, lane 2 reading src0 from lane 3) would come out different on an AMD GPU. I have not measured the _sdwa forms.

AI-assisted.

@evilclanker9000

Copy link
Copy Markdown
Contributor

The _sdwa half, measured now on the same gfx1036 (raw wave32 kernels, 32 lanes with different operands, result and carry-out of every lane): for v_add_co_ci_u32_sdwa, v_sub_co_ci_u32_sdwa and v_subrev_co_ci_u32_sdwa, src0_sel and sext() apply to the first source operand and src1_sel to the second, in assembler order, for all three ops (five select combinations each: BYTE_1/WORD_1, sext WORD_0/BYTE_3, BYTE_2/sext WORD_0, DWORD/BYTE_0, sext WORD_1/DWORD). So the SDWA operand layout in this PR is what the hardware does; only the _dpp select of v_subrev_co_ci_u32 is on the other operand, as in my comment above.

AI-assisted.

@crastinator

Copy link
Copy Markdown
Contributor

Tested 6ae5aff merged into main f847748c (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • New test passes natively: cs_co_ci_sdwa_dpp (268374580 4294868992 8192 30583 65546 131066 6 43981).
  • Whole run_gpu_tests.py: 186/200 native, 186/200 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 41/41.
  • tests/semantic/test_co_ci_sdwa_dpp.py, tests/test_sdwa_diff.py: 31 passed, 33 subtests passed.

No game files. AI-assisted (Claude Code).

@Wasler

Wasler commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@Vonsek Thank you for the RDNA2 (gfx1036) hardware verification!

Updated in 92e9c26:

  • Gen.dpp_insn ( ools/rdna2spirv.py) now applies the DPP lane select and �ound_ctrl:1 zero-substitution to �rgs[3] (the minuend / second source operand) for �_subrev_co_ci_u32_dpp, while keeping �rgs[2] (src0) for �_add_co_ci_u32_dpp / �_sub_co_ci_u32_dpp and keeping _sdwa selecting src0_sel on �rgs[2] and src1_sel on �rgs[3] in assembler order.
  • Updated
    untime/test/shaders/cs_co_ci_sdwa_dpp.asm case 7 (out[6]) so both sources vary per lane (�12 = 10 + lane, �19 = 20 + 4*lane, checking 32 - 12 - 1 = 19 =

@Wasler
Wasler force-pushed the fix/co-ci-sdwa-dpp branch from 92e9c26 to 2fadac6 Compare November 22, 2026 22:07
@JRamos1993

JRamos1993 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tested 2fadac6, alone and merged onto main aa2988c (Windows 11, Python 3.14, llvm-mc 21.1.8; GPU suite on an RTX 5090, driver 616.92).

  • GPU suite: scripts/run_gpu_tests.py gives 165/211 passed, 46 skipped, 0 failed. That's main's 164/210 plus the new cs_co_ci_sdwa_dpp, which passes.
  • tests/semantic/test_co_ci_sdwa_dpp.py: 10 OK.

tests/test_sdwa_diff.py fails 1 of 21, on this head and merged; it passes on main aa2988c. test_short_seeded_run_matches reports program 36: word 3 (VCC): reference 0x00000000, translated 0x00000001. The ops that set VCC there are:

s_mov_b32 vcc_lo, 0
v_cmp_nlt_f16_sdwa vcc_lo, -v6, v2 src0_sel:WORD_1 src1_sel:DWORD
v_cmp_class_f16_sdwa vcc_lo, 2.0, 1.0 src0_sel:DWORD src1_sel:WORD_1

with v2 = 0x80000000 and v6 = 0x78c9e147.

The translator change isn't the cause. With the merge base's tools/rdna2spirv.py and this PR's tools/sdwa_diff.py and test, the same program fails the same way. The new generator ops shift the seeded programs, so this run now reaches a case where main's translator and the reference already disagree.

The last compare reads an inline constant through src1_sel:WORD_1, so it depends on how the class-mask operand 1.0 is laid out for an f16 SDWA op: f16 0x3C00 in the low half gives a WORD_1 of 0, while f32 0x3F800000 gives 0x3F80. Settling which one hardware uses would decide whether the translator or sdwa_diff's reference needs the fix. Until then, the seeded run is red with this PR.

AI-assisted (Claude Code).

@PingasMech

Copy link
Copy Markdown

I reproduced the program 36 failure at 2fadac65 on main 98fa503f. #3894 (ce724210) fixes it with one translator change. For an f16 class comparison, the inline mask 1.0 is binary16 0x00003c00, so selecting its upper 16 bits gives zero. #3894 cites the native gfx1036 measurement for this rule.

I kept #3553’s generator, seed, reference model and tests identical. Changing only the mask read in Gen.cmp_class to use src_h for f16 took tests/test_sdwa_diff.py from 21/22 to 22/22. In a separate synthetic compute test on an Intel UHD 770 (Windows driver 32.0.101.7088), the failing comparison changed from true to false as expected. A second inline-mask case changed from false to true, and both register-mask controls kept their expected results.

With both PRs on that main commit, the 22 differential tests, 10 carry tests and five class-comparison tests passed. The original cs_co_ci_sdwa_dpp GPU fixture passed too. Git reported conflicts only in docs/design.md; I kept the current-side text in those hunks for this code test.

I’d keep #3553’s seed and expected result, and land #3894’s mask fix first. AI-assisted review using synthetic inputs.

@Wasler

Wasler commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased onto main 3faac557 in 78820bee (resolved only docs/design.md | DPP | and | SDWA | row conflicts, keeping main's new Gen.eager / MoltenVK notes alongside _co_ci_u32 docs).

@PingasMech @JRamos1993 Agreed on keeping the seed as-is and landing #3894 first so v_cmp_class_f16 reads its inline f16 mask via src_h.

Re-verified after rebase on Windows 11, CPython 3.14.4 (CPU only, no game files):

  • python -Wd -I tests/semantic/test_co_ci_sdwa_dpp.py -v: 10 OK.
  • pytest -q tests/semantic/test_co_ci_sdwa_dpp.py tests/test_docs_design_rows.py: 14 passed, 20 subtests passed.
  • python -Wd -I tests/test_sdwa_diff.py: 21 OK of 22 (FAILED (failures=1)), with only test_short_seeded_run_matches hitting the pre-existing v_cmp_class_f16_sdwa 1.0 inline-mask mismatch (program 36) fixed in rdna2spirv: read v_cmp(x)_class_f16 mask as f16 constant via src_h #3894.

AI-assisted.

@Wasler
Wasler force-pushed the fix/co-ci-sdwa-dpp branch from 2fadac6 to 78820be Compare November 23, 2026 09:34
@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 78820bee9301efb8baa3625a7d283ae35728d72d on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

At 78820bee, the translated wave32 fixture cs_co_ci_sdwa_dpp passed on a Linux GeForce RTX 5090 (driver 595.99.02). All eight words matched the current runner, including 19 for the reverse subtract in word 6 and 0xABCD for the masked destination in word 7.

For a control I enabled all banks on the final DPP add, changing only its bank mask from 0x1 to 0xf. Lane 4 then produced 16 (14 + 1 + carry-in 1), replacing the preserved 0xABCD. Only word 7 changed, and the runner caught it. Both modules passed SPIR-V validation. This check covers the GPU carry fixture on the rebased head. The separate f16 inline-mask dependency is tracked in #3894.

AI-assisted verification.

@douline

douline commented Nov 23, 2026

Copy link
Copy Markdown

Tested 78820be on Intel Arc A770 (DG2), Mesa ANV 25.2.8, Ubuntu 24.04 / Linux 7.0, llvm-mc 21.1.8: pass, compared with main 3faac55 on the same machine.

  • run_gpu_tests.py: 157/218 passed, 59 skipped native (main: 156/217 passed, 59 skipped), 188/218 passed, 28 skipped with LEONIDA_W64_EMULATE=1 (main: 187/217 passed, 28 skipped). Translation: 222 shaders: 221 translated, 221 pass spirv-val.
  • New tests in this PR: cs_co_ci_sdwa_dpp PASS: 268374580 4294868992 8192 30583 65546 131066 19 43981
  • No regressions against main.
  • Also failing on main on this GPU (known Mesa 25.2.8 issues, GPU test results (one comment per GPU and driver) #166): cs_fmt_int_narrow, cs_signed_zero_nan
    No game files. Automated run on my machine, AI-assisted (Claude Code).

@sovljanskii

Copy link
Copy Markdown
Contributor

Tested 78820bee (on top of main 3faac557) on Apple M4, macOS, MoltenVK 1.4.2, with main's AppleClang build of the runtime (this PR changes no C++) and Python 3.15.2: pass. This is the first Apple / arm64 run.

  • GPU suite: 153/218 passed, 58 skipped; main on the same machine gives 152/217, 58 skipped.
    • The only change is the new cs_co_ci_sdwa_dpp: PASS with 268374580 4294868992 8192 30583 65546 131066 19 43981, the same words as the RX 6700 XT, RTX 5090 and A770 runs.
    • 221/221 translated shaders pass spirv-val.
  • tests/semantic/test_co_ci_sdwa_dpp.py: 10 OK.
  • tests/test_sdwa_diff.py: 21/22. The one failure is program 36, the known v_cmp_class_f16 mask that rdna2spirv: read v_cmp(x)_class_f16 mask as f16 constant via src_h #3894 fixes.
  • Merged with rdna2spirv: read v_cmp(x)_class_f16 mask as f16 constant via src_h #3894 (ce763314, clean): test_sdwa_diff gives 22/22 on Python 3.15.2 and 3.12.16 on arm64. The GPU suite is identical per test to this PR alone (153/218).

So the landing order agreed here, #3894 first, holds on arm64 too. AI-assisted.

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 78820be on Intel UHD Graphics 630 (CFL GT2, subgroup 8..32): the GPU fixture passes, run_gpu_tests.py --filter cs_co_ci gives "PASS cs_co_ci_sdwa_dpp 268374580 4294868992 8192 30583 65546 131066 19 43981" and a nonexistent device name fails it, and tests/semantic test_co_ci_sdwa_dpp passes (10 tests). One Python test fails on this head: tests/test_sdwa_diff.py test_short_seeded_run_matches reports "(36, 'word 3 (VCC): reference 0x00000000, translated 0x00000001'" for a program containing v_cmp_nlt_f16_sdwa and v_cmp_class_f16_sdwa, and the file ends "FAILED (failures=1)". At base 3faac55 the same file passes, "Ran 21 tests ... OK". I did not isolate whether the translator change or the changed generator in tools/sdwa_diff.py causes it. tools/sdwa_diff.py --self-test passes, and --ops v_add_co_ci_u32,v_sub_co_ci_u32,v_subrev_co_ci_u32 --programs 1000 --seed 7 gives 1000 pass, 0 mismatch.

AI-assisted.

@Wasler

Wasler commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto main 561b65a83 in daec00724 (resolved docs/design.md and tests/semantic/regen_fixtures.py conflicts; #3894's v_cmp(x)_class_f16 fix is now on main).

Re-verified on Windows 11, RTX 5060 Ti (NVIDIA 621.01), CPython 3.14.4, llvm-mc 23.1.6, SPIRV-Tools 2026.4:

  • python -Wd -I tests/semantic/regen_fixtures.py --check: clean.
  • pytest -q tests/semantic/test_co_ci_sdwa_dpp.py tests/test_sdwa_diff.py tests/test_docs_design_rows.py tests/test_docs_repeated_lines.py tests/test_run_gpu_tests.py tests/test_shader_checks.py: 172 passed, 419 subtests passed (test_sdwa_diff.py now passes without dependency failures).
  • python -I scripts/run_gpu_tests.py --filter cs_co_ci_sdwa_dpp --require-pass: 1/1 passed (268374580 4294868992 8192 30583 65546 131066 19 43981).

AI-assisted.

@Wasler
Wasler force-pushed the fix/co-ci-sdwa-dpp branch from daec007 to d0d224f Compare November 23, 2026 14:43
@Wasler

Wasler commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 1cc6e3c12 in d0d224f28 (resolved only the docs/design.md | DPP | / | EXEC | adjacent hunk conflict, preserving main's updated | EXEC | row).

Re-verified on Windows 11, RTX 5060 Ti (driver 621.01), CPython 3.14.4:

  • python -I tests/semantic/regen_fixtures.py --check: exit 0
  • tests/semantic/test_co_ci_sdwa_dpp.py (10), tests/test_sdwa_diff.py (23), tests/test_docs_design_rows.py (4), tests/test_docs_repeated_lines.py (2), tests/test_run_gpu_tests.py (49), tests/test_shader_checks.py (84): all OK (172/172).
  • python -I scripts/run_gpu_tests.py --filter cs_co_ci_sdwa_dpp --require-pass: 1/1 passed (268374580 4294868992 8192 30583 65546 131066 19 43981).

AI-assisted.

@Mortify7612

Copy link
Copy Markdown

Tested d0d224f2 merged onto main 1cc6e3c1 (clean) on AMD Radeon RX 9060 XT (RDNA4, GFX1200, subgroup 32..64), RADV Mesa 25.0.7, Debian 12 Linux, llvm-mc 23.1.6: pass. I ran run_gpu_tests.py --filter <fixture> for the fixture(s) this PR adds or changes, not the full suite:

PASS cs_co_ci_sdwa_dpp 268374580 4294868992 8192 30583 65546 131066 19 43981

AI-assisted (Claude Code).

@Wasler

Wasler commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 413ffd6eb in 2d0cda9f2 (resolved the docs/design.md conflicts in | Execution model | / | DPP | and | SDWA |, keeping main's updated SHADER-1016 and 21,204 wording alongside _co_ci_u32).

Re-verified on Windows 11, RTX 5060 Ti (driver 621.01), CPython 3.14.4:

  • python -I tests/semantic/regen_fixtures.py --check: exit 0
  • tests/semantic/test_co_ci_sdwa_dpp.py (10), tests/test_sdwa_diff.py (23), tests/test_docs_design_rows.py (4), tests/test_docs_repeated_lines.py (2), tests/test_run_gpu_tests.py (58), tests/test_shader_checks.py (84): all OK (181/181).
  • python -I scripts/run_gpu_tests.py --filter cs_co_ci_sdwa_dpp --require-pass: 1/1 passed (268374580 4294868992 8192 30583 65546 131066 19 43981).

AI-assisted.

@Wasler
Wasler force-pushed the fix/co-ci-sdwa-dpp branch from d0d224f to 2d0cda9 Compare November 23, 2026 15:50

@shayderrr shayderrr 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.

Summary

rdna2spirv: fix operand layout and carry mask for _co_ci_u32 SDWA/DPP. Changes docs/design.md and runtime/test/shaders/check.py (plus 8 more). Adds regression tests test_cs_co_ci_sdwa_dpp_matches_on_cpu, test_gpu_runners_expect_the_same_words, test_sdwa_source_selects_sext_and_carry_chain, test_sdwa_dst_unused_modes_and_clamp.

Why merge

Addresses a concrete failure mode with a focused, scoped change and regression coverage. The patch stays within the affected code path, so it is low risk and prevents bad output or failures in real use.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary

rdna2spirv: fix operand layout and carry mask for _co_ci_u32 SDWA/DPP. Changes docs/design.md and runtime/test/shaders/check.py (plus 8 more). Adds regression tests test_cs_co_ci_sdwa_dpp_matches_on_cpu, test_gpu_runners_expect_the_same_words, test_sdwa_source_selects_sext_and_carry_chain, test_sdwa_dst_unused_modes_and_clamp.

Why merge

Addresses a concrete failure mode with a focused, scoped change and regression coverage. The patch stays within the affected code path, so it is low risk and prevents bad output or failures in real use.

Verdict: Approve

@Wasler

Wasler commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto upstream/main (d3266b570, cleanly resolving the docs/design.md conflict while keeping main's EXEC / Execution model rows and preserving _co_ci_u32 DPP/SDWA wording); head is now b3df21134.

Re-verified after rebase on Windows 11 + NVIDIA GeForce RTX 5060 Ti (driver 621.01, synthetic tests only):

  • python -I tests/semantic/regen_fixtures.py --check -> exit 0
  • tests/semantic/test_co_ci_sdwa_dpp.py (10), tests/test_sdwa_diff.py (23), tests/test_docs_design_rows.py (5), tests/test_docs_repeated_lines.py (2), tests/test_run_gpu_tests.py (58) -> 98/98 passed
  • python -I scripts/run_gpu_tests.py --filter cs_co_ci_sdwa_dpp --require-pass -> PASS cs_co_ci_sdwa_dpp 268374580 4294868992 8192 30583 65546 131066 19 43981 (1/1 passed)
    AI-assisted.

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested b3df21134ef6c9f5102e2b774916578fb8c5aaaf on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

The rebased wave32 fixture cs_co_ci_sdwa_dpp passed with all eight expected words on Linux. I also exercised two DPP add-with-carry cases in a temporary fixture:

  • With bound_ctrl:1 on the row shift, lane 0 used zero for the out-of-row source and returned 101 (0 + 100 + carry-in 1). The stock fixture preserves 0x7777 there.
  • With bank mask 0x2 enabling lane 4 and the second addend set to 0xffffffff, the lane returned 14 with carry-out set. The packed readback was 0x1000e.

The six other output words matched the stock run. Both modules passed SPIR-V validation. The stock expectations rejected the modified fixture, and a direct GPU dump matched all eight independently expected variant words.

AI-assisted verification.

@GustawMatuszewski

Copy link
Copy Markdown

Tested b3df21134 (this head, built in its own tree) on two devices. Ubuntu 26.04.1, llvm-mc 21.1.8 (AMDGPU), SPIRV-Tools 2026.1.

CPU: tests/semantic/test_co_ci_sdwa_dpp.py OK, tests/test_sdwa_diff.py OK. build.py: 269 shaders, 269 translated, 269 pass spirv-val.

NVIDIA GeForce RTX 5060 Laptop GPU (the mobile chip, 32..32), driver 595.99.02, Vulkan 1.4.329:

  • check.py: 175 of 211 pass, 35 skipped; the run hit one vkCreateDevice -> -4 (device lost, the known 595.99.02 Xid 32 flake) and its program is among the 36 that never reported
  • run_gpu_tests.py: 189/240 passed, 48 skipped; three failures, none from this PR: ms_wave_info_s3 fails identically on main at this base and with LEONIDA_W64_EMULATE=1 (reported separately), and ps_bary (4096/4096 exact) and ps_ssharp (8 S#/T# cases, 4096 pixels each exact) both pass 1/1 with --filter on the same build — the same Xid 32 flake

AMD Radeon 890M Graphics (RADV STRIX1, Mesa 26.0.8, 32..64), Vulkan 1.4.335:

  • check.py: 208 of 211 pass, 3 skipped, 0 failed (exit 0)
  • run_gpu_tests.py: 224/240 passed, 16 skipped, 0 failed (exit 0)

The _co_ci_u32 SDWA/DPP fixtures are exact on both devices. No game files; the repo's synthetic fixtures only. AI-assisted (Claude Code): it built the head, ran both devices and wrote this.

@nonverifiedperson

Copy link
Copy Markdown
Contributor

Tested head b3df211 on Windows, the first AMD run of this head (the earlier runs were NVIDIA on Linux):

  • python -I scripts/run_gpu_tests.py --filter co_ci_sdwa: cs_co_ci_sdwa_dpp PASS on the AMD Radeon iGPU (gfx1036, driver 32.0.13036.4) and on the NVIDIA RTX 5070 Ti. Both GPUs give the same words: 268374580 4294868992 8192 30583 65546 131066 19 43981.
  • python -I tests/test_sdwa_diff.py: OK
  • tests/semantic/test_co_ci_sdwa_dpp.py: OK

Windows 10 22H2, Vulkan SDK 1.4.363. Synthetic values only, no game files. AI-assisted (Claude Code).

@LukeOsland1

Copy link
Copy Markdown

Tested b3df21134e on Windows 11 build 26300, NVIDIA RTX 4070 Ti SUPER, driver 610.88. I used the PR’s GPU runner with LLVM 23.1.6 and the MSVC-built harness from the tested sources. The Vulkan loader was restricted to the NVIDIA ICD.

  • cs_co_ci_sdwa_dpp — 8 expected output words matched.

Xbox 1.0.2.1 coverage: 0 of 26,503 local shaders.rpf listings contain at least one of the following mnemonics. Static instruction counts (combining e32/e64 spellings): v_add_co_ci_u32_dpp 0, v_sub_co_ci_u32_dpp 0, v_add_co_ci_u32_sdwa 0, v_sub_co_ci_u32_sdwa 0. The counts describe opcode presence. The GPU readback above uses the hand-written fixture. AI-assisted with Codex.

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.