Skip to content

Shaders: name what a scalar memory read is, and which descriptor dword it reads - #1083

Open
adamdotpy wants to merge 2 commits into
Marvisak:mainfrom
adamdotpy:shader/descriptor-dwords
Open

adamdotpy wants to merge 2 commits into
Marvisak:mainfrom
adamdotpy:shader/descriptor-dwords

Conversation

@adamdotpy

Copy link
Copy Markdown

AI-assisted; measured on my own machine.

What

Two commits on the descriptor-data path, both about what a refusal says rather than what translates.

Name what a scalar memory read is. A scalar instruction that is not a load of dwords stopped the program with one string, "a scalar memory read as data", whatever it was. Each now names it: a timestamp (s_memtime/s_memrealtime), a wave's index in its group, a scalar cache instruction, a scalar store, a scratch load, or — the common one — a scalar memory read as data.

Name which descriptor dword. A descriptor dword the translation cannot rebuild from the host view stopped it with "a descriptor's address or format read as data" (92 programs at ffe310e), whichever dword it was. Each now names what it holds: an image's address, array pitch or mip limits, compression fields or metadata address; a buffer's address, stride or high address, or format and swizzle. A descriptor that a vector access uses later keeps a reason of its own, because an error at that point would give every dword the same one.

Only the reasons change; nothing translates that did not before. The point is victory translate and census output: it can say which descriptor dwords the title's programs actually need, and that is what decides whether a dword can come from the used-resource list (a buffer's stride can, for one).

Testing

  • cargo test -p victory-shader: 123 passed, 1 ignored (the new tests cover the instruction names and a table of image and buffer dwords).
  • cargo clippy -p victory-shader --all-targets --all-features -- -D warnings: clean.
  • cargo build --release -p victory: builds.

I did not run victory translate over the title's shader set for this revision — no title data on this machine — so the census numbers a full set gives are still to be measured.

Stacked

This is the naming change plus the per-dword reasons only. The root-view commit, which reads a root view's memory for scalar loads, is #1056 and is deliberately not included here.

adamdotpy and others added 2 commits November 24, 2026 15:43
The census's largest refusal row (771 programs at ffe310e) came from
three different places under one reason, so a census could not tell
which one to lower. Each now names what the program reads:

- a descriptor that scalar buffer loads (s_buffer_load_dword*) use
  first: its record count (dword 2) by the view's kind (raw,
  structured, constant buffer, other), or its address or format;
  "used by scalar loads before a vector access" when a vector access
  later decides the view;
- s_memtime and s_memrealtime as timestamps,
  s_get_waveid_in_workgroup as the wave's index in its group;
- scalar stores, scalar scratch loads and cache instructions.

A load through a root view's address now says it reads that view's
memory rather than "a descriptor read only as data".

Only the reasons change: every read stops the program as before, no
IR is emitted for them, and what translates today is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A descriptor dword the translation cannot rebuild from the host view
stopped the program with "a descriptor's address or format read as
data" (92 programs at ffe310e), whatever the dword. Each now names what
it holds: an image's address, array pitch or mip limits, compression
fields or metadata address; a buffer's address, stride or high address,
or format and swizzle. A census can then tell which ones a program
needs, as a buffer's stride, say, can come from the used-resource list.

Only the reasons change. Dwords past the descriptor keep the old one.

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

Copy link
Copy Markdown
Author

A reviewer's note on this one, since it is the least risky of the open shader PRs and the diff is bigger than it looks.

It cannot change what translates. Why is type Why = &'static str and the only consumers are the refusal message and the error text, so there is no decision downstream that reads a reason. descriptor_field has exactly one call site (lower.rs:3137, descriptor_field(image.is_some(), rel).unwrap_or(OTHER)), and every arm returns a string; the _ => return None arm keeps the old generic wording, so an unlisted dword cannot start behaving differently.

The one structural change, and it is the interesting half to review: the per-descriptor path collects all uses (filter_map(...).collect() into uses) instead of find_map-ing the first, so it can ask whether a vector access uses the descriptor later (uses[1..]) and give that its own reason. It is a read-only widening of what the diagnostic can see; the Some(&(at, first)) = uses.first() guard keeps the original path when there are no uses.

Measured on dbea3a1 (Windows 11, Rust 1.98.1): cargo test -p victory-shader 123 passed, 1 ignored; clippy -D warnings clean; cargo build --release -p victory builds. Base is current main (ffe310e), so it merges as it stands.

The one claim nobody here can check is the census number — "92 programs at ffe310e" and which dwords they read needs the title's shader set. That is the number that decides whether a dword can come from the used-resource list, so it is worth a re-measure by anyone with the pack before the follow-up that acts on it.

@Zipettte

Copy link
Copy Markdown

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at dbea3a1: cargo test -p victory-shader passes, 123 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

@adamdotpy

Copy link
Copy Markdown
Author

Thanks for the run @Zipettte — 123 passed / 0 failed at dbea3a1, baseline green. As noted on the branch this one is diagnostic-only, so a green run is the expected result; the dword reasons are what the next shader PRs will consume.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/lower.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto 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.

3 participants