Skip to content

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

Draft
Kaairim wants to merge 1 commit into
Marvisak:mainfrom
Kaairim:lds-host-limit
Draft

Kaairim wants to merge 1 commit into
Marvisak:mainfrom
Kaairim:lds-host-limit

Conversation

@Kaairim

@Kaairim Kaairim commented Nov 24, 2026

Copy link
Copy Markdown

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

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 <noreply@anthropic.com>
@SkippySteve

Copy link
Copy Markdown

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 mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
The tester tree (upstream main ffe310e plus its PRs, update 8; see its
INTEGRATION.md) ran 11-25 minutes in the world on an RTX 5070 without a
device removal. Where both sides carry the same PR (the wave64 stack
#223/#233/#320 with #439 and #180, #454, #336, #259, #331 and others), the
tester tree's newer head is taken; our own work and the PRs only we
merged are kept.

Conflicts, file by file:

- descriptor/host.rs: the tester layout (`spare`, the guard slot after the
  dynamic slots, `free_table`, the capped sampler heap). A capped view
  heap keeps `capped_reserve()` dynamic slots, now 2^18 by default (the
  tester measurement, and our 91fed158), still `VICTORY_DYNAMIC_SLOTS` in
  diagnostics builds; uncapped hosts keep our 2^19. Our slot statistics
  (TAKEN/PEAK/SHORT), the bindless plan cache (`CommittedRegions`,
  `timed_valid_title_address`, `timed_find`, `title_bounds`) and the
  revision triple are kept beside the tester's `guard_slot`.
- Buffer states: the tester tree's buffer-state tracker (#334: every list
  moves host copies of title memory between GENERIC_READ and
  UNORDERED_ACCESS and back to common before it closes) and depth twins
  (#469) are taken. #40's enhanced/legacy indirect barriers (the indirect
  prelude, `use_indirect_buffers`, the title buffer handoff mirrored in
  `host_barrier`) cannot share buffers with that tracker and are dropped;
  #40's argument checks (`byte_len`, exact spans, overflow-safe clamp
  shader, aligned counts) stay. `indirect::bound` and #282's
  `rectangles` go through `buffer_state`, and `indirect::execute` (#334)
  replaces `done`. #178's DXC fallback compiles both of our passes.
  Our segments (#387: `close` ends the segment, `close_native` closes a
  native list) carry the tracker: each native list returns its buffers
  to common and its twins to their depth targets, and each prelude also
  holds our texture uploads.
- shadow.rs: our write flow (`queue_write`, one `snapshot` after the
  batch's refreshes, `finish_writes`, the unchanged-page cache) with
  #261's copy-back that also gives the snapshot the title's bytes; its
  tests run through our flow.
- pipeline/make.rs: #275's per-frame budget and per-pipeline wake pair,
  with our compute waits (a dispatch waits for its pipeline, up to 20 s).
- pipeline/library.rs: the tester version (#347, #275's saver thread);
  our concurrent-write test kept. shader_cache.rs: our byte-returning
  cache API with #358's "translated, only not kept".
- draw.rs: #493's root SRV tables; where no table can stand in, our
  drop of a draw whose root view is unset or outside title buffers. Our
  refusal of a table offset past the capped heap stays.
- resource.rs: `HostTexture` has both our `staged` generation and the
  depth twin.
- Shaders: the tester's lower.rs for the wave64 stack, #160's image
  sampling (it covers our #73 and #136 sample forms) and #453/#587; kept
  from our side: #136's preference for an image or buffer use of a
  descriptor read as data and its `s_buffer_` arm, #422's nearest-even
  narrowing (also for #169's d16 loads and #453's interpolation), #452's
  spin-wait limit, #391's LDS limit, #302's spilled root arguments (now in
  `NativeProgram::translation_ir`), #136's PSV0 interpolation beside the
  tester's row harmonisation. split_tests.rs, lane_read_loop_tests.rs and
  docs/wave64-on-wave32.md are the tester versions (the same PRs at newer
  heads).
- Tests: #483's heap guard dwords filled in our GPU tests of #200
  (v_div_scale) and #437 (scalar loads from a raw view), which read
  through the guard slot otherwise; #334's debug-layer test passes an
  offset to our `indirect::bound`.

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

Copy link
Copy Markdown

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 6638098 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

Copy link
Copy Markdown
Owner

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants