Skip to content

rdna2spirv: signed sub-dword LDS reads sign-extend with xor/subtract, not OpBitFieldSExtract (FUZZ-66) - #5577

Open
KubickNubick wants to merge 2 commits into
ItsNotRexed:mainfrom
KubickNubick:lds-i8-d16-amd
Open

KubickNubick wants to merge 2 commits into
ItsNotRexed:mainfrom
KubickNubick:lds-i8-d16-amd

Conversation

@KubickNubick

@KubickNubick KubickNubick commented Nov 23, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue as: FUZZ-66, #5361 (comment) (my finding: #5256 (comment))

What and why

tools/lds_fuzz.py --seed 9950 program 95 at 64 lanes mismatches on AMD's Windows driver: 16 LDS dwords read 0x00ccXXXX where the model wants 0xffccXXXX. Reduced, it is two instructions:

ds_read_i8_d16 v33, v6 offset:1     ; D[15:0] = sign-extend 8 -> 16 of the byte, D[31:16] kept
ds_write_b16 v6, v33 offset:2532    ; writes D[15:0]

The half written is the byte zero-extended (0x0090 for the byte 0x90). The register itself, stored to the buffer, is right.

It is the driver, not the translator. One SPIR-V module (spirv-val clean), run at subgroup size 32 on both GPUs, writes 0xff90 on an NVIDIA RTX 4080 and 0x0090 on the Radeon. @danosovsky (Ryzen 5 7600X iGPU, 32.0.21036.18) and @Hiiva (32.0.21043.5001) reduced it to the same pair on two more drivers, and both found that hand-edited SPIR-V with the byte sign-extended as (b ^ 128) - 128 is right (their notes).

What narrows it, on this machine (AMD native against the RTX 4080 with wave64 emulation; all byte values negative):

Read, then write Radeon
ds_read_i8_d16 at byte 0, 1, 2 or 3, then ds_write_b16 wrong, all four
ds_read_i8 (full register), then ds_write_b16 right
ds_read_i8_d16_hi, then ds_write_b16_d16_hi right
ds_read_i16, then ds_write_b16 right
ds_read_i8_d16, then ds_write_b32 or ds_write_b8 right
ds_read_i8_d16 alone (the register stored to the buffer) right

The change. The signed sub-dword LDS reads (ds_read_i8, ds_read_i16, ds_read_i8_d16, ds_read_i8_d16_hi) take the field with OpBitFieldUExtract and sign-extend it as (field ^ sign) - sign, where they used OpBitFieldSExtract at a run-time offset. The words are the same; only the form the driver sees changes. I changed all four signed reads and not only the one that fails, so there is one lowering to keep right. Of two variants tried on the Radeon, replacing the OpBitFieldInsert with mask/or did not help, and this one did.

Also in this pull request:

  • runtime/test/shaders/cs_w64_lds_i8_d16_write.asm (new, registered in check.py and run_gpu_tests.py): LDS bytes A5 90 CC 80, each read with ds_read_i8_d16 and written back with ds_write_b16; four words are the dwords written, four the registers.
  • tests/semantic/test_lds_i8_d16_write.py (new): the fixture's eight words on the CPU, and that no signed LDS read is emitted with OpBitFieldSExtract.
  • tests/semantic/test_lds_subdword_wide.py, test_lds_subword_d16.py: their negative controls swapped OpBitFieldSExtract for OpBitFieldUExtract in the translated text, which no longer exists there; they now remove the xor/subtract pair and still require the result to change.
  • docs/design.md: the rule in the LDS row, with how it was confirmed.

Tested

Windows 11 Pro 26300, main 3faac55, llvm-mc 23.1.6, Vulkan SDK 1.4.363.0, test programs from main (no runtime source changes). NVIDIA RTX 4080 (621.01, subgroup 32..32) and the AMD Radeon iGPU of a Ryzen 9 9950X3D (RDNA2 gfx1036, 32.0.21042.62, subgroup 32..64). No game files.

