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 3 commits into
ItsNotRexed:mainfrom
zzEmmazz:shader-708-wave64-clear-race
Open

zzEmmazz wants to merge 3 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.

zzEmmazz and others added 3 commits November 23, 2026 00:37
… (SHADER-708)

Under --wave64-emulate the scheduler cleared parts of %x_buf (Workgroup memory)
with plain stores that several invocations aimed at one word: the zeroing before
the first barrier clamped its index with UMin, so every invocation past the end
of a range stored to its last word, and at the top of each round every
invocation with nothing to free stored 0 to a shared sink word. All stores wrote
0, so results did not depend on it, but it is a data race, and GPU-assisted
validation reports SharedMemoryDataRace-RaceOnStore on every emulated compute
shader.

Invocation i now clears word i of each row, a short last row is stored only by
the invocations that have a word in it, and in a round only lane 0 of a wave
(mask words) and invocation 0 (counts) store, each behind a selection that ends
before the barrier. The last word of %x_buf is no longer written; it stays
allocated so the buffer size does not change. No module changes without
--wave64-emulate.

tests/semantic/test_w64x_clear_single_writer.py runs the scheduler's head for
every invocation at nine workgroup sizes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…-writer clears

main split x_scheduler into x_prologue and x_round_loop_head and added structured
emulation (x_mini_scheduler, the x_pre_* helper functions). The one-writer clears
are ported to all four places that stored to the sink word. The helper functions
now have a selection, so the inliner of tests/semantic/test_wave64_emulate_opt.py
keeps their labels, and its lockstep interpreter fails when two invocations store
to one %x_buf word between two barriers.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…t fails without it (SHADER-708)

test_w64x_clear_single_writer.py gains a mesh shader and whole-workgroup runs of
programs that take the inline helpers (one wave and several), two local round
loops, and a round loop after a local one. The lockstep interpreter of
test_wave64_emulate_opt.py also fails when one invocation plain-stores a %x_buf
word that another loads or updates between two barriers. With any one of the
four places put back, both files fail. The design.md row has the numbers
measured on main aa2988c.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@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

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

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.

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.

8 participants