Skip to content

SHADER-638: prototype full 64 KiB LDS for emulated Wave64 compute - #3422

Draft
kacper-serewis wants to merge 4 commits into
ItsNotRexed:mainfrom
kacper-serewis:feat/shader638-lds-emulation
Draft

kacper-serewis wants to merge 4 commits into
ItsNotRexed:mainfrom
kacper-serewis:feat/shader638-lds-emulation

Conversation

@kacper-serewis

@kacper-serewis kacper-serewis commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

SHADER-638. Existing claim. Synthetic portability prototype for compute kernels that declare and use a full 65,536 B LDS and need Wave64 emulation.

The coordinator's RSRC2 census found zero 128-unit declarations among 2,689 indexed FSSM compute headers and 29 FSPX records. The two measured retail refusals use 64 units and are covered by #1882. This draft is for evaluating a general fallback and its execution cost. Updated to official main aa2988c, including the integrated SHADER-309 allocation checks. The native barrier-counter work in #3245 is independent.

Exchange timing

  • A guest segment writes its outgoing uint and mask contributions to Function storage before the existing split. Waiting and finished invocations skip guest execution and contribute neutral exchange inputs. All invocations enter the scheduler tail and contribute their live/runnable states.
  • The first workgroup barrier closes guest access. Each invocation saves and clears the LDS words it alone owns. A second barrier orders initialization before publication. Launched lanes publish a data word, mask contributions and the two scheduler counts. Missing lane slots stay zero.
  • After the third barrier every invocation captures all 64 values in its own wave, both mask words and both counts. The fourth barrier releases the stripe owners to restore the saved guest values. The fifth orders restoration before any guest continuation. Each barrier is outside the per-wave dispatch predicate.
  • Votes and ballot consumers read the captured reductions. Shuffle/readlane, swizzle, bpermute, quad reads and DPP read the private wave with the original selectors. DPP source-EXEC tests use masks from the same exchange. First-active selection can therefore depend on the newly reduced mask. Forward permute scans the previous snapshot for 32 targets, parks the winner in the existing Function variable, publishes the source data, and reads the winning lane from the next snapshot. Already computed results or selectors used in later segments still pass through the existing SSA spill logic.

CPU gates

  • The synthetic 1,024-invocation, 128-unit kernel changed from a 74,140 B refusal to exactly 65,536 B in the emitted module and index metadata. With a 64-unit declaration and synthetic constant offset 65,532, the 41,372 B output is byte-identical to f847748. Native 32/64 KiB controls, ordinary 32 KiB emulation and the 129-unit refusal also matched that base.
  • All five new semantic tests and all 15 shared-memory-limit tests passed. Forward and reverse subgroup orders matched the hand-derived values for cross-half reads, partial EXEC, scatter, DPP, WQM, votes, partial final waves, dynamic guest addresses and early completion during divergent barriers.
  • A separate 1,024-invocation handwritten sweep filled and read all 16,384 guest dwords, including the entire borrowed window. Both subgroup orders matched every expected dword. Seven synthetic modules assembled and passed Vulkan 1.2 spirv-val (SPIRV-Tools v2026.4).
  • Full semantic discovery on the rebased implementation ran 7,326 tests and reported OK with one expected failure. The final five-test SHADER-638 file was also run separately.
  • Follow-up 67d55f8 excludes DS no-ops from loan eligibility. The new regression fails on c84c065 and passes after the fix; all 6 full-LDS, 15 shared-memory-limit and 15 loop/barrier tests pass. Both the no-op reproduction and guest-write control pass Vulkan 1.2 spirv-val.
  • RTX 5070, Windows driver 616.56, reports maxComputeSharedMemorySize = 49,152 B. Its checker refused the 65,536 B native control before pipeline creation; the emulation has the same over-limit allocation. No module reached driver compilation or dispatch. Driver compilation, execution time and register spilling remain unmeasured on a device capable of 64 KiB. The straightforward snapshot costs 256 bytes of Function data per invocation plus five workgroup barriers per round. Keeping this as a draft lets the coordinator weigh that cost against presently unobserved demand.

Validation after merging main

  • The 64 KiB loan uses the global round scheduler so waiting and finished invocations participate in save and restore. Other kernels retain main’s structured scheduler. Native 32 and 64 KiB controls and ordinary 32 KiB emulation emitted byte-identical SPIR-V assembly to main.
  • Six full-LDS and 15 shared-memory-limit CPU tests passed. All seven distinct synthetic modules from the full-LDS suite assembled and passed Vulkan 1.2 spirv-val (SPIRV-Tools v2026.4).
  • The loop/barrier suite reproduced three failed subtests and two interpreter errors on both this head and clean main. Some assertions expect round scheduling, and the interpreter lacks OpFunctionCall support for inline exchanges.
  • Full semantic discovery on b77e6f4 ran 7,462 tests, versus 7,456 on its clean main parent 4c52ce2. The same seven failures and two errors appeared in both runs, with one skip and one expected failure each. The affected groups are loop/ballot, f64 class comparisons and the legacy multiply mutation anchor.
  • Main then advanced by one typed-buffer commit. Final head fe820c8 includes aa2988c. All 45 focused full-LDS, shared-limit and typed-buffer tests passed there, and all seven distinct full-LDS-suite modules again passed Vulkan 1.2 assembly and validation. Full discovery was run before that final merge.
  • Hardware handoff: run the full-LDS synthetic workload on a device advertising at least 65,536 bytes of compute shared memory and record driver, results, timing and spilling if available. This update used CPU fixtures only. A separately labelled unreachable DS write can still select the loan. The PR remains draft.

Depends on: #1882 (merged).

AI-assisted (Codex).

@kacper-serewis

Copy link
Copy Markdown
Contributor Author

Independent CPU re-review confirms ds_nop fixed at 67d55f8: all nine modules pass Vulkan 1.2 spirv-val. Nop, swizzle, bpermute and permute retain a 564 B exchange with no guest LDS; real reachable writes use the 65,536 B loan. A write after s_endpgm in the same block is ignored.

Remaining structural limitation: a separately labelled block skipped by an unconditional branch still participates in loan eligibility/code generation; its dead write can force 65,536 B rather than 564 B. This predates the no-op correction. Keep draft pending that scope decision and capable-device execution. Local RTX 5070 reports only 49,152 B. AI-assisted, synthetic CPU review only.

@ttd0x

ttd0x commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 67d55f87 on NVIDIA GeForce RTX 2080 Ti (Turing, subgroup 32..32, driver 610.88), Windows 11: pass, no regression.

  • tests/semantic (full discovery): 7,328 tests OK (1 expected failure). The three PR files alone (test_full_lds_wave64.py 6, test_cs_shared_memory_limit.py 15, test_loop_ballot_barrier.py 15) also OK.
  • scripts/run_gpu_tests.py with LEONIDA_W64_EMULATE=1, 204 shaders translated, all pass spirv-val: 183/199 passed, 15 skipped, 1 failed. Base f847748c gives the identical result lines, including the one failure (ps_sdwa_f16_const, a pixel shader, so not related to this PR). All 19 cs_w64x_* tests pass.
  • Not covered: the 64 KiB path itself. This device reports maxComputeSharedMemorySize = 49,152 B, so it cannot run it (same limit as the RTX 5070 in the description).

Test programs built with MSVC (VS 2026) via CMake; llvm-mc 23.1.5 from Fedora WSL. Synthetic fixtures only, no game data.

AI-assisted (Claude Code).

@memorypressure

Copy link
Copy Markdown

Verified on Linux: merges cleanly into current main. The new SHADER-638 suite passes (6 tests), shared_memory_limit 15, w64x_scalar_load_order 5, wave64_emulate_opt 22, and tests/test_translate.py 581 passed / 4 skipped under pytest. The rule arrives the right way: design.md contract row, hand-written .asm fixture, and the real translator driven through the shared helpers. Note: test_loop_ballot_barrier shows 3 failures + 2 errors on the merged tree, but the byte-identical set fails on plain main too (re-confirmed today) — pre-existing, not introduced here. The rsrc2 LDS_SIZE fix in that helper is genuine (field is [23:15], the baked 0x8090 set size+1). #4152 touches the same file; sequence accordingly. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants