Skip to content

tests/semantic: run LDS atomics in the interpreter, and value-test them - #812

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
LouisRiverstone:interp-lds-atomics
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
LouisRiverstone:interp-lds-atomics

Conversation

@LouisRiverstone

@LouisRiverstone LouisRiverstone commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Depended on #592, which is now merged; the branch is up to date with main, so the diff is this PR's change only.

tests/semantic/spirv_mini_interp.py runs 32-bit atomics only on physical-storage-buffer pointers. So the LDS atomics that tools/rdna2spirv.py already emits have no value test:

  • ds_add_u32, ds_sub_u32
  • ds_min_u32, ds_max_u32, ds_min_i32, ds_max_i32
  • ds_and_b32, ds_or_b32, ds_xor_b32
  • their _rtn_ forms, plus ds_wrxchg_rtn_b32 and ds_cmpst_rtn_b32

test_lds_atomic_add.py models OpAtomicIAdd in its own small interpreter. Claimed in #634.

Change

  • tests/semantic/spirv_mini_interp.py:
    • With one invocation, an atomic is read, combine, write on any pointer. So the atomic branch now also takes the variable-element pointers that OpLoad / OpStore use: Workgroup, which is LDS since Translator: ds_read_u8/i8_d16[_hi] 8-bit LDS reads into a 16-bit half (SHADER-85) #592, and Function. The PSB path is unchanged.
    • Push-constant pointers still raise, and so does a target that isn't a 32-bit integer. The module docstring says so.
  • tests/semantic/test_lds_atomics_values.py (new, stdlib unittest):
    • Each case runs a compute listing as one invocation. It seeds an LDS dword, runs the atomic, reads the dword back, and stores (returned value, new word) to a buffer.
    • It checks all nine _rtn_ kinds on a 7×4 grid of edge values, including the signed/unsigned min/max split at 0x80000000.
    • It checks the non-returning forms, which must leave vdst alone.
    • It checks ds_wrxchg_rtn_b32, and ds_cmpst_rtn_b32 with both a match and a mismatch (data0 is the comparator, data1 the value written).
    • It checks that offset: reaches the same dword, plus 20 seeded cases.

No translator change. All of these already matched the RDNA2 definitions; nothing checked their values before.

Tested

  • python -I -m unittest discover -s tests/semantic: all pass. Without the interpreter change, the new file has 307 errors (UnsupportedConstruct: Op… outside PhysicalStorageBuffer).
  • python -I tests/test_lds_fuzz.py and python -I tests/test_mem_diff.py pass. compileall passes. CPU only, no game files.

AI-assisted (Claude Code): it wrote the change and the tests, and ran the checks listed above.

spirv_mini_interp ran 32-bit atomics on physical-storage-buffer pointers
only, so the LDS atomics the translator emits (ds_add/sub/min/max/and/or/xor,
ds_wrxchg_rtn_b32, ds_cmpst_rtn_b32) had no value test. With one invocation an
atomic is read-combine-write on any pointer, so it now also takes the
variable-element pointers OpLoad/OpStore use (Workgroup = LDS since ItsNotRexed#592,
Function); push constants stay read-only.

tests/semantic/test_lds_atomics_values.py runs compute listings as one
invocation and checks the returned and stored words against a plain-Python
model of each RDNA2 DS atomic.
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026

@quackottu quackottu 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 e6e7ceb on NVIDIA GeForce RTX 5070 (subgroup 32), driver 621.24, Windows 11 Pro (26300), Vulkan SDK 1.4.363.0, llvm-mc 21.1.8 (built with scripts/build_llvm_mc.ps1), scripts/run_gpu_tests.py:

  • native: 71/98 passed, 27 skipped (main 8df277f here: 64/91 passed, 27 skipped, all wave64 tests needing a 64-wide subgroup)
  • LEONIDA_W64_EMULATE=1: 98/98 passed (main here: 91/91)
  • python -m unittest discover -s tests/semantic: Ran 980 tests in 224.316s OK

@ItsNotRexed
ItsNotRexed merged commit c45e375 into ItsNotRexed:main Nov 22, 2026
7 checks passed
@esteban-dcp

Copy link
Copy Markdown

Tested e6e7ceb on two GPUs, Linux 7.3.5 (CachyOS): pass.

  • NVIDIA RTX 4050 Laptop (Ada), driver 620.73.04, subgroup 32: 100 shaders: 100 translated, 100 pass spirv-val; 71/98 passed, 27 wave64 skipped; with LEONIDA_W64_EMULATE=1: 98/98 passed
  • AMD Radeon 740M (RDNA3, RADV, Mesa 26.3.1), subgroup 32..64: 98/98 passed
  • This PR adds no GPU test of its own, so this checks that it breaks nothing in the existing suite on either vendor (the test programs were built from this branch, which is 92 commits behind main).
  • CPU: unittest discover -s tests/semantic 980 OK

python -I scripts/run_gpu_tests.py --build runtime/build/linux on the PR head, VK_LOADER_DRIVERS_SELECT pinning each GPU (device line checked), VK_LOADER_LAYERS_DISABLE=~implicit~. 0 failures. (An earlier run of mine was on the previous head and I discarded it.)

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.

4 participants