Skip to content

Shaders: descriptors joined by nested control flow - #1012

Open
ThiagoAlexsander wants to merge 1 commit into
Marvisak:mainfrom
ThiagoAlexsander:shader/nested-descriptor-joins
Open

ThiagoAlexsander wants to merge 1 commit into
Marvisak:mainfrom
ThiagoAlexsander:shader/nested-descriptor-joins

Conversation

@ThiagoAlexsander

Copy link
Copy Markdown
Contributor

A descriptor every lane shares, chosen by an if/else nested in another, reaches the outer join with one edge that is itself a join (Source::Phi inside Source::Phi). handle took only heap loads on a join's edges and refused this with a descriptor chosen by control flow. In the title this stops indirect_diffuse_lighting:CS_ScreenProbes_ActivateRays.

Change

  • New uniform_heap_index: a load's heap index, or, for a join, a phi of the index each predecessor computes at its end, recursively. It is the old loop of the Source::Phi arm with the edge's source traced instead of required to be a load.
  • handle's Source::Phi arm calls it. A join whose edges are all loads emits the same DXIL as before.
  • Other edge kinds (a constant, a built descriptor, a select) are still refused with the same message.

Results

victory translate --validate over the title's files (main ffe310e against this branch, Windows SDK dxil.dll 10.0.26100), compared program by program: compute validated goes from 1,417 to 1,418 (CS_ScreenProbes_ActivateRays). No other program changes.

Testing

  • New descriptors_joined_by_nested_control_flow_lower_to_one_uniform_handle in emit/lower.rs: hand-written words choosing between two texture descriptors of the view table through nested if/else on a root constant. It lowers to one uniform image handle and passes dxil.dll. On main it fails with Unsupported { "a descriptor chosen by control flow" }.
  • cargo test --workspace --locked: 343 passed, 0 failed, 6 ignored (342 on main plus the new test).
  • cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features: clean. rustfmt --edition 2024 --check emit/lower.rs: no new hunks (the three in the v_perm test are on main too). cargo xtask policy: 154 files ok.
  • Not run on a GPU, and the program's host pipeline was not created.

Independent of #1008, which handles immediate samplers chosen by control flow; the two touch different arms of handle.

AI use: Claude Code (Claude Opus 5.5) found the case with the census, wrote the change and the test, and ran everything above. I reviewed the diff and the results.

🤖 Generated with Claude Code

A descriptor every lane shares, chosen by an if/else nested in another,
reaches the outer join with an edge that is itself a join. Such an edge
was refused with "a descriptor chosen by control flow": each edge had to
be a heap load. The heap index is now computed recursively: a load's
index, or a phi at the join of what each predecessor computes at its end.

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

Copy link
Copy Markdown

Independent validation of 0ba5b998e6df758d31d853b333b4dc423463e3b3 on base ffe310e: the nested-descriptor shader creates a hardware compute pipeline under Wine/vkd3d-proton, but the new test breaks the native Linux shader test build.

cargo test -p victory-shader --locked --offline fails with E0433 at lower.rs:7327–7328: validator is Windows-only, while the new test references it unconditionally. The same command on the base passes 96 tests, 1 ignored. Adding #[cfg(windows)] directly above the new if let Ok(mut v) = ...Validator::load(...) block makes this PR pass 97 tests, 1 ignored, keeping the lowering assertions active on Linux. This was a local verification change and is not included in the full Windows run below.

For the missing GPU check, I temporarily extended the new regression to construct a HostShader with its emitted root/descriptor layout and require Host::new(false) plus compute_pipeline. It passed on an RTX 5090 with NVIDIA 620.73.04, Wine 11.22 and vkd3d-proton 30b0eb9bc12dc9f. The resulting SPIR-V also passes spirv-val --target-env vulkan1.3. This checks pipeline creation, not dispatch/output correctness. The instrumentation was removed afterward.

