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

Open
Raxstreams wants to merge 1 commit from upstream-pr/329 into main
Raxstreams commented 2026-11-24 02:20:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Raxstreams on 2026-11-24T02:20:35Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6573147673 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/329). Originally posted by [Raxstreams](https://github.com/Raxstreams) on 2026-11-24T02:20:35Z. --- 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.
SpaghettiMaster545 commented 2026-11-24 06:55:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SpaghettiMaster545 on 2026-11-24T03:12:45Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7120877236 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/329#issuecomment-7120877236). Originally posted by [SpaghettiMaster545](https://github.com/SpaghettiMaster545) on 2026-11-24T03:12:45Z. --- **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 (#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 commented 2026-11-24 06:55:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by EduAzevedo on 2026-11-24T04:55:06Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122455668 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/329#issuecomment-7122455668). Originally posted by [EduAzevedo](https://github.com/EduAzevedo) on 2026-11-24T04:55:06Z. --- 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 commented 2026-11-24 06:55:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by EduAzevedo on 2026-11-24T05:02:56Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122575377 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/329#issuecomment-7122575377). Originally posted by [EduAzevedo](https://github.com/EduAzevedo) on 2026-11-24T05:02:56Z. --- 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.
mercuryVM commented 2026-11-24 12:56:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T12:56:22Z.

Review: COMMENTED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6039569931 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/329#pullrequestreview-6039569931). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T12:56:22Z. **Review:** COMMENTED --- 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).
Marvisak commented 2026-11-25 01:07:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:14:58Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148309349 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/329#issuecomment-7148309349). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:14:58Z. --- <!-- victory-triage v1 head=02564c5d9561021eb6cfba01e91b1898192a60ac verdict=needs-rebase at=2026-11-25T00:13:20Z --> 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](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/329:upstream-pr/329'
git switch 'upstream-pr/329'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/329'
git switch 'upstream-pr/329'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/329'
git switch 'upstream-pr/329'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/329'
git switch 'main'
git merge --squash 'upstream-pr/329'
git switch 'main'
git merge --ff-only 'upstream-pr/329'
git switch 'main'
git merge 'upstream-pr/329'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!329
No description provided.