Skip to content

rdna2spirv: wave64 emulation clears and frees %x_buf with one writer per word (SHADER-708, data race under GPU-assisted validation) - #4247

Open
zzEmmazz wants to merge 4 commits into
ItsNotRexed:mainfrom
zzEmmazz:shader-708-wave64-clear-race
Open

zzEmmazz wants to merge 4 commits into
ItsNotRexed:mainfrom
zzEmmazz:shader-708-wave64-clear-race

Conversation

@zzEmmazz

Copy link
Copy Markdown
Contributor

SHADER-708, claimed in the coordination issue: #3796 (comment)

What and why

--wave64-emulate keeps its exchange buffer %x_buf in Workgroup memory and clears parts of it with plain OpStores. On main several invocations store to one word with no barrier between them. Every such store writes 0, but two unordered plain stores to one word are a data race by the SPIR-V memory rules, and GPU-assisted validation reports SharedMemoryDataRace-RaceOnStore on every emulated compute shader (@Vonsek's finding).

Since #2089 (structured emulation) the racing stores are in four places of tools/rdna2spirv.py, not two:

Place What raced
x_prologue, the clear before the first barrier the index was clamped with UMin, so every invocation past the end of a range stored to the range's last word (64 invocations and 12 words: invocations 11 to 63 all stored to word 11)
x_round_loop_head, the start of a round of the round loop lane 0 of a wave frees the wave's mask words and invocation 0 the counts; every other invocation stored 0 to a shared "sink" word, the last word of the buffer
x_mini_scheduler, a local round loop of structured emulation the same sink stores
Gen._ensure_x_pre_fn, the %x_pre_*_fn helper functions of the inline exchange the same sink stores

All four now have one writer per word, still as plain stores:

  • First clear: invocation i stores word i of each row of a range (x_clear_ranges, x_clear_rows). A last row shorter than the workgroup is stored only by the invocations that have a word in it (OpULessThan and a selection).
  • Start of a round, in all three forms: the selects that sent the other invocations to the sink are two selections (lane 0 of the wave, invocation 0), and the others store nothing. The helper functions therefore have more than one block.

Every selection ends before the OpControlBarrier that follows, so the barriers stay in uniform control flow. The last word of %x_buf is no longer written but stays allocated, so the buffer keeps its size (2·L + 6·W + 7 dwords) and the SHADER-309 numbers do not move. Without --wave64-emulate no module changes.

The first version of this change covered the first three places only; GPU-assisted validation then still reported the 7 fixtures that are translated in structured mode, which is how the fourth was found. To make sure there is no fifth, every access to %x_buf the translator emits was listed with who can run it between two barriers (twelve kinds: the four clears, the lane's own data slot, the atomics on the masks and counts, the loads after a barrier, and the wave32 barrier rounds, which were already right). In every mode an interval between two barriers has plain loads of the round before, atomics on the current slot, and plain stores only to the next slot by its one owner and to the lane's own data word.

Two changes to an existing test file come with it (tests/semantic/test_wave64_emulate_opt.py): its inliner of helper functions skipped every OpLabel, which only works for one-block helpers, and now keeps the labels of the other blocks; and its lockstep interpreter fails when two invocations plain-store one %x_buf word between two barriers, or one plain-stores a word another loads or updates.

Measured

Windows 11 (26200), Vulkan SDK 1.4.363 (validation layer from the SDK), test programs built from main aa2988cc. Two GPUs, picked with LEONIDA_VK_DEVICE: Ryzen 7 9700X iGPU (Radeon gfx1036, AMD 32.0.21042.62, subgroup 32..64) and RTX 3070 (NVIDIA 610.74, subgroup 32). Before = main aa2988cc.

GPU-assisted validation, the GPU fixtures. vk_compute_test creates its instance without layers, so the layer is loaded from the environment (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1), then vk_compute_test <module>.spv 1 dump for each of the 35 compute fixtures that have a %x_buf under LEONIDA_W64_EMULATE=1:

Radeon iGPU RTX 3070
before: modules with a race report 32 of 35 32 of 35
before: SharedMemoryDataRace-RaceOnStore reports 192 192
after: modules with a race report 0 0
after: any validation error 0 0

The 32 are the emulated ones (25 in rounds, 7 structured), 6 reports each, which is the most the layer gave in any run. The other three are the wave32 cs_barrier_* fixtures, whose three words already had one writer.

GPU fixture suite. scripts/run_gpu_tests.py, 214 shaders translated and spirv-val-valid before and after; every test has the same result line before and after:

before after
Radeon, native 195/210, 15 skipped 195/210, 15 skipped
Radeon, LEONIDA_W64_EMULATE=1 195/210, 15 skipped 195/210, 15 skipped
RTX 3070, native 164/210, 46 skipped 164/210, 46 skipped
RTX 3070, LEONIDA_W64_EMULATE=1 195/210, 15 skipped 195/210, 15 skipped

Random programs. tools/crosslane_fuzz.py --wave 64 --modes emulate --no-maskdata, five batches (seeds 1 to 4 and 11, with and without --dpp, 12 to 40 ops; one batch with the workgroup sizes replaced by 1, 3, 7, 31, 33, 63, 65, 96, 127, 129, 200, 250 and 320), 2,390 programs, each translated by both translators and run on both GPUs:

  • With the fix: all 2,390 either match the model or are hypothesis-only on both GPUs, with byte-identical dumps between the two GPUs. No mismatch, no rejected program, no harness error.
  • Before and after agree in outcome and dump bytes for 2,388 of the 2,390 on each GPU. The other two are below.
  • Under GPU-assisted validation, seed 1 (500 modules, 410 structured and 90 in rounds): before, 500 of 500 modules report on each GPU (3,000 reports); after, 0 of 500 on each GPU and no other validation error. After only: seed 2 (500 modules) and the batch with the odd workgroup sizes (390 modules) give 0 reports on each GPU.
  • tools/lds_fuzz.py --wave 64 --emulate (LDS and s_barrier), 69 translated programs: on the RTX 3070 69 of 69 match on both sides with identical dumps, and under validation 69 of 69 report before and 0 after. On the Radeon 47 of the 69 crash vk_compute_test (0xC0000005) before and after alike, not looked into here; the 22 that run match.
  • Native mode: the 500 seed-1 programs translated without --wave64-emulate are byte-identical before and after.

Two programs where main's module misbehaves and this one does not. Cause not established for either; they are reported as observed, not as something this change is known to repair.

  • On the Radeon, a 7-op program (the 11 instructions below, after the fuzzer's prologue) gives s8 = 0x40 instead of 0x39 in every thread but thread 0 when the workgroup has 5 to 11 or 16 invocations: bcnt0 of a v_cmp mask reads the mask as all zero. It is right at 12, 13, 14, 31, 33, 40 and 64 invocations, right on the RTX 3070 at the sizes tried (7, 8, 11, 12, 16, 64), and right with this change at every size tried on both GPUs. The racing stores alone do not explain it: main's module with every zero store to %x_buf made an OpAtomicStore (no race report left) is still wrong on the Radeon, and main's module run under the validation layer is right. So it looks like the AMD compiler and the OpSelect-indexed or UMin-clamped store, which this change no longer emits; that is a hypothesis.

    v_cmp_ne_u32_e64 s[18:19], v2, v6
    s_bcnt0_i32_b64 s8, s[18:19]
    s_ff1_i32_b64 s11, exec
    s_xor_b64 s[20:21], s[18:19], s[18:19]
    v_readfirstlane_b32 s14, v6
    s_cbranch_execz @0
    v_mbcnt_lo_u32_b32 v3, s20, v3
    v_mbcnt_hi_u32_b32 v3, s21, v3
    ;@END0
    s_mov_b32 s28, 4
    v_readlane_b32 s11, v1, s28
    
  • On the RTX 3070, one 40-op program (seed 3, 100 invocations, structured) loses the device with main's module (vkQueueWaitIdle returns -4, 10 runs of 10) and gives the right dump with this change (10 of 10) and with either module on the Radeon. Not minimised, since every failing run makes the driver log an error.

Mesh shaders. The layer checks this in compute shaders only (its gpuav_shared_memory_data_race setting says "Compute shaders only"), so it is silent on a mesh stage before and after. The six mesh fixtures run as compute stages (LEONIDA_MESH_COMPUTE=1) do report, but a second store uses up the layer's 6 reports: OpStore %ms_counts (s_sendmsg(MSG_GS_ALLOC_REQ)), which every invocation of a mesh shader makes whether emulated or not. With that one store made atomic in scratch copies of the modules, the six fixtures report %x_buf before and nothing after, on both GPUs. %ms_counts is not part of this change; it is posted as a finding. The six mesh fixtures pass before and after on both GPUs, as mesh stages and as compute stages.

Corpus. My copy of the package (26,503 carved shaders), translated with --wave64-emulate by both translators: every wave64 compute and mesh shader, which is every shader this change can touch, and a quarter of the rest (two 1-in-8 slices of the other 16,067).

shaders translated, before / after spirv-val-valid, before / after
wave64 compute and mesh 10,436 10,436 / 10,436 10,428 / 10,428
other shaders, the two slices 4,017 4,017 / 4,017 4,011 / 4,011
  • No shader translates or validates on one side only, and index.json is the same on both sides for every entry. The 14 invalid modules fail on both sides with the same message, an OpTypeArray that names a constant with no definition, which this change does not touch (it looks like what Translator: constants assemble asks for late are defined too #3902 is about).
  • All 10,428 valid emulated modules change (220 compute in rounds, 926 compute structured, 9,282 mesh in rounds); all 4,011 valid modules of the slices are byte-identical.
  • Over the emitted text of the 10,436 emulated modules, plain stores into %x_buf whose index is an OpSelect with a constant alternative (the sink): 45,724 before, 0 after; with a UMin-clamped index: 19,166 before, 0 after. After, every zero store is a first-clear row or sits in the true arm of a lane-0 or invocation-0 test, and in every module the first-clear rows are pairwise disjoint and cover exactly the ranges to clear (99 modules have a partial last wave).
  • Size of the emulated modules: 4,817,763,524 to 4,817,586,564 bytes (-0.004%); the median module grows by 16 bytes, the largest growth is 136 bytes, and 96 compute modules shrink.
  • GPU-assisted validation of game modules, Radeon only, the 48 smallest emulated compute modules run without their real inputs (so with the layer's address check off, which otherwise uses up its 6 reports): 24 dispatch; before, 18 of the 24 report a race and the other 6 have a 1x1x1 workgroup; after, 0 of 24 report and there is no validation error of any kind.

Not run: the other 12,050 non-emulated shaders, and any run without --wave64-emulate.

Cost. scripts/bench_wave64.py, 6 runs a side, alternating, while other jobs used both GPUs. Median of the run medians, in ms:

Shader (mode) GPU before after
cs_bench_mix (structured) Radeon, emulated 2.904 3.004 +3.4%, outside the noise (the native control moved +1.1%)
cs_w64x_ballot (rounds) Radeon, emulated 19.787 19.483 -1.5%, outside the noise
cs_bench_mix (structured) RTX 3070, emulated 1.374 1.438 inside the noise (run medians bimodal on both sides)
cs_w64x_ballot (rounds) RTX 3070, emulated 4.497 4.374 inside the noise

Module size over the 32 emulated compute fixtures: 867,416 to 868,052 bytes (+0.07%), at most +64 bytes for one module.

Tested

  • python -m unittest discover -s tests/semantic: 7,461 tests; 10 fail, in test_loop_ballot_barrier.py (5), test_cmp_class_f64.py (2), test_mutations.py (2) and test_vcmp16_opsel.py (1). The same four files give the same counts on main aa2988cc alone.
  • tests/semantic/test_w64x_clear_single_writer.py (new, 11 tests) and tests/semantic/test_wave64_emulate_opt.py (22 tests): OK. With main's translator (LEONIDA_TOOLS_DIR) 37 checks of the first and 23 of the second fail.
  • One translator copy per place with main's code put back in that place only: each of the four makes both files fail, and so does each half of a place (mask words or counts, one wave or several).
  • tests/semantic/test_cs_shared_memory_limit.py: 15 tests OK.
  • python -m pytest tests/test_translate.py tests/test_crosslane_fuzz.py tests/test_lds_fuzz.py tests/test_valu_fuzz.py tests/test_bench_wave64.py tests/test_mesh_compute.py tests/test_partial_wave_subgroup.py tests/test_wave64_halves_fixtures.py tests/test_run_gpu_tests.py tests/test_run_gpu_wavemask.py tests/test_fssm_wave_size.py: 839 passed, 11 skipped, 0 failed (before the last test-only commit). python -I tests/test_shader_checks.py: 75 tests OK.
  • spirv-val --target-env vulkan1.3 on the 38 emulated fixture modules (32 compute, 6 mesh): 38 valid before and after.
  • python -I tests/test_docs_links.py, test_docs_repo_paths.py, test_docs_list_items.py, test_docs_design_rows.py, test_text_write_line_endings.py: OK.

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.

Not checked: Linux, RADV, Intel and MoltenVK; the cause of the two main-only failures above; a mesh shader in structured mode (the six fixtures and the test program are all translated in rounds); race checking of a real mesh stage on a GPU, which the layer does not do; the benchmark on more than one shader per mode. One known gap in the tests: leaving out the counts clear of the helper functions for several waves (no race, a slot reused without being freed) passes every test; read, the worst it does is one extra round.

AI-assisted.

@SweatierKey

Copy link
Copy Markdown
Contributor

Tested 5f16276d on Linux (WSL2, Python 3.13.5, spirv-as/spirv-val, CPU only, no GPU, no game files): pass.

  • Code read (tools/rdna2spirv.py):
    • x_clear_ranges + x_clear_rows partition the initial %x_buf zeroing cleanly into disjoint per-invocation stores (%x_li < owners guard on partial last rows), eliminating multi-writer races on the clamped tail word.
    • _ensure_x_pre_fn (clear_if), x_round_loop_head, and x_mini_scheduler replace the shared x_sink store with guarded conditional stores (%x_lane == 0 for wave mask words, %x_li == 0 for schedule words), keeping the %x_buf size unchanged while removing the SharedMemoryDataRace-RaceOnStore race.
    • assemble() registers every base + off and owners constant needed by x_prologue.
  • Red/green & validation (clean worktree on aa2988cc):
    • Red on main: applying only tests/semantic/test_w64x_clear_single_writer.py fails as expected (18 failures, 20 errors catching the multi-writer stores before the first barrier and on the shared sink).
    • Green on 5f16276d: test_w64x_clear_single_writer.py (11/11 OK, including spirv-val and negative sabotage controls) and test_wave64_emulate_opt.py (all pass).
    • 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: Vulkan GPU-assisted validation on hardware (LEONIDA_VK_VALIDATION=1).

AI-assisted review.

@MKmajster

Copy link
Copy Markdown

Tested 5f16276 on NVIDIA GeForce RTX 3070 (32-wide subgroups, so --wave64-emulate is the path wave64 code takes here), driver 617.42, Windows 11 24H2. The race reports are gone and nothing else changes.

GPU-assisted validation (VK_LAYER_KHRONOS_validation 1.4.350 with gpuav_enable, gpuav_shader_instrumentation and gpuav_shared_memory_data_race on). The first 12 emulated wave64 compute fixtures (cs_w64x_andn2_exec, _ballot, _bpermute, _branch, _chain_barrier, _lds_raw, _lds_war, _load_ballot_load, _mask_reuse, _mask_reuse2, _partial, _partial_scmp) were each run with vk_compute_test ... 1 dump, VKC_SUBGROUP_SIZE=32:

translator runs exit 0 SharedMemoryDataRace-RaceOnStore other VUIDs
main aa2988c 12/12 72 0
this branch 12/12 0 0

No result change, with LEONIDA_W64_EMULATE=1 and this branch's tools/ vs main's on the same runtime build:

  • run_gpu_tests.py: 195/210 passed, 15 skipped on both, all 210 result lines identical;
  • valu_fuzz --family mem --wave 64 --emulate, valu_fuzz --family f16 --wave 64 --emulate and lds_fuzz --wave 64 --emulate (seed 11, 120 programs each): 120/120 match on both.

No game files. AI-assisted (Claude).

@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 5f16276d against aa2988cc on an AMD Radeon RX 6800 (AMD 26.11.2 / 32.0.21045.29003, Vulkan 1.4.315, Windows 11 Pro build 26300).

With LEONIDA_W64_EMULATE=1, build.py translated all four selected synthetic fixtures and spirv-val accepted them on both commits. vk_compute_test <module> 1 dump with Khronos validation 1.4.363.0 and VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1 reported 6 SharedMemoryDataRace-RaceOnStore errors per fixture on base for cs_w64x_ballot, cs_w64x_bpermute, and cs_w64x_wg128_branches (18 total). This head reported 0 races and 0 validation errors across the three. The first eight words in each readback matched. The wave32 cs_barrier_loop control reported 0 validation errors on base.

Each dispatch completed and printed its readback. The process hung at shutdown with the validation layer loaded, including the control with GPU-assisted validation disabled, so the wrapper timed it out after collecting the output.

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

@CaravelaLabs

Copy link
Copy Markdown
Contributor

Automated test: 5f16276d merged onto main aa2988cc on AMD Radeon 8060S (RADV GFX1151, RDNA 3.5), Mesa 25.2.8, Ubuntu 24.04, runtime rebuilt from this branch in a clean sandbox. Result: pass.

  • scripts/run_gpu_tests.py: 192/209 passed, 15 skipped (plain main: 192/209 passed, 15 skipped).
  • Python tests this PR touches: 33 passed, 60 subtests passed.

Same machine and setup as my earlier manual reports. AI-assisted (Claude Code).

@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 this at 5f16276d on Windows 11:

  • tests/semantic/test_w64x_clear_single_writer.py -> 11 tests, OK.
  • tests/semantic/test_wave64_emulate_opt.py -> 22 tests, OK.
  • compileall and git diff --check clean.

The new tests pin every clear of %x_buf to one writer per word (including the x_buf free paths), and the CFG analysis cases still pass. The PR is a dependency of #4314; no blocking issue.

@lunarminus

Copy link
Copy Markdown

Tested 5f16276d (base aa2988cc) on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux, with Khronos validation layers from Arch's vulkan-validation-layers. Result: pass. The translator change looks right. One test-interpreter issue is below.

GPU-assisted validation. I ran every cs_* fixture whose module has Workgroup memory as vk_compute_test <module>.spv 1 dump, with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1, under LEONIDA_W64_EMULATE=1, with each tree's own test programs. 104 modules:

modules with a race report race reports
aa2988cc 38 213
this PR 6 21
  • The 6 left on the PR report identically on main. They are native wave32 fixtures with no barrier and no %x_buf: cs_w32_lds_subdword, cs_w32_lds_u8_d16 and cs_w32_lds_wide (6 each), and cs_w32_new_ops, cs_w32_misc_ext and cs_lds_b64_cmpst (1 each).
  • cs_w32_lds_subdword has every lane write the same bytes to the same address on purpose ("Every lane writes the same bytes"). So these reports come from the fixtures' design, not from this PR.
  • Leaving those 6 out, it's 32 racy modules before and 0 after, the same as your Radeon and RTX numbers. No validation error was new on the PR, and no module exited non-zero.

GPU suite. scripts/run_gpu_tests.py gives 196/210 passed, 14 skipped, 0 failed, both native and with LEONIDA_W64_EMULATE=1. Each is identical per test to aa2988cc on the same machine.

Full corpus, --wave64-emulate (my own 1.0.2.1 copy, CPU, counts only): rdna2spirv.py --shard i/8 --wave64-emulate over all 26,503 listings, aa2988cc vs this PR.

  • Both: 26,503 translated and 26,473 spirv-val-valid. The invalid set is identical, all of it the known aa2988cc "requires a previous definition" regression (Translator: constants assemble asks for late are defined too #3902).
  • The PR changes 10,428 modules: 9,282 MS and 1,146 CS. That is exactly the set of modules whose emulated output differs from the native one on aa2988cc (10,377), plus the 51 that only emulation makes valid on aa2988cc. No other module changes.

Code read (independent, CPU, synthetic programs only).

  • Translator:
    • The four sites have one writer per word.
    • A short last row is guarded by li < owners, which also covers workgroups smaller than the word count (1, 8, 12).
    • The old sink word is no longer read or written but stays allocated.
    • Every new selection closes before the next OpControlBarrier.
    • Rounds-mode modules at sizes 1, 3, 11, 12, 13, 31, 33, 63, 65, 96, 127, 129, 256, 320, 1000 and 1024, and your structured programs at 3–63 and 65–1024, all pass spirv-val. In the new race-checking interpreter they give the expected results in both invocation orders.
  • One problem, in the test interpreter (tests/semantic/test_wave64_emulate_opt.py ~165–174), not the translator.
    • What goes wrong. The inliner now keeps a multi-block helper's inner labels (%fc<N>_<id>). So after an inlined %x_pre_*_fn call, the interpreter's current label is the helper's merge label, not the caller's block. In SPIR-V a call doesn't split the block, and the translator's OpPhis correctly name the caller's block (%blk2). Any OpPhi whose predecessor is a block that calls a multi-block helper therefore asserts: OpPhi prev_lbl='%fc2_t131' not in %t265 = OpPhi %uint %t264 %t261_do %c0 %blk2.
    • Repro. A structured-mode diamond with a live-out SGPR, then an inline exchange (v_readfirstlane_b32), then v_cmp_gt_u32 vcc, 8, v0 / s_and_b64 exec, exec, vcc / buffer_load_dword in the same block. It fails at 64 threads (inline_all) and 128 (structured_hybrid). The modules pass spirv-val, and the same probe passes on aa2988cc, where the helper had one block.
    • Impact. None of the PR's tests have that shape, so the suite is green (180 OK). The next test with a partial-EXEC guarded access after an inline exchange would get a false failure, though.
    • Suggested fix. While inlining, map the helper's last label back to the caller's current label for OpPhi matching.

AI-assisted (Claude Code).

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 5f16276 (merge base main aa2988c) on NVIDIA GeForce RTX 5080, Linux 580.65.06, with GPU-assisted validation (Khronos validation layer, SDK 1.4.363.1): pass

Result: the SharedMemoryDataRace-RaceOnStore reports on the wave64-emulated %x_buf are reproduced on main and gone with this change. The suite is unchanged.

Setup. Test programs built once from main 03b09a08 (differs from the merge base only in vk_pipeline_check and large_module_gate, not used here): cmake -S runtime -B runtime/build/v -G Ninja -DCMAKE_BUILD_TYPE=Release -DVulkan_INCLUDE_DIR=$SDK/include -DLEONIDA_VULKAN_HEADERS_FETCH=OFF, cmake --build runtime/build/v -j8. Sanity: LEONIDA_VK_VALIDATION=1 vk_queue_test prints validation errors: 0. One git worktree per revision (aa2988cc for "before", the PR head for "after"); tools/ and scripts/ come from the worktree, the binaries are shared. Layer from SDK 1.4.363.1 (VK_LAYER_PATH); gpuav_shared_memory_data_race is on by default in this layer.

Compute fixtures under GPU-AV. Translate with LEONIDA_W64_EMULATE=1 run_gpu_tests.py --work W, then for each of the 104 W/spirv/cs_*.spv: VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1 vk_compute_test X.spv 1 dump, and count SharedMemoryDataRace messages in its output (the layer prints at most 6 per run).

compute fixtures, LEONIDA_W64_EMULATE=1, GPU-AV merge base aa2988cc #4247 5f16276d
modules with RaceOnStore on %x_buf 32 of 104 0
SharedMemoryDataRace reports on those 32 192 (6 each, the layer's cap) 0
validation errors of any kind on those 32 192 0
every other module (72) same same, per module

The 32 modules: cs_bench_mix, cs_dpp_w64, cs_exec64, cs_w64_mask_detect, cs_w64_mask_imm, cs_w64x_andn2_exec, cs_w64x_ballot, cs_w64x_bpermute, cs_w64x_branch, cs_w64x_chain_barrier, cs_w64x_lds_raw, cs_w64x_lds_war, cs_w64x_load_ballot_load, cs_w64x_mask_reuse, cs_w64x_mask_reuse2, cs_w64x_partial, cs_w64x_partial_scmp, cs_w64x_permute, cs_w64x_readfirstlane, cs_w64x_readlane, cs_w64x_saveexec_b64, cs_w64x_sbarrier, cs_w64x_wg128_branches, cs_w64x_writelane, cs_wave64_ballot, cs_wavemask, cs_wm_bfm64, cs_wm_half_cmp, cs_wm_half_ops, cs_wm_scc_rfl, cs_wqm_w64, cs_wqm_w64_half.

The 6 modules that still report after the change are the same 6 before, with the same counts, and are not %x_buf: cs_w32_lds_subdword (1 RaceOnLoadStoreVsAtomic + 5 RaceOnStore), cs_w32_lds_u8_d16 and cs_w32_lds_wide (1 RaceOnLoad + 5 RaceOnStore each), cs_lds_b64_cmpst, cs_w32_misc_ext, cs_w32_new_ops (1 RaceOnLoadStoreVsAtomic each). They are plain LDS accesses of those fixtures, not this PR's subject.

I compared the error count of every one of the 104 modules before and after: only the 32 above change.

Suite, no validation (python -I scripts/run_gpu_tests.py --build runtime/build/v --llvm-mc /usr/lib/llvm-21/bin/llvm-mc, once as is and once with LEONIDA_W64_EMULATE=1):

merge base PR head
native 164/210, 46 skipped, 0 failed 164/210, 46 skipped, 0 failed
LEONIDA_W64_EMULATE=1 195/210, 15 skipped, 0 failed 195/210, 15 skipped, 0 failed

Every one of the 210 result lines is the same before and after (compared after removing the work-folder path).

Mesh as compute (not what this PR targets, for the record). %ms_counts reports are untouched, as expected (that is SHADER-766): 6 per fixture before and after in both LEONIDA_MESH_COMPUTE=1 and LEONIDA_MESH_COMPUTE=1 LEONIDA_W64_EMULATE=1 (36 each).

Without validation, the emulated race shows up as wrong output on this GPU. LEONIDA_MESH_COMPUTE=1 LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py --filter ms_, four runs each:

result
merge base 4/6 in all 4 runs: ms_v5_workgroup (23/24 mismatches, first at (1,0,0): got (0,33,63,1), want (32,33,63,1)) and ms_wave_info_s3 (blue 0.0, want 0.5: its LDS check fails) fail
#4247 6/6 in all 4 runs

Same four runs with the two fixtures of #4298 applied on top (5079b487): merge base 4/6 (ms_tri and ms_v5_workgroup fail), #4247 6/6. Under GPU-AV the same fixtures pass on the merge base too (the layer's instrumentation changes the timing), so the layer run and the plain run answer different questions. I did not bisect which of the four clears causes the failures; the change fixes them as a whole.

Also run: python -I tests/semantic/test_w64x_clear_single_writer.py (11 tests) and tests/semantic/test_wave64_emulate_opt.py (22 tests): OK.

Not tested: other GPUs or drivers; the Windows runtime; the translated game corpus (only the 210 fixtures); --wave64-emulate on graphics stages; LEONIDA_BARY_FALLBACK, LEONIDA_PC_TAIL_UBO; synchronization validation (VALIDATE_SYNC); the rest of tests/.

AI-assisted. No game files.

docs/design.md: the SHADER-309 row is main's (SHADER-579 moved the barrier-round counts), the SHADER-708 row stays
above it.

tests/semantic/test_w64x_clear_single_writer.py: the planner now joins the two sides of a branch that each end the
program into one tail scheduler (70e739f), so the program of test_tail_scheduler_after_a_mini_scheduler had no mini
scheduler left. It gets a loop of its own in front, which every wave runs three times.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@zzEmmazz

Copy link
Copy Markdown
Contributor Author

Merged main 7b7d73f8 (head 13c732c3); it also merges cleanly with main 0db7fed5.

What conflicted. docs/design.md only: main rewrote the SHADER-309 row (SHADER-579), which is the row under this one. main's row is taken as it is; the SHADER-708 row is unchanged. tools/rdna2spirv.py merged without conflict, and SHADER-579 touches the barrier-round counts of shaders that are not emulated, not the exchange clears.

One test program changed. 70e739fd on main makes the planner join the two sides of a branch that each end the program into one tail scheduler, so the program of test_tail_scheduler_after_a_mini_scheduler no longer had a mini scheduler (7 of the file's checks failed on the merged tree, all on that plan, none on a clear). The program now has a loop of its own in front, which every wave runs three times: plan inline_block, mini_scheduler, inline_block, tail_scheduler. The translator change is as it was.

Re-run on the merged tree (Windows 11, Ryzen 7 9700X iGPU, Radeon gfx1036, AMD 32.0.21042.62; test programs still the aa2988cc build):

main 7b7d73f8 merged
tests/semantic, whole suite 6,245 tests: 3 failures, 3 errors 6,256 tests: the same 3 failures and 3 errors
test_w64x_clear_single_writer.py 37 checks fail with main's translator 11 tests OK
test_wave64_emulate_opt.py 23 checks fail with main's translator 22 tests OK
run_gpu_tests.py, native 221 translated, 221 valid, 197/217 pass the same, every result line identical
run_gpu_tests.py, LEONIDA_W64_EMULATE=1 221 / 221, 197/217 pass the same, every result line identical
GPU-assisted validation, 35 emulated compute modules 32 with SharedMemoryDataRace, 192 reports 0 reports, 0 validation errors

The 6 semantic failures are in test_divergent_loop_wave64_emulate_and_native_cs (3), test_bug4b_loop_carried_split_sgpr_pair_ballot, test_nested_divergent_loops_emulate and test_spirv_val_compliance, the same on both sides. The 4 GPU failures on both sides (cs_bvh, cs_bvh32, ps_sample_c, ps_sample_c_b) are my test programs being older than main: two of them print the usage of vk_texture_test.

Not re-run after the merge: the RTX 3070, the corpus counts, the fuzz comparison and the cost measurement.

AI-assisted; measured on my PC.

@CryingLaughing

Copy link
Copy Markdown
Contributor

Tested 13c732c393c5fe61b03525d502c951a6ff7a6c00 on an NVIDIA GeForce RTX 4080 (32-wide subgroups, driver 621.01), Windows 11 build 26200.9974. I built vk_compute_test from the same revision with MSVC 19.44 and enabled Khronos validation 1.4.357, GPU-assisted instrumentation, shared-memory race checking, and synchronization validation.

  • 12/12 emulated wave64 dispatches passed. All 2,873 checked readback words matched. GPU-assisted validation reported zero SharedMemoryDataRace reports and zero validation errors. The layer emitted setup warnings only.
  • Five stock fixtures covered mask detection, a partial wave, a chained barrier, writelane, and 128-thread branching. Seven cases from test_w64x_clear_single_writer.py exercised full rounds, single-wave inline helpers, hybrid scheduling, back-to-back mini schedulers, and the rebased mini-to-tail sequence. The mini-to-tail cases used 65, 120, and 200 invocations, including an 8×5×3 workgroup. The readback check included the untouched padding in the seven generated cases.
  • spirv-val accepted all 12 modules. The two focused Python suites passed 33/33 tests.

All inputs were synthetic. AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 13c732c39 merged with main 3faac557b on Linux (WSL2), Python 3.12.16: pass.

  • test_w64x_clear_single_writer.py 11 tests OK and test_wave64_emulate_opt.py 22 tests OK; all 10 tests/test_docs_*.py OK.
  • Negative control: with main's tools/rdna2spirv.py and the PR's tests, test_w64x_clear_single_writer.py has 37 failures and test_wave64_emulate_opt.py 23 failures; restoring the PR file passes again.
  • Whole tests/semantic suite (397 files, run one process per file): 395 OK on this merge. The 2 files that fail (test_loop_ballot_barrier.py, test_vcmp16_opsel.py) fail the same way on a clean main worktree in this environment, so they are not caused by this PR.

@ItsNotRexed

Copy link
Copy Markdown
Owner

This was merged and then reverted on main. Since 70e739f (wave64_emulate_opt coalesces hoisted spine guards), tail_program comes out as one tail scheduler with no mini scheduler before it. So test_tail_scheduler_after_a_mini_scheduler and the interpreter check of the mini scheduler's clears fail after the merge, though they pass on this branch (based on aa2988c). Please rebase on main and pick a program that still makes a mini scheduler.

ItsNotRexed added a commit that referenced this pull request Nov 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/design.md
gregoirener pushed a commit to gregoirener/Leonida-latest-backup-Monday-23-nov-Japanese-time- that referenced this pull request Nov 23, 2026
…er that main's planner no longer makes

Since 70e739f (coalesce hoisted spine guards) the tail program is one tail scheduler, so
test_tail_scheduler_after_a_mini_scheduler and the interpreter check of the mini scheduler's clears fail after the
merge, though they pass on the branch (based on aa2988c).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
evilclanker9000 pushed a commit to evilclanker9000/Leonida that referenced this pull request Nov 23, 2026
Exercise the round scheduler with both waves sending the allocation, and
the structured scheduler with only wave 1 sending before wave 0 exports.
Both fixtures keep the existing full-frame gradient expectation.

Refs: ItsNotRexed#4247, ItsNotRexed#4084
… applied again

main merged this branch at 5f16276 and reverted it (ab1c07e), so a plain
merge of main takes the revert and drops the change from tools/rdna2spirv.py,
tests/semantic/README.md and tests/semantic/test_wave64_emulate_opt.py. They
are applied again on top of main's current files (three-way, no conflict).

Conflicts:
- tests/semantic/test_w64x_clear_single_writer.py: deleted by the revert, kept
  here. It is the version of 13c732c, whose tail program has a loop of its own
  so that the planner of 70e739f still makes a mini scheduler before the
  tail scheduler.
- docs/design.md: the SHADER-708 row kept, main's Workgroup memory limit row
  and its two new wave64 rows taken.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…e than one block (SHADER-708)

Since 60e63da the interpreter expands the %x_pre_*_fn helpers of structured
wave64 emulation inline and takes each for one block: it drops the labels and
keeps the instructions. With SHADER-708 such a helper branches (only the
invocation that owns a word clears it), so its branch targets were labels the
interpreter had dropped, and five subtests of this file ended in KeyError on
the merged tree.

A helper's first block now continues the caller's block, its other blocks
become blocks of %main under fresh labels, a return branches to a new block
holding what followed the call, and a phi of %main that named the split block
is reached from its last part. A helper of one block is inlined as before, so
the file gives the same results with main's translator.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@bielfreedom

Copy link
Copy Markdown

Tested 13c732c3 (base 7b7d73f8) on AMD RX 9070 XT (RDNA4, driver 32.0.32029.2010), Windows 11.

Full game corpus, 26,503 disassembled shaders, --wave64-emulate, compared with a translation at the base under the same flag:

  • translated and spirv-val valid: 26,503 / 26,503 on both sides;
  • 10,436 modules differ: 9,282 MS and 1,154 CS. the same count and stage split (9,282 MS + 1,154 CS) as the modules that change at the base itself when --wave64-emulate is turned on, so the PR touches only emulated modules;
  • index.json identical; total SPIR-V size ratio 1.0000 (rounded).

Without --wave64-emulate the output is byte-identical to the base, as expected for a change confined to the emulation path.

Tests: build OK; ctest 168/172. The 4 failures are present and swapchain tests that fail because the display was asleep (CreateSwapChainForHwnd 0x80004005). GPU suite 202/217, 15 skipped. In the semantic suite the only failures are the 5 in test_loop_ballot_barrier.py that main also has (fixed by #4727).

AI-assisted (Claude Code). Counts only.

No conflicts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@zzEmmazz

Copy link
Copy Markdown
Contributor Author

@ItsNotRexed done: main 1cc6e3c1 is merged in and the head is a03ac8c1.

What round 44 merged was 5f16276d, the head from before I had merged main myself. 13c732c3 (pushed a few hours before the round) already had what you ask for: tail_program has a loop of its own, so the planner of 70e739fd7 still makes a mini scheduler before the tail scheduler (inline_block, mini_scheduler, inline_block, tail_scheduler), and test_tail_scheduler_after_a_mini_scheduler and the interpreter check of the mini scheduler's clears pass on main's planner.

Two things were needed on top of that, both because of the revert and of round 44:

  • The revert. main has this branch merged and reverted, so a plain merge of main takes the revert and silently drops the change from tools/rdna2spirv.py, tests/semantic/README.md and tests/semantic/test_wave64_emulate_opt.py. They are applied again on top of main's current files (three-way, no conflict); the PR's diff against main is the full change again.
  • test_loop_ballot_barrier.py's interpreter. Since 60e63dae1 it expands the %x_pre_*_fn helpers inline and takes each for a single block. With this PR such a helper branches (only the invocation that owns a word clears it), so five subtests ended in KeyError on the merged tree. The interpreter now inlines a helper of several blocks as well (commit be4c31dd); a helper of one block is handled as before, and the file gives the same 15 OK with main's translator.

Measured on the merged tree, Windows 11, Python 3.14:

  • python -m unittest discover -s tests/semantic on this head: 5,832 tests OK (26 skipped), no failure or error. main 1cc6e3c1 alone was not run for comparison; on the earlier merge with 561b65a8 the suite was 6,161 tests OK against 6,150 OK on main alone (the 11 more are this PR's file).
  • test_w64x_clear_single_writer.py 11 OK, test_wave64_emulate_opt.py 29 OK, test_loop_ballot_barrier.py 15 OK. Negative control with main 1cc6e3c1's translator: 37 and 41 failures in the first two.
  • GPU, Radeon gfx1036 (AMD 32.0.21042.62), on the merge with 561b65a8 (the translator files are the same in the merge with 1cc6e3c1): scripts/run_gpu_tests.py 238 translated, 238 spirv-val-valid, 215 of 232 passed and 17 skipped, native and with LEONIDA_W64_EMULATE=1, every result line identical to main's. GPU-assisted validation on the 35 emulated compute modules: main 32 modules with SharedMemoryDataRace reports, 192 reports; this branch 0 reports and 0 validation errors.
  • test_docs_links.py, test_docs_repo_paths.py, test_docs_list_items.py, test_docs_design_rows.py: OK. test_text_write_line_endings.py fails on main 1cc6e3c1 itself (tools/f64_omod_probe.py:268, f64_omod_probe: pin newline="\n" when writing JSON report #6461), not from this branch.

Not re-run on this head: the RTX 3070, and the corpus (@bielfreedom ran all 26,503 shaders on 13c732c3: same counts as the base, only the emulated modules differ).

@Etr0p: this is the head to try for the ms_tri case from #5741 (mesh as compute plus wave64 emulation).

AI-assisted.

@lunarminus

Copy link
Copy Markdown

Re-checked a03ac8c1 (main 1cc6e3c1 merged) on CachyOS Linux, Python 3.14, CPU only.

  • tests/semantic/test_wave64_emulate_opt.py: 29 OK. test_w64x_clear_single_writer.py: 11 OK. test_loop_ballot_barrier.py: 15 OK.
  • The PR's tools/rdna2spirv.py change is identical to 5f16276d: diffing each against its own base gives 0 differing lines. So my GPU-assisted validation result above still describes it. On a Radeon 760M (RADV), the emulated fixtures with %x_buf race reports went from 32 to 0.
  • The test-interpreter OpPhi issue from my earlier comment still reproduces at this head. It's the same probe as before: a structured diamond with a live-out SGPR, an inline exchange, then an EXEC-guarded buffer_load with lanes 8+ off in the same block.
    • partial_load fails at 64 (inline_all) and 128 (structured_hybrid): OpPhi prev_lbl='%fc2_t105' not in %t213 = OpPhi %uint %t212 %t209_do %c0 %blk2.
    • The load and none cases run fine.
    • The new comment in _parse_module ("entry block continues the caller's block") covers the helper's entry block. After the inlined call, though, execution continues under the helper's last (merge) label %fcN_…, while the translator's OpPhi names the caller's block %blk2 as the predecessor.
    • Suggested fix: map the helper's last block back to the caller's current label when the call returns.
    • None of the PR's own tests has that shape, so they stay green. It only bites the next test that does.

AI-assisted (Claude Code).

@SlopTart

Copy link
Copy Markdown

Native-wave64 GPU check of the new head a03ac8c1 (main 1cc6e3c1 merged) - RX 7900 XT (RADV NAVI31, subgroup 32..64), Mesa 26.2.5, Arch/Omarchy. Bad news, and it's exactly the failure mode I flagged in #6172: the merge does not carry the fix into the mesh fixture anymore.

  • ms_wave_info_s3.spv translated at a03ac8c1 hashes to 488eaf703ccfcf8d… - byte-identical to plain main 1cc6e3c1 (and to my synthetic main + #4247 -X theirs merge in ms_wave_info_s3 intermittently fails on RX 7900 XT / RADV NAVI31 (pass rate 100% -> 2.5%, same binaries) #6172). The fixed module from head 13c732c3 was f4fe9a8403b394ff….
  • tools/rdna2spirv.py still shows a large delta vs main at this head (81 insertions / 67 deletions), so the PR's code is textually there - it just no longer changes this fixture's output. The planner restructure in current main absorbs it.
  • Full GPU suite at a03ac8c1: 218/235 passed, 16 skipped - the single failure is ms_wave_info_s3, and it also fails in the LEONIDA_W64_EMULATE=1 lane. Same (-1,-1,-1,-1) zero-primitive signature as ms_wave_info_s3 intermittently fails on RX 7900 XT / RADV NAVI31 (pass rate 100% -> 2.5%, same binaries) #6172.
  • Same-window interleave, one harness (vk_harness built at a03ac8c1), modules alternated per iteration, 12 runs each: new-head module (488eaf70) 0/12 | 13c732c3-head module (f4fe9a84) 12/12. Not a window artifact: both modules see the identical window.

So test_w64x_clear_single_writer being green (lunarminus) is consistent: those semantic tests pin the clear/free planner behavior, but the fixture regression is back at the GPU level. The re-implementation against current main is still needed - merging main into the branch cannot reconstruct it, as predicted from the byte-identity finding.

Machine env as usual: no game files, your own fixtures, bare hardware. Posted by Hermes (agent) on my machine (RX 7900 XT, Arch; also the boxb/GTX 1070 reporter).

@zzEmmazz

Copy link
Copy Markdown
Contributor Author

@SlopTart thanks for the run. Both observations are right, but neither is this PR losing its fix; they are two other things:

What this PR is measured by is the data race on %x_buf: GPU-assisted validation on the 35 emulated compute modules, 192 SharedMemoryDataRace reports on main, 0 here (re-measured on the merge with 561b65a8; the translator files are the same at this head).

If you have a minute for one decisive run: ms_wave_info_s3 with #5741's tools/rdna2spirv.py on your RX 7900 XT should pass in both lanes, which would confirm it is that store and not this branch.

AI-assisted.

@lunarminus

Copy link
Copy Markdown

Correction to my comment above. I wrote that the translator change at a03ac8c1 is identical to 5f16276d, so my earlier GPU-assisted validation result "still describes it". The first half holds: each diff against its own base has the same text. The second half does not follow. main changed underneath (70e739fd7's planner), so the same text can produce different modules. Thanks @SlopTart for catching it. Measured on this machine (Radeon 760M, RDNA3 iGPU, RADV Mesa 26.3.1, CachyOS; test programs built at 561b65a8), run_gpu_tests.py --filter ms_wave_info_s3 on both trees:

ms_wave_info_s3.spv native LEONIDA_W64_EMULATE=1
this PR a03ac8c1 488eaf703ccfcf8d… afb6236a4cc60466…
main 1cc6e3c1 488eaf703ccfcf8d… f7e36a664047a815…
  • Native: byte-identical to main, the same hash SlopTart reports. The PR no longer changes this module there.
  • Emulated: the PR still changes the module.
  • GPU result here: PASS ms_wave_info_s3 4096/4096 pixels exact on both trees and in both modes. So the failure SlopTart sees on the RX 7900 XT (Mesa 26.2.5) doesn't reproduce on this RDNA3 iGPU with Mesa 26.3.1, on main or on the PR. It depends on the GPU or driver version (or is timing-dependent), and a pass here is no evidence against it.

My earlier 32 → 0 race count was measured at 5f16276d on aa2988cc, and it should be read only for that base. I haven't re-run GPU-assisted validation at this head.

AI-assisted (Claude Code).

@SlopTart

Copy link
Copy Markdown

@zzEmmazz ran your decisive test - it confirms your read, and my "the merge dropped the fix" interpretation was wrong. Retracting it with the numbers:

#5741 head 60c027c4 built fresh on the RX 7900 XT (Mesa 26.2.5), ms_wave_info_s3 module hashes 5ffb9fcdb7e6… (native) / 54067880ebb1… (emulated):

Your store-gate story also retroactively explains two of my own older findings on #6172, which I should have connected:

  • My wave-0 flip diagnostic: forcing the alloc request to be gated on wave 0 instead of wave 1 turned the flaky fixture from 10-16/40 into 70/70 across two paired windows. If the store is gated on invocation 0 and the sender is scheduling-dependent, a wave-0 sender stores and passes - exactly what the flip did.
  • The (-1,-1,-1,-1) "zero primitives" signature is just "nothing stored the counts", as you describe.
  • And the per-run sender explains why a pure logic bug appears window-dependent: which wave sends is scheduling luck.

Where that leaves my two earlier posts: the hash facts stand (a03ac8c1 native module == main's, byte-identical; the -X theirs merge module also matched), but I over-read them - if native output is by design identical to the base and only --wave64-emulate differs, then "identical hash" was never evidence of a lost fix. Same correction applies to my merge-forensics comment on #6172; I'll post the correction there. The 13-GPU table on #5741 plus 20/20+20/20 here makes the fixture story closed as far as this machine is concerned: #5741 is the fix, this branch's emulated %x_buf work is orthogonal, and #4247 should be judged by the GPUAV race count (192 -> 0), not by ms_wave_info_s3.

No game files - your fixtures, bare hardware. Posted by Hermes (agent) on my machine (RX 7900 XT, Arch; also the boxb/GTX 1070 reporter).

@Mob1K7105

Copy link
Copy Markdown

Re-check of the current head a03ac8c1 (it contains main 1cc6e3c1) on an AMD Radeon RX 6700 XT (RADV NAVI22, gfx1031, RDNA2, subgroup 32..64), Mesa 26.3.1-arch3.5, Linux, llvm-mc 23.1.5: pass, no change against main. Test programs built from 1cc6e3c1.

LEONIDA_W64_EMULATE main 1cc6e3c1 a03ac8c1 modules differing from main
0 218/235 passed, 16 skipped 218/235 passed, 16 skipped 0 of 244
1 218/235 passed, 16 skipped 218/235 passed, 16 skipped 38 of 244
  • Pass/skip/fail status is identical test by test in both modes. The one failure on both sides is ms_wave_info_s3.
  • scripts/run_semantic_tests.py -j 6 tests/semantic: 434 files, 5,832 tests, 0 failed.

On ms_wave_info_s3, this agrees with @zzEmmazz's read above. The failure is not this PR's to fix:

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

@TG0000

TG0000 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested a03ac8c on AMD Radeon RX 6800 (RDNA2 gfx1030, AMD 26.11.2, Windows 11): pass

Native device, subgroup 32..64, Vulkan 1.4.363, Khronos validation layer (MSYS2 ucrt64 build), llvm-mc 23.1.5, SPIRV-Tools v2026.4, Python 3.12. GPU test programs rebuilt from this head with llvm-mingw clang 23.1.6 + Ninja (-DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF). No game files.

  • Full python -I scripts/run_gpu_tests.py --llvm-mc <llvm-mc> --build runtime/build (74 s): 241 translated, 241/241 pass spirv-val; 218/235 GPU PASS, 17 skipped, 0 fail. All 20 runnable w64x fixtures pass; ps_w64x_readlane is skipped (the device cannot require a 64-wide fragment subgroup). ms_wave_info_s3 passes here (4096/4096 exact) on this 32-wide-native device.

  • GPU-assisted validation (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1, vk_compute_test <spv> 1 dump) on all 19 cs_w64x_* compute fixtures, this head against main 1cc6e3c1, built from the same tree:

    dispatch done SharedMemoryDataRace Validation Error Validation Warning
    a03ac8c1 19/19 12 12 57
    main 1cc6e3c1 19/19 12 12 57
    • The 57 warnings are the layer's 3 setup notices per run (GPU-AV together with core checks, adjusted feature settings, ray-tracing/mesh validation turned off). None of them is about a shader.
    • All 12 race reports come from cs_w64x_lds_raw (6) and cs_w64x_lds_war (6). In both, the race is on the module's only Workgroup variable: the fixture's own ds_write/ds_read between lane n and lane n^32, with no barrier, which these fixtures test on purpose. The race is not in the %x_buf clear/free. Both fixtures still give the right data, and main reports the same races.
    • ballot, bpermute, wg128_branches and the other 14 fixtures report 0 races and 0 errors.
  • Note: all 19 cs_w64x_* modules translated at this head are byte-identical to main 1cc6e3c1. Main already has 5f16276d from round 44, so these fixtures show no difference between the two. This agrees with @SlopTart's hash for ms_wave_info_s3. What this run confirms is that the merged head adds no regression and no new race on native 32-wide hardware. It is not an A/B of the fix itself.

  • Semantic tests (python -m unittest discover -s tests/semantic -p <file>): test_w64x_clear_single_writer 11 OK, test_wave64_emulate_opt 29 OK, test_loop_ballot_barrier 15 OK.

  • python -m pytest -q tests/test_shader_checks.py tests/test_docs_design_rows.py tests/test_run_gpu_tests.py: 141 passed, 374 subtests passed.

AI-assisted (Claude Code).

@bobcatchris

Copy link
Copy Markdown
Contributor

Tested a03ac8c167dc31f3eb5c5b7b44d587537b76c8b6 on AMD Radeon Pro V540 (Navi 12; tools/hw_oracle reports gfx1011), RADV Mesa 25.2.8-0ubuntu0.24.04.4, Ubuntu 24.04.4, kernel 7.0.0-31-generic, Vulkan 1.4.318, subgroup 32..64. Cards pinned with DRI_PRIME=pci-0000_1c:00.0! and pci-0000_1f:00.0!, one process each. Adds an RDNA1/RADV data point to the NVIDIA/RDNA2/RDNA4 results in the comments.

  • python3 -I scripts/run_gpu_tests.py --build runtime/build/linux: 205/235 passed, 29 skipped, 1 failed on both cards (241 shaders translated, 241 pass spirv-val), identical to current main 1cc6e3c12 with the same toolchain; no regression. The single failure (cs_w32_salu64) is unchanged from a clean main worktree.
  • python3 -I tests/semantic/test_w64x_clear_single_writer.py: 11 OK. python3 -I tests/semantic/test_wave64_emulate_opt.py: 29 OK. (Running these through pytest with -k errors because pytest injects its own size fixture into setup(size); the project's direct python -I runner is the supported path.)
  • Toolchain: Khronos Vulkan-Headers 1.4.335 locally (-DVulkan_INCLUDE_DIR=...), GCC 13.3.0, llvm-mc 21.1.8, SPIRV-Tools 2026.1.

Counts and pass/fail only; no game data. No code changes.

AI-assisted.

@GustawMatuszewski

Copy link
Copy Markdown

Tested a03ac8c16 (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_w64x_clear_single_writer.py 11 OK, test_wave64_emulate_opt.py 29 OK, test_loop_ballot_barrier.py 15 OK. build.py: 264 shaders, 264 translated, 264 pass spirv-val.

NVIDIA GeForce RTX 5060 Laptop GPU (the mobile chip, 32..32), driver 595.99.02, Vulkan 1.4.329 — the 32-wide case this branch is about, with LEONIDA_W64_EMULATE=1:

  • check.py: 171 of 206 pass, 35 skipped, 0 failed (exit 0)
  • run_gpu_tests.py: 216/235 passed, 17 skipped, 2 failed — ms_wave_info_s3 fails identically on main at this base and with emulation (pre-existing, reported separately) and ps_ops (and ps_ops2–ps_ops8) pass 8/8 with --filter, so that one is the known 595.99.02 Xid 32 device-lost flake
  • --filter cs_w64x with emulation: 19/19 pass

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

  • check.py: 203 of 206 pass, 3 skipped, 0 failed (exit 0)
  • run_gpu_tests.py with LEONIDA_W64_EMULATE=1 (so the emulated branch runs on this device too): 219/235 passed, 16 skipped, 0 failed (exit 0)

No game files; the repo's synthetic fixtures only. AI-assisted (Claude Code): it built the head, ran both devices and wrote this.

@mexht

mexht commented Nov 23, 2026

Copy link
Copy Markdown

Independent GPU-assisted-validation run on AMD Radeon RX 7800 XT (RDNA3, Navi 32), RADV / Mesa 26.3.1-arch3.5, Vulkan 1.4.363, Linux 7.3.5: the race is gone, with the same counts you measured.

Method, no game files: translate the 35 compute fixtures that get %x_buf under --wave64-emulate with LEONIDA_W64_EMULATE=1 python -I runtime/test/shaders/build.py <out>, then run each module with

VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1 \
vk_compute_test <module>.spv 1 dump
head modules with SharedMemoryDataRace-RaceOnStore reports
before, base 1cc6e3c1 32 of 35 192
after, a03ac8c16 0 of 35 0

After the fix there are 0 validation errors of any kind across the 35 modules. Functional results are unchanged: run_gpu_tests.py --filter w64x is 21/21 native and 21/21 with LEONIDA_W64_EMULATE=1 on this driver.

(For anyone reproducing: the harness prints the layer messages on stdout, so capture stdout rather than stderr.)

@berkay8987

Copy link
Copy Markdown

Tested a03ac8c1 against its merge base 1cc6e3c1 on NVIDIA GeForce RTX 5070 (Blackwell, desktop), NVIDIA 617.42, Vulkan 1.4.351, subgroup 32..32, Windows 11 Pro 26200. Vulkan SDK 1.4.363.0, llvm-mc 21.1.8 (WSL), MSVC 19.44. No game files. Pass, and it answers the ms_tri question from #5741.

@zzEmmazz asked in #5741 whether ms_tri drawing nothing in mesh-as-compute with wave64 emulation on Blackwell comes from the SHADER-708 race on %x_buf. On this card it does:

LEONIDA_MESH_COMPUTE=1 LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py --filter ms_tri, five runs each, in one worktree switched with git checkout between the two, with the same test programs for both:

translator runs ms_tri
merge base 1cc6e3c1 5 5 / 5 FAIL: at (0,0): got (-1,-1,-1,-1), want (0.0078,0.0078,0.5,1.0)
this PR a03ac8c1 5 5 / 5 PASS: 4096/4096 pixels exact

--filter ms_ on this head in the same mode: 5/6. ms_tri, ms_clip, ms_f16_pack, ms_v5_workgroup and ms_w64x_ballot pass; ms_wave_info_s3 fails, which is the separate %ms_counts bug #5741 fixes. On #5741's head 57cc1804 in this mode it is the mirror image: ms_wave_info_s3 passes and ms_tri fails. So the two mesh failures on Blackwell have one cause each, and one PR each.

For reference, main 07f1d7e8 alone in all four modes: ms_wave_info_s3 fails in every mode, and ms_tri only with MESH_COMPUTE=1 + W64_EMULATE=1 (3 / 3). ms_tri passes with MESH_COMPUTE=1 alone and with W64_EMULATE=1 alone, and adding LEONIDA_BARY_FALLBACK=1 to the failing mode doesn't change it.

tests/semantic: test_w64x_clear_single_writer.py, test_loop_ballot_barrier.py and test_wave64_emulate_opt.py pass.

One caveat: the test programs were built once from main 07f1d7e8, which is newer than 1cc6e3c1 (44 files under runtime/ differ). Both arms ran the same executables and this PR touches no C++, so the A/B isolates tools/rdna2spirv.py. If you want the programs from the exact base as well, I can rebuild at 1cc6e3c1 and run it again.

AI-assisted (Claude Code).

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.