xshader: lower ds_mskor_b32 and ds_wrxchg2_rtn_b32 on compute LDS #214

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

@⁠QuentinDanblon on GitHub · 2026-11-23 03:16 UTC · original
QuentinDanblon:pr/lds-mskor-wrxchg2 → main · +85 −0 · 5 files · 1 commits · closed without merging

Library / area: tombox-xshader, compute LDS: ds_mskor_b32, ds_mskor_rtn_b32, ds_wrxchg2_rtn_b32, ds_wrxchg2st64_rtn_b32

Exports changed (exports.txt rows): none

Source of the behaviour: opcodes from tests/isa_table/gfx1013.txt (DS 0x0c, 0x2c, 0x2e, 0x2f). Semantics from the measurements published by Leonida (GPL-3.0, commits 7e7f6ce02c and 6da90ef02e, docs/design.md), taken on a gfx1100 card. That is GFX11, not GFX10.1: the encodings used here are the gfx1013 ones, and only the memory rules come from that measurement. Rules only, no code taken. Two lines added to THIRD_PARTY/CREDITS, one per commit.

One topic, +85: 31 lines of translator, 52 lines of test, 2 credit lines.

What was missing

The decoder had no name for these four DS opcodes, so a compute shader that uses one was not translated.

The change

instruction rule lowering
ds_mskor_b32, ds_mskor_rtn_b32 M = (M & ~DATA) | DATA2. DATA2 bits outside DATA are ORed in too, it is not a masked insert. The returning form gives the old word. one compare-exchange loop on tb_lds, the same one ds_sub_u32 / ds_inc_u32 already use, so the whole update is atomic
ds_wrxchg2_rtn_b32 exchanges the dwords at vaddr + offset0 * 4 and vaddr + offset1 * 4 with data0 and data1; vdst and vdst + 1 get the two old words two InterlockedExchange, both done before either register is written, so vdst may alias the address or the data
ds_wrxchg2st64_rtn_b32 same, offsets times 64 dwords (256 bytes) same

With both offsets on one dword, the second exchange returns data0 and the memory keeps data1, as measured.

Compute stage only, like the other LDS atomics. With GDS=1 the four instructions stay refused by the existing ... with GDS=1 is not lowered error. A vdst of v255 for the exchange pair is refused.

Tests

ds_lds_mskor_wrxchg2 in tests/exec_mem/ds.rs, 25 cases on 64 threads, each thread reading its neighbour's slot after the op:

  • ds_mskor: 8 operand triples, each in both forms (16 cases), two offsets, including DATA2 outside DATA, mask = data, zero mask. The non-returning form also checks that vdst is left alone.
  • ds_mskor_b32 under contention: the 64 threads update one dword, each clearing and setting its own bit; the result must be 0xaaaaaaaa.
  • ds_wrxchg2_rtn_b32 and the st64 form: offsets (0,1), (1,0), (2,3), old words in vdst, new words read back.
  • both offsets on one dword.
  • vdst aliasing the address and data0.

To check that the cases discriminate, I ran them once against two deliberately wrong lowerings (a masked insert for ds_mskor, a 512-byte step for st64): 27 failing entries, on ds_mskor_b32, ds_mskor_rtn_b32 and ds_wrxchg2st64_rtn_b32.

cargo test -p tombox-xshader --release --no-fail-fast on c16f0fa plus this commit, WARP: 325 passed, 0 failed, 18 ignored (exec 120, lib 106, opcodes 26, synthetic 24, mesh 24). Rebased on 2f1a94c afterwards (only THIRD_PARTY/CREDITS conflicted); ds_lds*, scalar_mode_f16_f64 and isa_table rerun there, all pass. No hardware run: the GPU of this machine is busy, and it is not an AMD card anyway.

Not covered

  • The measurement is on gfx1100. Nothing here was run on a gfx1013 or on any AMD card.
  • The 64-bit forms (ds_mskor_b64, ds_wrxchg_rtn_b64, ds_wrxchg2_rtn_b64, ds_and/or/xor_b64) are not in this PR. I can send them next if you want them.

