fix(shader): apply returning LDS atomics in lane order on MoltenVK #14218

Open
frankea wants to merge 17 commits from upstream-pr/14218 into main
frankea commented 2026-11-01 00:27:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-11-01T00:27:13Z.


What

A wave's same-address LDS atomics with a used return value are now applied in ascending lane order on MoltenVK. Programs that rank lanes with the returned value, such as a radix sort that takes each record's position inside its wave from ds_add_rtn_u32 on byte-packed per-wave counters, were unstable on Apple GPUs.

Semantics and sources

  • RDNA 2 ISA reference guide (30 November 2020), section 12.13 "LDS & GDS Instructions", p. 193: DS_ADD_RTN_U32 is tmp = MEM[ADDR]; MEM[ADDR] += DATA; RETURN_DATA = tmp, per lane, and the other returning DS atomics follow the same pattern. Section 10.4.3 (p. 94) says only that atomic operations can return the LDS "pre-op" value. Neither states in which order the lanes of one wave that hit one address are applied. The only place the guide characterises LDS atomic ordering, section 2.3.1 "Local Data Share (LDS)" (printed page 9), calls them "fast, unordered atomic operations".
  • LLVM's AMDGPU atomic optimizer (which covers LDS) and Mesa's nir_opt_uniform_atomics replace same-address atomics with one atomic plus a lane-order exclusive scan, so AMD's compilers treat lane order as an allowed result. That does not say what the hardware does when every lane issues its own atomic.
  • This PR assumes ascending lane order, and the hardware oracle has now measured it. angrysandhill ran it on an AMD Radeon RX 6750 XT (gfx1031, RDNA2; Windows 10 22H2, Adrenalin 26.10.1) for ds_add_rtn_u32 with data 1 from every lane on one LDS dword, ds_wrxchg_rtn_b32, and the add under EXEC 0x55555555, in wave32 and wave64, with 5 identical runs each: lane i returned i (i/2 under the mask) in every case (comment). Jirka135 ran 12 returning forms (ds_add, sub, rsub, inc, dec, min_u32, max_u32, xor, mskor, wrxchg, cmpst, ds_add_rtn_u64) on an AMD Radeon 8060S (gfx1151, RDNA 3.5), 8,192 lanes per case in wave32 and wave64, all lanes and with about 1 lane in 8 masked off: 0 returns and 0 final LDS values differ from ascending lane order (comment). The console's gfx1013 is not measured; the debt entry now cites both runs and closes on that measurement. A shipped radix sort pass (GT7's BVH build, below) is only stable under this order: each record's rank is "lanes of this wave that hit this address before me".
  • Vulkan memory model: a scoped modification order totally orders the atomic writes to a location but "relates no other operations", and program order is defined per invocation. Nothing ties that order to SubgroupLocalInvocationId, so one OpAtomicIAdd per invocation may be applied in any lane order.
  • On MoltenVK, SPIRV-Cross emits that atomic as atomic_fetch_add_explicit(..., memory_order_relaxed) on threadgroup memory. Relaxed atomics give no order between threads, and the M5 Max uses that freedom (measured below).

Measured with the new agc_driver_lds_atomic_lane_order test on main (hand-encoded RDNA; 128 workgroups per case; for the order columns every lane of a wave does ds_add_rtn_u32 with data 1 on one LDS dword per wave, with and without an EXEC mask; the forms column uses random operands on up to 8 addresses per wave with about 1 lane in 8 masked off, in workgroup LDS and again with 16,384 LDS dwords, which puts the LDS in a storage buffer on every device):

GPU wave64, 64/128/256 threads wave32, 32/64/128/256 threads 18 returning 32-bit integer forms + ds_add_rtn_u64, wave32 and wave64, 256 threads, workgroup and device-memory LDS
Apple M5 Max, MoltenVK 1.4.2 0 waves in lane order; one lane-to-rank map in every wave: 0,1,2,3,8,9,10,11,16,17,18,19,24,25,26,27,4,5,6,7,12,13,14,15,20,21,22,23,28,29,30,31, then the same +32 for lanes 32-63 (lanes 0-31 always before 32-63) 0 waves in lane order, the same 32-lane map every 32-bit form differs from lane order (4,003 to 18,132 of 32,768 returns per form, the same in both LDS placements); ds_add_rtn_u64 is in lane order (the 64-bit LDS lock already serializes lanes with OpGroupNonUniformElect)
NVIDIA RTX 4090, 616.92 all waves in lane order all waves in lane order all in lane order, in both LDS placements

The M5 Max serves each 32-lane SIMD-group in quads 0,4,1,5,2,6,3,7. For ds_rsub, ds_inc, ds_dec, ds_mskor, ds_wrxchg, ds_wrxchg2, ds_cmpst and ds_wrap, the final LDS values differ as well, not just the returns. ds_wrxchg2_rtn_b32 and ds_wrxchg2st64_rtn_b32 lower to two ds_wrxchg_rtn_b32 halves; the test keeps their two addresses apart, so the order of the halves does not matter.