Full workspace unit/integration suite, all features, all 14 generated Windows MSVC test executables, Rust 1.98.1:

Tree Passed Failed Ignored
ffe310e baseline 341 5 6
This PR, unmodified 342 5 6

All five failures match baseline: empty pipeline library (#347), missing Wine Winsock export (#217), the shader-checksum rejection expectation, the nested Cargo fixture build, and Windows xtask attempting to launch host Git. Native Linux xtask separately passes all 4 tests. Windows-target workspace Clippy, all targets/features with -D warnings, and native cargo xtask policy pass.

Tests ran offline and offscreen, with native d3dcompiler_47 supplied for GPU shader fixtures and identical runtime DLLs to baseline. No game data was used. Gameplay, native Windows/WARP and Wine doctests were not tested. Aggregate counts include existing early-return tests when optional console compilers or the DXIL validator are unavailable; the instrumented pipeline check required real hardware and could not silently skip.

AI-assisted testing with Codex.

JMAN730 added a commit to JMAN730/project-flamingo that referenced this pull request Nov 24, 2026
The validator module is Windows-only, so the test upstream Marvisak#1012 added did not compile on Linux (lint and test (ubuntu-latest)).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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 0ba5b99: 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).

@MartinIndra02

Copy link
Copy Markdown

Independent verification at 0ba5b99 on Windows 11, NVIDIA GeForce RTX 3080 (driver 621.24, 32-32 wave lanes) + WARP, Rust 1.98.1:

  • cargo test -p victory-shader --lib -- --test-threads=1: 121 passed, 0 failed, 1 ignored (including descriptors_joined_by_nested_control_flow_lower_to_one_uniform_handle).
  • cargo clippy -p victory-shader --all-targets -- -D warnings (default + --features diagnostics): 0 warnings.
  • cargo xtask policy: 154 files ok.
  • Offline full-corpus A/B (victory translate on retail 1.0.2.1, 26,084 programs, release build vs main ffe310e):
    • Compute emitted: 1,441 → 1,442 (+1, zero regressions on vertex/pixel 12,231 and mesh 8,214).
    • a descriptor chosen by control flow: 41 → 40 (unblocks the compute lighting shader while 40 other programs still hit this refusal).

Aggregate counts only; no game data posted. AI-assisted; all builds and tests executed on my machine.

edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
Head 0ba5b99 (ThiagoAlexsander). Conflict in lower.rs: the join arm
of handle takes #1012's uniform_heap_index, which now gathers the loads
it reaches so #568's table views are still recorded for each of them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
…table names

Brings #193's runtime stride table (#155) with #704's raw view pool.

Conflicts and fitting it to this tree:
- Heap layout is title slots, dynamic slots, the guard slot, then the raw
  view pool (alias_base = count + extra + 1). A heap capped at
  PORTABLE_VIEWS takes a pool of 2^14 (ALIASES_CAPPED), not 2^16, since
  each pool slot is a mirrored title slot less.
- Stride entries follow every slot write of ours: mirror, make_at, the
  bindless buffer and placed-texture slots, typed nulls, null kinds,
  raw_at, bindless CBVs and unmapped nulls.
- viewed_bytes cuts the raw view to its host copy as make does
  (cut_to_copy), so the host never refuses it.
- stride_entry gets the slot through our uniform_heap_index (#1012);
  #704's heap_slot is dropped. handles keeps our props key.
- Our cut_to_copy clamps stay in buffer_srv/uav; #704's are dropped.
- The tests pass the heap guard in its user-data dword, take our make_at
  and emit signatures, and count the guard slot.
- Shader cache MAGIC VSH3, KeySpec version 3 (stride_table encoded).
- Formatting-only hunks from #704 left out.

translate --host-lanes 32-32: compute 2285 -> 2487, vertex/geometry/pixel
14186 -> 14256 (with #1073, #1084, #416 before it), mesh 8381 -> 8383;
"a structured buffer of unknown stride" 206 -> 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
Indirect lighting's CS_ScreenProbes_ActivateRays picks a descriptor in nested branches.

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

# Conflicts:
#	crates/victory-shader/src/emit/lower.rs
suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
…xel shader

A refused pixel shader dropped every draw of its mesh or vertex pipeline,
geometry included. The stand-in (emit::host::stub_ps: reads nothing,
writes zeros to target 0) keeps the geometry drawing: depth and shape, a
flat placeholder in target 0. On by default; VICTORY_NO_STAND_IN_PIXEL=1
turns it off. Also gates #1012's validator test to Windows (the validator
module is Windows-only), so the native test run builds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 18701e55fbc9065eea6d7fa67ef1819335d40d72)
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026

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.

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


Generated by Claude Code

Marvisak pushed a commit that referenced this pull request Nov 25, 2026
Takes back PR #1012's recursive heap index (an edge into a descriptor's
join that is itself a join). Across the title's shader list it lets one
program through, `indirect_diffuse_lighting:CS_ScreenProbes_ActivateRays`
(issued every cutscene frame), and that program's host pipeline does not
fit the machine: the DXIL validates in 4 s, but the AMD driver's compile
passed 6 GB after 64 s under a watchdog (unwatched it reached 26.7 GB
commit and starved a title run, drops2). Its DXIL has 22,382 branches,
2,609 heap handles and 2,478 size queries (151k lines), against 3,857
branches for the next largest newly emitted program, which compiles in
24 s and 0.8 GB.

The refusal is "a descriptor chosen by control flow" again, as on `main`;
edges no lane takes still join no heap index (previous commit). The
change can come back once pipelines this costly stay off the title's
pipeline worker (`shortcut:` at the arm).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Marvisak pushed a commit that referenced this pull request Nov 25, 2026
Lowering leaves much in the DXIL that never runs or counts: branches on
constants (lane conditions structurisation already knows, edges no lane
takes) and the code only their other edge reaches, empty blocks that only
forward to the next, size queries for descriptor words no path reads. The
host driver compiles all of it. `indirect_diffuse_lighting:CS_ScreenProbes_
ActivateRays` (with nested descriptor joins, PR #1012) is where it showed:
8,745 of its 10,040 conditional branches were on constants, 10,061 of its
22,384 blocks empty forwarders, about 70 % of its instructions reachable only
through constant branches' dead edges, and 556 of the 587 size queries in
the rest unread; the AMD driver never finished it (over 6 GB at 64 s).

The writer (`Module::plan`, `Module::kept`) now:
* takes a branch on a constant as a branch to its one target: blocks only
  the other edge reaches are not written, and phis lose the entries of edges
  that are gone (their other entries stay);
* folds an empty block with one predecessor into it (the predecessor
  branches to its target), unless it splits a critical edge (lowering keeps
  loops' exits and preheaders dedicated, as DXC emits them) or its
  predecessor would then reach the target twice (one phi entry per
  predecessor); empty latches fold as before;
* writes only instructions with effects (stores, atomics, calls neither
  read-none nor read-only: barriers, discard, wave operations, the write and
  read marks) and what they read, transitively (it dropped only unread phis
  before);
* declares only the functions it calls and the constant globals it reads
  (the validator refuses the others);
* and the shader flags of heap handles, wave operations and 64-bit integers
  follow what is written (`Module::uses`; the validator refuses a flag
  whose use is gone, "Flags must match usage").

Whole list (shaders.rpf, the exe, XboxBvhBuilder, the upscaler;
translate --list --validate, against 8ff7913): 0 programs change outcome
(14,254 VS/PS, 2,732 compute, 8,765 mesh emitted; 13,313 / 1,984 / 4,625
validated, as before); DXIL bitcode 1,423,424,800 -> 1,246,729,828 bytes
(-12.4 %), blocks 3,624,448 -> 3,554,816 (-1.9 %).

ActivateRays itself is still refused here (nested joins); its table is in
the commit that lets it through.

Tests (`emit::bitcode`): a constant branch drops its other side and that
side's phi entry only; a loop whose back edge is never taken; empty blocks
before a phi fold only where the entry can move; only values with effects or
readers are written (read-none and read-only calls, stores, atomics,
barriers); constant globals nothing reads are left out; uses count only
what is written. The writer's pinned
bytes are pinned anew (its test module's last call became one with effects).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Marvisak pushed a commit that referenced this pull request Nov 25, 2026
Brings back PR #1012's recursive heap index (taken back by fbac5bb): a
descriptor every lane shares, chosen by an if/else nested in another,
reaches the outer join with an edge that is itself a join; its heap index is
a phi at each join of what each predecessor computes at its end. It lets
`indirect_diffuse_lighting:CS_ScreenProbes_ActivateRays` (39f0e9aeb156a61c,
issued every cutscene frame) through, whose host pipeline the AMD driver
could not make before the two commits ahead of this one.

The program itself is large: 74,700 GFX10 instructions, 11,896 branches
(488 backward), 1,889 typed buffer loads, each after a reload of the same
descriptor. Its DXIL, and what the AMD driver (RX 6700 XT, 32.0.21045)
does with it:

| | #1012 alone | now |
|---|---|---|
| lines (dxc -dumpbin) | 151,610 | 24,896 |
| branches (conditional) | 22,382 (10,040) | 3,070 (1,295) |
| blocks | 22,384 | 3,072 |
| heap handles | 2,608 | 65 |
| size queries | 2,477 | 0 |
| phis | 2,883 | 1,124 |
| DXIL bytes | 864 K | 144 K |
| validator | passes | passes |
| host pipeline | over 6 GB at 64 s, never finished (26.7 GB unwatched) | 2.36-2.45 GB, 78-107 s (with other work on the machine) |

What remains costly is the program's shape: one loop of 2,941 blocks
holding 1,239 of its 1,295 conditional branches, an inner one of
1,440 (the largest loop of the largest program by DXIL bytes,
RTShadowTrace32TemporalHQ_OneOver4RPP_Tiled, has 110 blocks; it compiles in
14 s, 353 MB). Making every branch uniform (an experiment) took the compile
to 1.9 GB and 54 s, so divergence is not most of it. The pipeline library
keeps it after the first make.

WARP refuses the pipeline at once (E_INVALIDARG): the program declares the
console's wave size (32), which WARP's 4-lane waves cannot run, as for every
compute program that declares one.

Whole list, translate --list --validate: 0 newly failing, 1 newly emitted
and validated (this program). Test: the nested-join lowering test is back
(`descriptors_joined_by_nested_control_flow_lower_to_one_uniform_handle`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RomainKH added a commit to RomainKH/VIctory that referenced this pull request Nov 25, 2026
A descriptor every lane shares can reach its use through a tree of joins
and SCC selects: a select on an edge into a join, a join on an arm of a
select, or a join at a loop header whose back edge is lowered after the
body. `uniform_heap_index`, which took nested joins of loads (Marvisak#1012), now
also takes selects, so either may hold the other. A loop header's phi goes
to `pending_descriptors` and `fill_phis` fills it once every predecessor
has a tail; an edge no lane takes brings 0, as before.

`view_stride` takes the same trees, so a structured read through one gets
its stride; it refused a join ("a structured buffer of unknown stride").
An SCC select between two immediate samplers samples with both, as a join
of two already does. A tree with a leaf that a waterfall loop reads per
lane gets a non-uniform handle.

Tests, synthetic GFX10 programs, each validated by dxil.dll where it runs
(required in CI): a select inside nested joins and a descriptor phi at a
loop header, each with a raw and a structured read, and an immediate
sampler chosen by SCC. On `main` they are refused with "a descriptor chosen
by control flow" / "... by a condition".

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

Copy link
Copy Markdown

Isolated courtyard A/B on an RTX 5070 Ti, native Windows 11, driver 621.01. Both runs used the same local 940d32f-based build with the #2366 rectangle fix, save, initial pipeline cache, scripted input and stationary camera. The only source change in B was the recursive descriptor join from 0ba5b99, ported to the local lower.rs while retaining its buffer guard.

  • CS_ScreenProbes_ActivateRays (39f0e9aeb156a61c) went from one dropped dispatch per frame to a traced 3600x1x1 dispatch. The identical offline shader set gained one translation (25,635 → 25,636 of 25,985).
  • Thin magenta streaks on the lower-left part of the character’s shirt appeared in 20/20 baseline captures and 0/20 patched captures, about 199–289 s after launch. In the same 1920×1080 crop (x 4–23%, y 80–99%), the baseline had 163–519 pixels per capture with both R−G and B−G ≥12. The patched run had zero in every capture.
  • The character was still silhouetted. Mean head luminance was 6.6 → 6.5 on a 0–255 scale, taking the median of three matched late frames per run. Neither run logged device removal before its timed stop. One run per build.

AI-assisted local test.

RomainKH added a commit to RomainKH/VIctory that referenced this pull request Nov 26, 2026
A descriptor every lane shares can reach its use through a tree of joins
and SCC selects: a select on an edge into a join, a join on an arm of a
select, or a join at a loop header whose back edge is lowered after the
body. `uniform_heap_index`, which took nested joins of loads (Marvisak#1012), now
also takes selects, so either may hold the other. A loop header's phi goes
to `pending_descriptors` and `fill_phis` fills it once every predecessor
has a tail; an edge no lane takes brings 0, as before.

`view_stride` takes the same trees, so a structured read through one gets
its stride; it refused a join ("a structured buffer of unknown stride").
An SCC select between two immediate samplers samples with both, as a join
of two already does. A tree with a leaf that a waterfall loop reads per
lane gets a non-uniform handle.

Tests, synthetic GFX10 programs, each validated by dxil.dll where it runs
(required in CI): a select inside nested joins and a descriptor phi at a
loop header, each with a raw and a structured read, and an immediate
sampler chosen by SCC. On `main` they are refused with "a descriptor chosen
by control flow" / "... by a condition".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RomainKH added a commit to RomainKH/VIctory that referenced this pull request Nov 26, 2026
A descriptor every lane shares can reach its use through a tree of joins
and SCC selects: a select on an edge into a join, a join on an arm of a
select, or a join at a loop header whose back edge is lowered after the
body. `uniform_heap_index`, which took nested joins of loads (Marvisak#1012), now
also takes selects, so either may hold the other. A loop header's phi goes
to `pending_descriptors` and `fill_phis` fills it once every predecessor
has a tail; an edge no lane takes brings 0, as before.

`view_stride` takes the same trees, so a structured read through one gets
its stride; it refused a join ("a structured buffer of unknown stride").
An SCC select between two immediate samplers samples with both, as a join
of two already does. A tree with a leaf that a waterfall loop reads per
lane gets a non-uniform handle.

Tests, synthetic GFX10 programs, each validated by dxil.dll where it runs
(required in CI): a select inside nested joins and a descriptor phi at a
loop header, each with a raw and a structured read, and an immediate
sampler chosen by SCC. On `main` they are refused with "a descriptor chosen
by control flow" / "... by a condition".

`lower.rs` is within a few KiB of the repository's 512 KiB limit on a
file. `uniform_heap_index` and its two new helpers (`fill_descriptor_phi`,
`waterfall_leaf`) move to a child module, `emit/lower/trees.rs`, and the
tests join Marvisak#2558's in `emit/lower/tests/descriptors.rs`; `lower.rs` ends
slightly smaller than on `main`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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