No comment lines added (PR gate: 5 files checked, 0 problems).

  • cargo test -p tombox-xshader --release passes
  • No game or console files and no binaries included
  • No fake success; anything not possible is left missing with a note

🤖 Generated with Claude Code

**@⁠QuentinDanblon** on GitHub · 2026-11-23 03:16 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/214) `QuentinDanblon:pr/lds-mskor-wrxchg2` → `main` · +85 −0 · 5 files · 1 commits · closed without merging **Library / area:** tombox-xshader, compute LDS: `ds_mskor_b32`, `ds_mskor_rtn_b32`, `ds_wrxchg2_rtn_b32`, `ds_wrxchg2st64_rtn_b32` **Exports changed (exports.txt rows):** none **Source of the behaviour:** opcodes from `tests/isa_table/gfx1013.txt` (DS 0x0c, 0x2c, 0x2e, 0x2f). Semantics from the measurements published by Leonida (GPL-3.0, commits `7e7f6ce02c` and `6da90ef02e`, `docs/design.md`), taken on a gfx1100 card. That is GFX11, not GFX10.1: the encodings used here are the gfx1013 ones, and only the memory rules come from that measurement. Rules only, no code taken. Two lines added to `THIRD_PARTY/CREDITS`, one per commit. One topic, +85: 31 lines of translator, 52 lines of test, 2 credit lines. ### What was missing The decoder had no name for these four DS opcodes, so a compute shader that uses one was not translated. ### The change | instruction | rule | lowering | |---|---|---| | `ds_mskor_b32`, `ds_mskor_rtn_b32` | `M = (M & ~DATA) \| DATA2`. `DATA2` bits outside `DATA` are ORed in too, it is not a masked insert. The returning form gives the old word. | one compare-exchange loop on `tb_lds`, the same one `ds_sub_u32` / `ds_inc_u32` already use, so the whole update is atomic | | `ds_wrxchg2_rtn_b32` | exchanges the dwords at `vaddr + offset0 * 4` and `vaddr + offset1 * 4` with `data0` and `data1`; `vdst` and `vdst + 1` get the two old words | two `InterlockedExchange`, both done before either register is written, so `vdst` may alias the address or the data | | `ds_wrxchg2st64_rtn_b32` | same, offsets times 64 dwords (256 bytes) | same | With both offsets on one dword, the second exchange returns `data0` and the memory keeps `data1`, as measured. Compute stage only, like the other LDS atomics. With `GDS=1` the four instructions stay refused by the existing `... with GDS=1 is not lowered` error. A `vdst` of v255 for the exchange pair is refused. ### Tests `ds_lds_mskor_wrxchg2` in `tests/exec_mem/ds.rs`, 25 cases on 64 threads, each thread reading its neighbour's slot after the op: - `ds_mskor`: 8 operand triples, each in both forms (16 cases), two offsets, including `DATA2` outside `DATA`, mask = data, zero mask. The non-returning form also checks that `vdst` is left alone. - `ds_mskor_b32` under contention: the 64 threads update one dword, each clearing and setting its own bit; the result must be `0xaaaaaaaa`. - `ds_wrxchg2_rtn_b32` and the st64 form: offsets (0,1), (1,0), (2,3), old words in `vdst`, new words read back. - both offsets on one dword. - `vdst` aliasing the address and `data0`. To check that the cases discriminate, I ran them once against two deliberately wrong lowerings (a masked insert for `ds_mskor`, a 512-byte step for st64): 27 failing entries, on `ds_mskor_b32`, `ds_mskor_rtn_b32` and `ds_wrxchg2st64_rtn_b32`. `cargo test -p tombox-xshader --release --no-fail-fast` on `c16f0fa` plus this commit, WARP: 325 passed, 0 failed, 18 ignored (exec 120, lib 106, opcodes 26, synthetic 24, mesh 24). Rebased on `2f1a94c` afterwards (only `THIRD_PARTY/CREDITS` conflicted); `ds_lds*`, `scalar_mode_f16_f64` and `isa_table` rerun there, all pass. No hardware run: the GPU of this machine is busy, and it is not an AMD card anyway. ### Not covered - The measurement is on gfx1100. Nothing here was run on a gfx1013 or on any AMD card. - The 64-bit forms (`ds_mskor_b64`, `ds_wrxchg_rtn_b64`, `ds_wrxchg2_rtn_b64`, `ds_and/or/xor_b64`) are not in this PR. I can send them next if you want them. No comment lines added (PR gate: 5 files checked, 0 problems). - [x] `cargo test -p tombox-xshader --release` passes - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ds_mskor_b32 / ds_mskor_rtn_b32 (DS 0x0c / 0x2c): M = (M & ~DATA) | DATA2
as one compare-exchange loop on the groupshared mirror, the returning form
gives the old word.

