Shaders: refuse LDS past the host's group limit by name #391

Open
Kaairim wants to merge 1 commit from upstream-pr/391 into main
Kaairim commented 2026-11-24 02:52:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Kaairim on 2026-11-24T02:52:18Z.


What

emit now refuses, as Unsupported, a compute program that reads or writes more than 32 KiB of LDS and a mesh program that declares more than 28 KiB, with the limit in the message (compute LDS over the host's 32 KiB, mesh LDS over the host's 28 KiB).

Why

The console gives a thread group up to 64 KiB of LDS (rsrc2 LDS_SIZE, 512-byte granules); D3D12 gives group shared memory 32 KiB in a compute shader and 28 KiB in a mesh shader. Nothing compared the two: such a program was translated, counted as translated by victory translate, and then failed in the validator or at pipeline creation with an error that did not say why.

A compute program declares its LDS array only when it reads or writes it (Shader::lds is lazy; swizzles and permutes do not touch it), so one that asks for more but never uses it is left alone – it works today and keeps working. A mesh program always declares its size in PSV0, so it is checked as is.

Tested

Windows 11 (build 26300), Rust 1.98.1 (pinned toolchain), x86_64-pc-windows-msvc:

  • New test emit::tests::lds_past_the_host_limit_is_refused_by_name (synthetic words, no game data): a compute program with ds_read_b32 and 65 granules is refused through emit with the message; 64 granules (32 KiB) is not; 65 granules with no LDS access is not; a mesh program at 28 KiB + 4 is refused, at 28 KiB it is not. With the lds_fits call removed from emit the test fails.
  • cargo test --workspace --no-fail-fast: 265 passed, 0 failed, 4 ignored (main: 264 / 0 / 4).
  • cargo clippy --workspace --all-targets: the same two warnings as main.
  • rustfmt --check --edition 2024 crates/victory-shader/src/emit/mod.rs: clean.

Not run: the title, so I cannot say how many of its programs ask for more than the host limit; victory translate would now name them.

