Skip to content

rdna2spirv: work around an NVIDIA Blackwell select-after-shuffle miscompile (gate subgroup writes with EXEC read back after the shuffle) - #4233

Open
tedin7 wants to merge 8 commits into
ItsNotRexed:mainfrom
tedin7:nvidia-shuffle-select
Open

tedin7 wants to merge 8 commits into
ItsNotRexed:mainfrom
tedin7:nvidia-shuffle-select

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new SHADER item (#4084 (comment))

What and why

On an RTX 5080 (NVIDIA 580.65.06, Linux), tools/crosslane_fuzz.py --programs 1500 --seed 91001 --dpp --no-maskdata gives three wave32 native mismatches that the RTX 3060 does not: cs_xl32_9100373399, cs_xl32_9100373491 and cs_xl32_9100373841. Each reduces to four ops ending in a v_permlane16_b32 / v_permlanex16_b32 under EXEC = 0, and in each the permlane result lands in every lane anyway. The emitted SPIR-V is valid (write-up: #3918 comment).

It is a driver miscompile, reduced to a 10-line GLSL compute shader:

bool c = pc.flag != 0u;                 // false at run time
uint y = lane == 16u ? 16u : 31u;       // a select, made before the shuffle
uint s = subgroupShuffle(lane, 3u);
d[64u + lane] = c ? s : y;              // RTX 5080 stores 3 in all 32 lanes

The result is wrong when c is computed before the shuffle and the false operand is itself a select. Putting the same instructions in another order (c after the shuffle, or the shuffle first) gives the right words. A bitwise merge (s & m) | (y & ~m) or an if (c) around the write fails the same way. In the translator, c is the lane's %active flag. It is loaded just before the select, but after SPIR-V's load/store elimination it is the value of the last EXEC write, so it comes before the shuffle. The old VGPR value is the select of the previous VALU write.

The fix: when a write's value is a subgroup op's result (v_permlane16/x16_b32, ds_swizzle_b32, ds_bpermute_b32, ds_permute_b32, native subgroups only), dst() gates it with the EXEC bit read back after the shuffle: OpGroupNonUniformBallot of %active, then OpGroupNonUniformBallotBitExtract at the lane's own index (gate_after_subgroup). That is the same bit, so semantics don't change. The ballot sits right after the shuffle in the same block, so the shuffle still runs in every lane and only the write is gated. The cost is one ballot and one bit extract per instruction. --wave64-emulate has no shuffle and is unchanged. DPP already gates with active && row/bank mask, computed after its shuffle, and never failed, so it is left alone. The DS forms have the same shape but no failing program yet. They are included so that every subgroup result is gated the same way.

Two negative controls matched the old instruction sequence and are updated to the new one. test_valu_permlane16.py sabotage 4 now allows the ballot read-back between the %active load and the select. test_wave64_subgroup_ops.py's bpermute sabotage now targets only the select whose source is a computed index, not the new EXEC mask select. Both still fail on sabotaged output as before.

A contract-table row in docs/design.md gives the rule, the reason and the measurements.

The NVIDIA report (minimal SPIR-V, GLSL, a 100-line Vulkan runner, expected vs actual) is ready to send separately.

Tested

RTX 5080 16 GB (Blackwell), NVIDIA 580.65.06, Ubuntu 22.04, LunarG SDK 1.4.363.1, llvm-mc 21, at aa2988cc plus this change:

  • tools/crosslane_fuzz.py --programs 1500 --seed 91001 --dpp --no-maskdata:
    • wave32 native: 585 match, 0 mismatch, 165 hypothesis-only (before: 582 match, 3 mismatch, 165).
    • wave64 emulate: 561 match, 0 mismatch, 189 hypothesis-only (unchanged).
    • Time: 9 min 21 s (before: 10 min 15 s).
  • The three programs, three runs each: 0 mismatching lanes (before: 32 each).
  • scripts/run_gpu_tests.py: 164/210 passed, 46 skipped, 0 failed, the same tests as before. With LEONIDA_W64_EMULATE=1: 195/210 passed, 15 skipped, 0 failed, the same tests as before. 214 shaders translated, 214 pass spirv-val.
  • python3.13 -m pytest tests/semantic -q -n 16: 7454 passed, 9 failed. All 9 fail on origin/main too: 5 test_loop_ballot_barrier wave64-emulate subtests, 2 test_mutations v_mul_legacy anchor subtests and 2 test_cmp_class_f64 rejected forms. test_vcmp16_opsel passes with this SDK's spirv-val.
  • tests/test_crosslane_fuzz.py, test_lds_fuzz.py, test_translate.py, test_shader_ir.py, test_wave64_halves_fixtures.py, test_amd_swizzle.py: 717 passed, 7 skipped. test_design_contract_rows.py and test_docs_design_rows.py pass.

Not run: other GPUs. On AMD, the extra ballot per permlane or DS lane op is the only change.

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.

AI-assisted. Synthetic shaders only, no game files.

…the shuffle (NVIDIA Blackwell)

On an RTX 5080 (NVIDIA 580.65.06, Linux), select(c, shuffle, y) returns the
shuffle in lanes where c is false when c was computed before the shuffle and y
is itself a select. A 10-line GLSL compute shader shows it. crosslane_fuzz
(seed 91001, --dpp --no-maskdata) found it as three wave32 programs that kept a
v_permlane16/x16 result under EXEC = 0.

v_permlane16/x16, ds_swizzle, ds_bpermute and ds_permute (native subgroups) now
gate their write with the lane's EXEC bit read back through a ballot and a bit
extract right after the shuffle. Same bit, one ballot more per instruction.

RTX 5080: crosslane_fuzz wave32 native 585 match, 0 mismatch (was 582 and 3),
wave64 emulate unchanged. run_gpu_tests.py is unchanged: 164/210 native,
195/210 emulated, 0 failed. Two semantic negative controls follow the new
instruction sequence.
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

The minimal NVIDIA repro, for anyone with an NVIDIA developer account who wants to file it (I will not file it myself). Only run on an RTX 5080 so far: a run on another NVIDIA GPU (Ampere, Ada) with the GLSL below would make the report stronger.

Report draft

Vulkan: OpSelect returns the subgroup-shuffle operand when its condition is false (RTX 5080, Linux 580.65.06)

Summary

On a GeForce RTX 5080 with the Linux 580.65.06 driver, a compute shader of the form

bool c = pc.flag != 0;          // false at run time (flag = 0)
uint y = lane == 16 ? 16 : 31;  // a select, computed before the shuffle
uint s = subgroupShuffle(lane, 3);
out[lane] = c ? s : y;

stores 3 (the shuffle result) in all 32 lanes instead of y (31, and 16 in lane 16).
The condition is false in every lane; the result should never be the shuffle.

The miscompile depends only on instruction order. With the same instructions in a different order the result is
correct:

Order in the SPIR-V flag = 0 result Correct?
c, y = select(...), s = shuffle, r = select(c, s, y) 3 in every lane no
y = select(...), s = shuffle, c, r = select(c, s, y) 31 (16 in lane 16) yes
s = shuffle, c, y = select(...), r = select(c, s, y) 31 (16 in lane 16) yes

With flag = 1 all three give 3, as they should.

Environment

  • GPU: NVIDIA GeForce RTX 5080 (Blackwell), 16 GB, subgroup size 32
  • Driver: 580.65.06 (Linux), Vulkan driverVersion 0x91104180
  • OS: Ubuntu 22.04, LunarG Vulkan SDK 1.4.363.1 (glslangValidator, spirv-as, spirv-val)
  • The module passes spirv-val --target-env vulkan1.1.
  • An RTX 3060 (Ampere) ran the three larger programs this was reduced from correctly. The minimal case below has
    not been run on other GPUs yet.

Minimal reproducer (GLSL)

#version 450
#extension GL_KHR_shader_subgroup_shuffle : require
layout(local_size_x = 32) in;
layout(std430, set = 0, binding = 0) buffer B { uint d[]; };
layout(push_constant) uniform P { uint a; uint b; uint unused; uint flag; } pc;
void main() {
    uint lane = gl_LocalInvocationID.x & 31u;
    bool c = pc.flag != 0u;                  // false: flag = 0
    uint y = lane == 16u ? 16u : 31u;
    uint s = subgroupShuffle(lane, 3u);      // 3 in every lane
    d[64u + lane] = c ? s : y;               // expected y; observed 3
}

Compile with glslangValidator --target-env vulkan1.1 repro.comp -o repro.spv.

Minimal reproducer (SPIR-V, hand-written, no Function variables)

; Minimal repro: r = select(c, shuffle, y) must be y when c is false.
               OpCapability Shader
               OpCapability GroupNonUniform
               OpCapability GroupNonUniformShuffle
               OpMemoryModel Logical GLSL450
               OpEntryPoint GLCompute %main "main" %lid
               OpExecutionMode %main LocalSize 32 1 1
               OpDecorate %lid BuiltIn LocalInvocationId
               OpDecorate %arr ArrayStride 4
               OpDecorate %Buf Block
               OpMemberDecorate %Buf 0 Offset 0
               OpDecorate %PC Block
               OpMemberDecorate %PC 0 Offset 0
               OpMemberDecorate %PC 1 Offset 4
               OpMemberDecorate %PC 2 Offset 8
               OpMemberDecorate %PC 3 Offset 12
               OpDecorate %buf DescriptorSet 0
               OpDecorate %buf Binding 0
       %void = OpTypeVoid
         %fn = OpTypeFunction %void
       %bool = OpTypeBool
       %uint = OpTypeInt 32 0
     %v3uint = OpTypeVector %uint 3
        %arr = OpTypeRuntimeArray %uint
        %Buf = OpTypeStruct %arr
     %ptr_sb = OpTypePointer StorageBuffer %Buf
   %ptr_sb_u = OpTypePointer StorageBuffer %uint
         %PC = OpTypeStruct %uint %uint %uint %uint
     %ptr_pc = OpTypePointer PushConstant %PC
   %ptr_pc_u = OpTypePointer PushConstant %uint
  %ptr_in_v3 = OpTypePointer Input %v3uint
     %uint_0 = OpConstant %uint 0
     %uint_3 = OpConstant %uint 3
    %uint_16 = OpConstant %uint 16
    %uint_31 = OpConstant %uint 31
    %uint_64 = OpConstant %uint 64
        %buf = OpVariable %ptr_sb StorageBuffer
         %pc = OpVariable %ptr_pc PushConstant
        %lid = OpVariable %ptr_in_v3 Input
       %main = OpFunction %void None %fn
      %entry = OpLabel
         %xv = OpLoad %v3uint %lid
          %x = OpCompositeExtract %uint %xv 0
       %lane = OpBitwiseAnd %uint %x %uint_31
         %fa = OpAccessChain %ptr_pc_u %pc %uint_3
       %flag = OpLoad %uint %fa
       %is16 = OpIEqual %bool %lane %uint_16
          %c = OpINotEqual %bool %flag %uint_0       ; false: the host pushes flag = 0
          %y = OpSelect %uint %is16 %uint_16 %uint_31   ; 16 in lane 16, 31 elsewhere
        %shf = OpGroupNonUniformShuffle %uint %uint_3 %lane %uint_3   ; lane 3's id = 3
          %r = OpSelect %uint %c %shf %y               ; expected y, observed shf
        %idx = OpIAdd %uint %lane %uint_64
        %out = OpAccessChain %ptr_sb_u %buf %uint_0 %idx
               OpStore %out %r
               OpReturn
               OpFunctionEnd

Assemble with spirv-as --target-env vulkan1.1 repro.spvasm -o repro.spv.

How to run

nvrun.cpp (attached, about 100 lines, Vulkan 1.3 headers) creates a 256-word storage buffer at set 0,
binding 0, fills word i with 0x10000 * (i / 32 + 1) + i, pushes 16 bytes of constants (flag is the fourth
word, given as the second command-line argument), dispatches one workgroup of 32 invocations and prints words
64 to 127.

g++ -O1 -I$VULKAN_SDK/include nvrun.cpp -L$VULKAN_SDK/lib -lvulkan -o nvrun
./nvrun repro.spv 0 0     # flag = 0

Expected and actual (flag = 0, words 64-95)

Expected:

0000001f 0000001f 0000001f 0000001f 0000001f 0000001f 0000001f 0000001f
0000001f 0000001f 0000001f 0000001f 0000001f 0000001f 0000001f 0000001f
00000010 0000001f 0000001f 0000001f 0000001f 0000001f 0000001f 0000001f
0000001f 0000001f 0000001f 0000001f 0000001f 0000001f 0000001f 0000001f

Actual:

00000003 00000003 00000003 00000003 00000003 00000003 00000003 00000003
00000003 00000003 00000003 00000003 00000003 00000003 00000003 00000003
00000003 00000003 00000003 00000003 00000003 00000003 00000003 00000003
00000003 00000003 00000003 00000003 00000003 00000003 00000003 00000003

What else we observed

  • The result is wrong in lanes where the condition is false, also when it is true in some other lanes:
    with %c = OpULessThan %bool %lane %flag and flag = 4, all 32 lanes get 3 (lanes 4-31 should get 31 or 16).
  • Replacing the select with a bitwise merge (s & m) | (y & ~m), with m = c ? ~0u : 0u, gives the same wrong
    result. So does a structured if (c) around the store in the larger programs.
  • OpGroupNonUniformShuffleXor and OpGroupNonUniformBroadcastFirst in place of OpGroupNonUniformShuffle
    also fail in the larger programs. An integer add in place of the shuffle does not fail.
  • The result is correct when y is not itself a select, when the condition is a compile-time constant, or when
    the shuffle result has another use (for example, it is also stored elsewhere).
  • VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT does not change the result.
  • Workaround: compute the condition again after the shuffle, through a ballot:
    c2 = subgroupBallotBitExtract(subgroupBallot(c), gl_SubgroupInvocationID), then c2 ? s : y.

Found with a differential fuzzer that translates AMD RDNA2 cross-lane instructions to SPIR-V (open-source project
Leonida, tools/crosslane_fuzz.py). In the original programs the condition is the lane's EXEC bit and EXEC is
zero, so a v_permlane16_b32 must not write.

AI-assisted. Synthetic shader only, no game files.

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

Ran the exact reproducer at ca15eede on Windows 11, RTX 5070 Ti (Blackwell, driver 621.24), with a vk_compute_test built from this branch:

python -I tools/crosslane_fuzz.py --programs 1500 --seed 91001 --dpp --no-maskdata --exe .../vk_compute_test.exe

  • wave32 native: 750 programs, 586 match, 0 mismatch, 164 hypothesis-only, 0 rejected/harness errors.
  • wave64 emulate: 750 programs, 561 match, 0 mismatch, 189 hypothesis-only, 0 rejected/harness errors.

The three cs_xl32_9100373* cases from the report are not mismatches here, and the new gate_after_subgroup path leaves all 1,500 programs correct. I did not reproduce the original miscompile on this host/driver, so this is a no-regression check rather than proof the workaround is needed; the semantic tests (test_valu_permlane16.py 16 OK, test_wave64_subgroup_ops.py 6 OK) pin the changed writes. No blocking issue.

@akimfomin

Copy link
Copy Markdown

@tedin7 I ran the requested minimal reproducer on GeForce RTX 4070 Ti SUPER (Ada), NVIDIA 617.14 (Vulkan driverVersion 0x9a438000), Windows 11 28000.3501, Vulkan device API 1.4.351, subgroup size 32. The reported mismatch did not reproduce on this setup.

  • The exact posted hand-written SPIR-V (assembled with both Leonida's assembler and Khronos spirv-as) and the posted GLSL (glslang 16.6.0) produced 31 in all lanes except lane 16 (16) with flag 0, and 3 in all lanes with flag 1. Both instruction-order controls and the ballot workaround gave the same expected results.
  • 12/12 dispatches matched all 32 expected output words, and the remaining 224 guard words stayed unchanged. A forced-shuffle negative control with flag 0 wrote 3 in all 32 lanes and the checker caught it. All seven modules passed Khronos spirv-val --target-env vulkan1.1.

The runner used set 0/binding 0, the four push-constant words and one 32-invocation workgroup as described. This is an Ada/Windows result for the standalone synthetic reproducer. AI-assisted.

@dcastell1

dcastell1 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested b53dfcf on RTX 5090 (Blackwell), 621.24, Windows 11: pass. Programs rebuilt from this head, LEONIDA_W64_EMULATE=1: 195/210 passed, 15 skipped, 0 failed. CPU side: test_valu_permlane16.py and test_wave64_subgroup_ops.py → OK with the SDK on PATH.

What I could not do: reproduce the miscompile itself. This box runs 621.24 and does not show it, so the evidence for the bug remains your 580.65.06 Linux data; the workaround is green here either way. Worth a line in the PR naming the driver versions where it was seen, so nobody removes the gate later thinking it was cosmetic.

@SweatierKey

Copy link
Copy Markdown
Contributor

Independent code read + CPU semantic / spirv-val check at ca15eede on Linux (WSL2, Python 3.13.5, spirv-tools, CPU only, no GPU, no game files): pass (Blackwell / AMD 32-wide GPU run still needed for hardware confirmation).

  • Code read (tools/rdna2spirv.py):
    • gate_after_subgroup emits OpGroupNonUniformBallot %v4uint_bal %c3 {active} → OpLoad %uint %sg_lane → OpGroupNonUniformBallotBitExtract %bool %c3 {bal} {lane} and sets uses_subgroup = uses_ballot = True (%c3 is guaranteed by gen.consts.setdefault(3, "%c3") under uses_subgroup).
    • fresh = after_subgroup and not self.emulate keeps --wave64-emulate byte-identical while gating native v_permlane16_b32/v_permlanex16_b32, ds_bpermute_b32/ds_swizzle_b32 (ds_lane_read, eager=True), and ds_permute_b32.
    • Test regex updates in test_valu_permlane16.py and test_wave64_subgroup_ops.py remain strict so both negative/sabotage controls still catch regressions.
  • Checks run (clean worktree on aa2988cc):
    • python3 -m unittest tests/semantic/test_valu_permlane16.py tests/semantic/test_wave64_subgroup_ops.py tests/semantic/test_ds_permute.py -v (with spirv-as/spirv-val on PATH): 28/28 OK.
    • test_semantic_translator_use.py (3/3), test_docs_links.py (6/6), test_docs_repo_paths.py (2/2), test_text_write_line_endings.py (3/3), test_text_encoding.py (2/2), git diff --check: all pass.
  • Not run here: RTX 5080 / AMD 32-wide GPU execution (crosslane_fuzz.py, run_gpu_tests.py).

AI-assisted review.

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

Tested ca15eede against aa2988cc on an AMD Radeon RX 6800, driver 26.11.2 (32.0.21045.29003), Vulkan 1.4.315, Windows 11 Pro build 26300 (compute subgroup sizes 32–64).

  • Native python -I scripts/run_gpu_tests.py --build <standalone harnesses> --require-pass: 214/214 synthetic modules translated and passed spirv-val on each commit. Both runs reported 195 passed, 15 skipped, and 0 failed. All 83 retained raw readbacks matched byte for byte.
  • I regenerated the three wave32 cases reported in this PR with the existing crosslane_fuzz generator (DPP enabled, mask data disabled) and ran each three times. All 9 executions matched the CPU model on both commits.
  • The two changed semantic suites passed 22/22. Both GPU runs used the same harnesses (LLVM-MinGW Clang 23.1.6, AMDGPU llvm-mc 23.1.5, SPIRV-Tools v2026.4).

AI-assisted (OpenAI Codex). Synthetic inputs only.

@paratustra

Copy link
Copy Markdown
Contributor

Code read at ca15eed. No CPU test pins the workaround. The PR only loosens two existing pattern checks (test_valu_permlane16.py:802, test_wave64_subgroup_ops.py:119). With LEONIDA_TOOLS_DIR pointed at main's tools/, which has no gate, test_valu_permlane16, test_wave64_subgroup_ops and test_ds_permute all still pass (16, 6 and 6). So if a later refactor drops gate_after_subgroup, or moves the ballot back before the shuffle, nothing fails except the fuzzer on a Blackwell card. A text-level test would close that gap. It would check that the select's condition comes from OpGroupNonUniformBallotBitExtract on a ballot taken after the OpGroupNonUniformShuffle, for one permlane and one ds_swizzle case.

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

@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested ca15eed on Windows 11 (llvm-mc, spirv-tools; no Vulkan validation layer installed): AMD Radeon RDNA2 iGPU (gfx1036, driver 26.10.1, subgroup 32..64) and NVIDIA RTX 5080 (driver 616.92, subgroup 32..32), one GPU at a time, device line confirmed for each. run_gpu_tests.py full set: Radeon 195/210 passed, 15 skipped, 0 failed; RTX 5080 164/210 passed, 46 skipped, 0 failed. crosslane_fuzz.py --programs 850 --seed 91001 --dpp --no-maskdata --wave 32 --modes native (covers program indexes 396, 488 and 838, i.e. the three reported programs): 668 match, 0 mismatch, 182 hypothesis-only, 0 rejected on both GPUs. pytest test_valu_permlane16.py test_wave64_subgroup_ops.py test_docs_design_rows.py: 24 passed, 84 subtests passed; regen_fixtures.py --check clean. Pass. I did not reproduce the failure on main, and did not run the wave64 emulate fuzz.

AI-assisted.

@akimfomin

Copy link
Copy Markdown

I tried the CPU regression suggested above on Windows using the existing translate_cs helper. It follows the actual v2 writeback to the shuffle result and its EXEC gate in one v_permlane16_b32 case and one ds_swizzle_b32 case. The latter goes through a bitwise merge and has a separate source-presence ballot, so checking any ballot in the module would be too broad.

  • ca15eede: both cases pass.
  • aa2988cc: both fail because the writeback condition is a plain load.
  • Negative control: moving just the relevant EXEC load and ballot before their shuffle fails both cases on order. Both mutated modules still pass spirv-val --target-env vulkan1.2.
Runnable test for tests/semantic/test_subgroup_writeback_gate.py
"""Native subgroup writeback gates must read EXEC through a ballot after the shuffle."""
import os
import sys
import unittest

HERE = os.path.dirname(os.path.abspath(__file__))
if HERE not in sys.path:
    sys.path.insert(0, HERE)
from test_valu_permlane16 import translate_cs  # noqa: E402


class SubgroupWritebackGateTests(unittest.TestCase):
    def assert_post_shuffle_gate(self, spv, swizzle):
        rows = [line.split() for line in spv.splitlines()]
        defs = {row[0]: (number, row[2:]) for number, row in enumerate(rows)
                if len(row) >= 3 and row[1] == "="}

        def find(value, opcode):
            self.assertIn(value, defs)
            order, args = defs[value]
            self.assertEqual(args[0], opcode, f"{value} is defined by {' '.join(args)}")
            return order, args[1:]

        shuffles = [(name, number) for name, (number, args) in defs.items()
                    if args[0] == "OpGroupNonUniformShuffle"]
        self.assertEqual(len(shuffles), 1)
        shuffle, shuffle_order = shuffles[0]

        # Follow the stored value of v2, ignoring swizzle's separate pre-shuffle source-presence ballot.
        stores = [(number, row[2]) for number, row in enumerate(rows)
                  if number > shuffle_order and len(row) == 3 and row[0] == "OpStore"
                  and defs.get(row[1], (None, []))[1] ==
                  ["OpAccessChain", "%_ptr_Function_uint", "%vgpr", "%c2"]]
        self.assertEqual(len(stores), 1)
        store_order, stored = stores[0]
        if swizzle:
            _, (_, write, _) = find(stored, "OpBitwiseOr")
            _, (_, selected_value, mask) = find(write, "OpBitwiseAnd")
            _, (_, fetched, _) = find(selected_value, "OpBitwiseAnd")
            select_order, (_, gate, _, _) = find(mask, "OpSelect")
        else:
            select_order, (_, gate, fetched, _) = find(stored, "OpSelect")
        self.assertEqual(fetched, shuffle)

        extract_order, (_, _, ballot, lane) = find(gate, "OpGroupNonUniformBallotBitExtract")
        _, lane_source = find(lane, "OpLoad")
        self.assertEqual(lane_source, ["%uint", "%sg_lane"])
        ballot_order, (_, _, active) = find(ballot, "OpGroupNonUniformBallot")
        _, active_source = find(active, "OpLoad")
        self.assertEqual(active_source, ["%bool", "%active"])
        self.assertTrue(shuffle_order < ballot_order < extract_order < select_order < store_order,
                        "v2 must use an EXEC ballot taken after its shuffle")

    def test_native_writeback_uses_a_post_shuffle_exec_ballot(self):
        cases = (
            ("permlane", "v_permlane16_b32 v2, v1, 0, 0"),
            ("swizzle", "ds_swizzle_b32 v2, v1 offset:swizzle(QUAD_PERM, 1, 0, 3, 2)"),
        )
        for name, instruction in cases:
            with self.subTest(op=name):
                spv, _ = translate_cs(f"cs_writeback_gate_{name}", [
                    "v_mov_b32_e32 v1, v0",
                    "v_mov_b32_e32 v2, 99",
                    "s_mov_b32 exec_lo, 0x0000ffff",
                    instruction,
                ], 32, emulate=False)
                self.assert_post_shuffle_gate(spv, swizzle=name == "swizzle")


if __name__ == "__main__":
    unittest.main()

Run with python -B -I tests/semantic/test_subgroup_writeback_gate.py -v. AI-assisted.

…e miscompile

cs_w32_permlane_exec0 runs v_permlane16_b32 and v_permlanex16_b32 under
EXEC = 0, right after a v_writelane_b32. It is reduced from crosslane_fuzz
seed 91001 (cs_xl32_9100373491). On an RTX 5080 (580.65.06) it fails with
main's translator (1400 1256 1304 ...) and passes with the read-back gate
(7 58 109 ...). It is registered in run_gpu_tests.py and check.py.

docs/testing.md gets a Known problems row: drivers seen, symptom, the
workaround and where the repro is. The design.md row names the fixture.
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks all for the cross-checks. Summary of where the miscompile is seen, so nobody reads the gate as cosmetic (@dcastell1):

  • Seen: RTX 5080, Linux 580.65.06 (Vulkan driverVersion 0x91104180), the three cs_xl32_9100373* programs and the 10-line repro.
  • Not reproduced: RTX 5070 Ti and RTX 5090 on Windows 621.24 (@Kam471, @dcastell1), RTX 5080 on Windows 616.92 (@Vonsek), RTX 4070 Ti SUPER on Windows 617.14 with the standalone repro (@akimfomin), RX 6800 and gfx1036 (AMD, @TG0000, @Vonsek).
  • So it looks like a 580.x Linux driver bug that later drivers fixed. I could not test a newer Linux driver: the cloud hosts I can rent top out at the 580 series, which is also why Linux users can still be on it.

I am keeping the gate (one ballot per permlane/DS lane op, native subgroups only) and adding: the driver range to the docs/design.md row and a Known problems entry, so it can be dropped once 580.x is gone; a CPU test that pins the ballot-after-shuffle order in the emitted SPIR-V (@paratustra: it fails with main's translator); and a GPU fixture, which only fails on 580.x. Update follows in this PR.

@ElsCiber

Copy link
Copy Markdown

Turing data point: the minimal repro is correct on a GTX 1660 SUPER, and this PR doesn't change any fuzz result there. AI-assisted, synthetic shaders only.

  • GPU: NVIDIA GeForce GTX 1660 SUPER (Turing, subgroup 32), driver 621.14 (Vulkan driverVersion 0x9b438000), Windows 11 Pro 26300, Vulkan SDK 1.4.363.0

Minimal repro. I ran both forms from your report: the GLSL (glslangValidator --target-env vulkan1.1) and the hand-written SPIR-V (spirv-as, spirv-val --target-env vulkan1.1 clean). The runner is a small one I wrote to your description: a 256-word buffer at set 0 / binding 0 filled with 0x10000 * (i / 32 + 1) + i, 16 bytes of push constants with flag as the fourth word, one workgroup of 32, words 64-95 printed.

shader flag = 0 flag = 1
GLSL 0x1f in every lane, 0x10 in lane 16: correct 0x3 in every lane: correct
SPIR-V 0x1f in every lane, 0x10 in lane 16: correct 0x3 in every lane: correct

So Turing on 621.14 doesn't miscompile it, which fits the RTX 3060 result and points at Blackwell (or the 580.65.06 Linux driver).

Fuzzer, same command (tools/crosslane_fuzz.py --programs 1500 --seed 91001 --dpp --no-maskdata, test programs built from main aa2988cc):

translator wave32 native wave64 emulate
main aa2988cc 750 programs: 586 match, 0 mismatch, 164 hyp_only 750: 561 match, 0 mismatch, 189 hyp_only
this PR ca15eede 750: 586 match, 0 mismatch, 164 hyp_only 750: 561 match, 0 mismatch, 189 hyp_only

The gate costs nothing in correctness on a part without the bug. tests/semantic/test_valu_permlane16.py (16) and test_wave64_subgroup_ops.py (6) pass on the PR head. I didn't measure the runtime cost of the extra ballot.

tests/semantic/test_subgroup_writeback_gate.py follows the v2 write of one
v_permlane16_b32 and one ds_swizzle_b32 back to its select. It checks that
the condition is a BallotBitExtract of an %active ballot taken after the
OpGroupNonUniformShuffle. It fails with main's translator
(LEONIDA_TOOLS_DIR=<main>/tools python -B tests/semantic/...) and passes
with the gate. The test is akimfomin's, from the PR discussion.

The miscompile is seen only on Linux 580.65.06. Windows 616.92, 617.14 and
621.24 do not reproduce it. The fixture comment, the design.md row and the
Known problems row now say so, and say that the gate can go once 580.x
Linux drivers are no longer in use.
@akimfomin

Copy link
Copy Markdown

Thanks for incorporating the CPU test. I checked the exact head b53dfcf on Windows: test_subgroup_writeback_gate.py passes both cases, and using main's translator through LEONIDA_TOOLS_DIR fails both on the missing ballot gate as expected.

I also ran the new cs_w32_permlane_exec0 fixture on RTX 4070 Ti SUPER / 617.14 / Windows 11, native subgroup 32. Both the PR and main's translator gave 7 58 109 160 211 262 313 364 on all three runs each. All 56 guard words were untouched on every run. A control swapping the comparison operands to keep lanes active changed all eight output words and was caught by the check.

For this run the unchanged RDNA2 instructions were fed to the translator as a listing with the repository's compute header. The three SPIR-V modules passed Khronos validation and used this tree's vk_compute_test. This confirms the fixture behavior on 617.14. Synthetic inputs only. AI-assisted.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Pushed c788b676 and b53dfcfa on top of ca15eede. They add a GPU fixture, a CPU test, and the driver range in the docs.

Where the miscompile is seen (@dcastell1, @akimfomin, @Kam471, @Vonsek). Only on Linux 580.65.06 (RTX 5080, Vulkan driverVersion 0x91104180). It does not reproduce on Windows 616.92 (RTX 5080, @Vonsek: crosslane_fuzz seed 91001 on this PR, 0 mismatches), 617.14 (RTX 4070 Ti SUPER, @akimfomin: the standalone repro), 621.24 (RTX 5070 Ti and RTX 5090, @Kam471 and @dcastell1) and 621.14 (GTX 1660 SUPER, @ElsCiber). The gate stays: one ballot per permlane or DS lane op, native subgroups only. Linux users on 580.x get wrong results without it. The docs/design.md row and the new docs/testing.md Known problems row give the driver range, so the gate can be dropped once 580.x is gone. Ubuntu 22.04's archive already has nvidia-driver-590-server 590.48.01. I did not install it, so whether 590 fixes the bug is untested.

CPU test (@paratustra). tests/semantic/test_subgroup_writeback_gate.py is @akimfomin's test from above, unchanged apart from the docstring. For one v_permlane16_b32 and one ds_swizzle_b32, it follows v2's write back to its select. It checks that the condition is an OpGroupNonUniformBallotBitExtract of an %active ballot taken after the OpGroupNonUniformShuffle. On the pod (Python 3.13):

  • this PR: OK (2 subtests)
  • LEONIDA_TOOLS_DIR=<main checkout>/tools python -B tests/semantic/test_subgroup_writeback_gate.py: FAILED (2), 'OpLoad' != 'OpGroupNonUniformBallotBitExtract'

Under pytest the same switch still passes on main: tests/conftest.py imports the checkout's tools/rdna2spirv.py before the test module reads LEONIDA_TOOLS_DIR. That is probably why main's tools looked fine in your run. Run the module directly (unittest) for a main-vs-PR comparison.

GPU fixture cs_w32_permlane_exec0. It is registered in scripts/run_gpu_tests.py and check.py. Its v_permlane16_b32 and v_permlanex16_b32 run under EXEC = 0 right after a v_writelane_b32 (reduced from cs_xl32_9100373491). The expected words come from the ISA: 7 58 109 160 211 262 313 364. On the RTX 5080 with Linux 580.65.06, main's translator gives 1400 1256 1304 1304 1288 1384 1464 1400 (FAIL) and this PR passes, native and with LEONIDA_W64_EMULATE=1 alike (the fixture is wave32, so emulation doesn't change it). On other drivers it passes with or without the gate, as the fixture's header says.

Suite with this PR (RTX 5080, Linux 580.65.06):

  • scripts/run_gpu_tests.py: 165/211 passed, 46 skipped, 0 failed (before: 164/210).
  • With LEONIDA_W64_EMULATE=1: 196/211 passed, 15 skipped, 0 failed (before: 195/210).
  • 215 shaders translated, 215 pass spirv-val.
  • tests/test_docs_*.py, test_shader_checks.py, test_design_contract_rows.py, test_valu_permlane16.py, test_wave64_subgroup_ops.py and test_ds_permute.py pass.

AI-assisted, no game files.

@AC-Storm-YT

Copy link
Copy Markdown
Contributor

AMD data, both generations, including the wave64 modes nobody has posted yet: Windows 11, AMD Windows driver 26.11.2, Vulkan SDK 1.4.363.1, llvm-mc from AMD LLVM 23 (rocm-sdk-core 10.0.0), test programs built from this branch.

crosslane_fuzz.py --programs 1500 --seed 91001 --dpp --no-maskdata --w64-native, this PR's translator (ca15eede) and main aa2988cc's, same programs:

Ryzen 7 9800X3D iGPU (RDNA2, gfx1036, 32.0.21045.29003): PR / main RX 9070 XT (RDNA4, gfx1201, 32.0.32029.2010): PR / main
wave32 native 586 / 586 match, 0 mismatch, 164 hyp-only 586 / 586 match, 0 mismatch, 164 hyp-only
wave64 emulate 561 / 561, 0, 189 561 / 561, 0, 189
wave64 native 561 / 561, 0, 189 561 / 561, 0, 189

So on AMD the extra ballot gives the same result as main in every mode, including native wave64. c788b676 and b53dfcfa don't touch tools/rdna2spirv.py, so these numbers hold for the current head.

At b53dfcfa:

  • cs_w32_permlane_exec0 passes on both GPUs (7 58 109 160 211 262 313 364, with LEONIDA_VK_VALIDATION=1).
  • tests/semantic/test_subgroup_writeback_gate.py: OK.
  • Full run_gpu_tests.py on the RX 9070 XT with LEONIDA_VK_VALIDATION=1: 215 shaders translated, 215 pass spirv-val; 197/211 passed, 14 skipped, 0 failed. The 14 skips are the tests run by the d3d12_* programs instead. That's the first full run on RDNA4 here; @Vonsek has the gfx1036 one.

Synthetic shaders only, no game files.

@lunarminus

Copy link
Copy Markdown

Tested b53dfcfa on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux. The translator is unchanged since ca15eede, which I also ran: pass.

GPU

  • scripts/run_gpu_tests.py at b53dfcfa: 197/211 passed, 14 skipped, 0 failed, both native and with LEONIDA_W64_EMULATE=1. The new cs_w32_permlane_exec0 passes in both modes.

  • At ca15eede: 196/210 both ways, identical per test to aa2988cc on the same machine.

  • tools/crosslane_fuzz.py --programs 1500 --seed 91001 --dpp --no-maskdata gives the same result for the PR and aa2988cc:

    • wave32 native: 586 match, 0 mismatch, 164 hypothesis-only;
    • wave64 emulate: 561 match, 0 mismatch, 189 hypothesis-only.

    So RADV doesn't show the miscompile either.

CPU

  • tests/semantic/test_subgroup_writeback_gate.py: OK on the PR. With main's translator (LEONIDA_TOOLS_DIR) both cases fail, as they should.
  • An independent code read found the same gap before you pushed this test: stubbing gate_after_subgroup to return active passed every existing test, partly because sabotage 4's (?:.*\n){0,3}? also matches zero lines. The new test closes that gap.
  • The code read found no correctness problem. The gate is the lane's own bit of a ballot it takes part in, so it equals %active for wave32, for wave64 on 64- and 32-wide subgroups, and for partial waves.
    • Interpreter runs with shrinking-EXEC loops and partial waves (20 threads wave32, 40 threads wave64), all five ops: memory is identical on main and the PR in all 30 cases.
    • DPP, v_readlane/v_writelane and --wave64-emulate output are byte-identical to main.
    • The semantic suite fails the same 9 as main.

Full corpus (my own 1.0.2.1 copy, CPU, counts only): rdna2spirv.py --shard i/8 over all 26,503 listings, native mode as make_game.py uses it on this GPU.

  • 26,503 translated and 26,422 spirv-val-valid, the same as aa2988cc. The 81 invalid ones are the known aa2988cc regression that Translator: constants assemble asks for late are defined too #3902 fixes.
  • The PR changes 7,625 of the 26,422 valid modules: 6,578 PS, 987 CS, 59 MS and 1 VS. All of them are still valid. That's a larger footprint than the "only change on AMD" wording might suggest, and worth knowing for anyone measuring performance.

Side note, also on main, not this PR: v_permlanex16_b32 in a partial wave (20 threads wave32, 40 wave64) shuffles from lanes that don't exist. The interpreter rejects the value as undefined. Permlane has no "present" fallback like the DS lane ops do.

AI-assisted (Claude Code).

…merges identical ones)

A ballot of EXEC after the shuffle is merged with an earlier identical ballot, which puts the second gate before the v_writelane select and the shuffle again (crosslane_fuzz seed 70102, cs_xl32_7010410418). The gate is now a shuffle of EXEC ? K : 0 from the lane's own index, compared with K, with K different per gate. GPU fixture cs_w32_writelane_permlane_exec0 and a CPU test pin it.
@sperm

sperm commented Nov 23, 2026

Copy link
Copy Markdown

Tested 0d2d7a6 (a re-test at the new head) on AMD Radeon RX 9070 XT (RADV GFX1201, wave32/64) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.

No game files. AI-assisted.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Update 2: a second ballot gate is merged with the first (found by crosslane_fuzz seed 70102)

Found. crosslane_fuzz.py --programs 500 --seed 70102 --wave both --no-maskdata --ops 40 on the RTX 5080 (Linux 580.65.06) still gave one wave32 native mismatch with the #4233 gate: cs_xl32_7010410418 (v4 lanes 0-5 took the permlane result under EXEC = 0). Reduced to four ops:

v_cmpx_gt_u32 60, v3                       ; EXEC = 0
v_permlanex16_b32 v5, v2, K, s29
v_writelane_b32 v4, s8, 25
v_permlanex16_b32 v4, v3, K2, s29

Cause. It is not the kind of write before the permlane. SPIR-V edits on the GPU: replacing either of the two post-shuffle EXEC ballots with the plain %active makes the program pass. The two ballots read the same EXEC value, the compiler merges them, and the second gate is again computed before the shuffle and before the v_writelane_b32 select, which is the shape #4233 avoids. Writelane before both permlanes passes, and a single permlane passes. A tautology on the shuffle result (x | ~x != 0) is folded away and still fails; a ballot of the negated EXEC, or a self shuffle, passes.

Fix. The gate is now a shuffle from the lane's own index of EXEC ? K : 0, compared with K, with a different K for every gate of the module (gate_after_subgroup). No two gates read the same value, so none can be merged. It covers every user of the gate (permlane16/x16, ds_swizzle, ds_bpermute, ds_permute), whatever the register's previous write was (writelane, cndmask, plain VALU).

Fixture. cs_w32_writelane_permlane_exec0 (the four ops; v4 and v5 are stored so the first permlane is not dead code: with v5 dead it passes on every build). RTX 5080, 580.65.06:

CPU test. test_two_gates_in_a_module_read_different_values (two permlane writes with a writelane between, EXEC = 0): fails on b53dfcf, passes now. test_native_writeback_reads_exec_after_its_shuffle pins the order for the permlane and swizzle write.

Numbers (RTX 5080, 580.65.06):

  • crosslane_fuzz wave32 native, --no-maskdata: seed 70102 (--ops 40, 500 programs) 161 match, 0 mismatch (was 160 and 1); seed 91001 (1500, --dpp) 585 match, 0 mismatch; seed 70101 (500, --dpp) 197 match, 0 mismatch. Wave64 emulate: 0 mismatch in all three.
  • scripts/run_gpu_tests.py: 166/212 native, 197/212 with LEONIDA_W64_EMULATE=1, 0 failed (baseline 164/210 and 195/210 counted 210 rows; this build has 212, 2 more rows, with the new fixture one of them; the extra programs all pass).
  • CPU: the tests that read the touched files pass (1369 passed). test_loop_ballot_barrier.py has 5 failing subtests (NotImplementedError) on the unchanged rdna2spirv: work around an NVIDIA Blackwell select-after-shuffle miscompile (gate subgroup writes with EXEC read back after the shuffle) #4233 head too.
  • Cost, median of 5 runs of 300 dispatches (VKC_BENCH=300, 16384 groups): cs_bench_mix 0.646 ms against 0.641 ms before (the SPIR-V is byte for byte the same: it runs emulated and the gate is native only); 48 permlane16/x16 in a row (cs_bench_permlane, a local benchmark, not added) 0.337 ms against 0.336 ms.

Docs: design.md row "Write gate of a subgroup result" and the testing.md row now say the trigger is two identical post-shuffle EXEC reads being merged.

Thanks @sperm for re-testing this head on the RX 9070 XT and the gfx1036 iGPU (198/212, 0 failed, both new fixtures pass): so the salted gate changes nothing on AMD.

AI-assisted. No game files.

@Etr0p

Etr0p commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 0d2d7a6 on NVIDIA GeForce RTX 5070 Ti Laptop GPU (Blackwell, 621.24, subgroup 32..32) and AMD Radeon 610M (RDNA2 iGPU, AMD 26.11.2 / 32.0.21045.29003, subgroup 32..64), Windows 11 Home 26200: pass.

Same laptop, one GPU at a time through LEONIDA_VK_DEVICE. Test programs rebuilt from this head with llvm-mingw 23.1.6; llvm-mc 23.1.6 (conda-forge), SPIRV-Tools v2026.4 (Vulkan SDK 1.4.363.0), Python 3.13.14.

Run RTX 5070 Ti Laptop Radeon 610M
scripts/run_gpu_tests.py (native) 166/212 passed, 46 skipped, 0 failed 191/212 passed, 21 skipped, 0 failed
LEONIDA_W64_EMULATE=1 scripts/run_gpu_tests.py 197/212 passed, 15 skipped, 0 failed not run
crosslane_fuzz.py --programs 850 --seed 91001 --dpp --no-maskdata --wave 32 --modes native match 668, mismatch 0, hyp_only 182, harness_errors 0 match 668, mismatch 0, hyp_only 182, harness_errors 0
  • 216 shaders translated, 216 pass spirv-val.
  • cs_w32_permlane_exec0 (7 58 109 160 211 262 313 364) and cs_w32_writelane_permlane_exec0 pass in all three suite runs.
  • The fuzzer run covers cs_xl32_9100373399, ...491 and ...841: none of them is reported on either GPU. The 182 hyp_only programs are the same set on both GPUs.
  • CPU: test_subgroup_writeback_gate.py (2), test_valu_permlane16.py (16) and test_wave64_subgroup_ops.py (6) pass.

Not shown here: the miscompile itself. 621.24 on Windows is outside the driver range the PR names, so this is a check that the gate changes nothing on these two devices, not a reproduction. For comparison, main at 03b09a08 on the same machine: 164/210 (RTX native), 195/210 (RTX emulated), 189/210 (610M native), 0 failed.

One run of each. No game files. AI-assisted (Claude Code).

@AC-Storm-YT

Copy link
Copy Markdown
Contributor

Re-tested 0d2d7a61 on AMD's Windows driver, both generations, including native wave64 fuzzing, which isn't in the other re-tests: Windows 11, AMD 26.11.2, Vulkan SDK 1.4.363.1, llvm-mc from AMD LLVM 23 (rocm-sdk-core 10.0.0), test programs built from this head.

crosslane_fuzz.py --no-maskdata --w64-native, identical on both GPUs:

wave32 native wave64 emulate wave64 native
seed 70102, --programs 500 --ops 40 161 match, 0 mismatch, 89 hyp-only 146, 0, 104 146, 0, 104
seed 91001, --programs 1500 --dpp 586, 0, 164 561, 0, 189 561, 0, 189

RX 9070 XT (RDNA4, gfx1201, 32.0.32029.2010) and Ryzen 7 9800X3D iGPU (RDNA2, gfx1036, 32.0.21045.29003). Seed 91001 gives the same counts as ca15eede and main aa2988cc did on these GPUs, so the salted gate changes nothing on AMD either.

Full run_gpu_tests.py on the RX 9070 XT with LEONIDA_VK_VALIDATION=1: 216 shaders translated, 216 pass spirv-val; 198/212 passed, 14 skipped (the tests run by the d3d12_* programs), 0 failed. cs_w32_permlane_exec0 passes, and cs_w32_writelane_permlane_exec0 passes with 2123073880 4139845281 2123073932 4139845289 ..., the words you list as wanted.

CPU: test_subgroup_writeback_gate.py 2 OK, and with main's tools/rdna2spirv.py it fails 3 subtests (permlane, swizzle, two gates); test_valu_permlane16.py 16 OK; pytest tests/semantic/test_wave64_subgroup_ops.py 6 passed, 14 subtests.

No game files.

@bielfreedom

Copy link
Copy Markdown

Full-corpus check on the game copy (Xbox Series 1.0.2.1; Windows 11, RX 9070 XT). Counts only, no shader names or data.

PR head 0d2d7a61, merge-base aa2988cc (same commit as my baseline). All 26,503 disassembled shaders translated with --no-asm, 8 shards + --merge:

main aa2988cc this PR
translated 26,503 26,503
pass spirv-val 26,422 26,422
tier A / B / C (32-wide) 510 / 11 / 1,161 510 / 11 / 1,161
total .spv bytes — +0.05%
index.json — identical
  • What changed: 7,625 .spv differ: PS 6,578, CS 987, MS 59, VS 1. These are presumably the shipped shaders that reach a gated subgroup write.
  • Cost on the game corpus: the extra EXEC read-back is small. The total grows by 0.05%, and validity and the wave64 tiers are unchanged.

On this AMD card the workaround should be a no-op semantically. I did not run the crosslane fuzzer on this head, and I have no Blackwell GPU to confirm the fix itself.

@itsadhil

Copy link
Copy Markdown

Tested 8753aa73 on RTX 5070 Ti desktop (Blackwell), NVIDIA 621.24, Windows 11 Pro 26300, Vulkan SDK 1.4.363.0, llvm-mc 23.1.6 (conda-forge), test programs built with MSVC 19.44 from main 3faac557 (the PR doesn't touch runtime/): pass, and the miscompile does not reproduce on this driver.

  • The two new fixtures, cs_w32_permlane_exec0 and cs_w32_writelane_permlane_exec0, pass on the base 98fa503f too (the PR's fixtures and check.py on the base translator). So the Windows 621.24 driver doesn't show the select-after-shuffle miscompile seen on Linux 580.65.06.
  • crosslane_fuzz.py --programs 1500 --seed 91001 --dpp --no-maskdata --wave 32 --modes native: base and PR both 1188 match, 0 mismatch, 312 hypothesis-only.
  • scripts/run_gpu_tests.py, full suite: base and PR both 172/219 passed, 47 skipped, 0 failed; 223 shaders translated, 223 pass spirv-val.

No regression from the gate on this card. AI-assisted; synthetic shaders only, no game files.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @itsadhil. That fits the write-up: the miscompile was seen on Linux 580.65.06 (RTX 5080). Your Windows 621.24 run on a 5070 Ti shows it is driver-version specific, and that the gate costs nothing where the driver is right: 172/219 on both base and PR, and 0 fuzz mismatches on both. The two fixtures guard the gated form on drivers that do miscompile. A Linux 58x/59x run on Blackwell is the configuration that shows them fail on the base.

# Conflicts:
#	docs/design.md
#	runtime/test/shaders/check.py
#	tests/semantic/test_valu_permlane16.py
#	tools/rdna2spirv.py
@leozinhoszg

leozinhoszg commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested 8753aa73 on NVIDIA RTX PRO 500 Blackwell Laptop GPU, driver 581.95, Windows 11 Pro 26200, and re-checked the new head fccd6417: pass. This driver also reproduces the miscompile on Windows. The earlier Windows runs (616.92, 617.14, 621.x) didn't.

Re-check at fccd6417 (main merged in; the tools/rdna2spirv.py change is unchanged):

Setup: Vulkan SDK 1.4.363.0, llvm-mc 23.1.6 (conda-forge llvm-tools), MSVC 19.51, Python 3.13. Test programs built from main 3faac557 (the PR doesn't touch runtime/). "Base translator" below is the merge base 98fa503f's tools/rdna2spirv.py, run with this PR's fixtures and check.py. Device confirmed in vk_compute_test's device: line (subgroup 32..32).

The two new fixtures

base translator this PR
cs_w32_permlane_exec0 FAIL on 3 of 3 runs: 1400 1256 1304 1304 1288 1384 1464 1400 PASS on 3 of 3 runs: 7 58 109 160 211 262 313 364
cs_w32_writelane_permlane_exec0 PASS PASS

The same base-translator .spv gives the expected words on the Intel Arc 140T in the same laptop. So it's the NVIDIA driver, not the module.

scripts/run_gpu_tests.py, full suite on the RTX

  • main 3faac557: 170/217 passed, 47 skipped, 0 failed. 221 shaders translated, 221 pass spirv-val.
  • This PR: 172/219 passed, 47 skipped, 0 failed. 223 shaders translated, 223 pass spirv-val.
  • The only difference is the two new tests. Every other test has the same result.

crosslane_fuzz.py --wave 32 --modes native --no-maskdata, real mismatches on the RTX

base translator this PR
seed 91001, --programs 1500 --dpp 7 (1180 match, 313 hyp-only) 2 (1185 match, 313 hyp-only)
seed 70102, --programs 500 --ops 40 3 (309 match, 188 hyp-only) 0 (312 match, 188 hyp-only)
  • Seed 91001, base translator: the three programs from your report (cs_xl32_9100373399, …3491, …3841) plus …3226, …3366, …3402 and …4034. The PR fixes five of the seven.
  • Seed 70102, base translator: cs_xl32_7010410343, …0427 and …0780, all fixed by the PR. 7010410418 matched with both translators here.

Two programs still mismatch with the gate, cs_xl32_9100373366 and cs_xl32_9100374034 (seed 91001, indexes 363 and 1031, --ops 24 --dpp --no-maskdata, wave32 native). I re-ran just these two through crosslane_fuzz.run_translator, five times on each translator:

  • RTX 581.95: mismatch on every run, with both translators. …3366 has 32 wrong words and …4034 has 24.
  • Intel Arc 140T: match on every run, with both translators.
  • …3366 includes a permlane. …4034 has no permlane at all (ops: bcnt, cmp, cndmask, dpp, mask_salu, mbcnt_data, readlane, readlane_w32hi, salu, writelane).

So 581.95 looks like it has at least one more miscompile that the post-shuffle gate doesn't cover, probably not the same pattern. I don't think that should block this PR, which fixes what it claims. I haven't minimized the two programs. I can run --minimize on them and post the reduced ops here or as a finding:, if that's useful.

CPU: test_subgroup_writeback_gate, test_valu_permlane16 and test_wave64_subgroup_ops pass (24 tests). With LEONIDA_TOOLS_DIR pointed at the base translator, test_subgroup_writeback_gate fails as intended (3 failures).

AI-assisted (Claude Code). Synthetic shaders only, no game files.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 614f7b7 merged with main 561b65a on Linux (WSL2), CPython 3.12.16, CPU only: fail.

  • The PR's own new tests/semantic/test_subgroup_writeback_gate.py fails: test_native_writeback_reads_exec_after_its_shuffle (op='permlane') gets 3 != 2 shuffles (it expects the data shuffle plus the gate's). The same failure happens on the PR head alone, which is based on this main (merge-base 561b65a). The swizzle subtest passes.
  • It also breaks an existing test: tests/semantic/test_ds_swizzle_b32.py::NegativeControls::test_sabotage_quad_base_mask_shuffle_and_exec_guard fails with 2 != 1 (that file passes on main).
  • Full semantic suite with the ci: run the semantic suite one file per process on every CPU (405 s -> 83 s on 4 jobs) #4357 runner (scratch copy, --jobs 3): main 433 files / 6150 tests, 0 files not ok; merged 434 files / 6152 tests, 2 files not ok (the two above).
  • test_valu_permlane16.py 16/16 and test_wave64_subgroup_ops.py 6/6 pass.
  • No GPU run (the NVIDIA workaround itself needs a Blackwell card).

@cynbun

cynbun commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Data point (not claiming) for leozinhoszg's two seed-91001 DPP programs (#6089 finding), on RTX 5080 (desktop Blackwell), NVIDIA 615.78.08, Linux, llvm-mc 23.1.3: doesn't reproduce, on main 561b65a8 or on this PR's head fccd6417.

  • crosslane_fuzz.py --programs 1032 --seed 91001 --dpp --no-maskdata --wave 32 --modes native --minimize (and --programs 364): 1032/1032 match with either translator. vk_compute_test built from main (this PR doesn't touch runtime/).
  • cs_xl32_9100373366 and cs_xl32_9100374034, full (24 ops) and reduced to the 3 and 4 ops in the finding: 5 runs each, both translators, 0 wrong words in all 40 runs.
  • CPU check: I ran the translated SPIR-V (full and reduced, both translators) in tests/semantic/spirv_wave_interp.py, one subgroup per wave with the harness's push constants. It equals the fuzzer's ISA model in every word (448/448 and 1344/1344). That interpreter raises if a value SPIR-V leaves undefined is used, for example a shuffle from an invocation that isn't running, and it raised nothing. So the emitted SPIR-V is well-defined and correct here, and I'd put the 581.95 result down to the driver.

Where the 581.95 counts fit, from the ISA model (this is a hypothesis, since the finding gives counts but not the words):

  • …3366 looks like tedin7's DPP8 fi:1 under EXEC=0 case, not a row/bank-mask case. In the reduced program, s_and_saveexec_b32 s22, s18 runs with s18 = 0 from the prologue, so the final v_mov_b32_dpp v4, v3 dpp8:[…] fi:1 runs with EXEC=0. If that op wrote anyway, v4 would differ in all 32 lanes: exactly 32 words, the count reported. The row_mask:0x8 op is a no-op at wave32, because rows 2 and 3 don't exist there.
  • …4034 matches the bank mask being ignored. If the final row_half_mirror row_mask:0xf bank_mask:0xe bound_ctrl:1 fi:1 also wrote bank 0, v2 would differ in lanes 0–3 and 16–19 of each of the 3 waves: exactly 24 words, the count reported. Ignoring row_share:10 row_mask:0xc instead would give 72. EXEC is full in that program, so this one is a genuine partial-mask case that neither of the two cases in tedin7's update covers.

The words the RTX PRO 500 actually gets would confirm or rule out these two readings.

AI-assisted (Claude Code).

…ctivity shuffle (review: kapitche)

main's v_permlane16 with FI=0 shuffles the source lane's EXEC bit after the data shuffle, so a
native permlane now has three shuffles: data, source activity, and the gate's own-lane EXEC read.
test_subgroup_writeback_gate follows the value through the FI=0 select and checks FI=1 too;
test_ds_swizzle_b32's negative control sabotages the data shuffle only and the gated EXEC mask.
@sovljanskii

Copy link
Copy Markdown
Contributor

@tedin7 a heads-up on an overlap, nothing for you to do now. #6249 (BUILD-1895) changes the same v_permlane16/x16 lowering:

  • The value and active-bit shuffles go through eager(), because SPIRV-Cross inlined them into ?:/&& on MoltenVK.
  • The value shuffle reads the redirected lane.

Merged with this PR on an M4 (MoltenVK 1.4.2), it applies cleanly, and cs_w32_permlane_fi, cs_w32_permlane_exec0 and cs_w32_writelane_permlane_exec0 all pass.

test_subgroup_writeback_gate fails on main 561b65a8 + this PR already, without #6249: 3 != 2 : the data shuffle and the gate's, because SHADER-74 adds an active-bit shuffle for the default FI=0. With #6249 its fetched == shuffle check would also have to follow the value through the eager OpLoad. Whichever lands second adjusts that test. I can do it on #6249 if this lands first.

AI-assisted.

@thiefyzheng thiefyzheng left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Heads-up: tests/semantic/test_subgroup_writeback_gate.py is red at fccd6417, and it fails for a test-side reason, not a translator one — easy fix, but it will block the merge.

$ python3 -m unittest discover -s tests/semantic -p "test_subgroup_writeback_gate.py"
FAIL: test_native_writeback_reads_exec_after_its_shuffle (…(op='permlane'))
  self.assertEqual(len(shuffles), 2, "the data shuffle and the gate's")
AssertionError: 3 != 2

The permlane case emits three OpGroupNonUniformShuffle instructions, not two:

value used by what it is
%t34 OpSelect %uint %t36 %t34 %t37 the data shuffle
%t40 OpINotEqual %bool %t40 %c0 a source-presence ballot (compared with 0, not a gate)
%t51 OpIEqual %bool %t51 %c1 the write gate

cs_writeback_gate_swizzle gets away with it (2 shuffles), and the comment at :33 already acknowledges the case — "ignoring swizzle's separate pre-shuffle source-presence ballot" — but the permlane program (v_mov_b32_e32 v1, v0 / v_mov_b32_e32 v2, 99 / s_mov_b32 exec_lo, 0x0000ffff / v_permlane16_b32 v2, v1, 0, 0) produces one as well, so the count assertion sees 3.

Suggested: filter the helper's shuffles to the ones a gate actually compares, instead of counting every shuffle — the same exclusion the swizzle case already applies, made explicit:

shuffles = [(name, number) for name, (number, args) in defs.items()
            if args[0] == "OpGroupNonUniformShuffle"
            and any(a[1] == name and a[0] == "OpIEqual" for a in defs.values())]

Verified with python3 -m unittest discover -s tests/semantic -p "test_subgroup_writeback_gate.py" at your head; main has no such file, so this is only yours to fix. AI-assisted code read, per AGENTS.md — no GPU involved, this is all CPU-side SPIR-V text.

@thiefyzheng thiefyzheng left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Second, bigger one: this branch also breaks an existing test — tests/semantic/test_ds_swizzle_b32.py, one failure out of 20.

FAIL: test_sabotage_quad_base_mask_shuffle_and_exec_guard
  File "tests/semantic/test_ds_swizzle_b32.py", line 880, in ...
AssertionError: 2 != 1

The control sabotages the emitted module by turning the shuffle into an own-lane copy and expects exactly one match:

bad_shuf, n2 = re.subn(r"(%\w+) = OpGroupNonUniformShuffle %uint %c3 (%\w+) %\w+", r"\1 = OpCopyObject %uint \2", spv)
self.assertEqual(n2, 1)

With the gate there are now two shuffles in that module (the swizzle's and the gate's), so n2 == 2. Same shape as the test_subgroup_writeback_gate failure above: a test written for one shuffle, meeting two.

Attribution, so this is not guesswork — same machine, same command, three translators:

translator test_ds_swizzle_b32
main (561b65a8, no gate) OK (20 tests)
this branch's fccd6417 FAILED (2 != 1)
this branch + my SHADER-1035 DPP patch on top FAILED (identical)

So it is neither flaky nor mine — it comes from the two shuffles this PR introduces. Suggested fix: make the sabotage replace only the non-gate shuffle (match the one whose result is not compared by an OpIEqual, or count=1 after locating the gate), or assert n2 >= 1 and sabotage one at a time.

I have no PR touching this file; flagging it here because it is what CI will report on your pull request. AI-assisted review, per AGENTS.md — CPU only, no GPU involved.

@leozinhoszg

Copy link
Copy Markdown
Contributor

Intel regression at fccd6417: a two-op program fails on an Intel Arc 140T with this head, and passes with main and with this PR's earlier head. It looks like the same SHADER-74 interaction behind @kapitche's and @sovljanskii's 3 != 2 test failure, but on a GPU.

Intel Arc 140T, driver 32.0.101.8991, Windows 11, 32-lane subgroups pinned by crosslane_fuzz. Reduced from crosslane_fuzz --seed 91001 --dpp --no-maskdata --wave 32 --modes native, index 363, on the Intel with this head's translator:

s_mov_b32 s28, 0xe0a97906
s_mov_b32 s29, 0x8c638dcb
v_permlane16_b32 v2, v3, s28, s29
v_readfirstlane_b32 s14, v7

Wrong words, 3 runs each:

translator Intel Arc 140T RTX PRO 500 (581.95)
main 561b65a8 (no gate) 0 0
this PR at 8753aa73 (gate, before SHADER-74) 0 0
this PR at fccd6417 (gate + SHADER-74's FI=0 active-bit shuffle, 71d8f868) 448 0

The full 24-op program behaves the same way: 448 wrong words on the Intel at fccd6417, 0 at 8753aa73 and on main.

The emitted SPIR-V looks right to me, so this is probably the Intel driver. These are hand edits of the fccd6417 module for the reduced program, run on the Intel, 3 runs each:

  • As emitted (select(gate_shuffle == 1, permlane, old)): 448 wrong words.
  • Non-colliding salt. The gate's flag select(active, 1, 0) is the same value as SHADER-74's active-bit flag, so I tried salt 0xF1B0C746: still 448.
  • Gate shuffle left in, its result unused (select(active, …)): 0.
  • Gate as Ballot(active) + BallotBitExtract at the lane's own index instead of the self shuffle: 0 on the Intel, 0 on the RTX.

So on this Intel driver, it isn't the salt value. The problem shows up when the self-shuffle's result gates the write, after a permlane that has SHADER-74's second shuffle. I haven't checked whether the ballot form brings back the merged-ballot problem you found with seed 70102 on 580.65.06. On 581.95, cs_w32_writelane_permlane_exec0 passes even without any gate, so this card can't tell.

The words @cynbun asked for (RTX PRO 500, 581.95, translator at fccd6417, the two seed-91001 DPP programs, full 24 ops). Both of your readings hold:

  • cs_xl32_9100373366: 32 wrong words, all v4, lanes 0–31 of wave 0 (e.g. lane 0: expected 0xad6bdadc, got 0x72b0910c). That's the dpp8 … fi:1 write under EXEC = 0, the case you're folding into this PR.
  • cs_xl32_9100374034: 24 wrong words, all v2, lanes 0–3 and 16–19 of each of the 3 waves (e.g. lane 0: expected 0xe01555b2, got 0x3fa1c80c). That's bank 0 written despite bank_mask:0xe, the row/bank-mask case.

On the bank-mask case: in a local experiment, reading the whole DPP write condition (EXEC && row/bank && valid source) back through gate_after_subgroup fixed both programs on the RTX (5/5 runs). Gating only EXEC after the shuffle and ANDing the row/bank guard afterwards leaves the guard computed before the shuffle. I haven't run that variant on the RTX yet. I'll test #6270 on this card next.

AI-assisted (Claude Code). Synthetic programs only, no game files.

… the subgroup write gate (NVIDIA 580.65.06)

On the RTX 5080 (Linux 580.65.06), select(lane == 0, shuffle(v4, 7), v6) gave the shuffle to every
lane: a v_readlane_b32 result written by v_writelane_b32 v6, s13, 0 reached all of v6
(crosslane_fuzz --dpp --ext --no-maskdata, seed 2031, cs_xl32_203106417). The lane test now goes
through gate_after_subgroup, like the EXEC gate of a permlane/swizzle write.

GPU fixture cs_w32_readlane_writelane fails on the 5080 without the change and passes with it.
The CPU gate test follows a value through an eager() copy, so it also holds with ItsNotRexed#6249's eager
permlane shuffles. The DPP writes are left to ItsNotRexed#6270 (SHADER-1035).
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @kapitche for catching this, and @thiefyzheng for the breakdown of the three shuffles and the test_ds_swizzle_b32 attribution, @sovljanskii for the heads-up on #6249, and @leozinhoszg for the Intel and RTX PRO 500 runs.

Cause. Neither failure is in the translator. Since main's SHADER-74 change, a v_permlane16/x16_b32 with FI=0 (no op_sel) emits three OpGroupNonUniformShuffle instead of two. They are the data shuffle, the source lane's active-bit shuffle, and this PR's gate, which reads the lane's own EXEC bit. Two tests counted shuffles:

  • test_subgroup_writeback_gate expected two shuffles and read the permlane value straight from the data shuffle.
  • test_ds_swizzle_b32's negative control replaced every shuffle (2 != 1). Its third sabotage looked for the %active load in front of the write mask, but with the gate that mask now comes from the post-shuffle EXEC read.

Fix (1accd7e, tests only):

Extension (351e510): our fuzz campaign on the RTX 5080 (Linux 580.65.06, crosslane_fuzz --dpp --ext --no-maskdata) found one more form that still failed with the gate.

  • In cs_xl32_203106417, v_readlane_b32 s13, v4, 7 was followed by v_writelane_b32 v6, s13, 0, and every lane of v6 ended up with s13. A bare select(lane == 0, shuffle(v4, 7), v6) fails the same way, with no EXEC in it.
  • A native v_writelane_b32 now reads its lane test back through gate_after_subgroup. That makes one more own-lane shuffle per writelane; --wave64-emulate is unchanged.
  • Pinned on the GPU by cs_w32_readlane_writelane. On the 5080 it fails without the change (every word 0x9b75597d) and passes with it. Pinned on the CPU by test_writelane_of_a_readlane_reads_its_lane_test_after_the_shuffle.
  • The DPP case (cs_xl32_205106247, DPP8 fi:1 under EXEC = 0) is left to rdna2spirv: gate a DPP write like the other subgroup writes (SHADER-1035) #6270, which changes the same dst() line. Its translator change merges cleanly with this branch. The only conflicts are the neighbouring rows added to check.py and the docs, and they are easy to resolve.

Evidence on the RTX 5080 (Linux 580.65.06):

  • cs_xl32_203106417 failed and now matches.
  • scripts/run_gpu_tests.py native: 186/235 passed, 48 skipped. The one failure, ms_wave_info_s3, fails the same way with this PR's previous head.
  • crosslane_fuzz --wave both --modes native,emulate --dpp --ext --no-maskdata --programs 2000 --seed 4233: wave32 native 999 match, 0 mismatch, 1 hyp_only; wave64 emulate 1000 match, 0 mismatch. This run used the change plus a DPP8 gate that is now left to rdna2spirv: gate a DPP write like the other subgroup writes (SHADER-1035) #6270. The previous head gave the same counts on this seed, so the seed does not separate the two.

Seed 91001 programs 363 and 1031 (wave32 native, RTX 5080):

@leozinhoszg's Intel Arc 140T regression (363 reduced to v_permlane16_b32 v2, v3, s28, s29 + v_readfirstlane_b32 s14, v7):

  • With this head's translator it matches in tests/semantic/spirv_wave_interp.py and on the RTX 5080. Lavapipe can't run it, because it has no 32-lane subgroups.
  • So the module looks valid and this looks like an Intel driver problem with the self-shuffle gate after SHADER-74's second shuffle. This change doesn't fix it.
  • The ballot form you tested is the one that NVIDIA 580.65.06 merges (seed 70102, cs_w32_writelane_permlane_exec0). I don't want to switch to it without a run on the 5080. A gate form that works on both drivers is still open.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up with the GPU numbers at 351e5102, on an RTX 4090 (Linux, NVIDIA 595.112.07), main vs this branch:

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

crosslane_fuzz --wave both --modes native,emulate --dpp --ext --no-maskdata --programs 2000 --seed 4233 on an RTX 3090 (Linux 570.211.01), with the same vk_compute_test for both runs:

translator wave32 native wave64 emulate
main 561b65a8 1000 match, 0 mismatch 1000 match, 0 mismatch
this branch 351e5102 1000 match, 0 mismatch 1000 match, 0 mismatch

The gate changes nothing on a driver without the miscompile: no mismatch, no hypothesis-only result, nothing rejected or skipped. This card can't show the fix itself; that needs Linux 580.x on an RTX 50, where cs_w32_readlane_writelane and the seed 2031 program were the proof (see above).

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.