ds_wrxchg2_rtn_b32 / ds_wrxchg2st64_rtn_b32 (DS 0x2e / 0x2f): two
exchanges at vaddr + offset0 * 4 and vaddr + offset1 * 4 (times 64 for
st64), both done before vdst and vdst + 1 are written.

Compute only. The four names were not decoded before, so a shader using
them was refused. GDS=1 stays refused.

Rules from the gfx1100 measurements published by Leonida (GPL-3.0,
commits 7e7f6ce02c and 6da90ef02e), no code taken. Opcodes from the
gfx1013 table.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:14:15 +00:00
github-bot closed this pull request 2026-11-26 06:14:15 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 03:38 UTC · original

Applied in 689f690 (merged in 44597ab) with your authorship kept, thanks. Full tombox-xshader suite on WARP: exec 120/0, plus all other targets. The only failure, gcn::tests::dumped_durango_shaders, is pre-existing and comes from this machine's local dumps.

**@⁠omonkeyz** on GitHub · 2026-11-23 03:38 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/214#issuecomment-7090907515) Applied in 689f690 (merged in 44597ab) with your authorship kept, thanks. Full tombox-xshader suite on WARP: exec 120/0, plus all other targets. The only failure, gcn::tests::dumped_durango_shaders, is pre-existing and comes from this machine's local dumps.
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-23 06:16 UTC · original

Before I write the 64-bit LDS atomics I offered above, one question, because I do not think they can be exact with what the translator has today.

tb_lds is an array of dwords and HLSL only has 32-bit interlocked operations on it. So a 64-bit atomic has to be two 32-bit ones, low dword then high dword, the way ds_write_b64 is already split into two ds_write_b32 parts in hlsl/ds_ext.rs. Without contention on the element that is exact. With contention it is not:

instruction what two dword atomics can do that the console cannot
ds_wrxchg_rtn_b64, ds_wrxchg2_rtn_b64, ds_wrxchg2st64_rtn_b64 two threads exchanging into one element can leave one's low dword with the other's high dword
ds_and_b64, ds_or_b64, ds_xor_b64, ds_mskor_b64 same operation from every thread: memory is exact (bits are independent and the operation commutes). Two different operations on one element (an and and an or): the low dword can see them in one order and the high dword in the other
the _rtn_ forms of those memory as above, and the returned pair comes from two instants
ds_add_u64, ds_sub_u64, ds_min/max_*64, ds_cmpst_b64 need the carry or the compare across both dwords, not possible at all this way

Leonida ships the first three rows this way and documents the same limit (its notes call the bitwise memory result exact, which holds only when the racing operations are the same kind). Its gfx1100 measurements cover addressing and values, not contention.

I see three ways to go and would rather not pick for you:

  1. Leave all 64-bit LDS atomics refused, as today.
  2. Lower the exchanges and the bitwise forms per dword, with the limit above written in the PR and a test that pins the uncontended behaviour plus the same-operation contention case.
  3. Make them exact with a lock word next to tb_lds: every 64-bit atomic runs its two dword updates inside a compare-exchange loop on that word (critical section inside the loop body, so it cannot deadlock a wave). That would also allow add/sub/min/max/cmpst on 64 bits. It serialises 64-bit atomics against each other only: a 32-bit atomic or a plain write on half of the same element is still not ordered against them.

If 2 or 3 is acceptable, say which and I will send it as one small PR with exec tests on WARP. If you prefer 1, I drop it.

**@⁠QuentinDanblon** on GitHub · 2026-11-23 06:16 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/214#issuecomment-7093184009) Before I write the 64-bit LDS atomics I offered above, one question, because I do not think they can be exact with what the translator has today. `tb_lds` is an array of dwords and HLSL only has 32-bit interlocked operations on it. So a 64-bit atomic has to be two 32-bit ones, low dword then high dword, the way `ds_write_b64` is already split into two `ds_write_b32` parts in `hlsl/ds_ext.rs`. Without contention on the element that is exact. With contention it is not: | instruction | what two dword atomics can do that the console cannot | |---|---| | `ds_wrxchg_rtn_b64`, `ds_wrxchg2_rtn_b64`, `ds_wrxchg2st64_rtn_b64` | two threads exchanging into one element can leave one's low dword with the other's high dword | | `ds_and_b64`, `ds_or_b64`, `ds_xor_b64`, `ds_mskor_b64` | same operation from every thread: memory is exact (bits are independent and the operation commutes). Two different operations on one element (an `and` and an `or`): the low dword can see them in one order and the high dword in the other | | the `_rtn_` forms of those | memory as above, and the returned pair comes from two instants | | `ds_add_u64`, `ds_sub_u64`, `ds_min/max_*64`, `ds_cmpst_b64` | need the carry or the compare across both dwords, not possible at all this way | Leonida ships the first three rows this way and documents the same limit (its notes call the bitwise memory result exact, which holds only when the racing operations are the same kind). Its gfx1100 measurements cover addressing and values, not contention. I see three ways to go and would rather not pick for you: 1. Leave all 64-bit LDS atomics refused, as today. 2. Lower the exchanges and the bitwise forms per dword, with the limit above written in the PR and a test that pins the uncontended behaviour plus the same-operation contention case. 3. Make them exact with a lock word next to `tb_lds`: every 64-bit atomic runs its two dword updates inside a compare-exchange loop on that word (critical section inside the loop body, so it cannot deadlock a wave). That would also allow `add/sub/min/max/cmpst` on 64 bits. It serialises 64-bit atomics against each other only: a 32-bit atomic or a plain write on half of the same element is still not ordered against them. If 2 or 3 is acceptable, say which and I will send it as one small PR with exec tests on WARP. If you prefer 1, I drop it.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 06:22 UTC · original

Thanks for laying out the three options so clearly, and for raising it before writing code. The table of what two dword atomics can and can't do is exactly the analysis we needed. Here is the graphics lead's decision:

  • Option 2 is rejected. Tearing under contention is a wrong result that reports success, and the emulator's no-fake-success rule doesn't allow that, even if the limit is documented.
  • Option 3 is the acceptable design: exact 64-bit LDS atomics through a lock word next to tb_lds, with both dword updates inside the compare-exchange loop as you describe. That also covers add/sub/min/max/cmpst on 64 bits.
    • Please document in the PR and in the code path that 64-bit atomics are serialised only against each other. A 32-bit atomic or plain write to the same dwords is outside that guarantee.
    • If a title we test uses a 32-bit op on a dword that a b64 atomic also touches, that title stays refused rather than translated.
    • Tests: contention cases on WARP that show no tearing (several lanes racing on one element, mixed operations included), plus the uncontended cases.
  • Until option 3 lands, option 1 stands: every 64-bit LDS atomic stays refused.

If you take on option 3, one small PR with the exec tests is perfect. It will go through the graphics lead's review and a Trackmania check before it's merged.

**@⁠omonkeyz** on GitHub · 2026-11-23 06:22 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/214#issuecomment-7093268105) Thanks for laying out the three options so clearly, and for raising it before writing code. The table of what two dword atomics can and can't do is exactly the analysis we needed. Here is the graphics lead's decision: - **Option 2 is rejected.** Tearing under contention is a wrong result that reports success, and the emulator's no-fake-success rule doesn't allow that, even if the limit is documented. - **Option 3 is the acceptable design:** exact 64-bit LDS atomics through a lock word next to `tb_lds`, with both dword updates inside the compare-exchange loop as you describe. That also covers `add/sub/min/max/cmpst` on 64 bits. - Please document in the PR and in the code path that 64-bit atomics are serialised only against each other. A 32-bit atomic or plain write to the same dwords is outside that guarantee. - If a title we test uses a 32-bit op on a dword that a b64 atomic also touches, that title stays refused rather than translated. - Tests: contention cases on WARP that show no tearing (several lanes racing on one element, mixed operations included), plus the uncontended cases. - **Until option 3 lands, option 1 stands:** every 64-bit LDS atomic stays refused. If you take on option 3, one small PR with the exec tests is perfect. It will go through the graphics lead's review and a Trackmania check before it's merged.
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-23 06:27 UTC · original

Understood, option 3 with those conditions. Before any code I tried the lock itself, and it does not fit where I said it would. My mistake in the proposal, so I am reporting it rather than working around it.

tb_lds is groupshared uint tb_lds[8192], which is already the whole D3D limit. One more groupshared dword is rejected by DXC (1.9, cs_6_0), on a small shader with exactly the two declarations and the lock loop:

error: Total Thread Group Shared Memory used by 'main' is 32772, exceeding maximum: 32768.
Validation failed.

It is the same wall as the existing refusal in xlane_header ("the 32-lane exchange needs groupshared space beyond the 32 KiB LDS mirror"). For compute the translator does not know how much LDS the shader really uses (only mesh has groupshared_bytes), so it cannot give up a dword of the mirror safely either.

The same shader with tb_lds[8191] compiles, so the lock loop itself is not the problem. What is open is where the lock word lives. I see two places, and both are your call because they go beyond the translator:

where what it needs limit
A a reserved dword of the GDS mirror (gds_abi), taken with InterlockedCompareExchange on tb_gds a new reserved dword in gds_abi, the buffer bound for any compute shader that has a 64-bit LDS atomic, and that dword guaranteed 0 when the buffer is created the lock is device-wide: 64-bit LDS atomics of all thread groups and dispatches go one at a time. Still exact, only slower. Touches d3d12_xs, whose hardware tests I cannot run now (the GPU of this machine is busy)
B next to tb_lds, as planned the real LDS size of a compute shader, to declare tb_lds at that size. Is it available anywhere in the container, the way groupshared_bytes is for mesh? a shader that uses the full 32 KiB together with a 64-bit atomic stays refused, with an explicit error

A third variant, shrinking the mirror to 8191 dwords when a 64-bit atomic is present, I do not propose: an access to the last dword would silently alias or go out of bounds, and the address is not known at translation time.

Until you choose, nothing changes: every 64-bit LDS atomic stays refused. If B is possible, tell me where the size is and I will do it in the translator only. If you prefer A, I can write the translator half and the exec tests on WARP, and leave the gds_abi layout to you.

**@⁠QuentinDanblon** on GitHub · 2026-11-23 06:27 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/214#issuecomment-7093356227) Understood, option 3 with those conditions. Before any code I tried the lock itself, and it does not fit where I said it would. My mistake in the proposal, so I am reporting it rather than working around it. `tb_lds` is `groupshared uint tb_lds[8192]`, which is already the whole D3D limit. One more groupshared dword is rejected by DXC (1.9, `cs_6_0`), on a small shader with exactly the two declarations and the lock loop: ``` error: Total Thread Group Shared Memory used by 'main' is 32772, exceeding maximum: 32768. Validation failed. ``` It is the same wall as the existing refusal in `xlane_header` ("the 32-lane exchange needs groupshared space beyond the 32 KiB LDS mirror"). For compute the translator does not know how much LDS the shader really uses (only mesh has `groupshared_bytes`), so it cannot give up a dword of the mirror safely either. The same shader with `tb_lds[8191]` compiles, so the lock loop itself is not the problem. What is open is where the lock word lives. I see two places, and both are your call because they go beyond the translator: | | where | what it needs | limit | |---|---|---|---| | A | a reserved dword of the GDS mirror (`gds_abi`), taken with `InterlockedCompareExchange` on `tb_gds` | a new reserved dword in `gds_abi`, the buffer bound for any compute shader that has a 64-bit LDS atomic, and that dword guaranteed 0 when the buffer is created | the lock is device-wide: 64-bit LDS atomics of all thread groups and dispatches go one at a time. Still exact, only slower. Touches `d3d12_xs`, whose hardware tests I cannot run now (the GPU of this machine is busy) | | B | next to `tb_lds`, as planned | the real LDS size of a compute shader, to declare `tb_lds` at that size. Is it available anywhere in the container, the way `groupshared_bytes` is for mesh? | a shader that uses the full 32 KiB together with a 64-bit atomic stays refused, with an explicit error | A third variant, shrinking the mirror to 8191 dwords when a 64-bit atomic is present, I do not propose: an access to the last dword would silently alias or go out of bounds, and the address is not known at translation time. Until you choose, nothing changes: every 64-bit LDS atomic stays refused. If B is possible, tell me where the size is and I will do it in the translator only. If you prefer A, I can write the translator half and the exec tests on WARP, and leave the `gds_abi` layout to you.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 06:33 UTC · original

Thanks for trying the lock before writing anything else, and for reporting the 32 KiB wall rather than working around it. Not shrinking the mirror silently was the right call. The graphics lead chose B:

  • On GCN/RDNA, a compute shader declares its real LDS allocation in COMPUTE_PGM_RSRC2.LDS_SIZE, in granules. That should be in the container's register/state metadata, the same way groupshared_bytes is for mesh. Please find where the translator can read it, and size tb_lds from it with the lock word next to it.
  • If the real size leaves no room for the lock dword, or the size can't be found, that shader stays refused with an explicit error.
  • A is rejected: a device-wide lock couples unrelated dispatches, and it would add gds_abi binding in d3d12_xs for a feature no current title is known to need.
  • The WARP contention tests that show no tearing are still required, plus the uncontended cases.

Until then, every 64-bit LDS atomic stays refused.

**@⁠omonkeyz** on GitHub · 2026-11-23 06:33 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/214#issuecomment-7093441475) Thanks for trying the lock before writing anything else, and for reporting the 32 KiB wall rather than working around it. Not shrinking the mirror silently was the right call. The graphics lead chose **B**: - On GCN/RDNA, a compute shader declares its real LDS allocation in `COMPUTE_PGM_RSRC2.LDS_SIZE`, in granules. That should be in the container's register/state metadata, the same way `groupshared_bytes` is for mesh. Please find where the translator can read it, and size `tb_lds` from it with the lock word next to it. - If the real size leaves no room for the lock dword, or the size can't be found, that shader stays refused with an explicit error. - A is rejected: a device-wide lock couples unrelated dispatches, and it would add gds_abi binding in d3d12_xs for a feature no current title is known to need. - The WARP contention tests that show no tearing are still required, plus the uncontended cases. Until then, every 64-bit LDS atomic stays refused.
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-23 06:37 UTC · original

B it is. I have no console shader on my side, so I can find where the code should read the register but not check the offset against a real blob. Two things I need you to confirm on your fixtures before I rely on them:

  1. FSSM form. docs/BLOCKERS.md (s_trap entry) says COMPUTE_PGM_RSRC2 is "FSSM dword 0x130". I read that as the little-endian dword at byte offset 0x130 from the start of the inflated FSSM blob, the one ShaderExtract.fssm holds. Is that right, and is the offset fixed across your compute fixtures?
  2. Durango form (gcn::extract_durango, where fssm is the whole blob). I found nothing in the code or the notes that says where RSRC2 sits there. The thread-group size is read at 0x18..0x24 of the program prefix; is RSRC2 in that prefix too, and at which offset?

