Order consecutive LDS accesses in a one-wave compute group #138

Closed
github-bot wants to merge 1 commit from gh-pr/138/head into gh-pr/138/base
Owner

@⁠Yeetbot159 on GitHub · 2026-11-22 15:11 UTC · original
Yeetbot159:yeet/one-wave-lds → main · +61 −1 · 3 files · 1 commits · closed without merging

Summary

  • A compute group of 64 or fewer threads is one wave, and the console compiler can omit the barrier between two LDS accesses in the same direction. HLSL may reorder those accesses, so the translator inserts GroupMemoryBarrierWithGroupSync between them.
  • The size comes from a non-zero ISA preamble. A preamble of all zeros is left alone, because that is an unknown size rather than a one-thread group. A program that already has s_barrier is left alone. ds_swizzle_b32 does not count as an LDS access. Mesh shaders are unchanged.

Test plan

  • cargo test -p tombox-xshader --test synthetic one_wave_compute -- --exact one_wave_compute_separates_consecutive_lds_writes passed. It checks an 8x8 group, a 16x16 group, an s_barrier, and a zero preamble.
  • cargo test -p tombox-xshader --lib and cargo test -p tombox-xshader --test mesh passed (69 and 20 tests; GPU mesh cases included).
**@⁠Yeetbot159** on GitHub · 2026-11-22 15:11 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/138) `Yeetbot159:yeet/one-wave-lds` → `main` · +61 −1 · 3 files · 1 commits · closed without merging ## Summary - A compute group of 64 or fewer threads is one wave, and the console compiler can omit the barrier between two LDS accesses in the same direction. HLSL may reorder those accesses, so the translator inserts `GroupMemoryBarrierWithGroupSync` between them. - The size comes from a non-zero ISA preamble. A preamble of all zeros is left alone, because that is an unknown size rather than a one-thread group. A program that already has `s_barrier` is left alone. `ds_swizzle_b32` does not count as an LDS access. Mesh shaders are unchanged. ## Test plan - `cargo test -p tombox-xshader --test synthetic one_wave_compute -- --exact one_wave_compute_separates_consecutive_lds_writes` passed. It checks an 8x8 group, a 16x16 group, an `s_barrier`, and a zero preamble. - `cargo test -p tombox-xshader --lib` and `cargo test -p tombox-xshader --test mesh` passed (69 and 20 tests; GPU mesh cases included).
A console compiler can omit the barrier when the group fits in one wave. HLSL may reorder those accesses. A zero ISA preamble is not treated as a one-thread group, and a real s_barrier already orders them.

Co-authored-by: Cursor <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:11:27 +00:00
github-bot closed this pull request 2026-11-26 06:11:27 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 15:18 UTC · original

Thanks! The write-after-write case is a real gap: a one-wave console group can run as two PC waves, so two lanes writing the same LDS address need an order. Two small changes, please:

  1. Insert the extra barrier only for a write after a pending write. A read after a read has no hazard, and a barrier there costs every one-wave compute shader for nothing.
  2. Drop the // wave_lds_sync marker from the generated HLSL. The test can count GroupMemoryBarrierWithGroupSync calls instead.
**@⁠omonkeyz** on GitHub · 2026-11-22 15:18 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/138#issuecomment-7081208431) Thanks! The write-after-write case is a real gap: a one-wave console group can run as two PC waves, so two lanes writing the same LDS address need an order. Two small changes, please: 1. Insert the extra barrier only for a write after a pending write. A read after a read has no hazard, and a barrier there costs every one-wave compute shader for nothing. 2. Drop the `// wave_lds_sync` marker from the generated HLSL. The test can count `GroupMemoryBarrierWithGroupSync` calls instead.
Author
Owner

@⁠Yeetbot159 on GitHub · 2026-11-22 15:52 UTC · original

Rebased onto current main. The extra barrier is only a write after a pending write, and the generated HLSL no longer has the wave_lds_sync marker. The test counts GroupMemoryBarrierWithGroupSync between the first two LDS accesses: one between two writes in an 8x8 group, none between two reads, none in a 16x16 group, and none when the preamble size is unknown.

**@⁠Yeetbot159** on GitHub · 2026-11-22 15:52 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/138#issuecomment-7081643468) Rebased onto current main. The extra barrier is only a write after a pending write, and the generated HLSL no longer has the `wave_lds_sync` marker. The test counts `GroupMemoryBarrierWithGroupSync` between the first two LDS accesses: one between two writes in an 8x8 group, none between two reads, none in a 16x16 group, and none when the preamble size is unknown.
Author
Owner

@⁠MiguelMatMar on GitHub · 2026-11-22 16:03 UTC · original

Independent run at PR head 405bfb0: one_wave_compute_separates_consecutive_lds_writes passes, and opcodes, synthetic and gcn_dims pass on this branch. (The test checks the generated HLSL, so WARP vs hardware makes no difference to it.)

**@⁠MiguelMatMar** on GitHub · 2026-11-22 16:03 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/138#issuecomment-7081779295) Independent run at PR head 405bfb0: `one_wave_compute_separates_consecutive_lds_writes` passes, and `opcodes`, `synthetic` and `gcn_dims` pass on this branch. (The test checks the generated HLSL, so WARP vs hardware makes no difference to it.)
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 16:10 UTC · original

Applied in 734cda4 (merged in 1a1e283) with your authorship kept, thanks!

**@⁠omonkeyz** on GitHub · 2026-11-22 16:10 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/138#issuecomment-7081876495) Applied in 734cda4 (merged in 1a1e283) with your authorship kept, thanks!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.