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

Open
github-bot wants to merge 1 commit from github-bot/gh-391 into main AGit
Owner

@⁠Kaairim on GitHub · 2026-11-24 02:52 UTC · original
Kaairim:lds-host-limit → main · +95 −0 · 1 files · 1 commits · draft

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

**@⁠Kaairim** on GitHub · 2026-11-24 02:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/391) `Kaairim:lds-host-limit` → `main` · +95 −0 · 1 files · 1 commits · draft ## 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)
The console gives a thread group up to 64 KiB of LDS; D3D12 gives group
shared memory 32 KiB in compute shaders and 28 KiB in mesh shaders. A
program asking for more was translated anyway and failed later in the
validator or at pipeline creation, with an error that did not say why,
and counted as translated meanwhile. It is now refused as unsupported,
naming the limit. A compute program that never reads or writes its LDS
(swizzles and permutes do not) declares none and is left alone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:02:17 +00:00
Author
Owner

@⁠SkippySteve on GitHub · 2026-11-24 03:01 UTC · original

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.
**@⁠SkippySteve** on GitHub · 2026-11-24 03:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/391#issuecomment-7120697016) 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.
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-24 17:23 UTC · original

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

**@⁠alexdeliu** on GitHub · 2026-11-24 17:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/391#issuecomment-7139128245) 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>
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:14 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 03:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/391#issuecomment-7151733138) <!-- 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 can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/391/head:github-bot/gh-391'
git switch 'github-bot/gh-391'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-391'
git switch 'github-bot/gh-391'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-391'
git switch 'github-bot/gh-391'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-391'
git switch 'main'
git merge --squash 'github-bot/gh-391'
git switch 'main'
git merge --ff-only 'github-bot/gh-391'
git switch 'main'
git merge 'github-bot/gh-391'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!391
No description provided.