Shaders: descriptors set in a region s_cbranch_execz can skip are traced after it #2322

Closed
chippy01 wants to merge 1 commit from upstream-pr/2324 into main
chippy01 commented 2026-11-25 10:41:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by chippy01 on 2026-11-25T10:41:06Z.


Problem

On main (940d32f) three compute programs are refused at translation with resources: a descriptor neither loaded nor built. They are the last three of that class (#320 brings it from 298 to 3; main is at 3):

program hash refused at
shadowmask:CS_TraceShadowRays_ScreenSpaceOnlyCheckerboard e6ac855a4cddb16d 0x6dc8
alphaResolve:CS_AlphTransmissionPrefilterMip 2da4beb386509b77 0x4d0
indirect_light_probes:CS_Alpha_Schedule aab1b3c7248ee5de 0x140

All three set a descriptor (a table load in two of them, an immediate sampler in the third) inside a region that s_and_saveexec + s_cbranch_execz skips when no lane would run it, and read it after the region ends (s_mov exec, saved). The phi where the region ends joins the region's words with what the skip leaves in the registers (an EXEC save, a lane mask), and tracking refuses the read. CS_Alpha_Schedule also clears the high half of its table address only inside such a region, so after the first refusal it stops at an address into a descriptor heap with an untracked high half.

Why the read is the region's

The structuriser turns s_cbranch_execz into a per-lane branch, which holds for vector work but not for scalar writes: those are the whole wave's. A lane that reaches the region's end without running the region itself reads what another lane's run set. Only a wave none of whose lanes runs the region reads what the skip leaves, and compiled code does not read an EXEC save as a descriptor.

The change (crates/victory-shader/src/resource.rs)

  • phi(): when some predecessor edges fail to trace, past_skip takes the source of the others if every failing edge is the taken edge of an s_cbranch_execz into the join, and the other edges agree on one source whose handle can be made at the join. That means a constant, or a load or built descriptor whose address only reads values that dominate the join. Lowering makes the handle at the access from the load's base and offset registers, so those are what is checked.
  • high_half(): a phi at such a join whose non-skip edges are the expected high half (0 for a table) counts as that high half. A table's heap index only uses the low dword, which is unaffected.
  • Reads that trace today are unchanged: the new paths only run where tracking would otherwise refuse. A region that reloads a descriptor the skip also leaves stays a Phi (test below).

Tests

Five new unit tests in resource::tests, on synthetic code:

  • a_descriptor_loaded_in_a_skippable_region_is_read_after_it
  • a_sampler_set_in_a_skippable_region_is_the_constant_after_it
  • a_table_address_a_skippable_region_completes_is_traced_after_it
  • a_descriptor_a_skippable_region_reloads_is_still_joined (unchanged behaviour)
  • a_descriptor_read_after_a_skip_otherwise_still_fails: an offset computed inside the region, and a skip on a uniform s_cbranch_scc1, are still refused.

The three positive tests fail without the change.

Measurements

Offline victory translate --validate --list over the shader pack, the executable and its DLLs: 25,982 programs. Windows 11, dxil.dll from SDK 10.0.26100. Per #1945 that one prints 1.8 but behaves like 1.7; both runs used it, so the comparison holds.

main 940d32f this PR
programs validated 24,005 24,007
a descriptor neither loaded nor built 3 0

The only outcomes that change, across all 25,982 programs:

program main this PR
CS_TraceShadowRays_ScreenSpaceOnlyCheckerboard refused at 0x6dc8 validated
CS_AlphTransmissionPrefilterMip refused at 0x4d0 validated
CS_Alpha_Schedule refused at 0x140 emitted; the validator's compute-derivative check (Entry function performs some operation that is incompatible with the shader stage), the class #2027 addresses

Checks:

  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings, with and without --all-features: clean.
  • cargo test -p victory-shader --locked: 249 passed, 3 failed. The same three fail on main on this GPU (RTX 3070 Ti): a_heap_buffer_read_by_element_takes_the_views_stride and a_heap_buffer_read_where_no_buffer_view_is_reads_zeros (the 1,000,000 view-heap cap, #1835) and gathers_at_a_level_match_the_hardware.

In-game check

On an RTX 3070 Ti (32-lane waves, Windows 11), one run per row, each into the prologue's world from about 1.5 min:

  • every run is main + #1775 (to get past #1753's boot removal), as a diagnostics build;
  • the W, A and C programs of #1968 are skipped (VICTORY_SKIP_PIPELINES);
  • VICTORY_POKE=71b6331:1 and VICTORY_D3D12_DRED=1 are set;
  • each run starts from a cold shader cache of its own.
run 2da4beb386509b77 aab1b3c7248ee5de end
main + #1775 does not translate; 2 dispatches a frame dropped does not translate; 1 a frame dropped the title's own breakpoint at +0x5149aec after 11 min (#1232)
+ this PR translates; the driver refuses the pipeline (a wave64 program on a 32-lane host), so still dropped translates; pipeline made, runs every frame (writes its 32x16 target) device hung (0x887A0006) at 7.5 min in draw [vertex cb47fdb3b37b7880, pixel b335d5633b1ed53f]
+ this PR, aab1b3c7248ee5de skipped as above skipped the same draw hangs at 7.3 min

With aab1b3c7248ee5de skipped, the GPU runs exactly the work main does. The same draw then hangs, so the removal is the known hang in that draw (#1968, #452), not something this change makes run. The main run ended on the title's breakpoint before getting there. The third program, e6ac855a4cddb16d, was not requested in these runs.

Not covered

  • Other scalar values such a region sets and the code reads after it (a count read as data, say) still take the per-lane phi in lowering. That is a separate structuriser question.
  • A region source whose address the region computes is still refused: its handle could not be made where the region ends.

AI-assisted; measured on my own machine.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6602611553 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2324). Originally posted by [chippy01](https://github.com/chippy01) on 2026-11-25T10:41:06Z. --- ## Problem On `main` (`940d32f`) three compute programs are refused at translation with `resources: a descriptor neither loaded nor built`. They are the last three of that class (#320 brings it from 298 to 3; `main` is at 3): | program | hash | refused at | |---|---|---| | `shadowmask:CS_TraceShadowRays_ScreenSpaceOnlyCheckerboard` | `e6ac855a4cddb16d` | `0x6dc8` | | `alphaResolve:CS_AlphTransmissionPrefilterMip` | `2da4beb386509b77` | `0x4d0` | | `indirect_light_probes:CS_Alpha_Schedule` | `aab1b3c7248ee5de` | `0x140` | All three set a descriptor (a table load in two of them, an immediate sampler in the third) inside a region that `s_and_saveexec` + `s_cbranch_execz` skips when no lane would run it, and read it after the region ends (`s_mov exec, saved`). The phi where the region ends joins the region's words with what the skip leaves in the registers (an EXEC save, a lane mask), and tracking refuses the read. `CS_Alpha_Schedule` also clears the high half of its table address only inside such a region, so after the first refusal it stops at `an address into a descriptor heap with an untracked high half`. ## Why the read is the region's The structuriser turns `s_cbranch_execz` into a per-lane branch, which holds for vector work but not for scalar writes: those are the whole wave's. A lane that reaches the region's end without running the region itself reads what another lane's run set. Only a wave none of whose lanes runs the region reads what the skip leaves, and compiled code does not read an EXEC save as a descriptor. ## The change (`crates/victory-shader/src/resource.rs`) - `phi()`: when some predecessor edges fail to trace, `past_skip` takes the source of the others if every failing edge is the taken edge of an `s_cbranch_execz` into the join, and the other edges agree on one source whose handle can be made at the join. That means a constant, or a load or built descriptor whose address only reads values that dominate the join. Lowering makes the handle at the access from the load's base and offset registers, so those are what is checked. - `high_half()`: a phi at such a join whose non-skip edges are the expected high half (0 for a table) counts as that high half. A table's heap index only uses the low dword, which is unaffected. - Reads that trace today are unchanged: the new paths only run where tracking would otherwise refuse. A region that reloads a descriptor the skip also leaves stays a `Phi` (test below). ## Tests Five new unit tests in `resource::tests`, on synthetic code: - `a_descriptor_loaded_in_a_skippable_region_is_read_after_it` - `a_sampler_set_in_a_skippable_region_is_the_constant_after_it` - `a_table_address_a_skippable_region_completes_is_traced_after_it` - `a_descriptor_a_skippable_region_reloads_is_still_joined` (unchanged behaviour) - `a_descriptor_read_after_a_skip_otherwise_still_fails`: an offset computed inside the region, and a skip on a uniform `s_cbranch_scc1`, are still refused. The three positive tests fail without the change. ## Measurements Offline `victory translate --validate --list` over the shader pack, the executable and its DLLs: 25,982 programs. Windows 11, `dxil.dll` from SDK 10.0.26100. Per #1945 that one prints 1.8 but behaves like 1.7; both runs used it, so the comparison holds. | | `main` `940d32f` | this PR | |---|---|---| | programs validated | 24,005 | 24,007 | | `a descriptor neither loaded nor built` | 3 | 0 | The only outcomes that change, across all 25,982 programs: | program | `main` | this PR | |---|---|---| | `CS_TraceShadowRays_ScreenSpaceOnlyCheckerboard` | refused at `0x6dc8` | validated | | `CS_AlphTransmissionPrefilterMip` | refused at `0x4d0` | validated | | `CS_Alpha_Schedule` | refused at `0x140` | emitted; the validator's compute-derivative check (`Entry function performs some operation that is incompatible with the shader stage`), the class #2027 addresses | Checks: - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`, with and without `--all-features`: clean. - `cargo test -p victory-shader --locked`: 249 passed, 3 failed. The same three fail on `main` on this GPU (RTX 3070 Ti): `a_heap_buffer_read_by_element_takes_the_views_stride` and `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` (the 1,000,000 view-heap cap, #1835) and `gathers_at_a_level_match_the_hardware`. ## In-game check On an RTX 3070 Ti (32-lane waves, Windows 11), one run per row, each into the prologue's world from about 1.5 min: - every run is `main` + #1775 (to get past #1753's boot removal), as a diagnostics build; - the W, A and C programs of #1968 are skipped (`VICTORY_SKIP_PIPELINES`); - `VICTORY_POKE=71b6331:1` and `VICTORY_D3D12_DRED=1` are set; - each run starts from a cold shader cache of its own. | run | `2da4beb386509b77` | `aab1b3c7248ee5de` | end | |---|---|---|---| | `main` + #1775 | does not translate; 2 dispatches a frame dropped | does not translate; 1 a frame dropped | the title's own breakpoint at `+0x5149aec` after 11 min (#1232) | | + this PR | translates; the driver refuses the pipeline (a wave64 program on a 32-lane host), so still dropped | translates; pipeline made, runs every frame (writes its 32x16 target) | device hung (`0x887A0006`) at 7.5 min in `draw [vertex cb47fdb3b37b7880, pixel b335d5633b1ed53f]` | | + this PR, `aab1b3c7248ee5de` skipped | as above | skipped | the same draw hangs at 7.3 min | With `aab1b3c7248ee5de` skipped, the GPU runs exactly the work `main` does. The same draw then hangs, so the removal is the known hang in that draw (#1968, #452), not something this change makes run. The `main` run ended on the title's breakpoint before getting there. The third program, `e6ac855a4cddb16d`, was not requested in these runs. ## Not covered - Other scalar values such a region sets and the code reads after it (a count read as data, say) still take the per-lane phi in lowering. That is a separate structuriser question. - A region source whose address the region computes is still refused: its handle could not be made where the region ends. AI-assisted; measured on my own machine.
catminou4 commented 2026-11-25 11:04:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T10:54:00Z.

Review: APPROVED


Tested locally: merged into main 940d32f69b, cargo test -p victory-shader --locked on macOS arm64 — 149 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — descriptors set in a region s_cbranch_execz can skip, +5 tests and docs.

<!-- greyfinch-sync:Marvisak/VIctory:review:6056242417 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2324#pullrequestreview-6056242417). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T10:54:00Z. **Review:** APPROVED --- Tested locally: merged into main 940d32f69b, `cargo test -p victory-shader --locked` on macOS arm64 — 149 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — descriptors set in a region s_cbranch_execz can skip, +5 tests and docs.
upstream-sync closed this pull request 2026-11-25 16:07:33 +00:00
Marvisak commented 2026-11-25 16:09:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:19:57Z.


Automated triage for the maintainers.

Merge candidate (worth a look). In crates/victory-shader/src/resource.rs, Tracer::phi now goes through the new past_skip before it gives up: if the only predecessor edges that fail to trace are the taken edges of an s_cbranch_execz into the join, and the other edges agree on one source whose handle can be built at the join, the read takes that source; high_half does the same through past_skip_is. This matches GFX10 behaviour (scalar writes apply to the whole wave, and s_cbranch_execz skips only when EXEC is zero, so the skip edge carries a value the compiled code never reads as a descriptor), and the new paths run only where tracking used to refuse. The negative tests (an offset computed inside the region, a skip on a uniform s_cbranch_scc1) still refuse; the evidence covers the affected programs, an offline validation diff and an in-game run. CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7166674874 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2324#issuecomment-7166674874). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:19:57Z. --- <!-- victory-triage v1 head=bcb3268c010ae875fe8d73fcc3ee29f58674ff9c verdict=merge-candidate at=2026-11-25T15:25:00Z --> Automated triage for the maintainers. **Merge candidate (worth a look).** In `crates/victory-shader/src/resource.rs`, `Tracer::phi` now goes through the new `past_skip` before it gives up: if the only predecessor edges that fail to trace are the taken edges of an `s_cbranch_execz` into the join, and the other edges agree on one source whose handle can be built at the join, the read takes that source; `high_half` does the same through `past_skip_is`. This matches GFX10 behaviour (scalar writes apply to the whole wave, and `s_cbranch_execz` skips only when EXEC is zero, so the skip edge carries a value the compiled code never reads as a descriptor), and the new paths run only where tracking used to refuse. The negative tests (an offset computed inside the region, a skip on a uniform `s_cbranch_scc1`) still refuse; the evidence covers the affected programs, an offline validation diff and an in-game run. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
chippy01 commented 2026-11-25 16:09:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by chippy01 on 2026-11-25T15:47:26Z.


Superseded by ff47463 and 58b5255 on main, which handle the same three programs by proving that no lane takes the skip edge. On da82e44 the shader census gives what this PR aimed for: CS_AlphTransmissionPrefilterMip and CS_TraceShadowRays_ScreenSpaceOnlyCheckerboard validate, CS_Alpha_Schedule stops at the compute-derivative check (#2027), and no 'a descriptor neither loaded nor built' refusal is left.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167317549 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2324#issuecomment-7167317549). Originally posted by [chippy01](https://github.com/chippy01) on 2026-11-25T15:47:26Z. --- Superseded by ff47463 and 58b5255 on main, which handle the same three programs by proving that no lane takes the skip edge. On da82e44 the shader census gives what this PR aimed for: CS_AlphTransmissionPrefilterMip and CS_TraceShadowRays_ScreenSpaceOnlyCheckerboard validate, CS_Alpha_Schedule stops at the compute-derivative check (#2027), and no 'a descriptor neither loaded nor built' refusal is left.

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