Skip to content

Docs: no game CS takes the SHADER-309 LDS bounds check; drop the stale hypothesis - #3941

Open
465d6a0eac wants to merge 2 commits into
ItsNotRexed:mainfrom
465d6a0eac:docs-lds-bounds-count
Open

465d6a0eac wants to merge 2 commits into
ItsNotRexed:mainfrom
465d6a0eac:docs-lds-bounds-count

Conversation

@465d6a0eac

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new docs item, SHADER-309 follow-up

What and why

The "Workgroup memory limit (SHADER-309)" row in docs/design.md contradicts itself. It still says "Hypothesis, not yet counted over the corpus: the 16 of 486 LDS-using CS that index past LDS_SIZE with constant offsets (the Compute shaders row) now read 0 there", and the very next sentence is towade's count (#1882) answering it: none of the 485 does. That count also points at "the Compute shaders row" for the 16 of 486, but that row no longer has the figure. The only other copy is a comment in tools/rdna2spirv.py at the CS RSRC2 block, which still says "470 of 486 LDS-using CS stay below it; the rest index past it".

This PR merges the two sentences into one statement: no game shader takes the bounds-checked path, so only the synthetic tests exercise it. It adds my independent recount and fixes the code comment. No behaviour change.

When I claimed this I hadn't seen towade's sentence; it arrived on main in the last merge round. This PR therefore confirms that count rather than replacing it.

Measured (my own 1.0.2.1 copy, counts only)

At main aa2988cc, I ran rdna2spirv.translate() on each of the 2,689 CS and read the Gen it builds (lds_declared, lds_need, lds_bound, and calls to lds_access), natively and with --wave64-emulate:

native --wave64-emulate
CS with no LDS access and LDS_SIZE 0 2,204 2,204
CS that access LDS, all with an RSRC2 allocation 485 485
reach past the allocation with a constant offset (ds_const_extent) 0 0
bounds-checked (lds_bound set), including a shrunk array 0 0
past the allocation under the first count's offset // 4 + 4 bound 37 —

So "16 of 486" came from the older estimate, as towade's sentence says. That bound flags 37 of the 485 today, and every one of them is inside its allocation once the access width is counted. The 485 agree with the FSSM header's LDS byte count at +0x10C, which is non-zero in exactly 485 CS.

Tested

  • python -I tests/test_docs_*.py: all 7 OK (design_rows, links, list_items, repo_paths, table_rows, cli_flags, python_deps). compileall on tools/rdna2spirv.py is clean, and so is git diff --check.
  • tests/semantic/test_cs_shared_memory_limit.py in WSL (llvm-mc 21.1.8, SPIRV-Tools v2026.1): 15 tests OK.
  • Translator output unchanged: a --limit 200 slice from aa2988cc and from this branch is byte-identical, 200 translated and 200 passing spirv-val both times.
  • No GPU (comment and docs only).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no rule changes)

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…e hypothesis

The Workgroup memory limit row still opened with "Hypothesis, not yet
counted over the corpus: the 16 of 486 LDS-using CS ...", directly
before towade's count (ItsNotRexed#1882) that answers it, and the count pointed at
the Compute shaders row, which no longer has the figure. The comment at
the CS RSRC2 block in rdna2spirv.py still said 470 of 486 stay below
LDS_SIZE.

One statement now: no game shader takes the path. Recounted at
aa2988c by running translate() on all 2,689 CS of a 1.0.2.1 corpus
(counts only): 485 access LDS, all with an RSRC2 allocation; none
reaches past it with a constant offset and none is shrunk, natively or
with --wave64-emulate. The old offset + 4-dword bound flags 37 of the
485, all inside their allocation. The code comment says the same.
Comment and docs only: a 200-shader slice translates byte-identically.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sovljanskii

Copy link
Copy Markdown
Contributor

Independent recount with my own 1.0.2.1 copy (Apple M4, Python 3.15): your numbers hold exactly.

At main aa2988cc, I ran rdna2spirv.translate() on every CS listing, with assemble() swapped for a hook that keeps the Gen and with Gen.lds_access counted. I chose the listings from the carve index (stage_of), not by name.

native --wave64-emulate
CS listings, all translated 2,689 2,689
no LDS access and LDS_SIZE 0 2,204 2,204
LDS access, all with an RSRC2 allocation 485 485
lds_need > lds_declared (a constant offset past the allocation) 0 0
lds_bound set (bounds-checked, a shrunk array included) 0 0

That is the same split as your table, with the 485 read from the translator rather than from the FSSM header. So the rewritten row and the comment are right: no game CS takes the SHADER-309 bounds check.

On e2c7d8f3:

  • tests/test_docs_*.py: all 7 OK, and compileall on tools/rdna2spirv.py is clean.
  • The tools/rdna2spirv.py change is comment-only.

No game data (counts only). AI-assisted.

@Marukooh

Copy link
Copy Markdown
Contributor

