Skip to content

Shaders: classify code-built descriptors and route their reads - #3380

Closed
T1bolus wants to merge 7 commits into
trustno1-coder:mainfrom
T1bolus:fsr4-pr
Closed

T1bolus wants to merge 7 commits into
trustno1-coder:mainfrom
T1bolus:fsr4-pr

Conversation

@T1bolus

@T1bolus T1bolus commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #

What it changes

42 compute shaders that the tip refuses start lowering with this series, 1,377
shaders lower with more exact output than before, and no shader of the 6,532
recorded ones that translated before stops translating. The routed classes are
the ones FSR4-style programs are built from, so the series doubles as
groundwork for that path.

Measured on the recorded corpus (6,532 shaders, diffed against the plain tip on
the same corpus):

  • 42 shaders now lower that the tip refuses — all compute, and the classes
    FSR4-style programs live in: descriptors the code builds around memory,
    strides the layout does not declare, a heap base the records do not name.
    Wave 6's stride gate accounts for 40 of them per the per-commit sweeps, the
    rest come with the memory route.
  • 1,377 shaders lower differently by intent (mesh 757 / compute 420 /
    pixel 147 / vertex 53) — reads that guessed before now follow the machine's
    records: the descriptor classification (1), exact strides and samplers folded
    from constants (4), the host copy behind code-built descriptors (5), reset
    values for VCC/VCC+1/M0 (6).
  • 3,377 shaders come out byte-identical to the tip — the series changes only
    what it means to change.
  • 0 regressions per commit — no shader that translated before refuses after,
    no panics; held as an invariant through the series and re-verified across two
    corpus versions.

A note on FSR4, kept to what the measurements show: the classes above are the
ones FSR4-style programs are characterized by — descriptors built in code
around memory, descriptor dwords the code only patches, stride-0
constant-buffer slots read through tables, wave64 compute with exact folding.
This series puts exactly those classes on a measured, verified base. It does
not claim the title's own upscaler starts with it; the remaining wave work
decides that, in follow-up PRs.

The series itself, rewritten in this tree's idiom (descriptor_data.rs, the
lower/* modules, root_memory, s.entry) — 7 files, +1508/−37, all inside
the shader emit layer (no host or GPU structure touched):

  1. resource: descriptors the console keeps through xor shuffles and the table a root constant holds — the wave-5 classification: sop2_dword,
    xor_net/xor_leaves, kept_low, over_place, assembled, patched (via
    the by_address fallback at the Built pattern), plus the classify wiring
    (assembled before loaded, patched after it) and 10 tests in the
    dynamic2 form. (644+/17−)
  2. clippy: the unused imports and two allow notes the fresh tree needs. (5+/3−)
  3. shader: the heap base the records do not name, and a descriptor dword the code only patches — heap_base_only (a nameless heap base reads 0, with the
    64-visit cap) and patch_only (a descriptor dword the code only patches reads
    undefined instead of a missing host value), hooks in inputs() and
    descriptor_data.rs, +4 tests. (268+/6−)
  4. resource: the strides the layout does not declare, and the samplers built from constants — wave 6: PURE/pure (26 opcodes folded exactly),
    const_of (with the s_bfm_b64 pairs), exact site recording, and the
    indexed-buffer gate that lets slot_stride consult the table
    (slot_word(src, true)). (340+/12−)
  5. lower: an access through a descriptor built in the code reads the host copy of that memory — the memory route in the guard form
    (Source::Built { address.param == MEMORY }), reusing memory() and
    root_copy; indexed Built{MEMORY} accesses refuse. (110+/2−)
  6. lower: the machine registers a program starts with read their reset values
    — VCC/VCC+1/M0 read 0 before their first write (EXEC stays with s.entry,
    which is more precise). (26+/0−)
  7. lower: a stride the table does not hold refuses the indexed read — a
    Table-root gate now demands the record proof
    (used.is_some_and(|u| u.stride == 0 && u.kind != ResourceType::Cbv)): a
    dynamically indexed read through a Table slot with no record is refused
    instead of multiplying the element by the table's 0 — the host writes stride 0
    for constant-buffer slots, so the old form read element 0 and drew speckles,
    missing glyphs and diagonal lines. The Heap-root branch keeps this tree's own
    is_none_or gate. (119+/1−)

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray
    tracing): RTX 4070 Super host against the Series X dump (v1.0.2.1), 1440p with
    DLSS upscaling and DLSS frame generation on (1.00 upscalings per frame in the
    logs), ray-tracing passes present (the structure builder stays off, as on the
    tip).
  • Before: dynamically indexed reads through stride-0 constant-buffer slots read
    element 0 (missing glyphs, speckles, diagonal lines in UI text); compute
    programs built around memory refuse; a nameless heap base reads a missing host
    value; VCC/VCC+1/M0 read garbage before their first write.
  • After: the classes above lower through the classified routes; on the recorded
    corpus 0 shaders that translated before refuse after and no panics. In game on
    the base the waves were written for: 0 dropped-draw regressions against the
    pre-wave line, and the UI-text artifact class disappears with (7)'s gate
    discipline.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): both — the
    recorded corpus covers wave32 and wave64 programs (the tip's wave64 folding
    path included; our exact folding composes with it, verified shader-by-shader
    against the tip's own build).
  • cargo test passed for the crates it touches: yes — victory-shader 481 green
    (3 known PSV flakes excluded on this machine), victory-gpu 915 green, clippy
    -D warnings green.

Checked for overlap

…table a root constant holds

The bakes' descriptor dwords survive register shuffles the console
compiler interleaves (the three-xor swap keeps every value), and their
tables live at a byte a root constant holds. The classifier follows
both: an xor chain nets to the term its leaves reduce to, a dword is
read through the same place the trace pass falls back to, and the
second dword keeps its low half under an xor with none of its bits set.
A descriptor the code assembles from its load and constants, or patches
after it (a stride cleared, a size recomputed, flags set), is the
load's.

(Port of the fork's 8e3e231, wave 5, with c77bde8's wiring: the
assembled and patched sources hang from classify ahead of `loaded` and
behind it, the address tests take the dynamic2 form, and the
three-computed-terms refusal folds into the code table. The built
descriptor's address falls back to title memory as it stands where it
refuses, as the fork's own line has it since before the wave — its
test rides on that.)
… the code only patches

The console compiler picks descriptors from the heap by an index it
computes over a base dword; the records of other programs name that
dword the resource heap root, which the host binds to zero, and those
programs translated and ran. For the programs whose records miss the
name, the gate walks every read of the dword and binds zero where they
all reach a heap load the heap machinery recomputes from the load's own
operands; a read that goes anywhere else keeps the refusal. A
descriptor dword the code recomputes in place (a stride cleared, flag
bits set, often through a join the trace followed) reads back only as
the patch's input: the walk from the read to the descriptor operands
the trace took to the load proves it, and the dword stays undefined,
the handle coming from the load's own operands all the same. Both walks
stop at a fixed visit count - they run in the bake at game start and
must never hang it - and refuse past it.

(The descriptor arms live in emit/descriptor_data.rs here, extracted
from lower.rs; the walks stay beside `inputs`.)

(cherry picked from commit b0650fa)
…uilt from constants

The console compiler builds samplers in code (s_movk_i32, s_bfm_b32 and
s_bfm_b64 over inline constants) and reads structured buffers whose
stride the layout's record does not give. The classifier folds terms
computed from constants alone to their values, so such a sampler
registers as the constant it is. An access by index through a
descriptor whose dwords are the entry's own (recorded exact per access)
runs at the host's stride for its heap slot, as a raw one at the
element's byte; a descriptor the code recomputed keeps the code's
stride and stays refused.

Ported from fsr4-upstream ebe95b4 with the follow-up fix ffff8b1
folded in: the table gate keeps records of constant buffer views out
(the host's stride table holds nothing for constant buffer slots, so
element * stride would collapse to element 0; the console's CBV
descriptor strides by its 16-byte rows, which the constant-buffer path
below keeps).
…t copy of that memory

The console builds a descriptor over an address it computes (an add of two
dwords no root parameter gives) and reads its tables through it. The route
runs only for the descriptors it names — the source must be Built with
resource::MEMORY for the address — and rides on the host-copy machinery the
root views lower through: the sum and carry `root_memory` makes of the
address and the offset, the copy `memory` serves, and the handle stashed in
`root_copy` for the rest of the instruction. The scalar-memory path reads
the dwords the load names, and the buffer path hands the byte on to the
load, store or atomic it lowers; stores included, an indexed access stays
out, for the built descriptor names no stride the translation knows.
Upstream's tip folds the encodings it can and refuses the rest, and these
are the ones it cannot fold.
…alues

The console compiler saves the wave's state at the start through the pair
a move writes (s_mov_b32 s143, exec_lo), which reads the mask the wave
started with, and reads its VCC and M0 the same way before anything wrote
them. No program depends on what the wave was given: VCC and M0 are the
code's to set before any read of theirs, so those inputs lower to the
values that holds (zero, as the uninitialized registers do) instead of
stopping as hardware inputs the host does not give. Entry EXEC stays with
upstream's own machinery: a program dispatched with a thread count takes
the count's mask there, and both their test and ours hold.
the table gate let an indexed access through a table slot the records do
not name run at the host's stride word for that slot; the host writes
zero there for constant-buffer views (view_elements decodes only srv/uav
buffer views), so element * stride could collapse to element 0 - the
missing glyphs the sixteen-byte stride fix removed on the other line. a
table-rooted access now needs the record's proof (a stride-0 structured
one) to leave the index to the table; the view heap keeps upstream's own
gate. the 770 stride-0 structured reads the records name keep the table
path, and no shader of the 6531-dump sweep reaches the refused form.
@T1bolus T1bolus changed the title Shaders: classify code-built descriptors and route their reads [pr-fix] Shaders: classify code-built descriptors and route their reads Nov 29, 2026
@github-actions github-actions Bot added the pr-fix Pull request: fixes a bug label Nov 29, 2026
@github-actions github-actions Bot changed the title [pr-fix] Shaders: classify code-built descriptors and route their reads Shaders: classify code-built descriptors and route their reads Nov 29, 2026
moritz-eckhard-nickel added a commit to moritz-eckhard-nickel/VIctory-NVIDIA that referenced this pull request Nov 30, 2026
@T1bolus

T1bolus commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Holding this back for now rather than extending it. The in-game verification came through — 0 untranslated shaders, scenes, HUD and menu text render correctly (screenshots verified) — but the series carries a memory price that makes the title unplayable on 32 GB machines: the previously refused programs now translate, and with their sample-mask twins that roughly doubles the pipeline variants the loading phase needs (~2,585 translated shaders against ~1,720 on the tip). On a 31 GB machine the free commit falls under the floor: pipeline creation fails with E_OUTOFMEMORY from cold, and playback stutters while streaming — the tip alone holds 19-20 fps under the same conditions, verified both after a fresh boot and after hours of runs.

The fix is clear and I'm working on it: fold the sample-mask variant into the single translation (mask state as a binding, one PSO instead of two), which takes the added pipelines back near tip level. I'll reopen or follow up once that lands.

@T1bolus T1bolus closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-fix Pull request: fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant