Skip to content

fix(kyty): lower LDS atomics on private storage to a load and store - #291

Open
relativespace2K wants to merge 1 commit into
simnJS:AnyKytyfrom
relativespace2K:fix/kyty-graphics-lds-atomics
Open

relativespace2K wants to merge 1 commit into
simnJS:AnyKytyfrom
relativespace2K:fix/kyty-graphics-lds-atomics

Conversation

@relativespace2K

@relativespace2K relativespace2K commented Nov 24, 2026 •

Copy link
Copy Markdown

What

A pixel or vertex shader that runs an LDS atomic (ds_add_u32, ds_min_u32, …) keeps its LDS in a Function/Private variable, because those stages have no workgroup storage. The emitter still wrote OpAtomicIAdd and the other OpAtomic* forms against that pointer, and Vulkan allows atomics only on Uniform, Workgroup, Image, StorageBuffer, PhysicalStorageBuffer and TaskPayloadWorkgroupEXT storage:

AtomicIAdd: Vulkan spec only allows storage classes for atomic to be: Uniform, Workgroup,
Image, StorageBuffer, PhysicalStorageBuffer or TaskPayloadWorkgroupEXT.

spirv-val refuses the module, and a driver may crash or miscompile on it.

The atomic is now lowered to a load, the operation and a store when the LDS variable is private to the invocation, so no other invocation can race with it. This covers the 32-bit integer atomics, the 64-bit integer atomics, the float min/max, increment/decrement and masked-OR helpers that go through AtomicUpdate. Workgroup and storage-buffer LDS keep their atomic instructions and barriers; compute shaders are unchanged.

Tested

New hand-written cases in kyty_shim_recompiler_robustness: ds_add_u32 in a pixel shader and ds_min_u32 in a vertex shader.

KYTY_FUZZ_SPIRV=abort build/tests/kyty_shim_recompiler_robustness_tests.exe
  lds-atomic-in-a-pixel-shader: ok
  lds-umin-in-a-vertex-shader: ok
  kyty_shim_recompiler_robustness: ok

ctest -R '^kyty_shim_recompiler_(robustness|valid_spirv)$'
  100% tests passed, 0 tests failed out of 2

On Windows 11 IoT Enterprise LTSC 24H2, Ryzen 5 5600, RX 6800 XT (AMD proprietary 26.10.1, Vulkan 1.4.315), Release with WinLibs GCC 15.2.0 and LLVM 21.1.8, with Khronos validation 1.4.363:

ctest -R '^kyty_shim_'
  95 passed, 2 failed, 1 skipped out of 98 (44.1 s, zero VUID- lines)

The two failures are pre-existing and unrelated: kyty_shim_merged_hull_draw (#270) and kyty_shim_wave_split_written_reads (open PR #268); the skip is kyty_shim_rt_corpus.

Not done: the one-hour libFuzzer run of the acceptance criteria. This Windows build has no ANYPS5_KYTY_FUZZERS; the two discovered shapes are now locked by the hand-written cases, which run with spirv-val.

tools/check_conventions.py --base origin/AnyKyty, tools/check_kyty_settings.py and tools/pr_overlap.py --repo simnJS/AnyPS5 --base AnyKyty --branch fix/kyty-graphics-lds-atomics are clean.

Checklist

  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs
  • No notes or investigation files added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: part of shaders: two kinds of invalid SPIR-V the recompiler fuzzer still finds #209 (the atomic storage class kind)
  • GPUs tested: AMD Radeon RX 6800 XT, AMD proprietary
  • AI-assisted: yes

A pixel or vertex shader that runs a DS atomic keeps its LDS in a Function or
Private variable, because those stages have no workgroup storage. The emitter
still wrote OpAtomicIAdd and the other OpAtomic* forms against that pointer,
and Vulkan allows atomics only on Uniform, Workgroup, Image, StorageBuffer,
PhysicalStorageBuffer and TaskPayloadWorkgroupEXT storage. spirv-val refused
the module, and a driver may crash or miscompile on it.

The atomic is lowered to a load, the operation, and a store: the variable is
per invocation, so no other invocation can race with it. The same applies to
the 64-bit integer atomics, to the float min/max and increment/decrement
helpers that go through AtomicUpdate, and to the masked OR. The workgroup and
storage-buffer forms keep their atomic instructions and barriers.

Fixes the second kind of simnJS#209 for the stages the fuzzer found it on.
@relativespace2K
relativespace2K force-pushed the fix/kyty-graphics-lds-atomics branch from af1d7b3 to c997b1e Compare November 24, 2026 14:08
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.

1 participant