Change

  • New SpirvTarget::laneOrderedLdsAtomics, plumbed like ldsLockFences: SpirvTargetOptions, SpirvEmitterState, the shader cache key, agc_shader_replay --lane-ordered-lds-atomics.
  • The new SPIR-V test is registered in its own fragment, tests/cmake/agc_spirv_lds_atomic_lane_order_tests.cmake (written by tools/agc_test_split.py resolve during the rebase); the new execution test is picked up by the tests/execution glob.
  • VulkanDevice::buildTarget sets it only on VK_DRIVER_ID_MOLTENVK (LdsAtomicLaneOrderRequired). The RTX 4090 on Windows (616.92) was in lane order in every case measured here; domx4q's RTX 4090 run on Linux (620.70.06) was not for wave64 in one-wave 64-thread workgroups (the spanned mode), see Tested. Other drivers keep main's order in this PR.
  • It applies to an LDS atomic (SharedAtomic*) only when:
    • its result is used;
    • the LDS is workgroup memory or the device-memory LDS buffer;
    • the program does not already take the 64-bit LDS lock.
  • With laneCount 2 (wave64 on a 32-lane host), both halves are handled in one loop at the first half's emission, so lanes 0-31 rank before lanes 32-63 by construction rather than by issue order.
  • 32-bit add, sub, smin, umin, smax, umax, and, or and xor (aggregated path):
    • The leader is the first pending lane, found with a ballot and FindLSB.
    • Every pending lane on the leader's address joins the round.
    • The leader does one OpAtomic* with the combined operand of the round. Each lane returns the old value combined with an exclusive scan of the lower lanes' operands.
    • Add and sub use OpGroupNonUniformIAdd ExclusiveScan. The others use a Hillis-Steele scan over OpGroupNonUniformShuffle, with only the totals from Reduce. SPIRV-Cross refuses the other scans for Metal: Metal doesn't support ExclusiveScan for OpGroupNonUniformSMin appeared while testing on MoltenVK.
    • Cost: one loop round, with one atomic, per distinct address the wave touches, so 1 to 64 rounds per instruction. GT7's sort pass (8-bit digits) touches about 57 addresses per wave with random keys.
  • Every other returning LDS atomic, and every form on a device without subgroup arithmetic (serialized path):
    • Covers swap, inc, dec, rsub, mskor, cmpst, wrap, the float forms, and 64-bit forms in device-memory LDS.
    • Each loop iteration runs the existing emission for the first pending lane only, so 1 to 64 rounds per instruction.
    • Each round ends with OpControlBarrier whose execution and memory scopes are both the wave LDS scope (WaveLdsScope: Subgroup when one host subgroup holds the guest wave, Workgroup when the workgroup is one wave, including the spanned mode), with AcquireRelease|WorkgroupMemory, plus UniformMemory when the LDS is in device memory. Every invocation of the wave executes it after the leader branch and before the next ballot, so under the Vulkan memory model round k synchronizes with round k+1 and comes first in the address's modification order; the order does not rest on SIMD-group issue order. SPIRV-Cross emits it as simdgroup_barrier or threadgroup_barrier. The derivation is in this comment.
    • SPIR-V 1.6 (section 3.3.20) makes a Workgroup-scope OpControlBarrier undefined unless every invocation of the workgroup executes the same dynamic instance. Guest branches are scalar: s_cbranch_execz, execnz, vccz and vccnz become subgroup ballots and scc branches scalar values, and EXEC-inactive lanes run every round with nothing pending, so the rounds sit in uniform control flow. The emitter checks this on every module with rounds: it runs the barrier uniformity analysis the spanned mode uses, counting a subgroup-scope collective with an invocation-independent result (ballot, broadcast, Reduce, a shuffle from a uniform index) in uniform control flow as uniform, and throws if a control barrier sits in control flow a per-invocation value decides.
    • Where there is no wave LDS scope (non-compute stages, or several waves per workgroup on a host subgroup that is not 32 lanes wide), the serialized forms take the plain path and keep the host order. MoltenVK reports 32-lane subgroups, so it does not reach that case.
  • Spanned waves take the serialized path through the existing spanned ballot.
  • Split subgroups (wave32 on a host subgroup wider than 32 lanes): min, max, and, or and xor cannot use the shuffle scan, which reads lower host lanes that belong to the other wave and may be inactive, and the wave's ballot word is chosen by invocation index, which the uniformity check cannot prove uniform; so all per-lane forms take the plain path there. Add and sub keep the aggregated path, since their native scans count only active invocations. No tested GPU has such subgroups; agc_spirv_lds_atomic_lane_order checks the emission.
  • Measured cost on the M5 Max (the test's program as a microkernel: 8,192 workgroups of 256 threads, wave64, the returning atomic plus 9 other memory operations per thread; best of 7 dispatches, two runs, main vs this PR; the GPU was shared with a running game, so the numbers are noisy):
    • ds_add_rtn_u32, 64 distinct addresses per wave: 4.46-4.65 vs 5.35-5.73 ms (+15-29%).
    • ds_min_rtn_u32, 64 distinct addresses (shuffle scan): 4.58-4.69 vs 6.72-6.85 ms (+43-50%).
    • ds_wrxchg_rtn_b32 (serialized), 64 distinct addresses: 4.49-4.78 vs 4.63-4.77 ms (within noise; an earlier pair of runs gave +4-20%).
    • One address per wave, all three: within noise.
    • Serving several addresses per round would cut the many-address cost; that is left for a later change.
  • Not covered, recorded in docs/dev/debt/shader.md:
    • LDS atomics whose result is unused keep the host order. For add, sub, min, max, and, or and xor the final LDS value does not depend on the order. For rsub, inc, dec, mskor, cmpst, wrxchg, wrap and the float forms it can: with per-lane operands that differ, the M5 Max leaves 572 to 3,683 of 32,768 final dwords out of lane order for the non-returning ds_rsub_u32, ds_inc_u32, ds_dec_u32, ds_mskor_b32 and ds_cmpst_b32. Serializing those would cost up to 64 rounds per instruction on a still unmeasured assumption, and no title is known to need it. With one operand for every lane, as a ring counter's ds_inc_u32 has, the final value is the same in any order.
    • GDS atomics.
    • Flat atomics whose address lands in the LDS aperture.
    • AMD hosts, which are not reordered. angrysandhill's run of the three oracle bodies through the recompiler on the RX 6750 XT's Vulkan driver returned the same values as the hardware.

Tested

Run on 2026-10-31 with this branch at 0700fe6c79, rebased onto main b08c539c50. It was then rebased onto main 8a4fc62318 (head 2053545772) with no conflicts; on the M5 Max the focused set on that head gave the same result as below (41 pass, 6 skip, the same 2 LDS failures; 0 VUID- lines). Since then the branch has only gained commits: main merged at e07db72776 (11/07, including #10858), then the round barrier (98d69b6cb8) and its execution test (9c36d01079); see the head 9c36d01079 paragraph after this list. Builds: macOS 27.0.1 on an Apple M5 Max (x86_64 under Rosetta, AppleClang 21, MoltenVK 1.4.2 from LunarG SDK 1.4.363.0), and Windows 11 10.0.26200 on an RTX 4090 (driver 616.92, winlibs GCC 15.2). main does not build the AGC driver on macOS by itself, so both Mac trees carry the same local macOS build aids (27 files, not part of this pull request); only this change differs between them. Both machines run the same focused set on main (b08c539c50 plus only the new execution test, in the version without the two forced passes, which need the new flag) and on this branch, with and without VK_LAYER_KHRONOS_validation, using ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -V. The set is 49 tests on the branch and 48 on main (no agc_spirv_lds_atomic_lane_order there): agc_driver_lds_*, pixel_lds*, buffer and global atomics, wave, lane and subgroup tests, agc_spirv_lds_atomic_*, agc_subgroup_barrier and agc_shader_disk_cache. A VK_LOADER_DEBUG=layer probe shows Insert instance layer "VK_LAYER_KHRONOS_validation" on both sides on both machines. The rebase changed only where the SPIR-V test is registered; the cost figures and the non-returning counts above (a local probe, not part of this pull request) and the GT7 replay below come from the same emission code before the rebase.

  • Apple M5 Max:
    • On main, agc_driver_lds_atomic_lane_order fails (87 cases out of lane order; 0 of 14 same-address configurations in lane order), with and without the validation layer.
    • On the branch it passes, in all three passes: the device target, the flag forced on, and the flag forced on without GroupNonUniformArithmetic (serialized path). Each pass checks every form in workgroup and in device-memory LDS: 228 op lines, 0 differences.
    • agc_driver_lds_subword_store_branch and agc_driver_lds_tree_reduction fail identically on main and the branch. These are wave-LDS barriers in SIMD-group-divergent code, the issue #10858 addresses; they are not touched here.
    • 6 tests skip on both sides because MoltenVK lacks the feature: agc_driver_buffer_atomics, agc_driver_global_atomics64, agc_driver_global_atomics_float and agc_driver_global_atomics_lanes (no shaderBufferInt64Atomics), agc_driver_mesh_vector_window_waves (no VK_EXT_mesh_shader) and agc_driver_ngg_vertex_wave_reduction (no subgroup arithmetic in vertex shaders). So the branch passes 41 of the 43 tests that run and main 39 of 42.
    • 0 VUID-, SYNC-HAZARD or Validation Error lines on either side.
  • RTX 4090:
    • main: 47 of 48 pass and 1 is skipped, with and without the validation layer. The new execution test's device-target pass is in lane order for every case: 14 of 14 same-address configurations, and 76 op lines with 0 differences, in workgroup and device-memory LDS.
    • The branch: 48 of 49 pass and 1 is skipped, with and without the validation layer. That includes the new execution test's three passes (228 op lines, 0 differences); the forced passes run the aggregated path and, without subgroup arithmetic, the serialized path on NVIDIA as well.
    • The skip is agc_driver_vertex_elected_atomic_max on both sides (the device runs vertex programs in subgroups). tools/check_skips.py --job windows passes on all four reports.
    • 0 VUID-, SYNC-HAZARD or Validation Error lines on either side.
  • lavapipe (CI) was not run here. The new execution test skips on devices whose subgroups are narrower than 32 lanes, as agc_driver_ds_append_consume does, since a wave then spans several host subgroups; whether CI's lavapipe skips it or runs it is not checked. agc_spirv_lds_atomic_lane_order needs no GPU.
  • agc_spirv_lds_atomic_lane_order (new, no GPU) checks the emitted SPIR-V:
    • Wave64 ds_add_rtn_u32 emits one OpAtomicIAdd for both halves, with an exclusive scan and a reduce per half (wave32: one of each).
    • ds_min_rtn_u32 reduces with OpGroupNonUniformUMin and never scans with it.
    • ds_inc_rtn_u32 gains exactly one lane loop.
    • Wave32 on a 64-lane host: ds_add_rtn_u32 still scans once and adds once; ds_min_rtn_u32 in a one-wave workgroup compiles with the atomic, loop and control-barrier counts of the unordered compile; with several waves per workgroup ds_wrxchg_rtn_b32 and ds_min_rtn_u32 compile with the atomic, loop and control-barrier counts of the unordered compile.
    • Round barrier (head 9c36d01079): for each serialized atomic the test walks the control-flow graph and requires that every path from the atomic to the lane loop's latch passes an OpControlBarrier with execution scope equal to memory scope and to the expected wave scope, with the semantics above, in a block outside the leader branch that dominates the latch. Cases: masked ds_wrxchg_rtn_b32 for wave32 with 256 and 32 threads, wave64 on a 32-lane host, wave64 with device-memory LDS, spanned wave64 with workgroup and device-memory LDS, masked ds_cmpst_rtn_b32, and serialized ds_add_rtn_u32 without subgroup arithmetic. The aggregated ds_add_rtn_u32 must have no control barrier in its loop. The same module with its control barriers replaced by OpNop must fail the check; the emitter before 98d69b6cb8 fails it.
    • Divergent guest flow (head ea559cd2bf): ds_wrxchg_rtn_b32 behind s_cbranch_execz, s_cbranch_scc0 and s_cbranch_vccz after s_and_saveexec, and inside a loop that drops lanes from EXEC and repeats with s_cbranch_execnz, for wave32 with 256 and 32 threads, wave64 on a 32-lane host with 256 and 64 threads, and spanned wave64: all 20 compile and pass the round barrier check and the uniformity analysis; the 16 non-spanned modules with their ballots turned into OpGroupNonUniformInverseBallot are all rejected. spanned_uniformity adds 9 cases for the subgroup-collective analysis.
    • Without subgroup arithmetic, ds_add_rtn_u32 takes the serialized path.
    • An unused ds_add_u32 and programs under the 64-bit lock compile byte-identically with and without the flag.
  • agc_subgroup_barrier checks that only MoltenVK requires the order. agc_shader_disk_cache checks that the flag changes the cache key.

Head 9c36d01079, on the Apple M5 Max only (MoltenVK 1.4.2, both a locally built MoltenVK ICD and the Vulkan SDK 1.4.363.0 ICD; the RTX 4090 was not rerun on this head). The new CheckSwapChain case of agc_driver_lds_atomic_lane_order runs two back-to-back ds_wrxchg_rtn_b32 with unique data on one dword under 9 EXEC patterns (wave32) or 13 (wave64), with 256 threads and with a one-wave workgroup, in workgroup and device-memory LDS. The lane-ordered target gave 28,672 of 28,672 chains in lane order on each ICD; the unordered target, as a negative control, gave valid chains in another order (quads 0-3, 16-19, 4-7, 20-23, ...) for about 60% of chains and 0 broken chains. The emitter before the round barrier also passed, so these runs do not show the barrier's effect; the CPU test above is what checks it. The full LDS suites, including agc_driver_lds_subword_store_branch and agc_driver_lds_tree_reduction now that #10858 is in the branch, the subgroup barrier, LDS lock, spanned uniformity and shader disk cache tests pass on both ICDs. Details in this comment.

Head ea559cd2bf (main 70bb3678d8 merged), on the Apple M5 Max only (MoltenVK 1.4.2, the locally built ICD and the SDK 1.4.363.0 ICD, VK_LAYER_KHRONOS_validation loaded; the RTX 4090 was not rerun). agc_driver_lds_atomic_lane_order adds the swap pair behind s_and_saveexec and s_cbranch_execz: 28,672 of 28,672 chains in lane order, 0 reordered, 0 broken on each ICD, with 38 waves per ICD that had no active lane and skipped the block. ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -V over the agc_driver_lds_* suites, pixel LDS read-modify-write, spanned ballot sequence, agc_spirv_lds_atomic_*, agc_subgroup_barrier, agc_shader_disk_cache, the shader replay tests and spanned_uniformity: 25 of 25 pass on each ICD, 0 VUID lines. The device has no full 32-lane compute subgroups, so the spanned execution modes skip.

Head f9ae674592 (main ef7dc4452d merged in de7cde2ec1, which also puts 3rdparty/SDL2 back to main's commit; the previous merge 124e8bfdef had left the branch's older pointer). domx4q ran the focused set with the validation layer on an RTX 4090 under Linux (driver 620.70.06; comment): 0 VUID- lines, every lane-ordered target case in lane order, but the device-target pass of agc_driver_lds_atomic_lane_order failed in two wave64 cases with one 64-thread wave per workgroup, where the two 32-lane halves of the wave interleave (lane-to-rank map 0,1,3,5,...,61 for lanes 0-31 and 2,4,...,62,63 for lanes 32-63). That pass required lane order from targets that do not enable laneOrderedLdsAtomics, which this PR does not change. f9ae674592 makes the device-target pass a failure only when the device target enables the flag (MoltenVK) and otherwise prints the count, as the unordered-target swap chains already do. On the M5 Max with the locally built MoltenVK ICD and VK_LAYER_KHRONOS_validation (ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -V over the lane order, LDS atomics, 64-bit, mixed width, condxchg, read/write, tree reduction, LDS lock, spanned uniformity, subgroup barrier, shader disk cache and replay tests): 17 of 17 pass, the layer is inserted in all 8 device tests, 0 VUID- lines; agc_driver_lds_atomic_lane_order also passes with the SDK 1.4.363.0 ICD. The RTX 4090 was not rerun.

  • Title, offline (no game data in this PR): GT7's BVH radix sort pass, replayed outside the game on the M5 Max from a captured request with 1,152 synthetic records. Each row is a 4-pass sort compared with a CPU stable sort:
emission result
flag off (as on main) with the wave-LDS barrier fix of #10858 every pass is a permutation but unstable: 24, 21, 20 and 12 records out of place in passes 0 to 3; with 8-bit keys, up to 864
this PR + #10858 all 4 passes equal the CPU stable sort in 3 of 3 repeats; the same holds for seeds 1 to 5 with the equivalent waveLdsMemoryBarriers target knob in place of #10858
main before #10858, or this PR without it corrupted by the wave-LDS barrier issue that #10858 fixes: pass 0 loses about 600 of 1,152 records, and some runs hang in the look-back spin

In the game, on the M5 Max: this branch was not run by itself. A local GT7 build with this change, the GLC atomic load change #14217, a subgroup-scope variant of the #10858 barrier fix and other unmerged changes went through the Fit presentation, the scene that builds the large ray-tracing BVHs: no cyclic tree in about 1,800 checks of GT7's parent walk. In an earlier run without these fixes, 32 of the 32 trees it checked were cyclic.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none (GT7's sort also needs #10858, which merged on 11/02 and is in this branch. The GLC atomic load change #14217 adds lines at the same places in 7 files, so whichever of the two merges second will merge main and resolve them)
  • Fixes: none
  • Unblocks: PPSA01317 #4697 (the BVH radix sort on MoltenVK, together with #14217 and the merged #10858; checked offline, and in game only in a local build with other unmerged changes)
  • GPUs tested: Apple M5 Max, MoltenVK 1.4.2 (LunarG SDK 1.4.363.0), macOS 27.0.1, x86_64 build under Rosetta; NVIDIA GeForce RTX 4090, driver 616.92, Windows 11 (10.0.26200)
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5102901276 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14218). Originally posted by [frankea](https://github.com/frankea) on 2026-11-01T00:27:13Z. --- ### What A wave's same-address LDS atomics with a used return value are now applied in ascending lane order on MoltenVK. Programs that rank lanes with the returned value, such as a radix sort that takes each record's position inside its wave from `ds_add_rtn_u32` on byte-packed per-wave counters, were unstable on Apple GPUs. **Semantics and sources** - [RDNA 2 ISA reference guide](https://gpuopen.com/download/rdna2-shader-instruction-set-architecture.pdf) (30 November 2020), section 12.13 "LDS & GDS Instructions", p. 193: `DS_ADD_RTN_U32` is `tmp = MEM[ADDR]; MEM[ADDR] += DATA; RETURN_DATA = tmp`, per lane, and the other returning DS atomics follow the same pattern. Section 10.4.3 (p. 94) says only that atomic operations can return the LDS "pre-op" value. Neither states in which order the lanes of one wave that hit one address are applied. The only place the guide characterises LDS atomic ordering, section 2.3.1 "Local Data Share (LDS)" (printed page 9), calls them "fast, unordered atomic operations". - [LLVM's AMDGPU atomic optimizer](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp#L716-L780) (which covers LDS) and [Mesa's `nir_opt_uniform_atomics`](https://gitlab.freedesktop.org/mesa/mesa/-/blob/mesa-24.2.0/src/compiler/nir/nir_opt_uniform_atomics.c#L25-L35) replace same-address atomics with one atomic plus a lane-order exclusive scan, so AMD's compilers treat lane order as an allowed result. That does not say what the hardware does when every lane issues its own atomic. - This PR assumes ascending lane order, and the hardware oracle has now measured it. angrysandhill ran it on an AMD Radeon RX 6750 XT (gfx1031, RDNA2; Windows 10 22H2, Adrenalin 26.10.1) for `ds_add_rtn_u32` with data 1 from every lane on one LDS dword, `ds_wrxchg_rtn_b32`, and the add under EXEC `0x55555555`, in wave32 and wave64, with 5 identical runs each: lane i returned i (i/2 under the mask) in every case ([comment](https://github.com/boykopovar/AnyPS5/pull/14218#issuecomment-6797630524)). Jirka135 ran 12 returning forms (`ds_add`, `sub`, `rsub`, `inc`, `dec`, `min_u32`, `max_u32`, `xor`, `mskor`, `wrxchg`, `cmpst`, `ds_add_rtn_u64`) on an AMD Radeon 8060S (gfx1151, RDNA 3.5), 8,192 lanes per case in wave32 and wave64, all lanes and with about 1 lane in 8 masked off: 0 returns and 0 final LDS values differ from ascending lane order ([comment](https://github.com/boykopovar/AnyPS5/pull/14218#issuecomment-6805393095)). The console's gfx1013 is not measured; the debt entry now cites both runs and closes on that measurement. A shipped radix sort pass (GT7's BVH build, below) is only stable under this order: each record's rank is "lanes of this wave that hit this address before me". - Vulkan memory model: a [scoped modification order](https://docs.vulkan.org/spec/latest/appendices/memorymodel.html#memory-model-scoped-modification-order) totally orders the atomic writes to a location but "relates no other operations", and program order is defined per invocation. Nothing ties that order to `SubgroupLocalInvocationId`, so one `OpAtomicIAdd` per invocation may be applied in any lane order. - On MoltenVK, SPIRV-Cross emits that atomic as `atomic_fetch_add_explicit(..., memory_order_relaxed)` on threadgroup memory. Relaxed atomics give no order between threads, and the M5 Max uses that freedom (measured below). **Measured with the new `agc_driver_lds_atomic_lane_order` test on `main`** (hand-encoded RDNA; 128 workgroups per case; for the order columns every lane of a wave does `ds_add_rtn_u32` with data 1 on one LDS dword per wave, with and without an EXEC mask; the forms column uses random operands on up to 8 addresses per wave with about 1 lane in 8 masked off, in workgroup LDS and again with 16,384 LDS dwords, which puts the LDS in a storage buffer on every device): | GPU | wave64, 64/128/256 threads | wave32, 32/64/128/256 threads | 18 returning 32-bit integer forms + `ds_add_rtn_u64`, wave32 and wave64, 256 threads, workgroup and device-memory LDS | |---|---|---|---| | Apple M5 Max, MoltenVK 1.4.2 | 0 waves in lane order; one lane-to-rank map in every wave: `0,1,2,3,8,9,10,11,16,17,18,19,24,25,26,27,4,5,6,7,12,13,14,15,20,21,22,23,28,29,30,31`, then the same +32 for lanes 32-63 (lanes 0-31 always before 32-63) | 0 waves in lane order, the same 32-lane map | every 32-bit form differs from lane order (4,003 to 18,132 of 32,768 returns per form, the same in both LDS placements); `ds_add_rtn_u64` is in lane order (the 64-bit LDS lock already serializes lanes with `OpGroupNonUniformElect`) | | NVIDIA RTX 4090, 616.92 | all waves in lane order | all waves in lane order | all in lane order, in both LDS placements | The M5 Max serves each 32-lane SIMD-group in quads 0,4,1,5,2,6,3,7. For `ds_rsub`, `ds_inc`, `ds_dec`, `ds_mskor`, `ds_wrxchg`, `ds_wrxchg2`, `ds_cmpst` and `ds_wrap`, the final LDS values differ as well, not just the returns. `ds_wrxchg2_rtn_b32` and `ds_wrxchg2st64_rtn_b32` lower to two `ds_wrxchg_rtn_b32` halves; the test keeps their two addresses apart, so the order of the halves does not matter. **Change** - New `SpirvTarget::laneOrderedLdsAtomics`, plumbed like `ldsLockFences`: SpirvTargetOptions, SpirvEmitterState, the shader cache key, `agc_shader_replay --lane-ordered-lds-atomics`. - The new SPIR-V test is registered in its own fragment, `tests/cmake/agc_spirv_lds_atomic_lane_order_tests.cmake` (written by `tools/agc_test_split.py resolve` during the rebase); the new execution test is picked up by the `tests/execution` glob. - `VulkanDevice::buildTarget` sets it only on `VK_DRIVER_ID_MOLTENVK` (`LdsAtomicLaneOrderRequired`). The RTX 4090 on Windows (616.92) was in lane order in every case measured here; domx4q's RTX 4090 run on Linux (620.70.06) was not for wave64 in one-wave 64-thread workgroups (the spanned mode), see Tested. Other drivers keep main's order in this PR. - It applies to an LDS atomic (`SharedAtomic*`) only when: - its result is used; - the LDS is workgroup memory or the device-memory LDS buffer; - the program does not already take the 64-bit LDS lock. - With laneCount 2 (wave64 on a 32-lane host), both halves are handled in one loop at the first half's emission, so lanes 0-31 rank before lanes 32-63 by construction rather than by issue order. - 32-bit add, sub, smin, umin, smax, umax, and, or and xor (aggregated path): - The leader is the first pending lane, found with a ballot and FindLSB. - Every pending lane on the leader's address joins the round. - The leader does one `OpAtomic*` with the combined operand of the round. Each lane returns the old value combined with an exclusive scan of the lower lanes' operands. - Add and sub use `OpGroupNonUniformIAdd` `ExclusiveScan`. The others use a Hillis-Steele scan over `OpGroupNonUniformShuffle`, with only the totals from `Reduce`. SPIRV-Cross refuses the other scans for Metal: `Metal doesn't support ExclusiveScan for OpGroupNonUniformSMin` appeared while testing on MoltenVK. - Cost: one loop round, with one atomic, per distinct address the wave touches, so 1 to 64 rounds per instruction. GT7's sort pass (8-bit digits) touches about 57 addresses per wave with random keys. - Every other returning LDS atomic, and every form on a device without subgroup arithmetic (serialized path): - Covers swap, inc, dec, rsub, mskor, cmpst, wrap, the float forms, and 64-bit forms in device-memory LDS. - Each loop iteration runs the existing emission for the first pending lane only, so 1 to 64 rounds per instruction. - Each round ends with `OpControlBarrier` whose execution and memory scopes are both the wave LDS scope (`WaveLdsScope`: Subgroup when one host subgroup holds the guest wave, Workgroup when the workgroup is one wave, including the spanned mode), with `AcquireRelease|WorkgroupMemory`, plus `UniformMemory` when the LDS is in device memory. Every invocation of the wave executes it after the leader branch and before the next ballot, so under the Vulkan memory model round k synchronizes with round k+1 and comes first in the address's modification order; the order does not rest on SIMD-group issue order. SPIRV-Cross emits it as `simdgroup_barrier` or `threadgroup_barrier`. The derivation is in [this comment](https://github.com/boykopovar/AnyPS5/pull/14218#issuecomment-6712824766). - SPIR-V 1.6 (section 3.3.20) makes a Workgroup-scope `OpControlBarrier` undefined unless every invocation of the workgroup executes the same dynamic instance. Guest branches are scalar: `s_cbranch_execz`, `execnz`, `vccz` and `vccnz` become subgroup ballots and `scc` branches scalar values, and EXEC-inactive lanes run every round with nothing pending, so the rounds sit in uniform control flow. The emitter checks this on every module with rounds: it runs the barrier uniformity analysis the spanned mode uses, counting a subgroup-scope collective with an invocation-independent result (ballot, broadcast, `Reduce`, a shuffle from a uniform index) in uniform control flow as uniform, and throws if a control barrier sits in control flow a per-invocation value decides. - Where there is no wave LDS scope (non-compute stages, or several waves per workgroup on a host subgroup that is not 32 lanes wide), the serialized forms take the plain path and keep the host order. MoltenVK reports 32-lane subgroups, so it does not reach that case. - Spanned waves take the serialized path through the existing spanned ballot. - Split subgroups (wave32 on a host subgroup wider than 32 lanes): min, max, and, or and xor cannot use the shuffle scan, which reads lower host lanes that belong to the other wave and may be inactive, and the wave's ballot word is chosen by invocation index, which the uniformity check cannot prove uniform; so all per-lane forms take the plain path there. Add and sub keep the aggregated path, since their native scans count only active invocations. No tested GPU has such subgroups; `agc_spirv_lds_atomic_lane_order` checks the emission. - Measured cost on the M5 Max (the test's program as a microkernel: 8,192 workgroups of 256 threads, wave64, the returning atomic plus 9 other memory operations per thread; best of 7 dispatches, two runs, `main` vs this PR; the GPU was shared with a running game, so the numbers are noisy): - `ds_add_rtn_u32`, 64 distinct addresses per wave: 4.46-4.65 vs 5.35-5.73 ms (+15-29%). - `ds_min_rtn_u32`, 64 distinct addresses (shuffle scan): 4.58-4.69 vs 6.72-6.85 ms (+43-50%). - `ds_wrxchg_rtn_b32` (serialized), 64 distinct addresses: 4.49-4.78 vs 4.63-4.77 ms (within noise; an earlier pair of runs gave +4-20%). - One address per wave, all three: within noise. - Serving several addresses per round would cut the many-address cost; that is left for a later change. - Not covered, recorded in `docs/dev/debt/shader.md`: - LDS atomics whose result is unused keep the host order. For add, sub, min, max, and, or and xor the final LDS value does not depend on the order. For rsub, inc, dec, mskor, cmpst, wrxchg, wrap and the float forms it can: with per-lane operands that differ, the M5 Max leaves 572 to 3,683 of 32,768 final dwords out of lane order for the non-returning `ds_rsub_u32`, `ds_inc_u32`, `ds_dec_u32`, `ds_mskor_b32` and `ds_cmpst_b32`. Serializing those would cost up to 64 rounds per instruction on a still unmeasured assumption, and no title is known to need it. With one operand for every lane, as a ring counter's `ds_inc_u32` has, the final value is the same in any order. - GDS atomics. - Flat atomics whose address lands in the LDS aperture. - AMD hosts, which are not reordered. angrysandhill's run of the three oracle bodies through the recompiler on the RX 6750 XT's Vulkan driver returned the same values as the hardware. ### Tested Run on 2026-10-31 with this branch at 0700fe6c79, rebased onto `main` b08c539c50. It was then rebased onto `main` 8a4fc62318 (head 2053545772) with no conflicts; on the M5 Max the focused set on that head gave the same result as below (41 pass, 6 skip, the same 2 LDS failures; 0 `VUID-` lines). Since then the branch has only gained commits: main merged at e07db72776 (11/07, including #10858), then the round barrier (98d69b6cb8) and its execution test (9c36d01079); see the head 9c36d01079 paragraph after this list. Builds: macOS 27.0.1 on an Apple M5 Max (x86_64 under Rosetta, AppleClang 21, MoltenVK 1.4.2 from LunarG SDK 1.4.363.0), and Windows 11 10.0.26200 on an RTX 4090 (driver 616.92, winlibs GCC 15.2). `main` does not build the AGC driver on macOS by itself, so both Mac trees carry the same local macOS build aids (27 files, not part of this pull request); only this change differs between them. Both machines run the same focused set on `main` (b08c539c50 plus only the new execution test, in the version without the two forced passes, which need the new flag) and on this branch, with and without `VK_LAYER_KHRONOS_validation`, using `ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -V`. The set is 49 tests on the branch and 48 on `main` (no `agc_spirv_lds_atomic_lane_order` there): `agc_driver_lds_*`, `pixel_lds*`, buffer and global atomics, wave, lane and subgroup tests, `agc_spirv_lds_atomic_*`, `agc_subgroup_barrier` and `agc_shader_disk_cache`. A `VK_LOADER_DEBUG=layer` probe shows `Insert instance layer "VK_LAYER_KHRONOS_validation"` on both sides on both machines. The rebase changed only where the SPIR-V test is registered; the cost figures and the non-returning counts above (a local probe, not part of this pull request) and the GT7 replay below come from the same emission code before the rebase. - Apple M5 Max: - On `main`, `agc_driver_lds_atomic_lane_order` fails (87 cases out of lane order; 0 of 14 same-address configurations in lane order), with and without the validation layer. - On the branch it passes, in all three passes: the device target, the flag forced on, and the flag forced on without `GroupNonUniformArithmetic` (serialized path). Each pass checks every form in workgroup and in device-memory LDS: 228 op lines, 0 differences. - `agc_driver_lds_subword_store_branch` and `agc_driver_lds_tree_reduction` fail identically on `main` and the branch. These are wave-LDS barriers in SIMD-group-divergent code, the issue #10858 addresses; they are not touched here. - 6 tests skip on both sides because MoltenVK lacks the feature: `agc_driver_buffer_atomics`, `agc_driver_global_atomics64`, `agc_driver_global_atomics_float` and `agc_driver_global_atomics_lanes` (no `shaderBufferInt64Atomics`), `agc_driver_mesh_vector_window_waves` (no `VK_EXT_mesh_shader`) and `agc_driver_ngg_vertex_wave_reduction` (no subgroup arithmetic in vertex shaders). So the branch passes 41 of the 43 tests that run and `main` 39 of 42. - 0 `VUID-`, `SYNC-HAZARD` or `Validation Error` lines on either side. - RTX 4090: - `main`: 47 of 48 pass and 1 is skipped, with and without the validation layer. The new execution test's device-target pass is in lane order for every case: 14 of 14 same-address configurations, and 76 op lines with 0 differences, in workgroup and device-memory LDS. - The branch: 48 of 49 pass and 1 is skipped, with and without the validation layer. That includes the new execution test's three passes (228 op lines, 0 differences); the forced passes run the aggregated path and, without subgroup arithmetic, the serialized path on NVIDIA as well. - The skip is `agc_driver_vertex_elected_atomic_max` on both sides (the device runs vertex programs in subgroups). `tools/check_skips.py --job windows` passes on all four reports. - 0 `VUID-`, `SYNC-HAZARD` or `Validation Error` lines on either side. - lavapipe (CI) was not run here. The new execution test skips on devices whose subgroups are narrower than 32 lanes, as `agc_driver_ds_append_consume` does, since a wave then spans several host subgroups; whether CI's lavapipe skips it or runs it is not checked. `agc_spirv_lds_atomic_lane_order` needs no GPU. - `agc_spirv_lds_atomic_lane_order` (new, no GPU) checks the emitted SPIR-V: - Wave64 `ds_add_rtn_u32` emits one `OpAtomicIAdd` for both halves, with an exclusive scan and a reduce per half (wave32: one of each). - `ds_min_rtn_u32` reduces with `OpGroupNonUniformUMin` and never scans with it. - `ds_inc_rtn_u32` gains exactly one lane loop. - Wave32 on a 64-lane host: `ds_add_rtn_u32` still scans once and adds once; `ds_min_rtn_u32` in a one-wave workgroup compiles with the atomic, loop and control-barrier counts of the unordered compile; with several waves per workgroup `ds_wrxchg_rtn_b32` and `ds_min_rtn_u32` compile with the atomic, loop and control-barrier counts of the unordered compile. - Round barrier (head 9c36d01079): for each serialized atomic the test walks the control-flow graph and requires that every path from the atomic to the lane loop's latch passes an `OpControlBarrier` with execution scope equal to memory scope and to the expected wave scope, with the semantics above, in a block outside the leader branch that dominates the latch. Cases: masked `ds_wrxchg_rtn_b32` for wave32 with 256 and 32 threads, wave64 on a 32-lane host, wave64 with device-memory LDS, spanned wave64 with workgroup and device-memory LDS, masked `ds_cmpst_rtn_b32`, and serialized `ds_add_rtn_u32` without subgroup arithmetic. The aggregated `ds_add_rtn_u32` must have no control barrier in its loop. The same module with its control barriers replaced by `OpNop` must fail the check; the emitter before 98d69b6cb8 fails it. - Divergent guest flow (head ea559cd2bf): `ds_wrxchg_rtn_b32` behind `s_cbranch_execz`, `s_cbranch_scc0` and `s_cbranch_vccz` after `s_and_saveexec`, and inside a loop that drops lanes from EXEC and repeats with `s_cbranch_execnz`, for wave32 with 256 and 32 threads, wave64 on a 32-lane host with 256 and 64 threads, and spanned wave64: all 20 compile and pass the round barrier check and the uniformity analysis; the 16 non-spanned modules with their ballots turned into `OpGroupNonUniformInverseBallot` are all rejected. `spanned_uniformity` adds 9 cases for the subgroup-collective analysis. - Without subgroup arithmetic, `ds_add_rtn_u32` takes the serialized path. - An unused `ds_add_u32` and programs under the 64-bit lock compile byte-identically with and without the flag. - `agc_subgroup_barrier` checks that only MoltenVK requires the order. `agc_shader_disk_cache` checks that the flag changes the cache key. Head 9c36d01079, on the Apple M5 Max only (MoltenVK 1.4.2, both a locally built MoltenVK ICD and the Vulkan SDK 1.4.363.0 ICD; the RTX 4090 was not rerun on this head). The new `CheckSwapChain` case of `agc_driver_lds_atomic_lane_order` runs two back-to-back `ds_wrxchg_rtn_b32` with unique data on one dword under 9 EXEC patterns (wave32) or 13 (wave64), with 256 threads and with a one-wave workgroup, in workgroup and device-memory LDS. The lane-ordered target gave 28,672 of 28,672 chains in lane order on each ICD; the unordered target, as a negative control, gave valid chains in another order (quads 0-3, 16-19, 4-7, 20-23, ...) for about 60% of chains and 0 broken chains. The emitter before the round barrier also passed, so these runs do not show the barrier's effect; the CPU test above is what checks it. The full LDS suites, including `agc_driver_lds_subword_store_branch` and `agc_driver_lds_tree_reduction` now that #10858 is in the branch, the subgroup barrier, LDS lock, spanned uniformity and shader disk cache tests pass on both ICDs. Details in [this comment](https://github.com/boykopovar/AnyPS5/pull/14218#issuecomment-6712824766). Head ea559cd2bf (main 70bb3678d8 merged), on the Apple M5 Max only (MoltenVK 1.4.2, the locally built ICD and the SDK 1.4.363.0 ICD, `VK_LAYER_KHRONOS_validation` loaded; the RTX 4090 was not rerun). `agc_driver_lds_atomic_lane_order` adds the swap pair behind `s_and_saveexec` and `s_cbranch_execz`: 28,672 of 28,672 chains in lane order, 0 reordered, 0 broken on each ICD, with 38 waves per ICD that had no active lane and skipped the block. `ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -V` over the `agc_driver_lds_*` suites, pixel LDS read-modify-write, spanned ballot sequence, `agc_spirv_lds_atomic_*`, `agc_subgroup_barrier`, `agc_shader_disk_cache`, the shader replay tests and `spanned_uniformity`: 25 of 25 pass on each ICD, 0 `VUID` lines. The device has no full 32-lane compute subgroups, so the spanned execution modes skip. Head f9ae674592 (main ef7dc4452d merged in de7cde2ec1, which also puts `3rdparty/SDL2` back to main's commit; the previous merge 124e8bfdef had left the branch's older pointer). domx4q ran the focused set with the validation layer on an RTX 4090 under Linux (driver 620.70.06; [comment](https://github.com/boykopovar/AnyPS5/pull/14218#issuecomment-6922567948)): 0 `VUID-` lines, every lane-ordered target case in lane order, but the device-target pass of `agc_driver_lds_atomic_lane_order` failed in two wave64 cases with one 64-thread wave per workgroup, where the two 32-lane halves of the wave interleave (lane-to-rank map `0,1,3,5,...,61` for lanes 0-31 and `2,4,...,62,63` for lanes 32-63). That pass required lane order from targets that do not enable `laneOrderedLdsAtomics`, which this PR does not change. f9ae674592 makes the device-target pass a failure only when the device target enables the flag (MoltenVK) and otherwise prints the count, as the unordered-target swap chains already do. On the M5 Max with the locally built MoltenVK ICD and `VK_LAYER_KHRONOS_validation` (`ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -V` over the lane order, LDS atomics, 64-bit, mixed width, condxchg, read/write, tree reduction, LDS lock, spanned uniformity, subgroup barrier, shader disk cache and replay tests): 17 of 17 pass, the layer is inserted in all 8 device tests, 0 `VUID-` lines; `agc_driver_lds_atomic_lane_order` also passes with the SDK 1.4.363.0 ICD. The RTX 4090 was not rerun. - Title, offline (no game data in this PR): GT7's BVH radix sort pass, replayed outside the game on the M5 Max from a captured request with 1,152 synthetic records. Each row is a 4-pass sort compared with a CPU stable sort: | emission | result | |---|---| | flag off (as on `main`) with the wave-LDS barrier fix of #10858 | every pass is a permutation but unstable: 24, 21, 20 and 12 records out of place in passes 0 to 3; with 8-bit keys, up to 864 | | this PR + #10858 | all 4 passes equal the CPU stable sort in 3 of 3 repeats; the same holds for seeds 1 to 5 with the equivalent `waveLdsMemoryBarriers` target knob in place of #10858 | | `main` before #10858, or this PR without it | corrupted by the wave-LDS barrier issue that #10858 fixes: pass 0 loses about 600 of 1,152 records, and some runs hang in the look-back spin | In the game, on the M5 Max: this branch was not run by itself. A local GT7 build with this change, the GLC atomic load change #14217, a subgroup-scope variant of the #10858 barrier fix and other unmerged changes went through the Fit presentation, the scene that builds the large ray-tracing BVHs: no cyclic tree in about 1,800 checks of GT7's parent walk. In an earlier run without these fixes, 32 of the 32 trees it checked were cyclic. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none (GT7's sort also needs #10858, which merged on 11/02 and is in this branch. The GLC atomic load change #14217 adds lines at the same places in 7 files, so whichever of the two merges second will merge main and resolve them) - [x] Fixes: none - [x] Unblocks: PPSA01317 #4697 (the BVH radix sort on MoltenVK, together with #14217 and the merged #10858; checked offline, and in game only in a local build with other unmerged changes) - [x] GPUs tested: Apple M5 Max, MoltenVK 1.4.2 (LunarG SDK 1.4.363.0), macOS 27.0.1, x86_64 build under Rosetta; NVIDIA GeForce RTX 4090, driver 616.92, Windows 11 (10.0.26200) - [x] AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-11-01 01:21:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T01:21:36Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

The new path imposes ascending guest-lane order for returning LDS atomics without RDNA2 evidence that this is the PS5 behavior.

What I ran

Reviewed head 205354577202938a92836de7a3187ae14760ff02, based on PR base cc26ab44380db3cd7b53715b84f13945227ce28b; its merge preview onto current main c763ea56aae3bb60cd6e22064a6a21482a58a980 was clean. Environment: Debian Linux x86_64, Python 3.11.2, Git 2.39.5. No compiler or build was used.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14218
git diff --check cc26ab44380db3cd7b53715b84f13945227ce28b...205354577202938a92836de7a3187ae14760ff02
python3 tools/pr_stack_check.py 14218 --repo boykopovar/AnyPS5

Results

Check Result
Diff whitespace check Passed (exit 0, no output).
Repository conventions and PR template Passed.
Current-main merge preview Clean; no declared dependency.
Precheck's ABI and test-quality helper invocations Could not run because those helper files are absent from this PR's checkout; these are local-tool availability failures, not findings against the change.
Hosted CI Windows and relinker Linux/Windows/macOS/ASan jobs passed; Linux product, register-context, and write-watch jobs were skipped.
Unedited local check output

git diff --check exited 0 and printed no output.

Conventions check output:

All conventions checks passed.

Stack-check command output:

/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-14218-205354577202/stack/stack-report.md
/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-14218-205354577202/stack/stack-report.json

Findings

Blocking

  • CONTRIBUTING.md says shader semantics that the source does not settle must throw; the new path instead assigns ascending order to same-address lanes for used-return LDS atomics on MoltenVK. The PR states that RDNA2 ISA section 12.13 does not specify this order and that AMD hardware has not been measured. M5 Max measurements establish MoltenVK's host order, not the guest PS5/RDNA2 order. The debt entry records this uncertainty but does not prevent the implementation from selecting one guest behavior. Please either attach an RDNA2 hardware-oracle run for the stated lane-order case and record GPU/driver/OS, or leave the unsettled guest behavior unsupported until that measurement is available.

Non-blocking

  • The author reports matched focused runs on an M5 Max/MoltenVK and RTX 4090, including validation-layer runs. I did not independently reproduce them.

Sources

Not verified

No local build or C++/Vulkan tests were run. I did not test AMD hardware or a PS5; Linux product CI was skipped. The author-reported hardware results were read but not independently confirmed.

To get this to a good state

Provide the RDNA2 hardware-oracle result for returning LDS atomics, or keep the unsettled guest ordering unsupported. I will rerun the same relevant checks on the updated head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5725862811 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14218#pullrequestreview-5725862811). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-01T01:21:36Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested The new path imposes ascending guest-lane order for returning LDS atomics without RDNA2 evidence that this is the PS5 behavior. ## What I ran Reviewed head `205354577202938a92836de7a3187ae14760ff02`, based on PR base `cc26ab44380db3cd7b53715b84f13945227ce28b`; its merge preview onto current `main` `c763ea56aae3bb60cd6e22064a6a21482a58a980` was clean. Environment: Debian Linux x86_64, Python 3.11.2, Git 2.39.5. No compiler or build was used. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14218 git diff --check cc26ab44380db3cd7b53715b84f13945227ce28b...205354577202938a92836de7a3187ae14760ff02 python3 tools/pr_stack_check.py 14218 --repo boykopovar/AnyPS5 ``` ## Results | Check | Result | |---|---| | Diff whitespace check | Passed (exit 0, no output). | | Repository conventions and PR template | Passed. | | Current-main merge preview | Clean; no declared dependency. | | Precheck's ABI and test-quality helper invocations | Could not run because those helper files are absent from this PR's checkout; these are local-tool availability failures, not findings against the change. | | Hosted CI | Windows and relinker Linux/Windows/macOS/ASan jobs passed; Linux product, register-context, and write-watch jobs were skipped. | <details><summary>Unedited local check output</summary> `git diff --check` exited 0 and printed no output. Conventions check output: ```text All conventions checks passed. ``` Stack-check command output: ```text /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-14218-205354577202/stack/stack-report.md /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-14218-205354577202/stack/stack-report.json ``` </details> ## Findings ### Blocking - `CONTRIBUTING.md` says shader semantics that the source does not settle must throw; the new path instead assigns ascending order to same-address lanes for used-return LDS atomics on MoltenVK. The PR states that RDNA2 ISA section 12.13 does not specify this order and that AMD hardware has not been measured. M5 Max measurements establish MoltenVK's host order, not the guest PS5/RDNA2 order. The debt entry records this uncertainty but does not prevent the implementation from selecting one guest behavior. Please either attach an RDNA2 hardware-oracle run for the stated lane-order case and record GPU/driver/OS, or leave the unsettled guest behavior unsupported until that measurement is available. ### Non-blocking - The author reports matched focused runs on an M5 Max/MoltenVK and RTX 4090, including validation-layer runs. I did not independently reproduce them. ## Sources - [Contribution rule for shader semantics](https://github.com/boykopovar/AnyPS5/blob/205354577202938a92836de7a3187ae14760ff02/CONTRIBUTING.md#L8) - [PR's recorded LDS atomic return-order uncertainty](https://github.com/boykopovar/AnyPS5/blob/205354577202938a92836de7a3187ae14760ff02/docs/dev/debt/shader.md#L182) - [PR's lane-order implementation gate](https://github.com/boykopovar/AnyPS5/blob/205354577202938a92836de7a3187ae14760ff02/core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp#L1358) ## Not verified No local build or C++/Vulkan tests were run. I did not test AMD hardware or a PS5; Linux product CI was skipped. The author-reported hardware results were read but not independently confirmed. ## To get this to a good state Provide the RDNA2 hardware-oracle result for returning LDS atomics, or keep the unsettled guest ordering unsupported. I will rerun the same relevant checks on the updated head.
XairRrR commented 2026-11-03 08:20:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T08:20:51Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

This pull request does not merge cleanly into main (4f41f4c375): head 2053545772 conflicts in

  • core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp

Please rebase it onto current main. I will review the change once it merges cleanly.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5749007685 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14218#pullrequestreview-5749007685). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T08:20:51Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested This pull request does not merge cleanly into `main` (4f41f4c375f5abb487dbd184fbc150f31994d762): head 205354577202938a92836de7a3187ae14760ff02 conflicts in - `core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp` Please rebase it onto current `main`. I will review the change once it merges cleanly. <!-- anyps5-bots job=3051 head=205354577202938a92836de7a3187ae14760ff02 -->
MarcZX10 commented 2026-11-10 22:00:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-10T22:00:30Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

The lane-ordered fallback can put a workgroup control barrier inside lane-divergent shader control flow, which makes that generated shader undefined under the SPIR-V rules.

What I ran

Reviewed head e93b527937fbddb912de19d4b714ae67418c1f3e against current main base 539e858408186c0b510680a03a5243b761038730; the merge preview was clean. The PR still targets main, and the head and base stayed unchanged during the precheck.

Environment: Linux 6.1, Python 3.11.2, GCC 12.2.0.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14218 --output-dir /tmp/anyps5-pr-precheck-14218-latest

I read all 18 changed files and the full diff. I did not build or run C++ tests. GitHub Actions were read as a status snapshot; I did not run them.

Results

Check Result Note
Diff whitespace Passed git diff --check against the stated base and head.
Conventions and PR template Passed One debt-length warning; zero errors.
Export ABI audit Not applicable No changed export declaration or alias was recognized.
Dependency and mergeability check Passed Clean merge preview against current main.
Test registration heuristic Warning reviewed The new C++ test fragment is included through the directory glob and registers the test.
Build and C++ tests Not run This was the exact-head no-build precheck.
Hosted CI snapshot Incomplete Windows was pending; several jobs were skipped.
Recorded outputs and hosted status

Conventions output:

docs/dev/debt/shader.md:209: warning: [debt-length] Technical debt entry over 1000 characters: state the gap first (what differs from the console, what is unverified, what throws) and keep only the behaviour it needs: 1925 characters
1 findings, 0 errors; GitHub shows at most 10 error annotations, the job summary lists all

Dependency check report output:

- PR #14218: **clean** against current base; head `e93b527937fbddb912de19d4b714ae67418c1f3e`; changed paths: none reported

Test-registration heuristic output included possible-unregistered-test warnings for ShaderDiskCache.cpp, SpirvLdsAtomicLaneOrder.cpp, SubgroupBarrier.cpp, and execution/LdsAtomicLaneOrder.cpp. I checked the CMake test fragment discovery: CMakeLists.txt includes tests/cmake/*.cmake, and the new fragment registers the lane-order tests.

GitHub Actions snapshot: Windows pending; conventions, labels, intake, eligibility, report, library portability, relinker, and relinker ASan passed; Linux, edge-watch, pipe-write, register-context, and write-watch were skipped.

Negative control

Not run. No controlled mutation was made to the implementation or test. The new barrier tests do not exercise an atomic beneath a divergent IR branch.

Findings

Blocking

SerializedLdsAtomic emits OpControlBarrier after each lane’s atomic operation, at the current atomic call site. The backend also emits conditional branches as OpBranchConditional, preserving that call-site control flow. For a single-wave workgroup, WaveLdsScope selects Workgroup; therefore, if only some guest lanes enter a branch containing a returning LDS atomic, only those invocations execute this workgroup barrier. SPIR-V 1.6 Revision 8 specifies undefined behavior unless every invocation in a Workgroup-or-larger execution scope executes the same dynamic OpControlBarrier instance. Please make the serialization converge across the barrier’s whole execution scope (for example, have non-participating invocations take part in each round), or use a lowering that does not place a workgroup barrier under divergent control flow. Add a regression test with the atomic under a divergent branch.

Non-blocking

The PR description acknowledges that the required AMD hardware ordering has not been measured; the author has marked the PR draft. The hardware behavior remains unverified.

Sources

Not verified

  • No build or C++ test was run locally; no AMD GPU or console behavior was tested.
  • The current hosted Windows job was pending when checked; skipped hosted jobs provide no test evidence.
  • The hardware ordering assumption described by the PR has not been measured on the target AMD hardware.

To get this to a good state

Ensure all invocations in the selected barrier scope execute the same dynamic barrier instance even when the guest atomic is control-flow divergent, and add a divergent-branch regression test. I’ll rerun the same checks against the updated head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5850144576 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14218#pullrequestreview-5850144576). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-10T22:00:30Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested The lane-ordered fallback can put a workgroup control barrier inside lane-divergent shader control flow, which makes that generated shader undefined under the SPIR-V rules. ## What I ran Reviewed head `e93b527937fbddb912de19d4b714ae67418c1f3e` against current `main` base `539e858408186c0b510680a03a5243b761038730`; the merge preview was clean. The PR still targets `main`, and the head and base stayed unchanged during the precheck. Environment: Linux 6.1, Python 3.11.2, GCC 12.2.0. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14218 --output-dir /tmp/anyps5-pr-precheck-14218-latest ``` I read all 18 changed files and the full diff. I did not build or run C++ tests. GitHub Actions were read as a status snapshot; I did not run them. ## Results | Check | Result | Note | |---|---|---| | Diff whitespace | Passed | `git diff --check` against the stated base and head. | | Conventions and PR template | Passed | One debt-length warning; zero errors. | | Export ABI audit | Not applicable | No changed export declaration or alias was recognized. | | Dependency and mergeability check | Passed | Clean merge preview against current `main`. | | Test registration heuristic | Warning reviewed | The new C++ test fragment is included through the directory glob and registers the test. | | Build and C++ tests | Not run | This was the exact-head no-build precheck. | | Hosted CI snapshot | Incomplete | Windows was pending; several jobs were skipped. | <details> <summary>Recorded outputs and hosted status</summary> Conventions output: ```text docs/dev/debt/shader.md:209: warning: [debt-length] Technical debt entry over 1000 characters: state the gap first (what differs from the console, what is unverified, what throws) and keep only the behaviour it needs: 1925 characters 1 findings, 0 errors; GitHub shows at most 10 error annotations, the job summary lists all ``` Dependency check report output: ```text - PR #14218: **clean** against current base; head `e93b527937fbddb912de19d4b714ae67418c1f3e`; changed paths: none reported ``` Test-registration heuristic output included possible-unregistered-test warnings for `ShaderDiskCache.cpp`, `SpirvLdsAtomicLaneOrder.cpp`, `SubgroupBarrier.cpp`, and `execution/LdsAtomicLaneOrder.cpp`. I checked the CMake test fragment discovery: `CMakeLists.txt` includes `tests/cmake/*.cmake`, and the new fragment registers the lane-order tests. GitHub Actions snapshot: Windows pending; conventions, labels, intake, eligibility, report, library portability, relinker, and relinker ASan passed; Linux, edge-watch, pipe-write, register-context, and write-watch were skipped. </details> ## Negative control Not run. No controlled mutation was made to the implementation or test. The new barrier tests do not exercise an atomic beneath a divergent IR branch. ## Findings ### Blocking `SerializedLdsAtomic` emits `OpControlBarrier` after each lane’s atomic operation, at the current atomic call site. The backend also emits conditional branches as `OpBranchConditional`, preserving that call-site control flow. For a single-wave workgroup, `WaveLdsScope` selects `Workgroup`; therefore, if only some guest lanes enter a branch containing a returning LDS atomic, only those invocations execute this workgroup barrier. SPIR-V 1.6 Revision 8 specifies undefined behavior unless every invocation in a Workgroup-or-larger execution scope executes the same dynamic `OpControlBarrier` instance. Please make the serialization converge across the barrier’s whole execution scope (for example, have non-participating invocations take part in each round), or use a lowering that does not place a workgroup barrier under divergent control flow. Add a regression test with the atomic under a divergent branch. ### Non-blocking The PR description acknowledges that the required AMD hardware ordering has not been measured; the author has marked the PR draft. The hardware behavior remains unverified. ## Sources - [Barrier emitted in the lane-ordered loop at this head](https://github.com/boykopovar/AnyPS5/blob/e93b527937fbddb912de19d4b714ae67418c1f3e/core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp#L1839-L1840) - [Conditional branch emission at this head](https://github.com/boykopovar/AnyPS5/blob/e93b527937fbddb912de19d4b714ae67418c1f3e/core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp#L237-L246) - [Workgroup scope selection for single-wave workgroups at this head](https://github.com/boykopovar/AnyPS5/blob/e93b527937fbddb912de19d4b714ae67418c1f3e/core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp#L75-L86) - [Khronos SPIR-V 1.6 Revision 8, §3.3.20: `OpControlBarrier`](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpControlBarrier) ## Not verified - No build or C++ test was run locally; no AMD GPU or console behavior was tested. - The current hosted Windows job was pending when checked; skipped hosted jobs provide no test evidence. - The hardware ordering assumption described by the PR has not been measured on the target AMD hardware. ## To get this to a good state Ensure all invocations in the selected barrier scope execute the same dynamic barrier instance even when the guest atomic is control-flow divergent, and add a divergent-branch regression test. I’ll rerun the same checks against the updated head.
MarcZX10 commented 2026-11-20 07:57:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T07:57:13Z.

Review: COMMENTED


Reviewed — no blocking findings

The partial review of head 124e8bfdef212650e734741bf0e79df9d36b50ff found no verified blocking defect; several changed files and test results remain unverified.

What I ran

  • Read review materials and selected source ranges with the provided reader. No build or tests were run.

Results

Check Result Note
Review materials passed Description, commits, manifest, and selected diff ranges read
Source inspection not run Selected changed and related code ranges read
Build and tests not run No commands run

Negative control

Not run; no tests were run in this review.

Findings

Blocking

None verified in the code inspected.

Non-blocking

None.

Sources

Not verified

This was a partial review, so no conclusion is made about files or changed lines not inspected. Read: review/README.md, review/description.md, review/commits.md, review/manifest.json (initial range), selected ranges of review/diff.patch, core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp, core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp, core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp, core/shader/recompiler/SpirvBackend/src/SpirvSpannedUniformity.cpp, core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp, and core/libs/prx/libSceAgcDriver/tests/cmake/agc_spirv_lds_atomic_lane_order_tests.cmake. The full text of these sources was not read. Other changed files were not read; 3rdparty/SDL2 was excluded as unsupported non-text and VulkanDevice.cpp was too large for the review folder. Build and runtime behavior were not independently confirmed.

To get this to a good state

Nothing is required. Optional: complete review of the unread changed files and run the relevant checks before treating this as a complete review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5989276342 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14218#pullrequestreview-5989276342). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T07:57:13Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The partial review of head `124e8bfdef212650e734741bf0e79df9d36b50ff` found no verified blocking defect; several changed files and test results remain unverified. ## What I ran - Read review materials and selected source ranges with the provided reader. No build or tests were run. ## Results | Check | Result | Note | |---|---|---| | Review materials | passed | Description, commits, manifest, and selected diff ranges read | | Source inspection | not run | Selected changed and related code ranges read | | Build and tests | not run | No commands run | ## Negative control Not run; no tests were run in this review. ## Findings ### Blocking None verified in the code inspected. ### Non-blocking None. ## Sources - [Changed diff at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/124e8bfdef212650e734741bf0e79df9d36b50ff/core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp) ## Not verified This was a partial review, so no conclusion is made about files or changed lines not inspected. Read: `review/README.md`, `review/description.md`, `review/commits.md`, `review/manifest.json` (initial range), selected ranges of `review/diff.patch`, `core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp`, `core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp`, `core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp`, `core/shader/recompiler/SpirvBackend/src/SpirvSpannedUniformity.cpp`, `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp`, and `core/libs/prx/libSceAgcDriver/tests/cmake/agc_spirv_lds_atomic_lane_order_tests.cmake`. The full text of these sources was not read. Other changed files were not read; `3rdparty/SDL2` was excluded as unsupported non-text and `VulkanDevice.cpp` was too large for the review folder. Build and runtime behavior were not independently confirmed. ## To get this to a good state Nothing is required. Optional: complete review of the unread changed files and run the relevant checks before treating this as a complete review.
MarcZX10 commented 2026-11-22 08:52:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T08:52:10Z.

Review: COMMENTED


Reviewed — comments

Nothing blocks this; the points below are optional.

What I ran

Reviewed head f9ae674592a8170670541934ce903584ad937926 using the prepared diff and pinned repository reader. No build or tests were run. The author-reported test results in the PR description were not independently verified.

Results

Check Result Note
Patch and source review passed Changed logic and target plumbing inspected
Automated tests not run No local test execution in this review
Hardware behavior not run Reported measurements are author supplied

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp was read through the pinned reader at the changed ranges; the device flag is assigned from the MoltenVK driver ID and propagated to the shader target.
  • The new code serializes each address round with a control barrier only in the serialized path; the aggregated path does not add a control barrier in its loop. Focused inspection found no concrete defect in the reviewed emission paths.

Not verified

  • No tests, build, or hardware execution were performed. The PR description reports focused tests on an Apple M5 Max and RTX 4090; those results are not independently confirmed here.
  • VulkanDevice.cpp was inspected only at the changed ranges. Full texts of the remaining changed files were listed in the manifest but their complete contents were not read. Changed files inspected: SubgroupBarrier.hpp, VulkanDevice.cpp (changed ranges), ShaderDiskCache.cpp (changed line), SpirvLdsAtomicLaneOrder.cpp, SubgroupBarrier.cpp (changed line), agc_spirv_lds_atomic_lane_order_tests.cmake, LdsAtomicLaneOrder.cpp (diff), ShaderReplay.cpp (diff), CacheKey.hpp, Recompiler.cpp, Recompiler.hpp, SpirvEmitter.hpp, SpirvEmitterInstructions.hpp, SpirvEmitterState.hpp, SpirvSpannedUniformity.hpp, SpirvEmitter.cpp, SpirvFlowEmitter.cpp, SpirvMemoryInstructions.cpp, SpirvSpannedUniformity.cpp, SpannedUniformityTests.cpp, and docs/dev/debt/shader.md (diff). No changed files were excluded by rule; files.json was not available through the reader, so excluded-by-rule entries were not verified.

To get this to a good state

Nothing is required. Optional: run the focused test set on CI's lavapipe configuration and confirm whether the new execution test skips or runs there.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6011372590 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14218#pullrequestreview-6011372590). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T08:52:10Z. **Review:** COMMENTED --- # Reviewed — comments Nothing blocks this; the points below are optional. ## What I ran Reviewed head `f9ae674592a8170670541934ce903584ad937926` using the prepared diff and pinned repository reader. No build or tests were run. The author-reported test results in the PR description were not independently verified. ## Results | Check | Result | Note | |---|---|---| | Patch and source review | passed | Changed logic and target plumbing inspected | | Automated tests | not run | No local test execution in this review | | Hardware behavior | not run | Reported measurements are author supplied | ## Findings ### Blocking None. ### Non-blocking - `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` was read through the pinned reader at the changed ranges; the device flag is assigned from the MoltenVK driver ID and propagated to the shader target. - The new code serializes each address round with a control barrier only in the serialized path; the aggregated path does not add a control barrier in its loop. Focused inspection found no concrete defect in the reviewed emission paths. ## Not verified - No tests, build, or hardware execution were performed. The PR description reports focused tests on an Apple M5 Max and RTX 4090; those results are not independently confirmed here. - `VulkanDevice.cpp` was inspected only at the changed ranges. Full texts of the remaining changed files were listed in the manifest but their complete contents were not read. Changed files inspected: `SubgroupBarrier.hpp`, `VulkanDevice.cpp` (changed ranges), `ShaderDiskCache.cpp` (changed line), `SpirvLdsAtomicLaneOrder.cpp`, `SubgroupBarrier.cpp` (changed line), `agc_spirv_lds_atomic_lane_order_tests.cmake`, `LdsAtomicLaneOrder.cpp` (diff), `ShaderReplay.cpp` (diff), `CacheKey.hpp`, `Recompiler.cpp`, `Recompiler.hpp`, `SpirvEmitter.hpp`, `SpirvEmitterInstructions.hpp`, `SpirvEmitterState.hpp`, `SpirvSpannedUniformity.hpp`, `SpirvEmitter.cpp`, `SpirvFlowEmitter.cpp`, `SpirvMemoryInstructions.cpp`, `SpirvSpannedUniformity.cpp`, `SpannedUniformityTests.cpp`, and `docs/dev/debt/shader.md` (diff). No changed files were excluded by rule; `files.json` was not available through the reader, so excluded-by-rule entries were not verified. ## To get this to a good state Nothing is required. Optional: run the focused test set on CI's lavapipe configuration and confirm whether the new execution test skips or runs there.
MarcZX10 commented 2026-11-26 15:19:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T15:19:16Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the review supports merging, with the limits below recorded as not verified.

What I ran

Reviewed head 78ac787dfebb84fbfa1b00761f2706f6c4e61bc2. I did not run commands or tests; repo_read.py was used to read the prepared diff and targeted repository ranges at the pinned head.

Results

Check Result Note
Diff and targeted code review passed Emission, driver flag, and uniformity paths inspected
Programmatic checks not run No build or tests run in this review

Findings

Blocking

None.

Non-blocking

None.

Not verified

Hardware behavior, builds, and test results were not independently verified. The author reports these in the PR description. VulkanDevice.cpp was read only at the three changed ranges because its full text was excluded as too large; the other 20 changed files listed as reviewed in the manifest were read from the bundle or targeted head ranges. No other changed files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6076637380 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14218#pullrequestreview-6076637380). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-26T15:19:16Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the review supports merging, with the limits below recorded as not verified. ## What I ran Reviewed head `78ac787dfebb84fbfa1b00761f2706f6c4e61bc2`. I did not run commands or tests; `repo_read.py` was used to read the prepared diff and targeted repository ranges at the pinned head. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted code review | passed | Emission, driver flag, and uniformity paths inspected | | Programmatic checks | not run | No build or tests run in this review | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Hardware behavior, builds, and test results were not independently verified. The author reports these in the PR description. `VulkanDevice.cpp` was read only at the three changed ranges because its full text was excluded as too large; the other 20 changed files listed as reviewed in the manifest were read from the bundle or targeted head ranges. No other changed files were excluded. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-29 05:53:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T05:53:39Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: remove mesh-stage lane ordering or provide a valid wave LDS scope for mesh shaders before emitting serialized round barriers.

What I ran

Reviewed head c5eb84a11e7d9601612cd20c60fede657f9598fe using repo_read.py against the prepared diff; no build or tests were run. The description’s hardware and test results are author-reported.

Results

Check Result Note
Diff and targeted source review passed Core paths inspected
Build and tests not run No execution performed

Findings

Blocking

  • core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp:54 permits Mesh stage through the lane-ordering gate, but WaveLdsScope at lines 67–68 returns zero for every non-Compute stage. For a used returning LDS atomic that takes SerializedLdsAtomic, core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp:1922-1924 emits OpControlBarrier using state.waveLdsScope for both scope operands. A zero scope is invalid, so a MoltenVK mesh shader using such an atomic can fail SPIR-V validation or compilation. Exclude Mesh from LaneOrdersLdsAtomics or establish a valid mesh-stage barrier scope before selecting this path.

Non-blocking

None.

Not verified

No build, test, GPU, or console checks were run. Hardware and CI results in the PR description were not independently verified. The complete text of core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp was read through the pinned reader; files.json was unavailable in the reader, so the excluded-file inventory could not be checked. Other changed files outside the targeted paths were not read in full.

To get this to a good state

Exclude Mesh stage from lane-ordered LDS atomics or implement and validate the appropriate mesh-stage barrier scope, then run the relevant SPIR-V and execution checks.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6101648781 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14218#pullrequestreview-6101648781). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-29T05:53:39Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: remove mesh-stage lane ordering or provide a valid wave LDS scope for mesh shaders before emitting serialized round barriers. ## What I ran Reviewed head `c5eb84a11e7d9601612cd20c60fede657f9598fe` using `repo_read.py` against the prepared diff; no build or tests were run. The description’s hardware and test results are author-reported. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | Core paths inspected | | Build and tests | not run | No execution performed | ## Findings ### Blocking - `core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp:54` permits Mesh stage through the lane-ordering gate, but `WaveLdsScope` at lines 67–68 returns zero for every non-Compute stage. For a used returning LDS atomic that takes `SerializedLdsAtomic`, `core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp:1922-1924` emits `OpControlBarrier` using `state.waveLdsScope` for both scope operands. A zero scope is invalid, so a MoltenVK mesh shader using such an atomic can fail SPIR-V validation or compilation. Exclude Mesh from `LaneOrdersLdsAtomics` or establish a valid mesh-stage barrier scope before selecting this path. ### Non-blocking None. ## Not verified No build, test, GPU, or console checks were run. Hardware and CI results in the PR description were not independently verified. The complete text of `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` was read through the pinned reader; `files.json` was unavailable in the reader, so the excluded-file inventory could not be checked. Other changed files outside the targeted paths were not read in full. ## To get this to a good state Exclude Mesh stage from lane-ordered LDS atomics or implement and validate the appropriate mesh-stage barrier scope, then run the relevant SPIR-V and execution checks.
ligmaSec commented 2026-12-03 22:49:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:49:50Z.

Review: COMMENTED


I compiled the exact request serializer and checked a capture round trip with laneOrderedLdsAtomics=true. It deserializes as false. ShaderReplay has a manual override, so replay without that flag can exercise host lane order instead of the captured MoltenVK path even though the cache key distinguishes them. Please record the target bit in captures or make the required override explicit in replay diagnostics. The trial merge onto c1601e56d5 was clean. Paired shader validation is pending.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6180011226 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14218#pullrequestreview-6180011226). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T22:49:50Z. **Review:** COMMENTED --- I compiled the exact request serializer and checked a capture round trip with `laneOrderedLdsAtomics=true`. It deserializes as false. `ShaderReplay` has a manual override, so replay without that flag can exercise host lane order instead of the captured MoltenVK path even though the cache key distinguishes them. Please record the target bit in captures or make the required override explicit in replay diagnostics. The trial merge onto `c1601e56d5` was clean. Paired shader validation is pending. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/14218:upstream-pr/14218'
git switch 'upstream-pr/14218'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/14218'
git switch 'upstream-pr/14218'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/14218'
git switch 'upstream-pr/14218'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/14218'
git switch 'main'
git merge --squash 'upstream-pr/14218'
git switch 'main'
git merge --ff-only 'upstream-pr/14218'
git switch 'main'
git merge 'upstream-pr/14218'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!14218
No description provided.