Shaders: refuse LDS past the host's group limit by name #391
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/391"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by Kaairim on 2026-11-24T02:52:18Z.
What
emitnow refuses, asUnsupported, 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 (
rsrc2LDS_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 byvictory 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::ldsis 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:
emit::tests::lds_past_the_host_limit_is_refused_by_name(synthetic words, no game data): a compute program withds_read_b32and 65 granules is refused throughemitwith 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 thelds_fitscall removed fromemitthe 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 translatewould 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
Imported from Marvisak/VIctory. Originally posted by SkippySteve on 2026-11-24T03:01:21Z.
Reviewed and tested on Linux (
x86_64-unknown-linux-gnu, heada3f219e, which sits on currentmain). It looks correct to me. Results below; no title data was used.Tests
cargo test -p victory-shader: 57 passed, includinglds_past_the_host_limit_is_refused_by_name.lds_fits(native, p)?;call commented out, that test fails atmod.rs:515(theexpect("refused")). So the test does exercise the check throughemit.div_ceil(4)dwords, which is 28 KiB + 4, so comparing raw bytes is the right call. A compute program at the largestrsrc2LDS 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 warningsfails on the deadconstant_colortest helper, but it fails the same way onmain, so this PR doesn't cause it.Is the compute predicate in line with lowering? Yes, I believe so. In
lower.rs, theds()function declares the LDS global (Shader::lds) only from thedwordclosure, whichds_read*,ds_write*and theds_*atomics use. Everything else the predicate counts errors out before it reaches that closure:"GDS"ds_permute/ds_bpermute/ds_appendreturn"an LDS operation"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 isMalformed, because past that thelds_dwords * 4product in PSV0 can overflow. This PR adds the host limit inemit. They touch different files. Merged locally with no conflicts, the two together givecargo test -p victory-shader63 passed.Nits (none blocking)
32 << 10and28 << 10could be named constants next to the doc comment, likeMAX_GROUPinnative.rs, so the message and the number can't drift apart.computeandlds_fitsare rebound halfway through. The secondcomputedrops thewordsparameter, and the closurelds_fitshides the function of the same name. Different names would make it easier to read.Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T12:45:58Z.
Review: APPROVED
Tested
a3f219eon Windows 11, RTX 5070, MSVC:cargo test -p victory-shader -- --test-threads=170 passed, includinglds_past_the_host_limit_is_refused_by_name.cargo clippy -p victory-shader --all-targetsis clean.victory translate --validate --pipelineson the local title executable still reports 12 of 12 programs.emitwith 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.ds_swizzle/*permutefrom "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 largeLDS_SIZE.AI-assisted (Claude Code).
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:Main added a 4th parameter to
resource::track(theOption<&Structured>from #235-era structure tracking), and this PR's branch still calls it with 3. The fix is one line atemit/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.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:579callsresource::trackwith 3 arguments. Since6638098cit takes a 4th,lanes: Option<&Structured>; main's tests passSome(&st)withlet 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/ef9ef0ebc1776ff104b5aa8eaea18e87Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:14:53Z.
Automated triage for the maintainers.
This pull request conflicts with
mainincrates/victory-shader/src/emit/mod.rs. It will be reviewed once it is rebased onto currentmain.Generated by Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.