Shaders: hidden descriptor words joined with data are an undefined path (+494 programs, stacked on #1402) #1596

Closed
sinan-cmyk wants to merge 35 commits from upstream-pr/1597 into main
sinan-cmyk commented 2026-11-24 19:40:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T19:40:17Z.


Stacked on #1402. Until #1402 lands, the diff here shows #1402 too. The change itself is the last commit, 2d2a697: one file, emit/lower.rs, +93 lines including 2 tests.

Summary: This PR handles the 772 programs that reach "a descriptor's address or format read as data" through a join with data. On a retail dump it gains 435 programs on top of #1402 and loses none. With #1402, that failure is the largest one: 809 programs (measurement).

What the 809 programs do

I instrumented the translator on all 809 programs and recorded the first instruction that consumes the missing dword:

First consumer Programs
a phi (a join) 772
an SGPR spill (v_writelane_b32) 36
v_mov_b32 1

At those joins, another reachable edge brings real data (s_buffer_load results, for example), and the code after the join uses the value as a number (s_and_b32, s_cmp_*, s_lshl_b32, s_bfe_u32). The descriptor's registers are simply reused on one path. In a traced example, the read sits behind a branch that is taken only when the value came over the data edge.

Change

descriptor_data marks the dwords that no HLSL program can read as hidden. GetDimensions reads an image's sizes and levels (dwords 1–4), a buffer's record count (dword 2) and a structured buffer's stride (dword 1). It never reads these dwords:

  • addresses: image dword 0, buffer dwords 0 and 1, except the stride bits of a structured buffer
  • formats: buffer dword 3
  • an image's array pitch and meta data: dwords 5–7

At a join where a reachable edge brings data, a hidden dword on another edge is a register that a path left undefined. fill_phis takes 0 for it, which is the existing treatment of an unread join. What stays refused:

  • a hidden dword read directly, not through a join
  • a join of descriptor dwords only, with no data edge
  • the 36 spill cases

The assumption to review (marked shortcut: in the code): a program that really reads such a dword on that path now gets 0. Plain HLSL cannot express such a read, so the console compiler can only produce it for a value that is undefined in the source. If an Xbox-specific intrinsic exposes raw descriptor words, programs that use it would get 0 on that path.

Measurement

victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11, compared program by program (25,889 programs):

Build Validated Change Lost
#1402 head 2310409 23,412
this PR, 2d2a697 23,847 +435 0

Of the 809, 435 now validate. 53 more move on to later failures:

  • 35 to "a lane mask read as data"
  • 8 to "a lane mask holding lanes elsewhere read as data"
  • 8 to "a constant buffer's descriptor read as data"
  • 2 to "a descriptor read only as data"

321 still fail with this reason. Most of them are image dwords 0 and 5 that reach the read without a data edge, plus the spills.

Checks

  • Two synthetic tests, no game data:
    • A raw view's dword 1 read directly is still refused.
    • The same dword joined with s_buffer_load data now lowers. With the new rule turned off, this test fails with exactly the target error.
  • cargo test --locked -p victory-shader --lib: 139 passed, 0 failed, 1 ignored. The run used an RTX 4070 SUPER as the default adapter.
  • cargo clippy -p victory-shader --all-targets: clean.
  • The asset-policy check passed in the pre-commit hook.

Overlap: #1376 and #1230 also work on descriptor and missing-value joins. Both conflict with #1402 in emit/lower.rs, and I have not measured them stacked.

AI-assisted (Claude Code). No shader names or data are included, per the asset policy.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6589916365 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1597). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T19:40:17Z. --- **Stacked on #1402.** Until #1402 lands, the diff here shows #1402 too. The change itself is the last commit, 2d2a697: one file, `emit/lower.rs`, +93 lines including 2 tests. **Summary:** This PR handles the 772 programs that reach "a descriptor's address or format read as data" through a join with data. On a retail dump it gains **435 programs on top of #1402 and loses none**. With #1402, that failure is the largest one: 809 programs ([measurement](https://github.com/Marvisak/VIctory/pull/1402#issuecomment-7140318094)). ## What the 809 programs do I instrumented the translator on all 809 programs and recorded the first instruction that consumes the missing dword: | First consumer | Programs | |---|---| | a phi (a join) | 772 | | an SGPR spill (`v_writelane_b32`) | 36 | | `v_mov_b32` | 1 | At those joins, another reachable edge brings real data (`s_buffer_load` results, for example), and the code after the join uses the value as a number (`s_and_b32`, `s_cmp_*`, `s_lshl_b32`, `s_bfe_u32`). The descriptor's registers are simply reused on one path. In a traced example, the read sits behind a branch that is taken only when the value came over the data edge. ## Change `descriptor_data` marks the dwords that no HLSL program can read as hidden. `GetDimensions` reads an image's sizes and levels (dwords 1–4), a buffer's record count (dword 2) and a structured buffer's stride (dword 1). It never reads these dwords: - addresses: image dword 0, buffer dwords 0 and 1, except the stride bits of a structured buffer - formats: buffer dword 3 - an image's array pitch and meta data: dwords 5–7 At a join where a reachable edge brings data, a hidden dword on another edge is a register that a path left undefined. `fill_phis` takes 0 for it, which is the existing treatment of an unread join. What stays refused: - a hidden dword read directly, not through a join - a join of descriptor dwords only, with no data edge - the 36 spill cases **The assumption to review** (marked `shortcut:` in the code): a program that really reads such a dword on that path now gets 0. Plain HLSL cannot express such a read, so the console compiler can only produce it for a value that is undefined in the source. If an Xbox-specific intrinsic exposes raw descriptor words, programs that use it would get 0 on that path. ## Measurement `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11, compared program by program (25,889 programs): | Build | Validated | Change | Lost | |---|---|---|---| | #1402 head 2310409 | 23,412 | | | | this PR, 2d2a697 | 23,847 | **+435** | **0** | Of the 809, 435 now validate. 53 more move on to later failures: - 35 to "a lane mask read as data" - 8 to "a lane mask holding lanes elsewhere read as data" - 8 to "a constant buffer's descriptor read as data" - 2 to "a descriptor read only as data" 321 still fail with this reason. Most of them are image dwords 0 and 5 that reach the read without a data edge, plus the spills. ## Checks - Two synthetic tests, no game data: - A raw view's dword 1 read directly is still refused. - The same dword joined with `s_buffer_load` data now lowers. With the new rule turned off, this test fails with exactly the target error. - `cargo test --locked -p victory-shader --lib`: 139 passed, 0 failed, 1 ignored. The run used an RTX 4070 SUPER as the default adapter. - `cargo clippy -p victory-shader --all-targets`: clean. - The asset-policy check passed in the pre-commit hook. **Overlap:** #1376 and #1230 also work on descriptor and missing-value joins. Both conflict with #1402 in `emit/lower.rs`, and I have not measured them stacked. AI-assisted (Claude Code). No shader names or data are included, per the asset policy.
upstream-sync changed title from [PR #1597] Shaders: hidden descriptor words joined with data are an undefined path (+435 programs, stacked on #1402) to [PR #1597] Shaders: hidden descriptor words joined with data are an undefined path (+473 programs, stacked on #1402) 2026-11-24 21:02:45 +00:00
sinan-cmyk commented 2026-11-24 21:03:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:10:05Z.


Follow-up commit 6a94bb3: +38 more programs, 0 lost (+473 over #1402 in total).

This commit traced the 321 programs that still stopped at "a descriptor's address or format read as data" after 2d2a697, and handles two more paths. In both, the direct read stays refused.

  • A join whose edges are all hidden words is itself hidden (two loads of one descriptor meeting at a join). A join with data further on then takes it as the undefined path.
  • A hidden word spilled with v_writelane_b32 at a constant lane stays marked, and v_readlane_b32 of that lane gives the hidden word back.

I also tried counting a lane-mask edge (one whose ballot the join uses) as data. It gained no program, so I left it out to keep the assumption narrow.

Build Validated Change Lost
#1402 2310409 23,412
2d2a697 23,847 +435 0
6a94bb3 23,885 +38 0

About 48 programs still fail with this reason. Most of them read the hidden field on every path, so refusing them is correct. Two new synthetic tests (a_join_of_hidden_words_is_hidden, a_spilled_hidden_word_comes_back_hidden) each fail when their rule is turned off. cargo test -p victory-shader --lib: 141 passed, 0 failed. clippy: clean.

AI-assisted (Claude Code). No shader names or data are included, per the asset policy.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143135547 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1597#issuecomment-7143135547). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T20:10:05Z. --- **Follow-up commit 6a94bb3: +38 more programs, 0 lost (+473 over #1402 in total).** This commit traced the 321 programs that still stopped at "a descriptor's address or format read as data" after 2d2a697, and handles two more paths. In both, the direct read stays refused. - **A join whose edges are all hidden words is itself hidden** (two loads of one descriptor meeting at a join). A join with data further on then takes it as the undefined path. - **A hidden word spilled with `v_writelane_b32` at a constant lane stays marked**, and `v_readlane_b32` of that lane gives the hidden word back. I also tried counting a lane-mask edge (one whose ballot the join uses) as data. It gained no program, so I left it out to keep the assumption narrow. | Build | Validated | Change | Lost | |---|---|---|---| | #1402 2310409 | 23,412 | | | | 2d2a697 | 23,847 | +435 | 0 | | 6a94bb3 | 23,885 | **+38** | **0** | About 48 programs still fail with this reason. Most of them read the hidden field on every path, so refusing them is correct. Two new synthetic tests (`a_join_of_hidden_words_is_hidden`, `a_spilled_hidden_word_comes_back_hidden`) each fail when their rule is turned off. `cargo test -p victory-shader --lib`: 141 passed, 0 failed. clippy: clean. AI-assisted (Claude Code). No shader names or data are included, per the asset policy.
sinan-cmyk commented 2026-11-24 21:03:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:57:52Z.


Rebased onto the updated #1402 head 119b763. That commit is test-only: it skips two of #306's tests on older validators. My two commits are unchanged: 81f2545 (was 2d2a697) and 6c428a2 (was 6a94bb3). emit/lower.rs is byte-identical to before, so the measurement still holds: +473 over #1402, 0 lost. cargo test --locked -p victory-shader --lib on the rebased head: 141 passed, 0 failed.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144292288 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1597#issuecomment-7144292288). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T20:57:52Z. --- Rebased onto the updated #1402 head `119b763`. That commit is test-only: it skips two of #306's tests on older validators. My two commits are unchanged: `81f2545` (was 2d2a697) and `6c428a2` (was 6a94bb3). `emit/lower.rs` is byte-identical to before, so the measurement still holds: +473 over #1402, 0 lost. `cargo test --locked -p victory-shader --lib` on the rebased head: 141 passed, 0 failed. AI-assisted (Claude Code).
upstream-sync changed title from [PR #1597] Shaders: hidden descriptor words joined with data are an undefined path (+473 programs, stacked on #1402) to [PR #1597] Shaders: hidden descriptor words joined with data are an undefined path (+494 programs, stacked on #1402) 2026-11-24 21:28:07 +00:00
sinan-cmyk commented 2026-11-24 21:28:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T21:12:42Z.


Third commit f4e166a: a constant buffer's descriptor words are hidden too. +21 programs, 0 lost (+494 over #1402).

descriptor_data refused the whole load as soon as a descriptor whose use is a constant buffer had a word read as data. Plain HLSL can read no word of a CBV descriptor (GetDimensions has no cbuffer form), so all four words are hidden words now. A direct read is still refused under the same reason ("a constant buffer's descriptor read as data"). At a join with data, the words take the undefined path, as the first commit does for other hidden words. Words of the load beyond the descriptor stay "address or format" and are not hidden.

Build Validated Change Lost
#1402 119b763 23,412
6c428a2 (the two earlier commits, rebased) 23,885 +473 0
f4e166a 23,906 +21 0

No program fails with the CBV reason any more. 22 programs move on to "a descriptor's address or format read as data" (load words beyond the descriptor), and 9 to "a descriptor read only as data". New test: a_constant_buffers_descriptor_words_are_hidden. It fails at the join when the old refusal is put back. cargo test --locked -p victory-shader --lib: 142 passed, 0 failed.

No open PR targets this reason. AI-assisted (Claude Code). No shader names or data are included, per the asset policy.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144626878 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1597#issuecomment-7144626878). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T21:12:42Z. --- **Third commit f4e166a: a constant buffer's descriptor words are hidden too. +21 programs, 0 lost (+494 over #1402).** `descriptor_data` refused the whole load as soon as a descriptor whose use is a constant buffer had a word read as data. Plain HLSL can read no word of a CBV descriptor (`GetDimensions` has no cbuffer form), so all four words are hidden words now. A direct read is still refused under the same reason ("a constant buffer's descriptor read as data"). At a join with data, the words take the undefined path, as the first commit does for other hidden words. Words of the load beyond the descriptor stay "address or format" and are not hidden. | Build | Validated | Change | Lost | |---|---|---|---| | #1402 119b763 | 23,412 | | | | 6c428a2 (the two earlier commits, rebased) | 23,885 | +473 | 0 | | f4e166a | 23,906 | **+21** | **0** | No program fails with the CBV reason any more. 22 programs move on to "a descriptor's address or format read as data" (load words beyond the descriptor), and 9 to "a descriptor read only as data". New test: `a_constant_buffers_descriptor_words_are_hidden`. It fails at the join when the old refusal is put back. `cargo test --locked -p victory-shader --lib`: 142 passed, 0 failed. No open PR targets this reason. AI-assisted (Claude Code). No shader names or data are included, per the asset policy.
upstream-sync closed this pull request 2026-11-25 02:04:34 +00:00
Marvisak commented 2026-11-25 02:05:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:21:24Z.


Automated triage for the maintainers. Closing because by our reading the change is incorrect or would break something that works today.

Stacked on bundle #1402; its own change zero-fills stale descriptor words at joins with data ('shortcut: zero for the undefined path'), the policy main dropped as unsound (3dd467c), and main now proves such edges dead instead (a7fc47af dead_on_edge/live_edges).

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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149462533 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1597#issuecomment-7149462533). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:21:24Z. --- Automated triage for the maintainers. Closing because by our reading the change is incorrect or would break something that works today. Stacked on bundle #1402; its own change zero-fills stale descriptor words at joins with data ('shortcut: zero for the undefined path'), the policy main dropped as unsound (3dd467c), and main now proves such edges dead instead (a7fc47af `dead_on_edge`/`live_edges`). 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.
Marvisak commented 2026-11-25 02:06:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:31:41Z.


Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/mod.rs, crates/victory-shader/src/emit/shader.rs, crates/victory-shader/src/emit/valu_tests.rs, crates/victory-shader/src/structure.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149648421 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1597#issuecomment-7149648421). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:31:41Z. --- <!-- victory-triage v1 head=f4e166a8419983e40c1c5002f860b099f0c8c767 verdict=needs-rebase at=2026-11-25T01:31:41Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/lower.rs`, `crates/victory-shader/src/emit/mod.rs`, `crates/victory-shader/src/emit/shader.rs`, `crates/victory-shader/src/emit/valu_tests.rs`, `crates/victory-shader/src/structure.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
sinan-cmyk commented 2026-11-25 02:06:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T01:45:42Z.


Fourth commit cc7d30a: a structured buffer's dword 1 is hidden at a join too.

Why. I merged #995 by hand on top of this PR, and the result lost 21 programs. #995 turns some raw views into structured ones. This PR treated a raw view's dword 1 as hidden, but not a structured view's dword 1. descriptor_data gives that word no value: its low half is the address, its high half the stride. So programs that the raw-view rule had covered fell back to "a descriptor's address or format read as data". The fix: a direct read of a structured view's dword 1 stays refused, and at a join with data the word now takes the undefined path, as for a raw view.

Build Validated Change Lost
f4e166a 23,906
cc7d30a (this PR alone) 23,907 +1 0
#1597 + #995, without the fix 21
#1597 + #995, with the fix +1 0

Total for this PR: +495 over #1402 (119b763), 0 lost. cargo test --locked -p victory-shader --lib: 142 passed, 0 failed.

Method: victory translate --validate --list on shaders.rpf (1.0.2.1), dxil.dll 1.8.2502.11, compared program by program (25,889 programs). AI-assisted (Claude Code). No shader names or data are included, per the asset policy.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149925220 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1597#issuecomment-7149925220). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T01:45:42Z. --- **Fourth commit cc7d30a: a structured buffer's dword 1 is hidden at a join too.** **Why.** I merged #995 by hand on top of this PR, and the result lost 21 programs. #995 turns some raw views into structured ones. This PR treated a raw view's dword 1 as hidden, but not a structured view's dword 1. `descriptor_data` gives that word no value: its low half is the address, its high half the stride. So programs that the raw-view rule had covered fell back to "a descriptor's address or format read as data". The fix: a direct read of a structured view's dword 1 stays refused, and at a join with data the word now takes the undefined path, as for a raw view. | Build | Validated | Change | Lost | |---|---|---|---| | f4e166a | 23,906 | | | | cc7d30a (this PR alone) | 23,907 | +1 | 0 | | #1597 + #995, without the fix | | | **21** | | #1597 + #995, with the fix | | +1 | **0** | Total for this PR: +495 over #1402 (119b763), 0 lost. `cargo test --locked -p victory-shader --lib`: 142 passed, 0 failed. Method: `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), dxil.dll 1.8.2502.11, compared program by program (25,889 programs). AI-assisted (Claude Code). No shader names or data are included, per the asset policy.
sinan-cmyk commented 2026-11-25 02:06:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T01:59:49Z.


Thanks for the explanation. Understood: main proves those edges dead instead of zero-filling them, so this PR is superseded, and I won't reopen it.

To check whether anything was missed, I measured the current main (940d32f) on the dump. Method: translate --validate --list on shaders.rpf 1.0.2.1, dxil.dll 1.8.2502.11, program by program.

  • Over ffe310e, this PR made 2,183 more programs validate. main now validates 1,782 of them.

  • Of the other 401, main refuses 36 ("a descriptor read only as data"). The remaining 365 are emitted but rejected by the validator:

    • 318 with "Entry function performs some operation that is incompatible with the shader stage"
    • 47 with "Flags must match usage"

    So they are not proven-dead refusals.

  • Separately, 808 programs that validated on ffe310e fail on main with "Flags must match usage". I'm bisecting that now and will file it as its own issue with the commit.

AI-assisted (Claude Code). No shader names or data are included, per the asset policy.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150197681 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1597#issuecomment-7150197681). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T01:59:49Z. --- Thanks for the explanation. Understood: `main` proves those edges dead instead of zero-filling them, so this PR is superseded, and I won't reopen it. To check whether anything was missed, I measured the current `main` (940d32f) on the dump. Method: `translate --validate --list` on `shaders.rpf` 1.0.2.1, dxil.dll 1.8.2502.11, program by program. - Over `ffe310e`, this PR made 2,183 more programs validate. `main` now validates **1,782 of them**. - Of the other **401**, `main` refuses 36 ("a descriptor read only as data"). The remaining **365 are emitted but rejected by the validator**: - 318 with "Entry function performs some operation that is incompatible with the shader stage" - 47 with "Flags must match usage" So they are not proven-dead refusals. - Separately, 808 programs that validated on `ffe310e` fail on `main` with "Flags must match usage". I'm bisecting that now and will file it as its own issue with the commit. AI-assisted (Claude Code). No shader names or data are included, per the asset policy.

Pull request closed

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!1596
No description provided.