Repository navigation
Conversation
A wave's same-address ds_*_rtn returns rank its lanes only when the lanes are applied in ascending lane order. On an Apple M5 Max (MoltenVK 1.4.2) a 32-lane SIMD-group serves same-address threadgroup atomics in quads 0,4,1,5,2,6,3,7, so a radix sort that ranks records with ds_add_rtn_u32 is unstable there; an RTX 4090 (NVIDIA 616.92) returns lane order for every returning form. On MoltenVK the driver sets SpirvTarget::laneOrderedLdsAtomics. A returning 32-bit add, sub, min, max, and, or or xor then loops over the wave's distinct addresses, does one atomic per address with the combined operand and returns the old value combined with an exclusive scan of the lower lanes' operands. The other returning LDS atomics run one lane per loop iteration in lane order. Atomics whose result is unused, and programs that already serialize through the 64-bit LDS lock, are unchanged.
…plit subgroups A wave32 program on a host subgroup wider than 32 lanes shares the subgroup with another wave. The shuffle-based exclusive scan that the aggregated min, max, and, or and xor paths use reads lower host lanes, so when only the upper wave runs the atomic its first lanes read invocations of the other wave, which are inactive and undefined. These ops now take the serialized path in split subgroups. Add and sub keep the aggregated path: their native scans count only active invocations.
Measure ds_wrxchg2_rtn_b32 and ds_wrxchg2st64_rtn_b32, which lower to two ds_wrxchg_rtn_b32 halves, and repeat every operation with 16384 LDS dwords, which no device holds in workgroup memory, so the storage-buffer path of each target is checked too. Skip on devices whose subgroups are narrower than 32 lanes, where a wave spans several host subgroups.
…e check Name the ISA section that gives no lane order, extend the 4090 measurement to the 18 returning 32-bit integer forms in workgroup and device-memory LDS, state the cost per round, and list what keeps the host order: unused results, whose final value can still depend on the order for rsub, inc, dec, mskor, cmpst, wrxchg, wrap and the float forms, GDS and flat atomics. The entry closes on a hardware oracle measurement on RDNA2.
|
@frankea At Could you provide the documented MoltenVK/MSL guarantee that makes those issued rounds a same-address modification order, or enforce that order explicitly? Please cover a serialized noncommutative operation such as swap, with masked waves of 32 and 64 lanes, and check the ordering mechanism in the emitted code. The M5 Max measurements are useful evidence for that device, but the instruction-count tests and a lower lane being elected first do not establish the memory contract for every MoltenVK target. See the Vulkan synchronization rules. |
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
MarcZX10
left a comment
There was a problem hiding this comment.
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/AnyPS5Results
| 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.mdsays 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
- PR's recorded LDS atomic return-order uncertainty
- PR's lane-order implementation gate
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.
✅ NVIDIA GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (3, not counted against this PR)Validated but not compared (2, not in the main baseline's validation pass)Validation IDs already present on main (5 IDs in 480 tests)Skipped (44)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
…lds-atomic-return-lane-order # Conflicts: # core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp # core/libs/prx/libSceAgcDriver/tools/ShaderReplay.cpp # core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp # core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp
…arrier The per-lane loop that serves a returning LDS atomic one lane per round had no synchronizes-with edge between rounds: the leader's in-branch fence pairs with no later acquire, and ballots carry no memory semantics, so the Vulkan memory model left the order of same-address rounds open. Every invocation of the wave now executes OpControlBarrier with execution scope and memory scope both equal to the wave LDS scope after each round's leader branch, so round k happens-before round k+1 and precedes it in the location's modification order. Equal scopes keep SPIRV-Cross from widening a subgroup barrier to threadgroup_barrier. Where no scope covers exactly one guest wave (non-compute stages, or several waves per workgroup on a host subgroup that is not 32 lanes wide) the loop's trip count is not uniform over any barrier scope, so those forms take the plain atomic path. The aggregated path is unchanged. The lane order test now reads the module's control-flow graph and checks, for masked wave32 and wave64 swaps, cmpst and serialized add under the MoltenVK target flags, that a barrier with equal execution and memory scope lies on every path from the atomic to the loop latch, outside the leader branch, and that removing it fails the check.
Two back-to-back ds_wrxchg_rtn_b32 put every active lane of a wave on one dword with unique data, under 9 EXEC patterns for wave32 and 13 for wave64, in multi-wave and single-wave workgroups and in workgroup and device-memory LDS. The returns and the final value must form one chain in lane order; a valid chain in another order and a broken chain are reported separately. The unordered target runs as a negative control and is reported, not failed. A host-side self-test feeds the classifier synthetic in-order, reordered, duplicated and lost chains.
|
At 2053545 the serialized path had no ordering edge between rounds. Each round ballots the pending lanes, takes the lowest with Each round now ends with A control barrier has to be executed by every invocation in its execution scope, and the change keeps it where that holds. The loop's exit test is a ballot over the guest wave, so every invocation in scope runs the same rounds. Guest branches are scalar, EXEC is a predicate, and a nonzero wave LDS scope already disables early-stopping invocations. These are the same conditions main relies on for its existing wave-LDS control barriers. In the spanned mode the existing uniformity check ( Tests. Results on an Apple M5 Max, MoltenVK 1.4.2 (the local ICD's startup log reports Metal Shading Language 4.0; the SDK ICD logs no MSL version), with both the locally built MoltenVK ICD and the Vulkan SDK 1.4.363.0 ICD: the lane-ordered target gave 28,672 of 28,672 wave chains in lane order (855,264 same-address swaps), 0 reordered and 0 broken, on each ICD. The unordered target, as a negative control, gave valid chains in another order for 2,450 of 4,096 wave64 chains with 256 threads, 617 of 1,024 with 64 threads, 5,045 of 8,192 wave32 chains with 256 threads and 639 of 1,024 with 32 threads, the same in device-memory LDS, and 0 broken chains; the order is quads of four lanes, 0-3, 16-19, 4-7, 20-23 and so on. So the test can see a reordering on this device. The previous emitter, without the round barrier, also gave 28,672 of 28,672 chains in lane order on both ICDs, so these runs do not show the barrier's effect. Dispatch-plus-wait time was 277-329 µs per dispatch in every case with and without the barrier, which is submission overhead; the cost per round is below what this test resolves. The full LDS suites (atomics, 64-bit, mixed width, float modes, condxchg, src2, addtid, read/write, mask waterfall, subword store branch, tree reduction, pixel LDS read-modify-write, beyond device limit, spanned ballot sequence), the subgroup barrier, LDS lock, spanned uniformity and shader disk cache tests pass on both ICDs, and the CPU-only shader replay request and replay tool tests pass. What is contract and what is device evidence. The round order now rests on the Vulkan synchronizes-with rule for a control barrier and on SPIRV-Cross's lowering of an equal-scope barrier, both checked structurally by the CPU test. The execution test shows only what this device does, and here the previous code passed it as well. Two gaps outside this change remain. First, the edge from an earlier plain LDS write by another lane into the first round uses the existing wave-LDS ordering, which on MoltenVK is a subgroup AI-assisted: yes (Claude Code) |
|
MarcZX10, sorry for the slow answer; my 11/07 reply and the round-barrier commits dealt with oneandonlydean's ordering question, not with yours. You are right that nothing settles the guest order. I went through the RDNA2 ISA guide again: 12.13 gives only per-lane pseudocode, 10.1 says same-bank atomics are serialized without saying in which order, and the only place it describes LDS atomic ordering at all (2.3.1, printed page 9) calls them "fast, unordered atomic operations". LLVM's AMDGPU atomic optimizer and Mesa's On the second option: I don't see a compile-time throw that separates the order-dependent case. Whether a returned value depends on the order depends on how the program uses it and on how many lanes hit one address at run time, and neither is known when the shader is compiled. The narrowest throw would refuse every LDS atomic whose result is read on MoltenVK, including the many uses where any order is fine (unique slot allocation, counters) that main compiles and runs today. That is a regression, not a refusal of the new behaviour, and main's current MoltenVK order (Apple's quad order) is no better verified than lane order. So I'd rather take the first option. I don't have an AMD GPU (my machines are an RTX 4090 and an M5 Max), so I'm moving this to draft until someone with an RDNA2 card can run the case below with the hardware oracle. If the hardware is in lane order, the debt entry closes on that run. If it isn't, I'll change the emitter to the measured order or make the case throw. Would a gfx103x run be enough for you, given that HW_ORACLE.md already treats the DS encodings as shared with the console's gfx1013? The case, one wave per dispatch so every lane hits LDS byte 0, run with 32 rows and again with 64 rows and Lane order means every lane's first output dword equals its lane id. Two variants would cover the rest: The current head is 9c36d01 (main merged on 11/07, including #10858). XairRrR's 11/03 conflict request no longer applies; the branch merges cleanly. AI-assisted: yes (Claude Code) |
…lds-atomic-return-lane-order # Conflicts: # docs/dev/debt/shader.md
…-lane-order # Conflicts: # core/shader/recompiler/SpirvBackend/src/SpirvSpannedUniformity.cpp # core/shader/recompiler/tests/SpannedUniformityTests.cpp
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
|
|
Merged main (f171065) in 78ac787. Two files conflicted with main's #22432, which names the root of a per-invocation value in the spanned-uniformity rejection. In |
MarcZX10
left a comment
There was a problem hiding this comment.
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.
…-lane-order # Conflicts: # core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvSpannedUniformity.hpp # core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp # core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp # core/shader/recompiler/SpirvBackend/src/SpirvSpannedUniformity.cpp
MarcZX10
left a comment
There was a problem hiding this comment.
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:54permits Mesh stage through the lane-ordering gate, butWaveLdsScopeat lines 67–68 returns zero for every non-Compute stage. For a used returning LDS atomic that takesSerializedLdsAtomic,core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp:1922-1924emitsOpControlBarrierusingstate.waveLdsScopefor 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 fromLaneOrdersLdsAtomicsor 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.
|
MarcZX10, on the mesh-stage finding at c5eb84a: a zero What the Mesh term in So I am leaving the gate as it is. If you see a path to AI-assisted: yes (Claude Code) |
ligmaSec
left a comment
There was a problem hiding this comment.
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.
|
The request format does not carry any device-derived Recording device flags in captures, or printing them in replay diagnostics, would apply to all of these flags at once, so I would rather make that change in its own PR than in this one. AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this; the reviewed code and focused coverage support merging.
What I ran
Reviewed head 62895dca015ebae40dd459a2745557a838231a6a in the review container. I read the prepared description, commits, manifest, and diff, then used repo_read.py to inspect source context. I ran no builds or tests.
python3 repo_read.py search <name> <repository-path>
python3 repo_read.py cat <repository-path> <start> <end>
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | All 21 manifest entries reviewed |
| Tests | not run | Would require compilation or GPU execution |
| Negative control | not run | Author-reported controls were not independently verified |
Negative control
I did not run a negative control. The description reports SPIR-V barrier-removal and unordered-target controls; those results are author-reported and were not independently verified.
Findings
Blocking
None.
Non-blocking
None.
Sources
The driver flag is set for MoltenVK and passed into the shader target in VulkanDevice.cpp and SpirvEmitter.cpp. The lowering gates on used LDS atomic results and chooses aggregated or serialized handling in SpirvMemoryInstructions.cpp and SpirvFlowEmitter.cpp. The change also adds SPIR-V and execution coverage in SpirvLdsAtomicLaneOrder.cpp and LdsAtomicLaneOrder.cpp.
Not verified
No tests were run. The hardware measurements, CI behavior, and test results described by the author were not independently confirmed. All 21 files listed in manifest.json were reviewed; VulkanDevice.cpp was read using repo_read.py because it was not included in the prepared files. files.json lists no excluded paths.
To get this to a good state
Nothing is required.
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_u32on byte-packed per-wave counters, were unstable on Apple GPUs.Semantics and sources
DS_ADD_RTN_U32istmp = 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".nir_opt_uniform_atomicsreplace 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.ds_add_rtn_u32with data 1 from every lane on one LDS dword,ds_wrxchg_rtn_b32, and the add under EXEC0x55555555, 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".SubgroupLocalInvocationId, so oneOpAtomicIAddper invocation may be applied in any lane order.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_ordertest onmain(hand-encoded RDNA; 128 workgroups per case; for the order columns every lane of a wave doesds_add_rtn_u32with 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):ds_add_rtn_u64, wave32 and wave64, 256 threads, workgroup and device-memory LDS0,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)ds_add_rtn_u64is in lane order (the 64-bit LDS lock already serializes lanes withOpGroupNonUniformElect)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_cmpstandds_wrap, the final LDS values differ as well, not just the returns.ds_wrxchg2_rtn_b32andds_wrxchg2st64_rtn_b32lower to twods_wrxchg_rtn_b32halves; the test keeps their two addresses apart, so the order of the halves does not matter.Change
SpirvTarget::laneOrderedLdsAtomics, plumbed likeldsLockFences: SpirvTargetOptions, SpirvEmitterState, the shader cache key,agc_shader_replay --lane-ordered-lds-atomics.tests/cmake/agc_spirv_lds_atomic_lane_order_tests.cmake(written bytools/agc_test_split.py resolveduring the rebase); the new execution test is picked up by thetests/executionglob.VulkanDevice::buildTargetsets it only onVK_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.SharedAtomic*) only when:OpAtomic*with the combined operand of the round. Each lane returns the old value combined with an exclusive scan of the lower lanes' operands.OpGroupNonUniformIAddExclusiveScan. The others use a Hillis-Steele scan overOpGroupNonUniformShuffle, with only the totals fromReduce. SPIRV-Cross refuses the other scans for Metal:Metal doesn't support ExclusiveScan for OpGroupNonUniformSMinappeared while testing on MoltenVK.OpControlBarrierwhose 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), withAcquireRelease|WorkgroupMemory, plusUniformMemorywhen 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 assimdgroup_barrierorthreadgroup_barrier. The derivation is in this comment.OpControlBarrierundefined unless every invocation of the workgroup executes the same dynamic instance. Guest branches are scalar:s_cbranch_execz,execnz,vcczandvccnzbecome subgroup ballots andsccbranches 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.agc_spirv_lds_atomic_lane_orderchecks the emission.mainvs 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%).docs/dev/debt/changes/fix-lds-atomic-return-lane-order.md:ds_rsub_u32,ds_inc_u32,ds_dec_u32,ds_mskor_b32andds_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'sds_inc_u32has, the final value is the same in any order.Tested
Run on 2026-10-31 with this branch at 0700fe6c79, rebased onto
mainb08c539. It was then rebased ontomain8a4fc62 (head 2053545) 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; 0VUID-lines). Since then the branch has only gained commits: main merged at e07db72 (11/07, including #10858), then the round barrier (98d69b6) and its execution test (9c36d01); see the head 9c36d01 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).maindoes 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 onmain(b08c539 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 withoutVK_LAYER_KHRONOS_validation, usingANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -V. The set is 49 tests on the branch and 48 onmain(noagc_spirv_lds_atomic_lane_orderthere):agc_driver_lds_*,pixel_lds*, buffer and global atomics, wave, lane and subgroup tests,agc_spirv_lds_atomic_*,agc_subgroup_barrierandagc_shader_disk_cache. AVK_LOADER_DEBUG=layerprobe showsInsert 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.main,agc_driver_lds_atomic_lane_orderfails (87 cases out of lane order; 0 of 14 same-address configurations in lane order), with and without the validation layer.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_branchandagc_driver_lds_tree_reductionfail identically onmainand the branch. These are wave-LDS barriers in SIMD-group-divergent code, the issue fix(agc): order wave LDS accesses with memory barriers on MoltenVK #10858 addresses; they are not touched here.agc_driver_buffer_atomics,agc_driver_global_atomics64,agc_driver_global_atomics_floatandagc_driver_global_atomics_lanes(noshaderBufferInt64Atomics),agc_driver_mesh_vector_window_waves(noVK_EXT_mesh_shader) andagc_driver_ngg_vertex_wave_reduction(no subgroup arithmetic in vertex shaders). So the branch passes 41 of the 43 tests that run andmain39 of 42.VUID-,SYNC-HAZARDorValidation Errorlines on either side.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.agc_driver_vertex_elected_atomic_maxon both sides (the device runs vertex programs in subgroups).tools/check_skips.py --job windowspasses on all four reports.VUID-,SYNC-HAZARDorValidation Errorlines on either side.agc_driver_ds_append_consumedoes, 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_orderneeds no GPU.agc_spirv_lds_atomic_lane_order(new, no GPU) checks the emitted SPIR-V:ds_add_rtn_u32emits oneOpAtomicIAddfor both halves, with an exclusive scan and a reduce per half (wave32: one of each).ds_min_rtn_u32reduces withOpGroupNonUniformUMinand never scans with it.ds_inc_rtn_u32gains exactly one lane loop.ds_add_rtn_u32still scans once and adds once;ds_min_rtn_u32in a one-wave workgroup compiles with the atomic, loop and control-barrier counts of the unordered compile; with several waves per workgroupds_wrxchg_rtn_b32andds_min_rtn_u32compile with the atomic, loop and control-barrier counts of the unordered compile.OpControlBarrierwith 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: maskedds_wrxchg_rtn_b32for 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, maskedds_cmpst_rtn_b32, and serializedds_add_rtn_u32without subgroup arithmetic. The aggregatedds_add_rtn_u32must have no control barrier in its loop. The same module with its control barriers replaced byOpNopmust fail the check; the emitter before 98d69b6 fails it.ds_wrxchg_rtn_b32behinds_cbranch_execz,s_cbranch_scc0ands_cbranch_vcczafters_and_saveexec, and inside a loop that drops lanes from EXEC and repeats withs_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 intoOpGroupNonUniformInverseBallotare all rejected.spanned_uniformityadds 9 cases for the subgroup-collective analysis.ds_add_rtn_u32takes the serialized path.ds_add_u32and programs under the 64-bit lock compile byte-identically with and without the flag.agc_subgroup_barrierchecks that only MoltenVK requires the order.agc_shader_disk_cachechecks that the flag changes the cache key.Head 9c36d01, 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
CheckSwapChaincase ofagc_driver_lds_atomic_lane_orderruns two back-to-backds_wrxchg_rtn_b32with 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, includingagc_driver_lds_subword_store_branchandagc_driver_lds_tree_reductionnow 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 ea559cd (main 70bb367 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_validationloaded; the RTX 4090 was not rerun).agc_driver_lds_atomic_lane_orderadds the swap pair behinds_and_saveexecands_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 -Vover theagc_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 andspanned_uniformity: 25 of 25 pass on each ICD, 0VUIDlines. The device has no full 32-lane compute subgroups, so the spanned execution modes skip.Head f9ae674 (main ef7dc44 merged in de7cde2, which also puts
3rdparty/SDL2back to main's commit; the previous merge 124e8bf 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): 0VUID-lines, every lane-ordered target case in lane order, but the device-target pass ofagc_driver_lds_atomic_lane_orderfailed in two wave64 cases with one 64-thread wave per workgroup, where the two 32-lane halves of the wave interleave (lane-to-rank map0,1,3,5,...,61for lanes 0-31 and2,4,...,62,63for lanes 32-63). That pass required lane order from targets that do not enablelaneOrderedLdsAtomics, which this PR does not change. f9ae674 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 andVK_LAYER_KHRONOS_validation(ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -Vover 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, 0VUID-lines;agc_driver_lds_atomic_lane_orderalso passes with the SDK 1.4.363.0 ICD. The RTX 4090 was not rerun.Head 62895dc (main c0d8d6c merged in 020f2ae). Two conflicts:
ShaderReplay.cpp, where main now reads wide arguments through anargumentsvector and the--lane-ordered-lds-atomicscheck is kept on top of it, andSpirvEmitter.cpp, where main added its own refusal after the spanned-wave check (NarrowReadFirstLaneUnsupported) at the same place as this PR'sSubgroupBarrierInDivergentFlowcheck; both refusals now apply when the wave is not spanned. 62895dc moves the debt entry, unchanged, fromdocs/dev/debt/shader.mdinto a fragment, as main's CONTRIBUTING now requires. On the M5 Max (MoltenVK, SDK 1.4.363.0 ICD,VK_LAYER_KHRONOS_validationloaded, confirmed withVK_LOADER_DEBUG=layer): the lane order, LDS atomics, 64-bit, integer, mixed width, condxchg, tree reduction, beyond-device-limit and SPIR-V lock tests,spanned_uniformity,agc_subgroup_barrier,agc_shader_disk_cacheandagc_shader_replay, 15 of 15 pass, 0VUID-lines. The RTX 4090 was not rerun.main) with the wave-LDS barrier fix of #10858waveLdsMemoryBarrierstarget knob in place of #10858mainbefore #10858, or this PR without itIn 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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)