Skip to content

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

Closed
MartinIndra02 wants to merge 1 commit into
Marvisak:mainfrom
MartinIndra02:fix/shader-smem-descriptor-data
Closed

MartinIndra02 wants to merge 1 commit into
Marvisak:mainfrom
MartinIndra02:fix/shader-smem-descriptor-data

Conversation

@MartinIndra02

Copy link
Copy Markdown

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 Shaders: a descriptor dword needed as another s_load's address stops translation (879 programs on 1.0.2.1) #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.

@MichaelSmithAI

Copy link
Copy Markdown

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.

MfDev0 pushed a commit to MfDev0/victory that referenced this pull request Nov 24, 2026
A descriptor whose only use is an s_buffer_load is a raw buffer to the
host; descriptor_data fell through to "a scalar memory read as data".
Upstream reports 771 -> 0 such failures and +231 programs translated.

From upstream PR Marvisak#953 (c42cbb0), hand-ported.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
Callimann8 added a commit to Callimann8/VIctory-fork that referenced this pull request Nov 24, 2026
Callimann8 added a commit to Callimann8/VIctory-fork that referenced this pull request Nov 24, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Machad3x

Copy link
Copy Markdown

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.

@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 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).

@adamdotpy

Copy link
Copy Markdown

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 Shaders: name what a scalar memory read is, and which descriptor dword it reads #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.

@jebaczydow

Copy link
Copy Markdown

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).

@Ctrl-Alt-Haze

Copy link
Copy Markdown

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.

Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
`smem` reads an `s_buffer_load` through a raw view of the descriptor when
the tracked use is an SRV, and through a constant buffer for every other
kind. The arm added for Marvisak#953 annotated the size query as a raw view for
any use but a CBV, so a descriptor used as a UAV, or one loaded from a
resource heap (neither of which `used_kind` reports), asked for the
dimensions of a view its load never reads.

Found by the Codex review of the change. No program in the title's 26,148
is affected: the offline A/B is unchanged (862 -> 571 refusals, 291
emitted, 0 newly refused).

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
Jarrrk pushed a commit to Jarrrk/VIctory that referenced this pull request Nov 24, 2026
A descriptor dword read only as data no longer stops the program: when no
instruction uses it, the table's range names its kind (eight dwords is an
image, else a structured or raw buffer), and an SMEM buffer load of a
descriptor reads it as a raw buffer view. A constant buffer's descriptor
read as data stays refused.

Pixel inputs of packed 16-bit values now pair each packed row with its
unlisted partner row, as the console's input table does, instead of
refusing a packed input half no element holds.

Ported from Marvisak/VIctory Marvisak#1067, Marvisak#953 and Marvisak#176.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
KainanP added a commit to KainanP/VIctory that referenced this pull request Nov 24, 2026
…sak#704 + Marvisak#1511

Conflicts in crates/victory-shader/src/emit/lower.rs, resolved by hand:

1. descriptor_data: the bundle (Marvisak#953 s_buffer_load uses, Marvisak#1067 "read only as data"
   from the table's range) and Marvisak#180 (twin loads of the same dwords) both rewrote how
   the view's kind is found. Kept Marvisak#180's lookup (own uses, else a twin load's) and the
   bundle's handling of the use and of the unused case, plus the one case Marvisak#180 accepted
   that the bundle did not: an 8-dword load outside a table/heap range, taken as a 2D
   image (Marvisak#180's "image the program only measures"). Where both accepted a descriptor
   they built the same view.
2. phi joins: the bundle's arm (Marvisak#1073, a mask dword joined by ballot) and Marvisak#180's arm
   (a descriptor dword at a data join is undef) were inserted at the same place. Both
   kept, bundle first; the first needs a tracked lane mask, which a descriptor dword
   is not, so they do not overlap.
3. No textual conflict, did not compile: the bundle (Marvisak#306) gave `addr_val` a start
   position (`addr_val(l, start, k)`); Marvisak#180's compute image_sample_b arm read the bias
   with the old form at dword 0 through `as_float`. It now reads it as the bundle's
   sampleBias does: after the offset word when there is one, an f16 with a16
   (`to_float`). This is the bias half of the Marvisak#160/Marvisak#180 interaction described in
   Marvisak#160 (comment) , which the
   bundle's offset forms already expose.
@Marvisak

Copy link
Copy Markdown
Owner

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; 75677cb).

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 Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants