Skip to content

Shaders: recover record counts for descriptor-only structured buffers - #329

Open
Raxstreams wants to merge 1 commit into
Marvisak:mainfrom
Raxstreams:codex/data-only-buffer-records
Open

Raxstreams wants to merge 1 commit into
Marvisak:mainfrom
Raxstreams:codex/data-only-buffer-records

Conversation

@Raxstreams

Copy link
Copy Markdown

Some compute shaders load a four-dword buffer descriptor and test its record count without ever issuing a buffer access. The emitter previously needed a resource instruction to infer the view type and stopped at a descriptor read only as data.

For a static table load at an exact binding offset, the emitter can recover the record count with GetDimensions when the native metadata supplies a valid structured stride and the original PSV0 declarations confirm a structured buffer. Conflicting declarations across register spaces, unknown bindings, and dynamic ranges keep the existing unsupported path.

On Windows with an RTX 3080 Ti, the isolated CS_MinTimestepReduce shader validated and created a D3D12 compute pipeline on this branch, based on upstream main. A synthetic GPU test checks the actual returned counts for buffers with 3 and 11 records and covers conflicting declarations. All 70 shader library tests and the repository asset-policy check passed.

This is independent of the SGPR spill work in #298 and #309 and leaves the world-rendering issue open.

muhammed-aksoy pushed a commit to muhammed-aksoy/VIctory that referenced this pull request Nov 24, 2026
@SpaghettiMaster545

Copy link
Copy Markdown

Tested 02564c5 merged alone onto main d2a4bae, with the title, against main on the same machine.

  • NVIDIA GeForce RTX 5070 Ti, driver 621.24 (32.0.16.2124); Ryzen 7 9800X3D; Windows 11 10.0.26100; Rust 1.98.1; diag build, its own empty VICTORY_CACHE_DIR, scripted keys into story mode, until the host GPU failure (NVIDIA RTX 5070 Ti: world hang (DEVICE_HUNG) on 97c78d1 is not one program, not loops, not barriers; 77 compute pipelines refused #71, unrelated).
  • a descriptor read only as data: on main, 21 programs stop with this reason (15–21 over three runs, depending on how far each run gets). With this PR, 1 of those 21 translates and 20 still stop with the same reason. No program stops with it that did not on main.
  • Program by program against main, nothing that ran there stops with this PR.

So on this title the PR's case covers one of the programs with this reason. The other 20 load the descriptor in some other way than a static table load at an exact binding offset with a native structured stride, or lack one of the conditions the PR checks. I have not looked at which.

Not tested

  • AMD GPUs, a release build, the PR's synthetic GPU test on this card.

(Claude Code, Claude Opus 5.5: ran the title on both builds and compared the logs program by program.)

@EduAzevedo

Copy link
Copy Markdown

Measured 02564c5 on the retail shaders (v1.0.2.1, Series X package), offline with victory translate --jobs 8 --list, all 26,148 programs, against main d2a4bae, alone and merged with #309 (64c7188, clean merge):

main this PR #309 this PR + #309
Vertex and pixel programs emitted 12,284 12,302 12,380 12,398
a descriptor read only as data 183 164 692 673

19 more programs translate (18 pixel, 1 compute); none that translate on main stop. For comparison on the same corpus, #180 takes a descriptor read only as data to 1 (with or without #309), so the two overlap; I have not measured them together.

AI-assisted.

@EduAzevedo

Copy link
Copy Markdown

Follow-up to the overlap question above, from the same logs: the 19 programs this PR makes translate do not translate with #180 (5ff639e, alone or with #309). With #180, 18 of them get past a descriptor read only as data and stop at a scalar memory read as data; the other 1 is the single a descriptor read only as data program #180 leaves. So on the title's shaders the two are complementary rather than redundant: this PR finishes those 19, #180 covers the other ~160.

AI-assisted.

Kam471 pushed a commit to Kam471/VIctory that referenced this pull request Nov 24, 2026
…Marvisak#329)

A program that only reads NUM_RECORDS from a descriptor has no resource
use to tell lowering what the descriptor is, so it stopped with "a
descriptor read only as data". When the read is statically addressed and
PSV0 declares a structured buffer at exactly that table binding, lower it
to a structured raw handle and read the count through getDimensions.

Only an exact four-dword table binding (table_offset_dwords * 4 equals
the scalar offset), no computed address, stride 4..=2048 in multiples of
4, and a matching structured PSV0 declaration qualify. Other data-only
descriptor reads keep their previous handling.
Kam471 pushed a commit to Kam471/VIctory that referenced this pull request Nov 24, 2026
Brings in Marvisak#704/Marvisak#193 raw-view stride table and VSH3 cache, Marvisak#329 PSV record counts, and precise copy invalidation. Kept Marvisak#54's host wave range and Marvisak#298's spilled-mask resolution; Parts now carries psv, options and host_waves, and test initializers cover all three.

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested 02564c5 on Windows 11, RTX 5070, MSVC: cargo test -p victory-shader -- --test-threads=1 70 passed, and cargo clippy -p victory-shader --all-targets is clean. victory translate --validate --pipelines on the local title executable still reports 12 of 12 programs, so the new path isn't hit there. The PR adds no tests.

The guards are careful: a static table load only, exact table_offset_dwords * 4 match, 4 dwords, SRV or UAV, a stride of 4 to 2048 that's a multiple of 4, and every covering PSV0 declaration structured. That's the right shape, since a wrong guess here mis-annotates a handle. Two requests before approving:

  • A test: a synthetic compute program with s_load_dwordx4 of a table entry whose NUM_RECORDS dword only feeds a compare, with matching PSV0 and native used. One case where it lowers to GetDimensions with the stride annotation, and one where the PSV0 declaration is typed or raw and it still refuses. Nothing in the suite reaches the None arm today.
  • declares_structured_buffer reads PSV0's resource table with a hard-coded layout (info size at 0, count and stride at 4 + info). That holds for the PSV versions dxc emits today, but a short comment naming the PSV version it assumes would help the next change there.

AI-assisted (Claude Code).

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

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/mod.rs, crates/victory-shader/src/emit/valu_tests.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

alex3112 pushed a commit to alex3112/VIctory that referenced this pull request Nov 25, 2026
…d only through their descriptor) into the integration

Our descriptor data keeps its skewed and twin loads and the runtime stride table of Marvisak#193; the PR's new case (a four-dword structured buffer the program only counts the records of) joins our image-only case in the branch for descriptors nothing else uses. Parts gains psv; the PR's emit-based test helper replaces the hand-built one in valu_tests and names the target.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants