Skip to content

Shaders: s_buffer descriptor reads, signature/PSV0 fixes, gather4_l, a16 samples (+479 VS/PS, +200 mesh validated) - #136

Closed
mpDom wants to merge 2 commits into
Marvisak:mainfrom
mpDom:pr/shader-sbuffer-psv0-gather4l
Closed

mpDom wants to merge 2 commits into
Marvisak:mainfrom
mpDom:pr/shader-sbuffer-psv0-gather4l

Conversation

@mpDom

@mpDom mpDom commented Nov 24, 2026

Copy link
Copy Markdown

Raises the number of GTA VI shaders in shaders.rpf that translate and pass dxil.dll validation (translate --validate, all 26,503 containers):
vertex/pixel 12,690 -> 13,169 of 13,169 emitted (0 validator errors), mesh ~8,100 -> 8,302 of 8,506, compute 1,672 -> 1,717 validated (2,032 emitted).

  • s_buffer_load_dword* on a loaded descriptor read as data (descriptor_data), including structured buffers (scalar loads now use the view's stride, not a raw view): 726 -> 0 'a scalar memory read as data'.
  • Dead descriptor-dword phi edges no longer fail a join that also carries real data (700 -> 31, 187 -> 40).
  • ISG1/OSG1 rows are in register order, and PSV0 interpolation modes are taken from the container: 55 signature validator errors -> 0.
  • calculateLOD takes only the spatial coordinates (array slice undef).
  • image_gather4_l and image_gather4_l_o (explicit mip) via clamped textureLoad in gather order: 12 -> 0, unblocks the meshlet culling compute shaders (pipeline creation checked on the host adapter).
  • a16 biased/clamped/compare samples (separates 32-bit leading VGPRs from packed 16-bit coordinates) and centroid SV_Position for conservative depth outputs.

Tested: cargo test -p victory-shader -p xtask (0 failures).

Dom added 2 commits November 24, 2026 00:49
@DaviTostes

Copy link
Copy Markdown

Tested 8ae232f on Arch Linux x86_64, rustc 1.98.1: cargo test -p victory-shader: 51 passed, 0 failed (2 test binaries). The full workspace still needs #112 for the victory-gpu E0425.

  • The diff adds no test, and the title bundles several independent changes (s_buffer descriptor/structured loads, dead descriptor phis, PSV0/ISG1, calculateLOD, image_gather4_l). A regression in one of them would not show in this run; small fixtures per feature (or splitting the PR) would make review and bisecting much easier.
  • No conflict seen with the current victory-shader tests; the new paths are simply unexercised here.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

@HenriqueSBueno

Copy link
Copy Markdown
Contributor

Tested on NVIDIA. This PR turns the menus black here. Windows 11, RTX 3080 (10 GB, driver 616.92), i5-10400F, 32 GB RAM, retail title, diagnostics build, no pad input.

  • main at 9aef3d9: the first-boot screens and the account prompt render. Captured frames ~1200–2400 are real images.
  • main at 9aef3d9 + this PR (8ae232f), same run: every captured frame is black (0,0,0), and there is no audio.
  • The log difference: with this PR, several compute pipelines fail to be created during boot with E_OUTOFMEMORY. The driver is out of memory compiling them; it isn't host memory, since the process sits far below the limit there. main has none of these:
WARN victory_gpu::pipeline::host: host pipeline refused error=E_OUTOFMEMORY (0x8007000E) shaders=[compute 1c8165626a581de4]
WARN victory_gpu::pipeline::host: host pipeline refused error=E_OUTOFMEMORY (0x8007000E) shaders=[compute d240837d597ce9d1]
WARN victory_gpu::pipeline::host: host pipeline refused error=E_OUTOFMEMORY (0x8007000E) shaders=[compute 738350c1a01b713a]
...

Counts in the same ~110 s run: E_OUTOFMEMORY refusals 0 on main, 11 with this PR. E_INVALIDARG refusals are 3 in both runs.

Bisect, 110 s each: main renders. main + #135 + #136 + #40 is black. main + #136 alone is black. Happy to rerun a newer head on this card.

AI-assisted (Claude Code)

@Sunkiller-qc

Copy link
Copy Markdown

The a16 sampling part here (full-dword offset/bias/compare, packed coordinates, _cl clamp, lower.rs:5324 and :5559) is almost line for line the same as #73 (lower.rs:5233 and :5461 there), and the two PRs conflict. #138 is also stacked on #73. Would you consider rebasing this on #73, or dropping that part, so only one version lands? The other changes (s_buffer descriptor reads, ISG1/OSG1/PSV0, gather4_l) don't overlap.

Static review, not built or run.

@ifBars

ifBars commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

I tested the three scalar-buffer hunks from 8ae232f on Windows 10 with Microsoft's DXIL validator and a native D3D12 device (RTX 3060 Ti, driver 610.88). The input was a private sample of 50 previously rejected shaders from first-story loading. Baseline was 9 validated programs and 9 host pipelines. With just the scalar load and descriptor changes it was 13 validated and 13 pipelines. The four additions were vertex shaders. All nine baseline successes remained.

This measurement isolates the scalar changes from the sampling, gather and signature changes. It covers pipeline creation; it does not measure output pixels.

@ifBars

ifBars commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

A follow-up title test found a startup regression worth isolating. With the three scalar-buffer hunks together, four shaders gained pipelines but the returning-profile Player screen rendered uniformly black. Keeping the descriptor reconstruction hunks while restoring the ordinary scalar SRV load path kept all four vertex pipeline gains. On that build the Player capture matched the known-good reference pixel for pixel, and the original movie and the first two story cards rendered. One run per configuration, with cold host pipeline libraries.

@Raxstreams

Raxstreams commented Nov 24, 2026 •

Copy link
Copy Markdown

I tested the explicit-mip gather change on seven meshlet_culling:CS_BatchCull* compute shaders from a world-loading run. This was an offline A/B on Windows with an RTX 3080 Ti (617.14), using the 10.0.26100 DXIL validator and D3D12 compute pipeline creation.

Before adding this PR to my integration branch, all four shaders using image_gather4_l stopped at that instruction. With the change, all four validated and created pipelines: the three CS_BatchCullPreSkinnedMeshlets variants and CS_BatchCullBatchCSMeshlets. The three other batch-cull variants still stop at a hardware SGPR input in both builds.

Both builds include the local integration of #180. I kept the pre-PR ordinary scalar SRV read path in the second build given the Player-screen report above. This result covers translation and pipeline creation. I did not run a frame or compare gather output pixels.

The complete 311-shader replay has now finished. Adding this integration to the #180 build raised the count passing both checks from 53 to 65. In addition to the four gathers, eight shaders previously stopped at a scalar memory read as data passed, including a CS_PedStandardSkinning variant. All 53 previous successes still passed.

@Sunkiller-qc

Copy link
Copy Markdown

Follow-up to my earlier note: I suggested rebasing the a16 part on #73, but both versions read an a16 LOD bias as a full f32 dword (lower.rs:5660-5661 here). With a16 it's an f16 in the low half of its dword, and the high half is undefined (LLVM lowerImage, D111754). #160 handles it that way. So whichever version lands should convert the low half (legacyF16ToF32) instead of as_float on the dword.

Static review, not built or run.

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

A note on the a16 samples in this PR, from comparing with #160 (same family): the bias dword is read here as a full f32 (addr_dword, with the comment that offset, bias and z-compare are always 32-bit). For the bias that does not hold with a16. LLVM's SITargetLowering::lowerImage:

// Special handling of bias when A16 is on. Bias is of type half but
// occupies full 32-bit.
SDValue Bias = DAG.getBuildVector(
    MVT::v2f16, DL,
    {Op.getOperand(ArgOffset + I), DAG.getPOISON(MVT::f16)});

The bias keeps its own dword but is an f16 in the low half; offset and comparison reference are 32-bit as the comment says. Read as an f32, an f16 bias is a denormal near zero, so a biased a16 sample would silently lose its bias.

Also, in case it applies here: on GFX10.3 a16 packs the coordinates and the level but not the derivatives (only _g16 opcodes have 16-bit derivatives); LLVM's gfx10_asm_mimg.s has image_sample_d ... 2D a16 with five address dwords. The decoder on main counts them packed, which I fixed in #160.

From the sources only, not run on hardware. No game data used.

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Two more review notes on this PR (besides the a16 bias above), both about results that can change without a refusal:

  1. image_gather4_l as four textureLoads. The emulation clamps the texel coordinates to the edge and never uses the sampler, so a gather through a wrap, mirror or border sampler reads different texels at the edges than the console does. For level 0 a real textureGather keeps the sampler's address mode (Shaders: texel offsets, comparison and gather forms of image samples #160 does that and refuses other levels); the emulation is only needed for levels other than 0, and there it could apply the address mode from the sampler state, or refuse samplers that are not clamp.

  2. fill_phis. A phi edge that is Missing("a descriptor's address or format read as data" | "a descriptor read only as data") now becomes i32(0) whenever another edge carries data. Nothing checks that the value is dead on the path that takes the edge, so a program that does use it there gets 0 instead of a refusal.

The s_buffer descriptor-read fix (the part behind the 726 to 0 count, and the a scalar memory read as data row of #293) looks like the piece testers need most. Would you consider splitting it into its own PR, so it can go in without the two points above?

From reading the diff only; I have no copy of the title.

@MichailiK

Copy link
Copy Markdown

Ran the full corpus (26,084 programs) and the game on an NVIDIA RTX 3060 12 GB

  • a scalar memory read as data: 573 -> 0. Emitted +41 VS/PS, +11 CS, +29 MS. 80 of the 81 validate, 80 create host pipelines (one invalid module, one wave64 compute the host refuses, as on main).
  • It moves programs rather than closing them: a descriptor's address or format read as data 71 -> 547.
  • The full PR black-screens with 31 E_OUTOFMEMORY refusals (21 compute, 10 mesh).
    • The regression is in the scalar-path/a16 half: dropping the scalar SRV path change makes the game render into the intro with no pipeline refusals.
    • Descriptor hunks alone fail the same 3,652 programs as with that change, so dropping it loses none of the gains.

@claude-GTA6

Copy link
Copy Markdown

From a tester working with Claude (AI-assisted); measured on my own machine.

Heads-up from an RTX 5090 (driver 621.24, Windows 11 26200): #136 alone turns every first-boot and loading screen black. #437 fixes it, so the two should probably land together, or #437 first.

How I found it: I bisected with a diag build, capturing presented frame 256 (the start screen), no input:

build frame 256
d2a4bae + #305 + #177 + #197 start screen
+ #136 first commit (d112889, a16 samples) start screen
+ #136 second commit (8ae232f) black (presented frame is all zeros)
+ #136 + #437 (also with about 30 other open PRs merged, mostly shader ones) start screen

Within 8ae232f, it isn't the PSV0 interpolation modes or the signature sort order (both reverted, still black). It's in the lower.rs part. Given #437's title ("keep scalar byte-offset loads compatible with raw buffer views"), I'd guess it's the raw-to-structured switch for scalar/buffer loads when a stride is declared.

Same effect on the loading screen: its art is drawn into a colour target, but the pass that copies it into the sRGB target outputs nothing. With #437 the art shows again.

Validated counts over the whole package don't show it: #136 is +651 validated, but those shaders draw the wrong thing.

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
Seven more upstream PRs are in (Marvisak#493, Marvisak#483, Marvisak#206, Marvisak#469, Marvisak#459, Marvisak#454,
Marvisak#579) and the wave64 stack is at Marvisak#439's head 965ce30. Records how each
was combined with what the tree had, that a capped view heap keeps
2^18 dynamic slots and why, Marvisak#189 and Marvisak#578 as left out, and a new
section with testers' reports from the title: the set without the
world-entry hang on three NVIDIA cards and how this tree differs from
it, VICTORY_SKIP_WAVE64 as the switch to try, and Marvisak#136 bisected as
making every frame black.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jeremygold02

Copy link
Copy Markdown
Contributor

Verified the scalar structured-SRV path on two vertex shaders at 8ae232f1d7 on Windows 11. Both fail on the same scalar descriptor-data read on the PR merge base (9aef3d9) and on my mission build. Both emit DXIL and pass Windows SDK 10.0.26100.0 validation with this PR.

I checked the descriptor actually supplied by the title at draw entry, before the missing host PSO rejects the draw. Across the two shaders the observer recorded 14 and 11 distinct declarations for the relevant table slot. All were buffer SRVs with DXGI_FORMAT_UNKNOWN, the RAW flag clear and StructureByteStride=80; element counts ranged from 10 to 256 overall. Each original shader also has a singleton structured-SRV declaration covering that register. This verifies the shape of this slot for these observations.

In both validated outputs the count comes from GetDimensions on StructuredBuffer<stride=80>. The scalar load uses (record_count - 1) * 80 as its byte address and splits it into the record index and the offset within that record. All 21 scalar dword loads on that table expression in each shader use the same stride.

I exercised the changed lowering separately on a physical RTX 5070 with a one-thread synthetic shader and three 80-byte records. It reported 3 records. With a matching guard, reads at bytes 160 and 164 returned the two expected third-record words; with a mismatched guard, both initialized output words remained intact. The adjacent sentinels stayed intact and both fences completed with the device reporting S_OK.

The two guest vertex shaders were checked through SDK validation. Their graphics PSOs, actual draws, and effect on the mission picture remain unverified.

@iurysf

iurysf commented Nov 24, 2026

Copy link
Copy Markdown

Measured offline against main d2a4bae with victory translate --list --validate over the title's shaders.rpf + executable (26,096 programs), dxil.dll 1.9.2602.17:

failures "descriptor read only as data" "scalar memory read as data" rejected by validator
main 3,733 183 573 185
main + this PR 3,119 (−614) 40 0 152
main + this PR + #180 3,080 (−653) 1 0 53 (mesh only)

AI-assisted.

@slint6614-dev

Copy link
Copy Markdown

Measured on the full retail shader pack (26,503 containers) with victory translate --validate, against main d2a4bae (emitted / validated):

VS/PS CS MS cargo test -p victory-shader
main 12272 / 12172 1693 / 1670 8191 / 8129 ok
#694 12272 / 12172 1705 / 1682 8191 / 8129 ok
#563 12297 / 12197 1693 / 1670 8191 / 8129 ok
#160 12345 / 12237 1705 / 1682 8191 / 8129 ok
#136 12619 / 12619 1796 / 1697 8355 / 8302 ok

Windows 11, dxil.dll from SDK 10.0.26100.

@Marvisak Marvisak closed this Nov 24, 2026
jeremygold02 added a commit to jeremygold02/VIctory that referenced this pull request Nov 24, 2026
Merge upstream main, retain both shader regression tests, and pass absent PSV metadata in the three synthetic fixtures that construct lowering inputs directly.

Refs: Marvisak#136, Marvisak#329, Marvisak#437
edsuuu pushed a commit to edsuuu/VI-BR-PORT that referenced this pull request Nov 24, 2026
A console buffer descriptor can carry a stride while its host view is
raw. Lower the scalar loads with byte addressing so the DXIL matches
that view. A synthetic GPU regression used to read zero at byte offset
20 and now reads the expected dword.

Builds on Marvisak/VIctory#136 by mpDom. Adapted from 0628716 in the
local RTX bring-up branch.
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
…es, gather4_l, a16 samples (+479 VS/PS, +200 mesh validated)

Resolved: lower.rs keeps HEAD's a16 sample addressing (32-bit gradients unless _g16, f16 bias in the low half); takes the PR's image_gather4_l forms. mod.rs keeps both lds_fits and psv_interp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bodnjenie14 added a commit to bodnjenie14/VIctory that referenced this pull request Nov 24, 2026
A console buffer descriptor can carry a stride while its host view is
raw. Lower the scalar loads with byte addressing so the DXIL matches
that view. A synthetic GPU regression used to read zero at byte offset
20 and now reads the expected dword.

Builds on Marvisak#136 by mpDom. Adapted from 0628716 in the
local RTX bring-up branch.
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>
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
Two testers bisected #136 as making every frame black on RTX 5080 and
4080, loading screens included (upstream issue #71); the tester tree
leaves it out. A plain revert of 5254cfa conflicts with #160, #437 and
the tester merge, so each of #136's constructs is set to the tester
tree's form:

- s_load through a tracked descriptor: SRV only, as before #136 (no UAV
  raw reads); #437's byte offsets and its test stay.
- A descriptor read as data: the first use found, not #136's preference
  for an image or vector buffer use; #136's s_buffer_ arm is gone.
- PSV0 interpolation modes (psv_interp) are no longer read; the
  conservative-depth centroid and the row harmonisation stay (tester).
- calculateLOD passes cs[0..2] as the tester tree does.
- Dead descriptor dwords at data joins: the tester's undef arm
  (descriptor_dword) only, not #136's zero for has_data joins.

Kept because the tester tree has the same form: the signature sort by
row, barycentrics (23 => 28), the comparison-sample check, and #160's
gather and a16 sampling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.