Shaders: handle s_buffer_load SMEM uses in descriptor_data (#798) #953

Closed
github-bot wants to merge 1 commit from gh-pr/953/head into gh-pr/953/base
Owner

@⁠MartinIndra02 on GitHub · 2026-11-24 14:27 UTC · original
MartinIndra02:fix/shader-smem-descriptor-data → main · +46 −0 · 1 files · 1 commits · closed without merging

Addresses #798

Summary

In crates/victory-shader/src/emit/lower.rs, descriptor_data previously matched only Fields::Image and Fields::Buffer on the using instruction ui, causing s_buffer_load* (Fields::Smem) buffer descriptor uses to fall through to a scalar memory read as data.

Handling Fields::Smem { .. } if un.starts_with("s_buffer_load") as a raw buffer ((11 | u, 0), still refusing ResourceType::Cbv) eliminates 100% of a scalar memory read as data (771 -> 0) and immediately translates +231 shaders on build 1.0.2.1 (+166 mesh, +57 vertex/pixel, +8 compute), while routing the remaining subset that reads dword 0/1 (address/format) accurately to a descriptor's address or format read as data.

Full-corpus A/B (victory translate on retail 1.0.2.1, 26,084 programs)

Metric main (ffe310e) This PR (c42cbb0) Delta
Vertex & Pixel emitted 12,231 / 14,027 12,288 / 14,027 +57
Compute emitted 1,441 / 2,582 1,449 / 2,582 +8
Mesh emitted 8,214 / 8,713 8,380 / 8,713 +166
Total emitted 21,886 22,117 +231
a scalar memory read as data 771 0 -771

Verification (Windows 11, RTX 3080 621.24, Rust 1.98.1)

  • New unit test emit::lower::tests::s_buffer_load_descriptor_size_reads_as_data (covers both ResourceType::Srv lowering and ResourceType::Cbv refusal).
  • Independent native D3D12 + WARP GPU readback verified by @fuzeofficlal in #798 (32-byte view returned [86, 32], 48-byte view returned [86, 48]).
  • cargo test -p victory-shader --lib -- --test-threads=1: 121 passed, 0 failed, 1 ignored
  • cargo clippy -p victory-shader --all-targets -- -D warnings (default + --features diagnostics): 0 warnings
  • cargo xtask policy: 154 files ok

Aggregate counts only; no game data used. AI-assisted; all builds and tests executed on my machine.

**@⁠MartinIndra02** on GitHub · 2026-11-24 14:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/953) `MartinIndra02:fix/shader-smem-descriptor-data` → `main` · +46 −0 · 1 files · 1 commits · closed without merging Addresses #798 ### Summary In `crates/victory-shader/src/emit/lower.rs`, `descriptor_data` previously matched only `Fields::Image` and `Fields::Buffer` on the using instruction `ui`, causing `s_buffer_load*` (`Fields::Smem`) buffer descriptor uses to fall through to `a scalar memory read as data`. Handling `Fields::Smem { .. } if un.starts_with("s_buffer_load")` as a raw buffer (`(11 | u, 0)`, still refusing `ResourceType::Cbv`) eliminates **100% of `a scalar memory read as data`** (`771 -> 0`) and immediately translates **+231 shaders** on build 1.0.2.1 (`+166` mesh, `+57` vertex/pixel, `+8` compute), while routing the remaining subset that reads `dword 0/1` (address/format) accurately to `a descriptor's address or format read as data`. ### Full-corpus A/B (`victory translate` on retail 1.0.2.1, 26,084 programs) | Metric | `main` (`ffe310e`) | This PR (`c42cbb0`) | Delta | |---|---:|---:|---:| | Vertex & Pixel emitted | `12,231 / 14,027` | **`12,288 / 14,027`** | **`+57`** | | Compute emitted | `1,441 / 2,582` | **`1,449 / 2,582`** | **`+8`** | | Mesh emitted | `8,214 / 8,713` | **`8,380 / 8,713`** | **`+166`** | | **Total emitted** | **`21,886`** | **`22,117`** | **`+231`** | | `a scalar memory read as data` | `771` | **`0`** | **`-771`** | ### Verification (Windows 11, RTX 3080 `621.24`, Rust `1.98.1`) - New unit test `emit::lower::tests::s_buffer_load_descriptor_size_reads_as_data` (covers both `ResourceType::Srv` lowering and `ResourceType::Cbv` refusal). - Independent native D3D12 + WARP GPU readback verified by `@fuzeofficlal` in #798 (32-byte view returned `[86, 32]`, 48-byte view returned `[86, 48]`). - `cargo test -p victory-shader --lib -- --test-threads=1`: **121 passed, 0 failed, 1 ignored** - `cargo clippy -p victory-shader --all-targets -- -D warnings` (default + `--features diagnostics`): **0 warnings** - `cargo xtask policy`: **154 files ok** *Aggregate counts only; no game data used. AI-assisted; all builds and tests executed on my machine.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:49 +00:00
github-bot closed this pull request 2026-11-26 04:14:49 +00:00
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 14:42 UTC · original