Improvements by William "kaairim" Deivid (wdcore). AI-assisted: Claude Code with Claude Opus 5.5 wrote the change, the test and this description; a second Claude Opus 5.5 agent reviewed the diff.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6573528300 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/391). Originally posted by [Kaairim](https://github.com/Kaairim) on 2026-11-24T02:52:18Z. --- ## What `emit` now refuses, as `Unsupported`, a compute program that reads or writes more than 32 KiB of LDS and a mesh program that declares more than 28 KiB, with the limit in the message (`compute LDS over the host's 32 KiB`, `mesh LDS over the host's 28 KiB`). ## Why The console gives a thread group up to 64 KiB of LDS (`rsrc2` LDS_SIZE, 512-byte granules); D3D12 gives group shared memory 32 KiB in a compute shader and 28 KiB in a mesh shader. Nothing compared the two: such a program was translated, counted as translated by `victory translate`, and then failed in the validator or at pipeline creation with an error that did not say why. A compute program declares its LDS array only when it reads or writes it (`Shader::lds` is lazy; swizzles and permutes do not touch it), so one that asks for more but never uses it is left alone – it works today and keeps working. A mesh program always declares its size in PSV0, so it is checked as is. ## Tested Windows 11 (build 26300), Rust 1.98.1 (pinned toolchain), x86_64-pc-windows-msvc: - New test `emit::tests::lds_past_the_host_limit_is_refused_by_name` (synthetic words, no game data): a compute program with `ds_read_b32` and 65 granules is refused through `emit` with the message; 64 granules (32 KiB) is not; 65 granules with no LDS access is not; a mesh program at 28 KiB + 4 is refused, at 28 KiB it is not. With the `lds_fits` call removed from `emit` the test fails. - `cargo test --workspace --no-fail-fast`: 265 passed, 0 failed, 4 ignored (main: 264 / 0 / 4). - `cargo clippy --workspace --all-targets`: the same two warnings as main. - `rustfmt --check --edition 2024 crates/victory-shader/src/emit/mod.rs`: clean. Not run: the title, so I cannot say how many of its programs ask for more than the host limit; `victory translate` would now name them. Improvements by William "kaairim" Deivid (wdcore). AI-assisted: Claude Code with Claude Opus 5.5 wrote the change, the test and this description; a second Claude Opus 5.5 agent reviewed the diff. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
SkippySteve commented 2026-11-24 06:55:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SkippySteve on 2026-11-24T03:01:21Z.


Reviewed and tested on Linux (x86_64-unknown-linux-gnu, head a3f219e, which sits on current main). It looks correct to me. Results below; no title data was used.

Tests

  • cargo test -p victory-shader: 57 passed, including lds_past_the_host_limit_is_refused_by_name.
  • With the lds_fits(native, p)?; call commented out, that test fails at mod.rs:515 (the expect("refused")). So the test does exercise the check through emit.
  • I added two extra probe cases locally (not pushed). A mesh at 28 KiB + 1 byte is refused. Lowering would declare div_ceil(4) dwords, which is 28 KiB + 4, so comparing raw bytes is the right call. A compute program at the largest rsrc2 LDS size (0x1FF granules, about 255 KiB) with no DS instructions passes.
  • cargo fmt -p victory-shader --check: clean. cargo clippy -p victory-shader --all-targets -- -D warnings fails on the dead constant_color test helper, but it fails the same way on main, so this PR doesn't cause it.

Is the compute predicate in line with lowering? Yes, I believe so. In lower.rs, the ds() function declares the LDS global (Shader::lds) only from the dword closure, which ds_read*, ds_write* and the ds_* atomics use. Everything else the predicate counts errors out before it reaches that closure:

  • a GDS op returns "GDS"
  • ds_permute/ds_bpermute/ds_append return "an LDS operation"
  • byte and half reads and writes have their own refusals

So the predicate covers everything that declares LDS and a few things that don't. A shader that translates today is never newly refused. The only change is which reason a few already-refused programs report: GDS plus more than 32 KiB of LDS now says "compute LDS over the host's 32 KiB" instead of "GDS". That seems fine.

It works alongside #333. #333 adds a separate check in native.rs: a mesh record with more than 64 KiB of LDS is Malformed, because past that the lds_dwords * 4 product in PSV0 can overflow. This PR adds the host limit in emit. They touch different files. Merged locally with no conflicts, the two together give cargo test -p victory-shader 63 passed.

Nits (none blocking)

  • 32 << 10 and 28 << 10 could be named constants next to the doc comment, like MAX_GROUP in native.rs, so the message and the number can't drift apart.
  • In the test, compute and lds_fits are rebound halfway through. The second compute drops the words parameter, and the closure lds_fits hides the function of the same name. Different names would make it easier to read.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7120697016 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/391#issuecomment-7120697016). Originally posted by [SkippySteve](https://github.com/SkippySteve) on 2026-11-24T03:01:21Z. --- Reviewed and tested on Linux (`x86_64-unknown-linux-gnu`, head `a3f219e`, which sits on current `main`). It looks correct to me. Results below; no title data was used. **Tests** - `cargo test -p victory-shader`: 57 passed, including `lds_past_the_host_limit_is_refused_by_name`. - With the `lds_fits(native, p)?;` call commented out, that test fails at `mod.rs:515` (the `expect("refused")`). So the test does exercise the check through `emit`. - I added two extra probe cases locally (not pushed). A mesh at 28 KiB + 1 byte is refused. Lowering would declare `div_ceil(4)` dwords, which is 28 KiB + 4, so comparing raw bytes is the right call. A compute program at the largest `rsrc2` LDS size (0x1FF granules, about 255 KiB) with no DS instructions passes. - `cargo fmt -p victory-shader --check`: clean. `cargo clippy -p victory-shader --all-targets -- -D warnings` fails on the dead `constant_color` test helper, but it fails the same way on `main`, so this PR doesn't cause it. **Is the compute predicate in line with lowering?** Yes, I believe so. In `lower.rs`, the `ds()` function declares the LDS global (`Shader::lds`) only from the `dword` closure, which `ds_read*`, `ds_write*` and the `ds_*` atomics use. Everything else the predicate counts errors out before it reaches that closure: - a GDS op returns `"GDS"` - `ds_permute`/`ds_bpermute`/`ds_append` return `"an LDS operation"` - byte and half reads and writes have their own refusals So the predicate covers everything that declares LDS and a few things that don't. A shader that translates today is never newly refused. The only change is which reason a few already-refused programs report: GDS plus more than 32 KiB of LDS now says "compute LDS over the host's 32 KiB" instead of "GDS". That seems fine. **It works alongside #333.** #333 adds a separate check in `native.rs`: a mesh record with more than 64 KiB of LDS is `Malformed`, because past that the `lds_dwords * 4` product in PSV0 can overflow. This PR adds the host limit in `emit`. They touch different files. Merged locally with no conflicts, the two together give `cargo test -p victory-shader` 63 passed. **Nits (none blocking)** - `32 << 10` and `28 << 10` could be named constants next to the doc comment, like `MAX_GROUP` in `native.rs`, so the message and the number can't drift apart. - In the test, `compute` and `lds_fits` are rebound halfway through. The second `compute` drops the `words` parameter, and the closure `lds_fits` hides the function of the same name. Different names would make it easier to read.
mercuryVM commented 2026-11-24 13:01:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T12:45:58Z.

Review: APPROVED


Tested a3f219e on Windows 11, RTX 5070, MSVC: cargo test -p victory-shader -- --test-threads=1 70 passed, including lds_past_the_host_limit_is_refused_by_name. cargo clippy -p victory-shader --all-targets is clean. victory translate --validate --pipelines on the local title executable still reports 12 of 12 programs.

  • Refusing at emit with the host limit in the message (32 KiB compute, 28 KiB mesh) is much easier to act on than a validator or pipeline failure later. The boundary is exact: 64 granules (32 KiB) passes and 65 is refused, which the test covers.
  • Excluding ds_swizzle/*permute from "uses LDS" is right, since they move data through the crossbar without group memory. A compute program that never touches LDS isn't refused for a large LDS_SIZE.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6039424115 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/391#pullrequestreview-6039424115). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T12:45:58Z. **Review:** APPROVED --- Tested a3f219e on Windows 11, RTX 5070, MSVC: `cargo test -p victory-shader -- --test-threads=1` 70 passed, including `lds_past_the_host_limit_is_refused_by_name`. `cargo clippy -p victory-shader --all-targets` is clean. `victory translate --validate --pipelines` on the local title executable still reports 12 of 12 programs. - Refusing at `emit` with the host limit in the message (32 KiB compute, 28 KiB mesh) is much easier to act on than a validator or pipeline failure later. The boundary is exact: 64 granules (32 KiB) passes and 65 is refused, which the test covers. - Excluding `ds_swizzle`/`*permute` from "uses LDS" is right, since they move data through the crossbar without group memory. A compute program that never touches LDS isn't refused for a large `LDS_SIZE`. AI-assisted (Claude Code).
catminou4 commented 2026-11-24 14:03:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T13:19:37Z.

Review: COMMENTED


Test-merge with current main (ffe310e) is textually clean but breaks compilation — a semantic conflict, not a textual one:

error[E0061]: this function takes 4 arguments but 3 arguments were supplied
   --> crates/victory-shader/src/emit/mod.rs:579:23
    |
579 |   let res = resource::track(&p, &native.layout, native.stage).unwrap();
    |            ^^^^^^^^^^^^^^^  argument #4 of type `Option<&structure::Structured>` is missing

Main added a 4th parameter to resource::track (the Option<&Structured> from #235-era structure tracking), and this PR's branch still calls it with 3. The fix is one line at emit/mod.rs:579 — pass the structure variable (the same way the neighbouring test helpers do after rebase). Please rebase and re-run; I'll re-review then.

<!-- greyfinch-sync:Marvisak/VIctory:review:6039898956 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/391#pullrequestreview-6039898956). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T13:19:37Z. **Review:** COMMENTED --- Test-merge with current main (`ffe310e`) is textually clean but **breaks compilation** — a semantic conflict, not a textual one: ``` error[E0061]: this function takes 4 arguments but 3 arguments were supplied --> crates/victory-shader/src/emit/mod.rs:579:23 | 579 | let res = resource::track(&p, &native.layout, native.stage).unwrap(); | ^^^^^^^^^^^^^^^ argument #4 of type `Option<&structure::Structured>` is missing ``` Main added a 4th parameter to `resource::track` (the `Option<&Structured>` from #235-era structure tracking), and this PR's branch still calls it with 3. The fix is one line at `emit/mod.rs:579` — pass the structure variable (the same way the neighbouring test helpers do after rebase). Please rebase and re-run; I'll re-review then.
alexdeliu commented 2026-11-24 18:05:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T17:23:43Z.


Merged onto main @ ffe310eb, this PR (a3f219ec) no longer compiles its tests. crates/victory-shader/src/emit/mod.rs:579 calls resource::track with 3 arguments. Since 6638098c it takes a 4th, lanes: Option<&Structured>; main's tests pass Some(&st) with let st = structure::structure(&p).unwrap();.

Checked with CI's steps (both clippy runs with -D warnings, cargo test --workspace) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139128245 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/391#issuecomment-7139128245). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-24T17:23:43Z. --- Merged onto `main` @ `ffe310eb`, this PR (`a3f219ec`) no longer compiles its tests. `crates/victory-shader/src/emit/mod.rs:579` calls `resource::track` with 3 arguments. Since 6638098c it takes a 4th, `lanes: Option<&Structured>`; main's tests pass `Some(&st)` with `let st = structure::structure(&p).unwrap();`. <sub>Checked with CI's steps (both clippy runs with `-D warnings`, `cargo test --workspace`) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87</sub>
Marvisak commented 2026-11-25 04:06:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:14:53Z.


Automated triage for the maintainers.

This pull request conflicts with main in crates/victory-shader/src/emit/mod.rs. It will be reviewed once it is rebased onto current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151733138 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/391#issuecomment-7151733138). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T03:14:53Z. --- <!-- victory-triage v1 head=a3f219ecbdb7601fbee235515d41d1114eaf2195 verdict=needs-rebase at=2026-11-25T03:15:30Z --> Automated triage for the maintainers. This pull request conflicts with `main` in `crates/victory-shader/src/emit/mod.rs`. It will be reviewed once it is rebased onto current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/391:upstream-pr/391'
git switch 'upstream-pr/391'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/391'
git switch 'upstream-pr/391'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/391'
git switch 'upstream-pr/391'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/391'
git switch 'main'
git merge --squash 'upstream-pr/391'
git switch 'main'
git merge --ff-only 'upstream-pr/391'
git switch 'main'
git merge 'upstream-pr/391'
git push origin 'main'
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
Marvisak/VIctory!391
No description provided.