xshader: declare the console's group memory size for compute programs #633

Merged
NickStallman merged 1 commit from upstream-pr/633 into main 2026-12-01 20:33:01 +00:00
NickStallman commented 2026-12-01 18:08:56 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-12-01T18:08:56Z.


Summary

An ordinary compute program that uses group memory declared tb_lds at 8192 words, the whole 32 KiB, whatever the console allocated. On NVIDIA a group's shared memory limits how many groups an SM holds: at 32 KiB a 32-thread group leaves room for about seven, so a latency-bound program runs with few warps.

The console's allocation is in the program's FSSM (fssm::compute_lds_bytes, which the swizzle and indexed-lane paths already use). The emitter now declares that, rounded up to 512-byte (128-word) granules. That granularity is inferred: AMD's public compiler encodes LDS_SIZE in 512-byte units from GFX7 on. Reads past TB_LDS_WORDS already return 0 and writes are dropped (tb_lds_load, tb_lds_store, and the bounds on every atomic), which is what the console does past its allocation, so a program that strays past it behaves as on the console.

The default of 8192 words stays:

  • when the size is unknown or zero;
  • for the 8x8 tile filter (lds_tile), whose exchange reuses the array at its own lane offsets;
  • wherever a size was already chosen (the reflected size of the swizzle and indexed-lane paths, wave_cull::lds_words, micropoly).

Mesh programs are unchanged.

Tested

Unit test. group_memory_is_the_console_allocation_in_its_granules builds a layout-6 FSSM and checks that 2048 bytes gives 512 words, 100 bytes gives 128, 32768 gives 8192, and that 0 or no FSSM gives 8192. It fails without the change (8192 where 512 is expected).

Survey of all 5,367 compute programs a ProjectScarlett run recorded. Every program was translated in the ordinary form, plus the 32-lane-host form of the 1,222 that need 64-lane waves: 6,589 translations, base fb17e160 against this branch.

  • 783 programs change: 762 ordinary translations and 508 paired forms, 1,270 translations in all.
  • In every one the only difference is the #define TB_LDS_WORDS line, always from 8192. The new sizes, commonest first, are 128 words (427), 512 (167), 1024 (70), 256 (67), 3072 (63) and 896 (58).
  • DXC with the runtime's flags, then dxv, passes on all 1,270.
  • 4,811 translations are unchanged, and the 508 refused before are still refused. Nothing is newly refused.

GPU time affected. In a 20-minute timed run on an RTX 5090, the programs this changes took 63 ms of GPU time a frame (of about 413 ms timed). The largest is one ray-query program: 28 ms in one call a frame, 32-thread groups, 2 KiB allocated on the console against the 32 KiB declared until now.

Microbenchmark, RTX 5090, driver 620.70.10, GE-Proton11-15 vkd3d-proton.

  • The program is a latency-bound 32-thread group: 64 dependent loads through a 16 MB permutation after one exchange through group memory. The array is indexed from a root constant so it cannot be shrunk.
  • 16,384 groups, median of 10 dispatches each submitted alone, 3 rounds.
  • With 8192 words declared: 671.6–673.3 µs. With 256 words: 613.2–614.6 µs. That is 8.7% less, with the same output in both.
  • This shows the effect; it does not predict a game program's gain. Two runs on the AMD iGPU checked correctness only.

Code checks. python tuxbox.py check --no-gpu: Evidence: TuxBox check of 99160d28fcb0, no uncommitted changes, no GPU checks: 13 passed, 0 failed, 0 not run.

GPU checks: the translator row of the table (translator checks and the lanes-shader-cache, lanes-raster-tables, lanes-compute-root, lanes-compute-root-recovery and lanes-bindless-compute suites) on AMD and NVIDIA. Full python tuxbox.py check of 99160d28 (GE-Proton11-15), which includes the translator checks and the Lanes suites: RTX 5090 (10de:2b85, 620.70.10) 210 pass, AMD iGPU (1002:13c0, RADV) 209 pass. The one failure on each is lanes-selftest-texture-publication, which is #625 and fails on main too.