The fixture, old against new lowering (run_gpu_tests.py --filter lds_i8_d16; old = tools/rdna2spirv.py from main, everything else from this branch):

Radeon, native wave64 RTX 4080, LEONIDA_W64_EMULATE=1
old lowering FAIL 0xa5 0x90 0xcc 0x80 0xbeefffa5 0xbeefff90 0xbeefffcc 0xbeefff80 PASS
this PR PASS 0xffa5 0xff90 0xffcc 0xff80 0xbeefffa5 0xbeefff90 0xbeefffcc 0xbeefff80 PASS

tests/semantic/test_lds_i8_d16_write.py fails with the old lowering too (the OpBitFieldSExtract assertion) and passes with this one.

The whole GPU suite, 0 failures in every run:

run_gpu_tests.py build.py + check.py
RTX 4080 native 170/218, 48 skipped 153 of 189, 36 skipped
RTX 4080 emulated 202/218, 16 skipped 185 of 189, 4 skipped
Radeon native 202/218, 16 skipped 185 of 189, 4 skipped
Radeon emulated 202/218, 16 skipped 185 of 189, 4 skipped

main gives 170/217 and 201/217 here, so this adds the one fixture and changes nothing else. On the RTX 4080 without emulation the fixture is skipped (no 64-wide subgroups).

lds_fuzz, 200 programs, seeds 9950 and 4080, 0 mismatches and 0 harness errors:

seed 9950 seed 4080
Radeon native, both waves 400/400 (399/400 on main: program 95) 400/400
RTX 4080 native, wave32 200/200 200/200
RTX 4080 emulated, both waves 400/400 400/400

I did not rerun the Radeon with emulation: that crashes on main in the driver (#857) and is unrelated.

Unit tests, pytest -n 14 tests (Python 3.13.6): 13286 passed, 40 failed, 116 skipped on this branch; 13288 passed, 41 failed, 108 skipped on main built and run the same way. The failing tests are the same on both, except test_f32_fuzz.py::CliTests::test_no_arguments_prints_usage, which failed only in the main run. They are this machine's, not this change's: test_viewer_serve.py behind an HTTP filter (#4985), test_cf_diff.py, test_rdna2_decode.py and test_build_batch_launch.py. The 8 extra skips on the branch are tests that need a built vk_harness / vk_pipeline_check, which this worktree does not have. tests/semantic test_lds_*.py: 672 OK. regen_fixtures.py --check, python -m compileall -q make_game.py tools tests, git diff --check: clean.

The corpus, measured by @Kev-Ball (comment) on the Xbox 1.0.2.1 listings: none of the 26,503 shaders uses any of the four signed reads, so this change does not touch the game's own shaders, and the 15 listings with the unsigned reads translate to byte-identical SPIR-V before and after. The fix is for the translator's correctness on the fuzzer's program, not for a shader the game ships.

Not tested:

  • RADV or any hardware oracle: that the Radeon's old result is wrong rests on the model, on the RTX 4080 running the same module, and on the two other AMD drivers above, not on a native AMD run.
  • global_load_sbyte_d16 uses a similar form, OpBitFieldSExtract (at offset 0) followed by OpBitFieldInsert (tools/rdna2spirv.py, the global d16 loads). I did not test it and did not change it.

AI-assisted: yes (Claude Code ran the fuzzers, the reduction and the tests and wrote the change; I checked the results).

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.

🤖 Generated with Claude Code

@Kev-Ball

Copy link
Copy Markdown

The retail corpus question has a zero count on my Xbox 1.0.2.1 copy. Across all 26,503 disassembly listings I found no occurrences of any of the four affected instructions (ds_read_i8, ds_read_i16, ds_read_i8_d16, ds_read_i8_d16_hi). There are 27 ds_write_b16 instructions, but none can be paired with the signed LDS read from the reproducer in these listings.

As a control for the adjacent unsigned lowering, 15 listings contain 75 ds_read_u16 and four ds_read_u16_d16_hi instructions in total. I translated all 15 with wave64 emulation on the parent and on 4ca0031c. All 15 emitted SPIR-V binaries were byte-identical between revisions. The new synthetic fixture therefore covers a signed path this corpus cannot exercise. CachyOS, CPU only. AI-assisted.

@KubickNubick

Copy link
Copy Markdown
Author

Thanks @Kev-Ball, that settles the corpus question; I've moved it from "Not tested" into the description.

AI-assisted (Claude Code).

@Darkz0rz

Copy link
Copy Markdown

Tested 4ca0031c on Windows 11 (build 26300), Vulkan SDK 1.4.363.0, llvm-mc 21.1.8, adding a before/after run of the new fixture: pass, and the fixture catches the bug on the AMD driver.

python -I scripts/run_gpu_tests.py --filter lds (8 fixtures), with LEONIDA_VK_DEVICE set to the GPU. In the "main's translator" row, the PR's fixtures run with tools/rdna2spirv.py from 3faac557:

AMD Radeon iGPU (Ryzen 7 9800X3D, gfx1036), AMD 25.10.36 (32.0.21036.18), native wave64 RTX 4090, 617.42, LEONIDA_W64_EMULATE=1
this PR 8/8 pass; cs_w64_lds_i8_d16_write 0xffa5 0xff90 0xffcc 0xff80 0xbeefffa5 ... 8/8 pass
main's translator 7/8: cs_w64_lds_i8_d16_write FAIL 0xa5 0x90 0xcc 0x80 0xbeefffa5 0xbeefff90 0xbeefffcc 0xbeefff80 8/8 pass

So on main the four ds_write_b16 words come out zero-extended on this driver while the register words are right, as in your reduction. On the 4090 natively, the 3 wave64 fixtures skip (5/8 pass), the same on both translators.

CPU: python -I -m unittest discover -s tests/semantic -p "test_lds_*.py": 672 tests OK.

AI-assisted: runs were done with Claude Code.

@Halfect

Halfect commented Nov 23, 2026

Copy link
Copy Markdown

Independent before/after verification of 4ca0031c5380f0ddd49b71b7a9abc60393fb1900: the PR fixes the fixture on another gfx1036 / AMD Windows driver combination.

Environment: Windows 11 (10.0.22631), CPython 3.12.16, llvm-mc 23.1.6, AMD Radeon Graphics (gfx1036, PCI device 0x13c0), driver 32.0.21030.2001, native subgroup 64 (reported range 32..64). No game files.

I built only cs_w64_lds_i8_d16_write, then ran vk_compute_test <fixture.spv> 1 dump once for each lowering (one group of 64 lanes per run). The negative used this PR's files except tools/rdna2spirv.py from base 3faac557.

lowering out[0..7]
this PR 0x0000ffa5 0x0000ff90 0x0000ffcc 0x0000ff80 0xbeefffa5 0xbeefff90 0xbeefffcc 0xbeefff80 — expected result
base translator 0x000000a5 0x00000090 0x000000cc 0x00000080 0xbeefffa5 0xbeefff90 0xbeefffcc 0xbeefff80 — reproduces the zero-extended writes while the register words remain correct

CPU checks: the three touched semantic test files passed 15/15 (test_lds_i8_d16_write.py, test_lds_subdword_wide.py, test_lds_subword_d16.py). With only the translator reverted, the new test file had the expected single failure at test_signed_reads_are_not_lowered_with_a_signed_field_extract. Targeted compileall and git diff --check passed.

Scope/limitation: I did not run the full GPU suite or fuzzing. The standalone spirv-val executable is unavailable on this machine, so I assembled with the repository's in-process tools/spirv_asm.py; the AMD Vulkan driver accepted both modules. This is not an external spirv-val pass.

AI-assisted: Kimi Work performed the isolated builds, tests, and this report.

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

Reviewed head 4ca0031c5 (base 3faac557b). git diff --check clean.

CPU: python tests/semantic/test_lds_i8_d16_write.py -> 3 tests OK; test_lds_subdword_wide.py -> 4 OK; test_lds_subword_d16.py -> 8 OK; all 34 tests/semantic/test_lds*.py OK.
Negative control with main's tools/rdna2spirv.py: test_lds_i8_d16_write.py FAILED (words and the lowering assertion), so it pins the change.
GPU (RTX 5070 Ti): LEONIDA_W64_EMULATE=1 python scripts/run_gpu_tests.py --filter cs_w64_lds_i8_d16_write -> PASS 0xffa5 0xff90 0xffcc 0xff80 0xbeefffa5 0xbeefff90 0xbeefffcc 0xbeefff80; native run skips (no 64-wide subgroup). --filter lds -> 5/8 passed, 3 skipped.
The lowering is exact: (field ^ 0x80) - 0x80 under %uint wrap is the same word as sign extension, for every field.

Blocker: conflicts with current main (561b65a83) in scripts/run_gpu_tests.py and tests/semantic/regen_fixtures.py (53 commits to the runner since 3faac557b). Rebase needed.

Verdict: change is correct; request rebase.

@KubickNubick

Copy link
Copy Markdown
Author

Rebased onto main 561b65a (round 44); the head is now fa0e331. Two conflicts, both in lists of fixture names where a neighbouring name was added on main (scripts/run_gpu_tests.py, tests/semantic/regen_fixtures.py); the change itself is as before.

Re-tested on the rebased head, test programs rebuilt from it (MSVC 19.51), same machine: NVIDIA RTX 4080 (621.01) and the Radeon iGPU of a Ryzen 9 9950X3D (gfx1036, 32.0.21042.62).

Radeon, native wave64 RTX 4080, LEONIDA_W64_EMULATE=1
cs_w64_lds_i8_d16_write, tools/rdna2spirv.py from main FAIL 0xa5 0x90 0xcc 0x80 ... PASS
cs_w64_lds_i8_d16_write, this branch PASS 0xffa5 0xff90 0xffcc 0xff80 ... PASS
scripts/run_gpu_tests.py result
Radeon native 216/233, 17 skipped, 0 failed
Radeon emulated 216/233, 17 skipped, 0 failed
RTX 4080 native 183/233, 49 skipped, 1 failed
RTX 4080 emulated 215/233, 17 skipped, 1 failed

The one failure on the RTX 4080 is ms_wave_info_s3 (at (0,0): got (-1,-1,-1,-1)). It fails the same way on unchanged main 561b65a here and passes on the Radeon; it is the round-44 regression on 32-wide GPUs that @zzEmmazz reported and claimed in #5581, not this change.

lds_fuzz --seed 9950, 200 programs: Radeon native 400/400, RTX 4080 emulated 400/400. tests/semantic test_lds_*.py: 674 OK. regen_fixtures.py --check: clean.

Not rerun on the new base: the full pytest tests comparison and check.py. AI-assisted (Claude Code).

@Halfect

Halfect commented Nov 23, 2026

Copy link
Copy Markdown

Correction to the tooling limitation in my previous comment: the standalone SPIRV-Tools executables were installed in the local Vulkan SDK (1.4.363.0), but were not on PATH. My earlier statement that they were unavailable on the machine was wrong.

I have now run actual spirv-val v2026.4 with --target-env vulkan1.2 --allow-offset-texture-operand: both GPU-tested modules pass, and fresh spirv-as assemblies of both .spvasm files pass as well. The before/after GPU results and the rest of the report are unchanged.

@memorypressure

Copy link
Copy Markdown

Verified at the PR head (branch reports no CI checks): test_lds_i8_d16_write 3, test_lds_subdword_wide 4, test_lds_subword_d16 8 all pass, the translator-use guard is green, and neighbouring LDS suites stay green. Not superseded — main's LDS site still emits OpBitFieldSExtract at a run-time offset, verified. Two notes: the branch does not merge cleanly with 561b65a (round-44 added shader names to the exact run_gpu_tests.py tuple and regen_fixtures.py SHADERS lines you extend — keep both entries), and main's LDS row already repeats a couple of clauses, with your new sentence landing in the first copy, so tidy that while rebasing. A push to trigger CI would also help — the gfx1036/32.0.21042.62 lds_fuzz seed-9950 failure is a hardware claim this CPU-only host cannot confirm. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested fa0e331 on Intel UHD Graphics 630 (CFL GT2), Mesa ANV, subgroup 8..32: run_gpu_tests.py --filter lds_i8_d16 gives "SKIP cs_w64_lds_i8_d16_write SKIP (no 64-wide compute subgroup on this device)", 0/1 passed, 1 skipped, so the fixture is not checked on this GPU. test_lds_i8_d16_write (3 tests), test_lds_subdword_wide (4) and test_lds_subword_d16 (8) pass, and test_lds*.py runs 674 tests OK. With the tools from the parent commit, test_signed_reads_are_not_lowered_with_a_signed_field_extract fails ("'OpBitFieldSExtract' unexpectedly found"). tests/test_rdna2_decode.py test_parity_with_llvm_mc_on_shader_fixtures fails with "Lists differ: ['op_sel:[0,1,0,0]'] != ['op_sel:[0,1]']" on this head and on the parent commit alike.

AI-assisted.

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

Reviewed exact head fa0e33152c3247bcd3df3af05e6524478dd8296d, rebased onto current main 561b65a832218fbb9e6d2effd392a8eef093a3f8.

The production lowering passes this independent bounded check. One P2 issue remains in the new GPU fixture: its initial same-address, non-atomic LDS writes are a data race. The inline comment is limited to that fixture.

Independent GPU comparison

Windows 11 Pro 10.0.26200; Vulkan SDK 1.4.363.0; LLVM 21.1.8; MSVC 19.44.35228.0. AMD Radeon(TM) Graphics driver 32.0.21043.5001 and NVIDIA RTX 4080 driver 610.62 (Windows 32.0.16.1062).

I used the retained, byte-identical synthetic lds_fuzz seed 9950/program 95 and its earlier minimal reduction, with distinct per-invocation write addresses. The original program's initialization and each writing operation have disjoint active-lane byte spans, and its operations are separated by barriers. The unsigned control changes only the reduction's signed read to its unsigned counterpart.

Fixture Words compared Radeon main, subgroup 64 Radeon head, subgroup 64 RTX main, emulated at 32 RTX head, emulated at 32
Original seed 9950/program 95 2,048 16 mismatches 0 0 0
Minimal signed read/write, preserving the other register and LDS halves 128 64 mismatches 0 0 0
Adjacent unsigned read/write control 128 0 0 0 0

In the minimal Radeon negative, each register is correctly 0x1234ffcc, but its LDS word is 0x00cc5678 instead of 0xffcc5678. The head produces the expected pair. The unsigned pair remains 0x123400cc, 0x00cc5678 on both revisions.

These are 12 single-dispatch runs through a freshly built, unchanged current-main vk_compute_test. Every expected word was checked from binary readback, along with 16 untouched trailing sentinel words per run. Device selection and actual subgroup width were checked in every log. All runs had validation enabled, zero validation-error exits, and no VUID or synchronization-hazard diagnostics. The intentionally mismatching Radeon negatives exited successfully at the harness level and were detected by the independent readback oracle.

The Radeon results are Vulkan execution at native subgroup 64, required by the harness. The RTX results are wave64 workgroup emulation pinned to subgroup 32; their metadata reports workgroup exchange with no required native subgroup size. This is not native AMD ISA evidence, and I made no performance or corpus claim.

CPU and module checks

  • All 21 focused methods passed on the new exact head: the three changed semantic test files, the current cross-dword boundary tests, and the unsigned d16 read tests.
  • The new lowering assertion fails against unchanged current main, as expected.
  • All 12 current-main/head modules passed SDK spirv-val --target-env vulkan1.3. The six exact-head binaries and their metadata also matched a separate current-main integration containing only the author's production hunk.
  • Source, executable, fixture, module and dump hashes were retained. No owner files were edited.

I did not execute the owner's stock fixture as a correctness oracle. A separate exact-head build passed spirv-val but still emitted its five initialization stores as plain OpStore accesses to the same LDS words from all 64 invocations before the first barrier. The Vulkan memory model treats same-value stores as writes and requires applications to avoid unordered conflicting non-atomic accesses; a later barrier does not order those initial stores with each other. The valid retained fixtures above establish the production result independently.

AI-assisted review. All inputs were synthetic; no game files.

Comment on lines +20 to +25
ds_write_b32 v2, v3
v_mov_b32_e32 v3, 0
ds_write_b32 v2, v3 offset:16
ds_write_b32 v2, v3 offset:20
ds_write_b32 v2, v3 offset:24
ds_write_b32 v2, v3 offset:28

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.

[P2] Give the LDS initialization a single writer

All 64 invocations reach these five ds_write_b32 instructions with v2 == 0, so they perform concurrent writes to byte addresses 0, 16, 20, 24 and 28. The emitted module uses ordinary OpStore for these accesses. Equal values do not make the writes race-free, and the barrier below only orders them against later accesses, not against each other. This violates the Vulkan data-race requirement, making this new regression fixture an unreliable correctness oracle even when it passes validation. Restrict the initialization stores to one invocation and restore all invocations before the barrier. The production lowering itself passes the separate valid seed/minimal controls described in the review body.

@danosovsky

Copy link
Copy Markdown

Independent before/after run of the rebased head fa0e3315, as offered for FUZZ-66: the PR fixes it here, and the fixture catches the bug on the AMD driver.

Ryzen 5 7600X iGPU (gfx1036, AMD 32.0.21036.18, native wave64) and RTX 4070 SUPER (621.24, emulated wave64), Windows 11 Pro 26300, MSVC 14.44, Vulkan SDK 1.4.363, llvm-mc 23.1.5. Test programs built from this head. "old" is the same tree with only tools/rdna2spirv.py from 561b65a8.

this PR old
cs_w64_lds_i8_d16_write, Radeon native PASS 0xffa5 0xff90 0xffcc 0xff80 0xbeefffa5 ... FAIL 0xa5 0x90 0xcc 0x80 0xbeefffa5 ...
cs_w64_lds_i8_d16_write, RTX 4070 SUPER emulated PASS PASS
lds_fuzz --seed 9950 program 95, wave64, Radeon native 3 of 3 runs match 0 of 3 runs match
lds_fuzz --seed 9950 program 95, wave64, RTX 4070 SUPER emulated matches matches

tests/semantic/test_lds_i8_d16_write.py: 3 tests OK. This is the same AMD driver version as @Darkz0rz's run, so it adds a second machine rather than a new driver.

Not run: the full GPU suite, the rest of the fuzz seeds, and the emulated Radeon path. No game files. AI-assisted (Claude Code).

@bunbeans2-arch

Copy link
Copy Markdown

RDNA4 data point: AMD Radeon RX 9070 XT (gfx1201), AMD Windows 26.10.1 (32.0.32015.7029). I ran cs_w64_lds_i8_d16_write with main d974c88a's lowering (4 OpBitFieldSExtract in the module) and with this head's (none), 3 runs each, wave64 pinned (VKC_SUBGROUP_SIZE=64, "compute subgroup size: 64"). All six give the expected 0x0000FFA5 0x0000FF90 0x0000FFCC 0x0000FF80 0xBEEFFFA5 0xBEEFFF90 0xBEEFFFCC 0xBEEFFF80.

So on RDNA4 the old lowering is already right. The zero-extended half looks specific to the RDNA1/RDNA2 path of AMD's Windows compiler (a guess from one RDNA4 card; RDNA3 not tested), like the items in #5934 (comment 7101923660). That means this fixture can tell the two lowerings apart only there. This is not a positive control: the card shows no failure.

spirv-val isn't installed here, so the modules were assembled with each tree's tools/spirv_asm.py. Synthetic program only. AI-assisted (Claude Code). No game files.

KubickNubick added a commit to KubickNubick/Leonida that referenced this pull request Nov 23, 2026
…Rexed#5577)

All 64 invocations stored the five initial dwords to the same LDS words with plain stores before the first
barrier: a data race under Vulkan's memory model, equal values or not (@Hiiva's review). The fill now runs in
lane 0 only (v_cmpx_eq_u32 0, v0), and EXEC goes back to all lanes before the barrier. The later ds_write_b16
writes from every lane are atomic and/or pairs and stay as they were. The fixture still fails on the Radeon
with the old lowering (3 of 3) and passes with the new one.

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

Copy link
Copy Markdown
Author

Thanks @Hiiva, you are right, and thank you for the independent check of the lowering itself. Fixed in 84d285a, on top of a rebase onto main 1cc6e3c (0b5ecbd is the original commit, rebased; the conflict was again one list of fixture names in scripts/run_gpu_tests.py).

The fixture's fill has one writer now. v_cmpx_eq_u32_e32 0, v0 leaves lane 0 alone to do the five ds_write_b32, then s_mov_b64 exec, -1 brings all 64 lanes back before the barrier. The later ds_write_b16 from every lane are OpAtomicAnd / OpAtomicOr pairs on the same word, so they are ordered; each lane's "or" follows its own "and", so the word ends as that value whichever lane goes last. The header says both. Expected words are unchanged.

It still catches the driver. Radeon iGPU (gfx1036, 32.0.21042.62), native wave64, tools/rdna2spirv.py from main against this branch, three runs each on the fixed fixture before the rebase and one each after it:

Radeon, native wave64 RTX 4080 (621.01), LEONIDA_W64_EMULATE=1
old lowering FAIL 0xa5 0x90 0xcc 0x80 ..., every run PASS
this branch PASS 0xffa5 0xff90 0xffcc 0xff80 ..., every run PASS

On the rebased head, test programs rebuilt from it: scripts/run_gpu_tests.py Radeon native 219/236 and emulated 219/236, 0 failed; RTX 4080 native 186/236 and emulated 218/236, each with the one ms_wave_info_s3 failure that main has on 32-wide GPUs (#5741). lds_fuzz --seed 9950, 200 programs: Radeon native 400/400, RTX 4080 emulated 400/400. tests/semantic test_lds_*.py: 375 OK. regen_fixtures.py --check: clean.

Thanks also @danosovsky for the before/after run on the 7600X and @bunbeans2-arch for the RX 9070 XT: so the old lowering fails on the gfx1036 drivers measured (32.0.21036.18, 32.0.21042.62, 32.0.21043.5001) and not on gfx1201 with 32.0.32015.7029.

Not rerun on this base: the full pytest tests comparison and check.py. I did not run the fixture under the validation layer's race check. AI-assisted (Claude Code).

@MuratK20

Copy link
Copy Markdown

Tested 84d285a merged on main 1cc6e3c on an RDNA2 iGPU (Radeon Graphics, gfx1036, 1002:13c0), AMD Windows driver 32.0.13036.4 (Vulkan 24.30.36), Windows 11: pass.

  • scripts/run_gpu_tests.py: 242/242 translated and spirv-val-valid; 215/236 pass, 20 skipped. The new cs_w64_lds_i8_d16_write passes. The only other non-pass is ms_wave_info_s3, which fails on main on this device as well; no other test changed vs main (214/235).
  • llvm-mc 21.1.8, Vulkan SDK 1.4.363.0, MSVC RelWithDebInfo.

AI-assisted (Claude Code).

@bobcatchris

Copy link
Copy Markdown
Contributor

Tested 84d285a58aa699b94369c8f9f07d85289a63a387 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. This is the RDNA1/RADV data point the earlier comment asked about for the RDNA1 compiler path.

  • python3 -I scripts/run_gpu_tests.py --filter cs_w64_lds_i8_d16_write --build runtime/build/linux: 1/1 passed, words 0xffa5 0xff90 0xffcc 0xff80 0xbeefffa5 0xbeefff90 0xbeefffcc 0xbeefff80 — the sign-extended halves, not the zero-extended ones suspected for the AMD Windows path.
  • Full python3 -I scripts/run_gpu_tests.py --build runtime/build/linux: 206/236 passed, 29 skipped, 1 failed on both cards, identical to this PR's base 0b5ecbd44 with the same toolchain; no regression. The single failure (cs_w32_salu64) is unchanged from base.
  • 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.

KubickNubick and others added 2 commits November 23, 2026 23:31
… not OpBitFieldSExtract (FUZZ-66)

AMD's Windows driver (gfx1036; 32.0.21042.62 here, 32.0.21036.18 and 32.0.21043.5001 on two other testers'
machines) loses the sign extension of ds_read_i8_d16 when the register is then written back with ds_write_b16:
the half written is 0x0090 for the byte 0x90, while the register stored to the buffer is right and the same
SPIR-V module is right on an NVIDIA RTX 4080. Found by tools/lds_fuzz.py --seed 9950, program 95 at 64 lanes.

The signed reads (ds_read_i8, ds_read_i16, ds_read_i8_d16, ds_read_i8_d16_hi) now take the field with
OpBitFieldUExtract and sign-extend it as (field ^ sign) - sign. The words are the same.

- runtime/test/shaders/cs_w64_lds_i8_d16_write.asm: GPU fixture, red on that driver with the old lowering and
  green with this one; registered in check.py and run_gpu_tests.py.
- tests/semantic/test_lds_i8_d16_write.py: the fixture's words on the CPU, and no OpBitFieldSExtract in the
  signed LDS reads.
- tests/semantic/test_lds_subdword_wide.py, test_lds_subword_d16.py: their negative controls swapped
  OpBitFieldSExtract for OpBitFieldUExtract; they now remove the xor/subtract pair.
- docs/design.md: the rule in the LDS row, with how it was confirmed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…Rexed#5577)

All 64 invocations stored the five initial dwords to the same LDS words with plain stores before the first
barrier: a data race under Vulkan's memory model, equal values or not (@Hiiva's review). The fill now runs in
lane 0 only (v_cmpx_eq_u32 0, v0), and EXEC goes back to all lanes before the barrier. The later ds_write_b16
writes from every lane are atomic and/or pairs and stay as they were. The fixture still fails on the Radeon
with the old lowering (3 of 3) and passes with the new one.

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

Copy link
Copy Markdown
Author

Rebased onto main 23060e0: 231fab1 is 0b5ecbd and 551effb is 84d285a, with no change to the lowering or the fixture. There were three conflicts, all next to this PR's lines rather than in them:

  • docs/design.md: main added the "LDS access order within a wave (Volatile)" row right after the LDS row. Both rows are kept, the LDS row as in this PR.
  • scripts/run_gpu_tests.py: the fixture-name list again. cs_w64_lds_i8_d16_write is added to main's list.
  • tests/semantic/regen_fixtures.py: since regen_fixtures: find the generated fixtures by their header instead of the SHADERS list #6680 it finds its sources by the marker line instead of SHADERS, so main's version is kept and cs_w64_lds_i8_d16_write.asm now starts with the ; regen_fixtures: … marker.

Checked without a GPU, on Windows 11:

I did no GPU run on this rebase. The GPU side of the PR is unchanged since the two passes on 84d285a above. The branch also merges cleanly into the current main dfe4e4a. AI-assisted.

@slint6614-dev

Copy link
Copy Markdown
Contributor

AMD Windows GPU check of 551effb04 (AI-assisted). AMD Adrenalin 26.11.2 on Windows 11 26300: Radeon RX 9070 (RDNA4, Vulkan driver 2.0.416) and Ryzen 9600X iGPU "AMD Radeon(TM) Graphics" (RDNA2 gfx1036, the console's family, driver 2.0.353); test programs from a fresh RelWithDebInfo build of main 867d922, Python 3.12.

scripts/run_gpu_tests.py --filter lds_i8_d16: PASS on both GPUs, same words on both: cs_w64_lds_i8_d16_write 0xffa5 0xff90 0xffcc 0xff80 0xbeefffa5 0xbeefff90 0xbeefffcc 0xbeefff80. All translated, all pass spirv-val.

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.