Skip to content

Shaders: a descriptor only read as data takes its kind from its table - #1067

Closed
undeadhuman37 wants to merge 1 commit into
Marvisak:mainfrom
undeadhuman37:pr/descriptor-read-as-data
Closed

undeadhuman37 wants to merge 1 commit into
Marvisak:mainfrom
undeadhuman37:pr/descriptor-read-as-data

Conversation

@undeadhuman37

Copy link
Copy Markdown

What changed

An s_load_dword* of a descriptor whose dwords the code reads as numbers (an image's width and levels) but never samples was refused with "a descriptor read only as data", because the view's kind came only from a use point. Now:

  • the table's range names the kind when it has one;
  • an entry in the resource heap that no range names (a run-time index reaches it) is an image when it is eight dwords, taken for 2D.

Known limit, marked shortcut: in the code: an unnamed eight-dword heap entry is taken as a 2D image, so a cube, 3D or array texture reads sizes of the wrong rank.

Measured

victory translate over the title's shader archive, taken on our integration branch (this commit on top of other fixes, not on bare main), so the deltas on main may be smaller:

before after
programs refused 4123 3749
"a descriptor read only as data" 395 18
compute programs emitted 1441 1743
compute programs validated 1417 1647

A hand-assembled waterfall program that reads two textures' sizes is the new test (waterfall_tests.rs). It fails with the old refusal without the change, and passes on the host GPU and on WARP.

Checks on current main (ffe310e)

  • cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features: clean
  • cargo test -p victory-shader --locked: 121 passed, 0 failed, 1 ignored

No game data is included, only counts. This work was AI-assisted.

🤖 Generated with Claude Code

An s_load_dword* of a descriptor whose dwords the code reads as numbers
(an image's width and levels) but never samples was refused with "a
descriptor read only as data": the view's kind came only from a use. Now
the table's range names it, and an entry in the resource heap that no
range names (a run-time index reaches it) is an image if it is eight
dwords, taken for 2D (shortcut noted in the code).

Offline over the whole corpus, programs refused: 4123 -> 3749; "a
descriptor read only as data" 395 -> 18; compute programs emitted
1441 -> 1743 (validated 1417 -> 1647). Tested with a hand-assembled
waterfall program that reads two textures' sizes, on the host GPU and
WARP; it fails with the old refusal without the change.

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

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A descriptor read only as data no longer refuses the whole program — and since that path errored before, the heuristic cannot regress anything that compiled. The kind guess is grounded in the console descriptor format (8-dword image vs 4-dword buffer ranges), the structured-buffer stride check (stride >= 4 && is_multiple_of(4)) is conservative, and the CBV guard from the loaded-use path is preserved. The admitted shortcut (image taken as 2D, buffer as raw/structured) is documented in the comment, and the new waterfall test pins the ray-tracing-resolve shape (size read through v_alignbit_b32) with per-lane expected values.

Verified locally: test-merge with main clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 96 passed / 0 failed / 1 ignored. Scope note: a_descriptor_only_read_as_data_gives_its_views_size executes on the host harness, which is Windows-gated, so macOS covers compilation + existing tests only; the build_with refactor keeps the old assertions intact (wave_ops expectation correctly parameterized). Approving; a cube/MSAA size-read case would be a good follow-up test on the Windows lane.

@sambagarandawertanda

Copy link
Copy Markdown

I ran the same small fixture with and without the #1067 lowering on our integration tree. The shader loads a fixed 8-dword SRV table entry with s_load_dwordx8, reads width and height without sampling, and writes the encoded dimensions to a raw UAV. The input is a generated 8×4 RGBA32F texture.

  • The original lowering stopped at byte offset 40 with a descriptor read only as data.
  • With the patch, all 32 lanes returned 0x00030007 (width minus one = 7, height minus one = 3) on RTX 3080 (driver 32.0.16.2114) and WARP.

Two distinct compute shaders hit the same translation refusal in an earlier prologue trace. This test covers a 2D table entry. Array and 3D dimensions and the effect on the prologue remain unverified.

AI-assisted fixture, tested locally with generated data.

@NuraadGit

Copy link
Copy Markdown
Contributor

Sizing for NVIDIA: with console-flow wave64 in place, this refusal becomes the largest one in compute, so it pairs well with #439.

Full offline census (26,503 containers, DXIL validation, --host-lanes 32-32) of ffe310e + #439 (bf0f951) + r4tedx's shader/wave-per-group + #493 + #206 + #667 + #704 + #878 + #489 + #294/#709, without this PR:

a descriptor read only as data programs
compute 891
all stages 998

Of the 411 compute programs my #189 (Wave32) stack refuses for its two main wave reasons, 253 reach this one next on the #439 stack, and only 103 validate. r4tedx counts 730 compute programs at it on #439 alone (#439 (comment)).

JMAN730's fork has an independent change for the same class, 57c98c7 ("twin descriptor loads and quad gradients for compute samples"). My stack on that fork is at 1 compute program for this reason (7 in all stages). #979 infers the view in a similar way. So there are three versions of this, worth comparing before one lands.

I haven't measured this PR on the #439 stack. The known limit you mark, the 2D guess for an unnamed heap entry, is what I'd check at runtime.

AI-assisted (Claude Code): the census was automated. The hardware, title copy and runs are the user's.

@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 6d30fd7: 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).

@pablogonz12

pablogonz12 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Independent check on Linux (RX 9070 XT, RADV/Mesa 26.3.1, dxil-spirv master, spirv-val 1.3). Your head 6d30fd7 applied alone onto origin/main ffe310e, then the offline four-stage check over the 751-program world dump plus the 52-program BVH capture (768 programs once 35 duplicate containers are skipped):

translated translate refusals "a descriptor read only as data" spirv-val / pipeline failures
main ffe310e 666 102 4 (2 compute, 2 pixel) 10 / 0
your head 670 98 0 10 / 0

Exactly those 4 programs clear and nothing else changes: no new refusal, and the 10 spirv-val failures are the same pre-existing ones. "a descriptor's address or format read as data" stays at 1.

For comparison I also built my own attempt at the same 4 programs (a raw buffer view, commit 61085ee in our tree, not pushed): it clears them too, but one lands on "a descriptor's address or format read as data", so 669 translated. Taking the kind from the table is the better fix; I did not open a competing PR.

Not tested: the full archive (only these dumps), in-game, native Windows.

@shortselow-byte

Copy link
Copy Markdown

#1067 and #1130 both remove the refusal "a descriptor read only as data", in different ways, and neither mentions the other:

Tested on Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT, both on main ffe310e (neither has a CI run yet):

workspace tests clippy (default, --all-features) policy
#1067 6d30fd7 343 passed, 0 failed clean ok
#1130 98f073d 343 passed, 0 failed clean ok

They conflict in lower.rs (descriptor_data), so whichever merges second needs a rebase. They combine naturally: in #1067's version, match use_at.or_else(|| self.same_entry_use(site)), so #1130's lookup runs first and #1067's table/heap fallback only when no other load of the entry is used. With that one-line resolution (local, not pushed), both new tests pass together (a_descriptor_only_read_as_data_gives_its_views_size on the AMD device and WARP, a_descriptor_read_only_as_data_takes_the_kind_of_its_entrys_use), the workspace has 344 passed, 0 failed, and both clippy runs are clean.

That order would also keep #1067's 2D guess for heap entries that #1130 can't name, instead of using it first.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Reviewed 6d30fd7 alongside #979 / #1130 / #953 and found three edge cases worth tightening in the None fallback path:

  1. None if in_views => (false, count as u8, 0) fabricates 2D SRVs for untracked 8-dword loads & passes mip = 0 for UAVs:
    • When used_kind(&src) returns None (for example an s_load_dwordx8 spanning two adjacent 4-dword CBVs or an untracked ResourceHeap load), count == 8 unconditionally declares a 2D SRV (2, 0x409); if the backing slot is actually an RWTexture2D UAV, uav = false passes mip = 0 instead of undef to dx.op.getDimensions (rejected by dxil.dll). Requiring let used = self.used_kind(&src).ok_or(NONE)?; avoids guessing untracked slots.
  2. Load width / narrowed intra-slot offset vs used.dwords:
    • used_kind matches u.table_offset_dwords <= dword with no upper bound, so an s_load_dwordx8 (count = 8) after an earlier 4-dword buffer range (u.dwords = 4) is misclassified as a 4-dword buffer unless in_slot + count <= u32::from(used.dwords) is checked (in_slot = (a.offset % 32) / 4).
    • Accounting for in_slot in rel = (in_slot + k).wrapping_sub(u32::from(first)) also supports LLVM-narrowed single-dword NUM_RECORDS loads at +0x08 (in_slot = 2) instead of failing at rel = 0 ("a descriptor's address or format read as data").
  3. Non-dword-multiple stride fallback (4 if used.is_some() => (11 | u, 0)):
    • When u.dwords == 4 has a non-zero stride that is not a multiple of 4 (e.g. stride = 2), falling through to raw buffer (11 | u, 0) causes getDimensions to return byte length (2 * N) rather than record count (N). Only stride == 0 should map to raw (11 | u, 0).

Verified across 8-dword Texture2D/RWTexture2D, 4-dword StructuredBuffer/ByteAddressBuffer, and narrowed +0x08 RWByteAddressBuffer size readbacks on RTX 5090 + D3D12 WARP + dxil.dll in fuzeofficlal/VIctory@66a9fde.

@justlovett0

Copy link
Copy Markdown

Runtime verification on Win10/RTX 3080 (driver 621.24): this PR clears the dominant runtime failure class.

We dumped the exact containers of every shader that failed at runtime (VICTORY_DUMP_REFUSALS, a small diagnostics addition) and censused them with victory translate. Across the world runs, the captured failing set was ~466 unique shaders, dominated by "a descriptor read only as data" (303) after the mask classes were cleared by #309.

With this PR stacked (main ffe310e + #175/#994/#302/#193/#704/#309/#953 + this), a re-census of the same captured containers emits 313/381 compute, 11/14 VS/PS, 4/21 mesh — and the in-game untranslated count fell from 444 to 100. Visibly more character and scene geometry loads.

Note for the record: #1056 (which we tried first) gained ~0 on this class, consistent with the #1247 benchmark; this PR is the one that moves it. The residual "descriptor read only as data" cases now report as "a descriptor's address or format read as data" (40) — the dword-0/1 subset your summary routes onward.

Remaining runtime classes after this: descriptor-address/format-as-data 40, address-not-from-root 29 (#1276's pattern), address-from-phi 11, image_gather4_l 9, root-UAV/typed-root-view 8.

AI use: Qwen Code (underlying model name not disclosed by the tool) ran the builds/censuses and drafted this comment at the user's request.

@dragoso

dragoso commented Nov 24, 2026

Copy link
Copy Markdown

Offline pipeline-creation check on an RTX 5060 Ti: #1067 on top of #585 adds 540 host pipelines and loses none. Together with #585 it adds 563 over main. Counts only; no shader names or dumps.

victory translate --validate --pipelines --list over shaders.rpf (retail 1.0.2.1, 26,084 programs). A program counts as usable only when its D3D12 pipeline is created on this GPU (NVIDIA RTX 5060 Ti, 32-lane, driver 32.0.16.1742, dxil.dll from SDK 10.0.26100).

I measured #1067 stacked on #585 (ffe310e + #585 + #1067), not alone. The merge has one conflict, in descriptor_data's branch for a descriptor with no use. Both PRs rewrite it; I took #1067's side, which covers #585's (#585 only handles the case where used_kind is known).

pipelines created
main ffe310e 21,566
+ #585 21,589
+ #585 + #1067 22,129

In the game (same machine, same save, empty shader cache), the stacked build had 0 regressions: no shader whose pipeline was created on main fails with it. Like main, it reaches the world and is removed with 0x887A0006.

AI-assisted (Claude Code); everything was run on our machine.

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>
justr4mzi added a commit to justr4mzi/VIctory that referenced this pull request Nov 24, 2026
@ScarionWorkspace

Copy link
Copy Markdown

#1067 vs #1130 head-to-head, full archive, bare main. Windows 11, RX 9070 XT, Rust 1.98.1, dxil.dll from SDK 10.0.26100. victory translate --list --validate over shaders.rpf + the executable (1.0.2.1, 25,901 programs), each PR alone merged onto main ffe310e, compared program by program:

validated "a descriptor read only as data" gained lost
main 21,736 394 – –
#1067 (6d30fd7) 22,031 17 +295 0
#1130 (98f073d) 21,976 53 +240 0
both, #1130's same_entry_use tried before #1067's table fallback 22,012 17 +276 0

AI-assisted (Claude); counts only, no game data.

@BitWuehler

Copy link
Copy Markdown

In-game Linux + Proton + NVIDIA RTX 5080 A/B verification combining #585 and #1067 (using @dragoso's descriptor_data merge resolution where #1067 supersedes #585's None arm):

In-world metric Before (n = 30) With #585 + #1067 (n = 28)
Unique untranslated shaders 415 308 (−107)
• "a select on an untracked mask" (#585) 89 0
• "a descriptor read only as data" (#1067) 67 0 (18 moved downstream to "descriptor's address or format read as data")
host pipeline refused warnings 137 134
draws/frame (median / max) 2,076 / 5,662 3,051 / 8,073 (+47%)
GPU faults / device removals / Xids 0 / 0 / 0 0 / 0 / 0 (reached frame=1523)

No regressions observed (cargo test -p victory-shader --locked: 97 passed, 0 failed, 1 benchmark ignored). Cross-posted briefly on #585.

AI-assisted log analysis; built and run locally on my own retail copy, no game files or raw logs attached.

MfDev0 pushed a commit to MfDev0/victory that referenced this pull request Nov 24, 2026
Port of Marvisak#1067 (6d30fd7) onto the victory-gta6 base, after
its lane-copied, sampler and view-address cases. An s_load_dword* of a
descriptor whose dwords the code reads as numbers (an image's width and
levels) but never samples was refused with "a descriptor read only as
data": the view's kind came only from a use. Now the table's range names
it, and an entry in the resource heap that no range names is an image if it
is eight dwords, taken for 2D (shortcut noted in the code).

Upstream measured over the whole corpus: "a descriptor read only as data"
395 -> 18. The two pixel shaders 7d0f14ce44746d7e and 6b6db9f1a526daeb that
victory-gta6 JMAN730#26 still drops in the prison interior fail this way.

(cherry picked from commit 6d30fd7)

Co-authored-by: arena-agent <297053741+arena-agent@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.
@thatirishguyyy

Copy link
Copy Markdown

I rebased 6d30fd7 onto 70564ae, preserving main’s descriptor-address fallback. Over 26,096 programs, the rebase added 36 DXIL-valid shaders with zero validation regressions. Both PS_PuddleDetect variants from my RX 9070 XT logs now validate, and all six waterfall tests pass. Cutscene rendering remains unverified on the rebased build. AI-assisted.

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

Main takes a size-only descriptor's kind from a twin load (75677cb). What this adds beyond that is a guess: any eight-dword entry with no use is a 2D image. Main's notes rule that out (a 2D getDimensions on a view of another dimension is invalid in D3D12; the open case, PS_PuddleDetect, needs a size table from the host).

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.

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.