Independently checked the LDS census in e2c7d8f from my local 1.0.2.1 package. CachyOS Linux 7.3.5, LLVM 23.1.5, translator aa2988c. I ran all 2,689 compute listings through translate() in native mode and with wave64 emulation. Both modes translated all 2,689, with 485 LDS users, zero constant extents beyond the declared allocation and zero shaders setting lds_bound. These are CPU-side translator counts. No game data attached.

@SebSilent

Copy link
Copy Markdown

Checked this on my machine (RTX 2070, Linux), one data point for the pile:

  • Ran scripts/run_gpu_tests.py against this head with the LLVM 23.1.5 llvm-mc: 214 shaders translated, 214 pass spirv-val, 164/210 passed, 46 skipped. Identical to my baseline on main from the same runtime build, so nothing moved under the comment rewrite.
  • test_docs_design_rows, test_docs_links, test_docs_table_rows, test_docs_list_items, test_docs_repo_paths, test_docs_cli_flags, test_docs_python_deps all pass; compileall on tools/rdna2spirv.py clean; git diff --check clean.
  • I re-read the bounds-check code at the lines the docs row cites: the declared allocation is ((rsrc2 >> 15) & 0x1FF) * 128 dwords, ds_const_extent covers offset/offset0/offset1 with the instruction widths the table says, and lds_bound is only set when the reach exceeds the allocation. The docs text now matches what the code actually does, and the old offset // 4 + 4 line is exactly the rough bound the PR describes (it over-flags offset1-style accesses, which is why 37 looked scary).

One honest limit: my local shader carve is 11,983 blobs and contains no CS with LDS memory access at all (only ds_swizzle), so I could not independently reproduce the 485/0/0 counts from my own copy. My check covers the code path and the GPU suite, not the corpus tally. From what I can see, LGTM.

@bielfreedom

Copy link
Copy Markdown

Checked against my own 1.0.2.1 copy (counts only) at main aa2988cc, Windows 11, AMD Radeon RX 9070 XT: the claim holds.

I translated every corpus compute shader (2,689 .s files from shader_disasm.py, llvm-mc 23.1.6) through rdna2spirv.translate(), with a local stderr probe (not committed) at the two SHADER-309 branches: need > g.lds_declared (a constant offset past the RSRC2 allocation) and fit_shared_memory's shrink.

MAX_SHARED_BYTES wave64 translated past allocation shrunk refused
65536 (default) native 2,689 0 0 0
65536 (default) --wave64-emulate 2,689 0 0 0
32768 native 2,687 0 0 2
32768 --wave64-emulate 2,683 0 24 6

So no game CS takes the bounds-checked path at the default cap, either way, which is what the updated row says.

A related number for the 32 KiB drivers (AMD Windows, which this row measures on an RX 9070 XT, and Intel). In the full-corpus index.json of the same commit (native wave64), lds_bytes > 32768 for 2 CS, and both are 32,780, i.e. a 32 KiB LDS allocation plus the 12-byte %x_buf of the barrier-round counts. So with the runtime's create_compute check, those two pipelines would be refused on a 32 KiB device only because of those 12 bytes. Over the other thresholds: > 16384: 31, > 49152: 0, max 32,780. That may be worth an item of its own: the barrier-round counts could live outside Workgroup memory when LDS already fills the limit.

AI-assisted (Claude Code).

docs/design.md conflicted in the Workgroup memory limit (SHADER-309) row:
main added the SHADER-579 clause (the 3 barrier-round counts move into the
LDS array past 16,384 B), this branch rewrote the hypothesis sentence.
Both kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G9awjJFWaLKL6vcYaYtu2r
@465d6a0eac

Copy link
Copy Markdown
Contributor Author

Merged main 0db7fed5 into the branch (head ae06dddb). docs/design.md conflicted in the Workgroup memory limit row: main had added the SHADER-579 clause (the 3 barrier-round counts move into the LDS array past 16,384 B), and this branch rewrote the hypothesis sentence. I kept both. Compared with the merge base, main changed only that clause in the row, and the rest of the row is this branch's text as already reviewed.

Recount at the merge, so the claim holds on today's main. I ran translate() on all 2,689 CS of my own 1.0.2.1 copy, same method as before, counts only:

native --wave64-emulate
LDS-using (RSRC2 allocation > 0) 485 485
constant offsets past the allocation 0 0
lds_bound set (bounds-checked) 0 0

test_docs_design_rows, test_docs_links, test_docs_list_items, test_docs_repo_paths, test_docs_table_ids, test_docs_table_rows and test_docs_cli_flags pass (Windows, Python 3.12.10, python -I). py_compile and git diff --check are clean. The branch still changes only those two places compared with main: the row and the RSRC2 comment.

Tested under WSL Ubuntu (Python 3.14.4, llvm-mc 21.1.8), CPU only.

AI-assisted (Claude Code).

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.

5 participants