Limits

  • Not measured in the game. I haven't run the game with this change, so I don't know how much of the 63 ms a frame it saves. The microbenchmark suggests a gain on the order of 10% where occupancy is the limit; programs with large groups or high register use gain less.
  • Granule size is inferred. It comes from the public compiler, not from a console manual. A smaller granule would only grow the declared array, never shrink it below what the program can address on the console.
  • Unknown sizes keep 8192 words. 31 programs that declare group memory have no known allocation.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5591602074 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/633). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-12-01T18:08:56Z. --- ## Summary An ordinary compute program that uses group memory declared `tb_lds` at 8192 words, the whole 32 KiB, whatever the console allocated. On NVIDIA a group's shared memory limits how many groups an SM holds: at 32 KiB a 32-thread group leaves room for about seven, so a latency-bound program runs with few warps. The console's allocation is in the program's FSSM (`fssm::compute_lds_bytes`, which the swizzle and indexed-lane paths already use). The emitter now declares that, rounded up to 512-byte (128-word) granules. That granularity is inferred: AMD's public compiler encodes `LDS_SIZE` in 512-byte units from GFX7 on. Reads past `TB_LDS_WORDS` already return 0 and writes are dropped (`tb_lds_load`, `tb_lds_store`, and the bounds on every atomic), which is what the console does past its allocation, so a program that strays past it behaves as on the console. The default of 8192 words stays: - when the size is unknown or zero; - for the 8x8 tile filter (`lds_tile`), whose exchange reuses the array at its own lane offsets; - wherever a size was already chosen (the reflected size of the swizzle and indexed-lane paths, `wave_cull::lds_words`, micropoly). Mesh programs are unchanged. ## Tested **Unit test.** `group_memory_is_the_console_allocation_in_its_granules` builds a layout-6 FSSM and checks that 2048 bytes gives 512 words, 100 bytes gives 128, 32768 gives 8192, and that 0 or no FSSM gives 8192. It fails without the change (8192 where 512 is expected). **Survey** of all 5,367 compute programs a ProjectScarlett run recorded. Every program was translated in the ordinary form, plus the 32-lane-host form of the 1,222 that need 64-lane waves: 6,589 translations, base fb17e160 against this branch. - 783 programs change: 762 ordinary translations and 508 paired forms, 1,270 translations in all. - In every one the only difference is the `#define TB_LDS_WORDS` line, always from 8192. The new sizes, commonest first, are 128 words (427), 512 (167), 1024 (70), 256 (67), 3072 (63) and 896 (58). - DXC with the runtime's flags, then dxv, passes on all 1,270. - 4,811 translations are unchanged, and the 508 refused before are still refused. Nothing is newly refused. **GPU time affected.** In a 20-minute timed run on an RTX 5090, the programs this changes took 63 ms of GPU time a frame (of about 413 ms timed). The largest is one ray-query program: 28 ms in one call a frame, 32-thread groups, 2 KiB allocated on the console against the 32 KiB declared until now. **Microbenchmark, RTX 5090, driver 620.70.10, GE-Proton11-15 vkd3d-proton.** - The program is a latency-bound 32-thread group: 64 dependent loads through a 16 MB permutation after one exchange through group memory. The array is indexed from a root constant so it cannot be shrunk. - 16,384 groups, median of 10 dispatches each submitted alone, 3 rounds. - With 8192 words declared: 671.6–673.3 µs. With 256 words: 613.2–614.6 µs. That is 8.7% less, with the same output in both. - This shows the effect; it does not predict a game program's gain. Two runs on the AMD iGPU checked correctness only. **Code checks.** `python tuxbox.py check --no-gpu`: `Evidence: TuxBox check of 99160d28fcb0, no uncommitted changes, no GPU checks: 13 passed, 0 failed, 0 not run`. **GPU checks:** the translator row of the table (translator checks and the `lanes-shader-cache`, `lanes-raster-tables`, `lanes-compute-root`, `lanes-compute-root-recovery` and `lanes-bindless-compute` suites) on AMD and NVIDIA. Full `python tuxbox.py check` of 99160d28 (GE-Proton11-15), which includes the translator checks and the Lanes suites: RTX 5090 (`10de:2b85`, 620.70.10) 210 pass, AMD iGPU (`1002:13c0`, RADV) 209 pass. The one failure on each is `lanes-selftest-texture-publication`, which is #625 and fails on main too. ## Limits - **Not measured in the game.** I haven't run the game with this change, so I don't know how much of the 63 ms a frame it saves. The microbenchmark suggests a gain on the order of 10% where occupancy is the limit; programs with large groups or high register use gain less. - **Granule size is inferred.** It comes from the public compiler, not from a console manual. A smaller granule would only grow the declared array, never shrink it below what the program can address on the console. - **Unknown sizes keep 8192 words.** 31 programs that declare group memory have no known allocation. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
brcly/TuxBox!633
No description provided.