What I plan to do with the value, so you can stop me early:

  • LDS_SIZE = bits [23:15] (COMPUTE_PGM_RSRC2__LDS_SIZE_MASK 0x00FF8000 in gc_10_3_0_sh_mask.h), in units of 128 dwords (LLVM AMDGPU LDSAlignShift = 9 from Bonaire on, Mesa ac_shader 128 * 4 bytes for GFX7+ compute).
  • Only a compute shader that contains a 64-bit LDS atomic is affected. For it: tb_lds is declared with LDS_SIZE * 128 dwords and tb_lds64_lock next to it. Every other shader keeps the 8192-dword mirror, byte for byte as today.
  • Refused with an explicit error: the register cannot be read, LDS_SIZE is 0, or LDS_SIZE * 512 + 4 > 32768.
  • A guard against reading the wrong dword: the value must have TRAP_PRESENT, EXCP_EN and EXCP_EN_MSB at 0 (your note says TRAP_PRESENT is 0 in every compute fixture; tell me if the other two are not always 0) and bit 31 at 0, otherwise the shader is refused too.
  • One open point: in that resized mirror, an LDS access past LDS_SIZE cannot wrap at 32 KiB as it does today. I would refuse a static DS offset that reaches past the declared size (as mesh.rs does) and index the rest modulo the declared size. If you know what the hardware does with an out-of-range LDS address, I will follow that instead.

I will start on the lock and the tests now, with the reader isolated in one function, and wire the offsets once you confirm them.

**@⁠QuentinDanblon** on GitHub · 2026-11-23 06:37 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/214#issuecomment-7093514450) B it is. I have no console shader on my side, so I can find where the code should read the register but not check the offset against a real blob. Two things I need you to confirm on your fixtures before I rely on them: 1. **FSSM form.** `docs/BLOCKERS.md` (s_trap entry) says `COMPUTE_PGM_RSRC2` is "FSSM dword 0x130". I read that as the little-endian dword at byte offset 0x130 from the start of the inflated FSSM blob, the one `ShaderExtract.fssm` holds. Is that right, and is the offset fixed across your compute fixtures? 2. **Durango form** (`gcn::extract_durango`, where `fssm` is the whole blob). I found nothing in the code or the notes that says where RSRC2 sits there. The thread-group size is read at 0x18..0x24 of the program prefix; is RSRC2 in that prefix too, and at which offset? What I plan to do with the value, so you can stop me early: - `LDS_SIZE` = bits [23:15] (`COMPUTE_PGM_RSRC2__LDS_SIZE_MASK 0x00FF8000` in `gc_10_3_0_sh_mask.h`), in units of 128 dwords (LLVM AMDGPU `LDSAlignShift = 9` from Bonaire on, Mesa `ac_shader` 128 * 4 bytes for GFX7+ compute). - Only a compute shader that contains a 64-bit LDS atomic is affected. For it: `tb_lds` is declared with `LDS_SIZE * 128` dwords and `tb_lds64_lock` next to it. Every other shader keeps the 8192-dword mirror, byte for byte as today. - Refused with an explicit error: the register cannot be read, `LDS_SIZE` is 0, or `LDS_SIZE * 512 + 4 > 32768`. - A guard against reading the wrong dword: the value must have `TRAP_PRESENT`, `EXCP_EN` and `EXCP_EN_MSB` at 0 (your note says TRAP_PRESENT is 0 in every compute fixture; tell me if the other two are not always 0) and bit 31 at 0, otherwise the shader is refused too. - One open point: in that resized mirror, an LDS access past `LDS_SIZE` cannot wrap at 32 KiB as it does today. I would refuse a static DS offset that reaches past the declared size (as `mesh.rs` does) and index the rest modulo the declared size. If you know what the hardware does with an out-of-range LDS address, I will follow that instead. I will start on the lock and the tests now, with the reader isolated in one function, and wire the offsets once you confirm them.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 06:48 UTC · original