On c42cbb0, a second live scalar-load case passed on an RTX 4090 under Wine/vkd3d-proton 3.2. The raw table started at slot 1 with a different valid view in slot 0. A two-dword scalar load returned the expected words 86 and 87 from the selected view. The shader also stored the reconstructed view size between those words, giving [86, 32, 87] and [86, 48, 87] for the two view sizes. The original single-dword control passed on the same build.

On ffe310e, the same two-dword fixture stopped in lowering at byte 52 with a scalar memory read as data, before dispatch. This verifies table selection, both loaded words, and the live size in this compute case. The reported 231 additional programs are an offline emission count. Their runtime output remains unmeasured here.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 14:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/953#issuecomment-7134816489) On `c42cbb0`, a second live scalar-load case passed on an RTX 4090 under Wine/vkd3d-proton 3.2. The raw table started at slot 1 with a different valid view in slot 0. A two-dword scalar load returned the expected words 86 and 87 from the selected view. The shader also stored the reconstructed view size between those words, giving `[86, 32, 87]` and `[86, 48, 87]` for the two view sizes. The original single-dword control passed on the same build. On `ffe310e`, the same two-dword fixture stopped in lowering at byte 52 with `a scalar memory read as data`, before dispatch. This verifies table selection, both loaded words, and the live size in this compute case. The reported 231 additional programs are an offline emission count. Their runtime output remains unmeasured here.
Author
Owner

@⁠Machad3x on GitHub · 2026-11-24 14:48 UTC · original

Offline measurement (fork github.com/Machad3x/VIctory branch claude/gta6-shader-translation-crashes-705550, tip 9018be9) over 78 console shader containers dumped from an RTX 3080 Ti world run (victory translate --list --validate): MESH programs emitted 0 of 21 on the branch without these changes; 4 of 21 after cherry-picking MartinIndra02's c42cbb0 (PR #953: a descriptor whose only use is s_buffer_load is a raw buffer; 'a scalar memory read as data' 25 -> 0); 19 of 21 (18 validated) after one more change: when the console reuses a dead descriptor's SGPRs for loaded data, a join of that descriptor's address/format dword with a data edge no longer refuses the program (the join reads undefined on that edge, like the lane-mask join already does; commit 9018be9, assumption: the value is only read on paths from the data edge). One of the newly emitted mesh programs (mesh f841ad74ec6e7367) fails DXIL validation: "Container part 'Program Output Signature' does not match expected for module". Remaining mesh failures: structured buffer of unknown stride (2), descriptor read from the first lane of computed VGPRs (4 by group count), descriptor partly joined by control flow (1). In the game (4-minute runs, wave64 mesh allowed by a diagnostics switch) the world still shows only the background plus the loading artwork; one run ended with a title fault writing to a reserved never-committed address.

**@⁠Machad3x** on GitHub · 2026-11-24 14:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/953#issuecomment-7134993124) Offline measurement (fork github.com/Machad3x/VIctory branch claude/gta6-shader-translation-crashes-705550, tip 9018be9) over 78 console shader containers dumped from an RTX 3080 Ti world run (victory translate --list --validate): MESH programs emitted 0 of 21 on the branch without these changes; 4 of 21 after cherry-picking MartinIndra02's c42cbb0 (PR #953: a descriptor whose only use is s_buffer_load is a raw buffer; 'a scalar memory read as data' 25 -> 0); 19 of 21 (18 validated) after one more change: when the console reuses a dead descriptor's SGPRs for loaded data, a join of that descriptor's address/format dword with a data edge no longer refuses the program (the join reads undefined on that edge, like the lane-mask join already does; commit 9018be9, assumption: the value is only read on paths from the data edge). One of the newly emitted mesh programs (mesh f841ad74ec6e7367) fails DXIL validation: "Container part 'Program Output Signature' does not match expected for module". Remaining mesh failures: structured buffer of unknown stride (2), descriptor read from the first lane of computed VGPRs (4 by group count), descriptor partly joined by control flow (1). In the game (4-minute runs, wave64 mesh allowed by a diagnostics switch) the world still shows only the background plus the loading artwork; one run ended with a title fault writing to a reserved never-committed address.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 15:40 UTC · original

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

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 15:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/953#issuecomment-7136425082) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at c42cbb0: `cargo test -p victory-shader` passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠adamdotpy on GitHub · 2026-11-24 15:48 UTC · original

Reviewed c42cbb0 here (Windows 11, Rust 1.98.1): cargo test -p victory-shader — 121 passed, 1 ignored. That agrees with @⁠Zipettte's RDNA3 run, so the change is green on a second machine and a second vendor.

The design reads right, and one detail in it deserves a sentence in the code, because it is what keeps the change honest: with image: None the only dword given a value is 2, and the tail loop inserts Val::Missing(OTHER) for every other dword — so a program that reads the address or format still stops, rather than silently reading a zero. That is the correct shape for "translate what can be proven".

One question about dword 2 when the descriptor is structured. getDimensions().x is the view's element count: for the raw view this arm asks for (11 | u, 0) that is bytes/4, while a console buffer descriptor's dword 2 is records of its STRIDE, so bytes/stride. For a used entry with stride >= 4 the two differ by the stride — 4× at stride 16. The Fields::Buffer arm already draws that distinction ((12 | u, stride) when the stride is usable), and since the handle here is only used for getDimensions, taking (12 | u, stride) when used.stride >= 4 would give bytes/stride and cost nothing else.

Why it matters: that count is usually a loop bound, and translation success proves the program lowered, not that its loop ends where the console's does. A GPU test in the style of root_view_tests — structured view with a known stride, s_buffer_load_dword of dword 2, store it, read it back — would settle which value the title's programs need. If a run in-game shows some of the +231 programs looping long or reading past their buffer, I would look here first.

Two smaller things:

  • The ResourceType::Cbv refusal duplicates the one in the Fields::Buffer arm; hoisting it above the match would cover every arm once.
  • Overlap with #1083: it adds an arm at the same place for the same condition (Fields::Smem), but names the dword instead of lowering it. If this merges, that arm is superseded and I will drop it — and the two will conflict textually in descriptor_data, so whichever lands second wants a rebase.
**@⁠adamdotpy** on GitHub · 2026-11-24 15:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/953#issuecomment-7136652590) Reviewed `c42cbb0` here (Windows 11, Rust 1.98.1): `cargo test -p victory-shader` — 121 passed, 1 ignored. That agrees with @⁠Zipettte's RDNA3 run, so the change is green on a second machine and a second vendor. The design reads right, and one detail in it deserves a sentence in the code, because it is what keeps the change honest: with `image: None` the only dword given a value is 2, and the tail loop inserts `Val::Missing(OTHER)` for every other dword — so a program that reads the address or format still stops, rather than silently reading a zero. That is the correct shape for "translate what can be proven". One question about dword 2 when the descriptor is structured. `getDimensions().x` is the view's element count: for the raw view this arm asks for (`11 | u, 0`) that is bytes/4, while a console buffer descriptor's dword 2 is records of its STRIDE, so bytes/stride. For a `used` entry with `stride >= 4` the two differ by the stride — 4× at stride 16. The `Fields::Buffer` arm already draws that distinction (`(12 | u, stride)` when the stride is usable), and since the handle here is only used for `getDimensions`, taking `(12 | u, stride)` when `used.stride >= 4` would give bytes/stride and cost nothing else. Why it matters: that count is usually a loop bound, and translation success proves the program lowered, not that its loop ends where the console's does. A GPU test in the style of `root_view_tests` — structured view with a known stride, `s_buffer_load_dword` of dword 2, store it, read it back — would settle which value the title's programs need. If a run in-game shows some of the +231 programs looping long or reading past their buffer, I would look here first. Two smaller things: - The `ResourceType::Cbv` refusal duplicates the one in the `Fields::Buffer` arm; hoisting it above the match would cover every arm once. - Overlap with #1083: it adds an arm at the same place for the same condition (`Fields::Smem`), but names the dword instead of lowering it. If this merges, that arm is superseded and I will drop it — and the two will conflict textually in `descriptor_data`, so whichever lands second wants a rebase.
Author
Owner

@⁠jebaczydow on GitHub · 2026-11-24 16:01 UTC · original

Offline count with this PR on top of the #439 stack (RTX 5070 Ti host, 32-lane waves)

Tree: main ffe310e + #439 (bf0f951) + #334, #578, #452 and #650. This PR applies cleanly on top of that.

Input: the 6,633 mesh programs the title created in one run, from my own copy. Command: victory translate --validate --host-lanes 32-32. Counts only.

without this PR with this PR
mesh emitted 6,180 6,307
mesh validated 6,140 6,267
"a scalar memory read as data" 342 0
"a descriptor's address or format read as data" 0 191
"a lane mask read as data" 103 109

With this PR applied, cargo test --workspace --locked gives 395 passed, 0 failed, 6 ignored on the 5070 Ti.

Not tested in a title run.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠jebaczydow** on GitHub · 2026-11-24 16:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/953#issuecomment-7137003094) **Offline count with this PR on top of the #439 stack (RTX 5070 Ti host, 32-lane waves)** Tree: `main` `ffe310e` + #439 (`bf0f951`) + #334, #578, #452 and #650. This PR applies cleanly on top of that. Input: the 6,633 mesh programs the title created in one run, from my own copy. Command: `victory translate --validate --host-lanes 32-32`. Counts only. | | without this PR | with this PR | |---|---|---| | mesh emitted | 6,180 | 6,307 | | mesh validated | 6,140 | 6,267 | | "a scalar memory read as data" | 342 | 0 | | "a descriptor's address or format read as data" | 0 | 191 | | "a lane mask read as data" | 103 | 109 | With this PR applied, `cargo test --workspace --locked` gives 395 passed, 0 failed, 6 ignored on the 5070 Ti. Not tested in a title run. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠Ctrl-Alt-Haze on GitHub · 2026-11-24 16:51 UTC · original

Independent verification at c42cbb0 on Windows 11, RTX 5070 Ti + WARP (VICTORY_D3D12_DEBUG=1), dxil.dll 1.8.2502.11, Rust 1.98.1 against upstream/main (ffe310eb):

  • Clean on ffe310eb; policy (154 ok), both clippy checks, workspace (343 passed, 0 failed, 6 ignored), victory-shader --features host (121/0/1 ign RTX & WARP), and victory-gpu --features diagnostics (53/0/1 ign RTX & WARP) all pass with 0 D3D12 errors/warnings.
  • However, for structured SRVs (stride >= 4), lowering Fields::Smem with raw (11 | u, 0) causes getDimensions().x to return bytes / 4 instead of NUM_RECORDS (bytes / stride), and #953 conflicts textually in lower.rs with #995 (78c8078), which resolves structured NUM_RECORDS via PSV0 proof + per-dword splitting.

AI-assisted verification on local RTX 5070 Ti + WARP; no game data.

**@⁠Ctrl-Alt-Haze** on GitHub · 2026-11-24 16:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/953#issuecomment-7138309480) Independent verification at `c42cbb0` on **Windows 11**, **RTX 5070 Ti** + **WARP** (`VICTORY_D3D12_DEBUG=1`), **dxil.dll `1.8.2502.11`**, **Rust `1.98.1`** against `upstream/main` (`ffe310eb`): - Clean on `ffe310eb`; `policy` (`154 ok`), both `clippy` checks, `workspace` (**343 passed, 0 failed, 6 ignored**), `victory-shader --features host` (**121/0/1 ign** RTX & WARP), and `victory-gpu --features diagnostics` (**53/0/1 ign** RTX & WARP) all pass with 0 D3D12 errors/warnings. - However, for structured SRVs (`stride >= 4`), lowering `Fields::Smem` with raw `(11 | u, 0)` causes `getDimensions().x` to return `bytes / 4` instead of `NUM_RECORDS` (`bytes / stride`), and `#953` conflicts textually in `lower.rs` with `#995` (`78c8078`), which resolves structured `NUM_RECORDS` via `PSV0` proof + per-dword splitting. AI-assisted verification on local RTX 5070 Ti + WARP; no game data.
Author
Owner

@⁠ghost on GitHub · 2026-11-24 17:32 UTC · original

In-game result on AMD, which this PR hasn't had yet: RX 9060 XT (RDNA4, 64-lane waves), Windows 11, diag build. Tree: r4tedx's integration/testers update 9 (94e0ea5, on main ffe310e) with this PR's code change from c42cbb0 hand-applied (6 lines; its test left out), against the same tree without it. VICTORY_HEAP_GUARD_FORM=umin in both (the tree's default form crashes AMD's compiler, see #293).

update 9 (2 runs) + this PR (1 run, ~4x longer)
programs refused for "a scalar memory read as data" 17 / 18 (19 different) 0
of those 19 at the same tree + this PR 16 translated, 3 never bound, none refused for another reason
dropped per frame, mesh 910b4be059bfb28f 236 / 182 0
mesh 321d411b20a35ef9 121 / 94 0
vertex 4e35b816f2f91d68 39 / 26 0
all draws/dispatches dropped per frame, any reason 2,734 / 2,172 2,370

(Per-frame means over the log's summary lines that name each program.) Offline over the title's shader file on the same tree: +269 programs translate, 0 lost, all of them previously "a scalar memory read as data".

Not shown: whether what they draw is correct (the presented image is still black on this tree).

AI-assisted (Claude Code, Claude Opus 5.5); no game data.

**@⁠ghost** on GitHub · 2026-11-24 17:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/953#issuecomment-7139346846) In-game result on AMD, which this PR hasn't had yet: RX 9060 XT (RDNA4, 64-lane waves), Windows 11, diag build. Tree: r4tedx's `integration/testers` update 9 (`94e0ea5`, on `main` `ffe310e`) with this PR's code change from `c42cbb0` hand-applied (6 lines; its test left out), against the same tree without it. `VICTORY_HEAP_GUARD_FORM=umin` in both (the tree's default form crashes AMD's compiler, see #293). | | update 9 (2 runs) | + this PR (1 run, ~4x longer) | |---|---|---| | programs refused for "a scalar memory read as data" | 17 / 18 (19 different) | **0** | | of those 19 at the same tree + this PR | | 16 translated, 3 never bound, none refused for another reason | | dropped per frame, mesh `910b4be059bfb28f` | 236 / 182 | 0 | | mesh `321d411b20a35ef9` | 121 / 94 | 0 | | vertex `4e35b816f2f91d68` | 39 / 26 | 0 | | all draws/dispatches dropped per frame, any reason | 2,734 / 2,172 | 2,370 | (Per-frame means over the log's summary lines that name each program.) Offline over the title's shader file on the same tree: +269 programs translate, 0 lost, all of them previously "a scalar memory read as data". Not shown: whether what they draw is correct (the presented image is still black on this tree). AI-assisted (Claude Code, Claude Opus 5.5); no game data.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:28 UTC · original

Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

descriptor_data handles s_buffer_load uses in main (Fields::Smem arm: structured by the used entry's stride, else raw; 75677cb8).

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/953#issuecomment-7148549561) Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. descriptor_data handles s_buffer_load uses in main (Fields::Smem arm: structured by the used entry's stride, else raw; 75677cb8). If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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!953
No description provided.