Thanks for the detailed plan. We don't have a verified offset for RSRC2 in either container, so neither 0x130 in the inflated FSSM blob nor a Durango prefix offset can be assumed. To go ahead, please add a fixture test that reads RSRC2 from several compute fixtures, in both Scarlett (FSSM) and Durango containers. For each one, check that LDS_SIZE covers that shader's known ds_* address range or declared LDS use. If the offset isn't fixed, parse it from the container's own table rather than hard-coding it. Until a Durango container is proven this way, Durango shaders that use 64-bit LDS atomics stay refused. The rest of your plan (refusing when TRAP_PRESENT, EXCP_EN, EXCP_EN_MSB or bit 31 is set, and handling out-of-range LDS) is fine.

**@⁠omonkeyz** on GitHub · 2026-11-23 06:48 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/214#issuecomment-7093695500) Thanks for the detailed plan. We don't have a verified offset for RSRC2 in either container, so neither 0x130 in the inflated FSSM blob nor a Durango prefix offset can be assumed. To go ahead, please add a fixture test that reads RSRC2 from several compute fixtures, in both Scarlett (FSSM) and Durango containers. For each one, check that LDS_SIZE covers that shader's known ds_* address range or declared LDS use. If the offset isn't fixed, parse it from the container's own table rather than hard-coding it. Until a Durango container is proven this way, Durango shaders that use 64-bit LDS atomics stay refused. The rest of your plan (refusing when TRAP_PRESENT, EXCP_EN, EXCP_EN_MSB or bit 31 is set, and handling out-of-range LDS) is fine.
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-23 07:59 UTC · original

The 64-bit LDS atomics are in omonkeyz/xbox-emulator#257, built the way you set out here.

  • The fixture test you asked for is in it: hlsl::lds64::tests::compute_pgm_rsrc2_covers_the_lds_reach_of_every_compute_fixture. It reads RSRC2 from every compute fixture, FSSM and Durango, checks that LDS_SIZE covers the static ds_* reach, and prints the offsets that fit when 0x130 does not hold (fixed, and counted back from the ISA).
  • I have no console shader, so I could not run it. Please do not merge before it has passed on your fixtures: cargo test -p tombox-xshader --release --lib compute_pgm_rsrc2 -- --nocapture.
  • Durango containers stay refused whatever the test prints.
  • The guarantee is documented as you asked: 64-bit LDS atomics are serialised only against each other, and a shader where a 32-bit access could run against one in a branch or a loop is refused.
  • Everything was run on WARP only. The contention tests and the mutations that show they bite are in the PR description.

🤖 Generated with Claude Code

**@⁠QuentinDanblon** on GitHub · 2026-11-23 07:59 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/214#issuecomment-7094915077) The 64-bit LDS atomics are in omonkeyz/xbox-emulator#257, built the way you set out here. - The fixture test you asked for is in it: `hlsl::lds64::tests::compute_pgm_rsrc2_covers_the_lds_reach_of_every_compute_fixture`. It reads RSRC2 from every compute fixture, FSSM and Durango, checks that `LDS_SIZE` covers the static `ds_*` reach, and prints the offsets that fit when 0x130 does not hold (fixed, and counted back from the ISA). - I have no console shader, so I could not run it. Please do not merge before it has passed on your fixtures: `cargo test -p tombox-xshader --release --lib compute_pgm_rsrc2 -- --nocapture`. - Durango containers stay refused whatever the test prints. - The guarantee is documented as you asked: 64-bit LDS atomics are serialised only against each other, and a shader where a 32-bit access could run against one in a branch or a loop is refused. - Everything was run on WARP only. The contention tests and the mutations that show they bite are in the PR description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)

Pull request closed

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