Shaders: compute exact dx.viewIdState and PSV0 input-output dependencies #1985

Open
github-bot wants to merge 1 commit from github-bot/gh-1985 into main AGit
Owner

@⁠nathanbzrr on GitHub · 2026-11-25 02:21 UTC · original
nathanbzrr:shader/exact-view-id-dependencies → main · +1390 −43 · 3 files · 1 commits · open

Summary

Replace the conservative all-ones dx.viewIdState metadata and PSV0 input-to-output dependency table in victory-shader (crates/victory-shader/src/emit/shader.rs and crates/victory-shader/src/emit/container.rs) with an exact forward SSA + post-dominator control-dependence + global/LDS/resource dependency analysis over main, matching Microsoft DXC's DxilComputeViewIdState output on equivalent HLSL shaders while staying sound across title-memory / UAV store-to-load round-trips and pixel discard.

Why drivers and the D3D12 runtime need exact dx.viewIdState / PSV0 tables

In DXIL containers (PSV0 pipeline state validation data and !dx.viewIdState bitcode metadata), the input-to-output dependency bitmatrix is consumed by:

  1. D3D12 PSO multi-stage linking (CreateGraphicsPipelineState / CreatePipelineState):
    • The D3D12 runtime and IHV driver backend (AMD PAL/LLPC, NVIDIA DX12, Intel IGC) compose per-stage PSV0 / dx.viewIdState matrices across VS -> GS -> PS (or MS -> PS) to compute transitive attribute liveness and SV_ViewID / multi-view amplification state.
    • When PSV0 and dx.viewIdState are filled with all-ones ((1 << no) - 1 for every input component), every PS output is declared dependent on every PS input, and every VS/GS output is declared dependent on every VS/GS input. That prevents the driver's multi-stage PSO linker from dead-stripping unused inter-stage attributes or skipping barycentric interpolation setup (v_interp_p1_f32 / v_interp_p2_f32 on RDNA) for dead vector channels within partially-read signature rows, and forces transitive ViewID / multi-stage state propagation across every stage attribute.
  2. DXIL validator (dxil.dll) consistency enforcement:
    • dxil.dll validates that PSV0's InputToOutputTable matches !dx.viewIdState in the DXIL module and conforms to the shader's declared ISG1 / OSG1 scalar counts (in_vectors * 4 * ceil(out_vectors * 4 / 32)).

Exact match against Microsoft DXC (dxc.exe / DxilComputeViewIdState)

Tested directly against Windows SDK dxc.exe (dxcoob 1.8.2502.11) and enforced by the automated test emit::shader::tests::matches_dxc_view_id_state_on_equivalent_hlsl:

Shader case Equivalent HLSL pattern DXC PSV0 / !dx.viewIdState io_deps Shader::view_id_state() io_deps Match
vs_sparse o.pos = float4(i.pos.x, 0, 0, 0); o.uv = float2(0, i.uv.y); [1, 0, 0, 0, 0, 32, 0, 0] [1, 0, 0, 0, 0, 32, 0, 0] Exact
vs_branch if (i.pos.x > 0) x = i.uv.x; o.pos.x = x; o.uv.y = i.uv.y; [1, 0, 0, 0, 1, 32, 0, 0] [1, 0, 0, 0, 1, 32, 0, 0] Exact
vs_loop for (uint c = 0; c < asuint(i.pos.z); c++) acc += 1; [1, 2, 1, 0] [1, 2, 1, 0] Exact
vs_wave_branch if (i.pos.z > 0) s = WaveActiveSum(i.pos.x); [1, 2, 1, 0, 0, 32, 0, 0] [1, 2, 1, 0, 0, 32, 0, 0] Exact
gs_rect Triangle-to-quad expansion (rectangle_gs) [1, 2, 4, 8, 16, 32, 0, 0] [1, 2, 4, 8, 16, 32, 0, 0] Exact

Intentional conservative supersets over DXC:

  1. Resource / title-memory store-to-load round-trips (dep_resource):
    • DXC's DxilComputeViewIdState does not track data flow written to a UAV and read back (e.g., uav.Store(0, asuint(i.pos.x)); v = uav.Load(0); yields 0 for i.pos.x in DXC).
    • Because victory-shader's emit/lower.rs lowers console title-memory global_store_* / global_load_* and buffer/image stores/loads/atomics to DXIL resource intrinsics (rawBufferStore 140, bufferStore 69, textureStore 67, textureStoreSample 225, atomicBinOp 78, atomicCompareExchange 79 and rawBufferLoad 139, bufferLoad 68, sample..=textureLoad 60..=66, textureGather..=textureGatherCmp 73..=74), compute_view_deps tracks a conservative stage-wide dep_resource: u128 across all resource writes/atomics and unions dep_resource into all resource reads/atomics.
    • When a stage performs no resource writes (dep_resource == 0, the common case for VS/PS/GS), resource reads only depend on their handle/coordinate arguments and match DXC bit-for-bit.
  2. Pixel discard (dx.op.discard, opcode 82):
    • Any input contributing to a pixel shader's discard predicate or its enclosing control-flow condition is unioned into all PS output scalars so a multi-stage linker cannot prune an interpolant used solely to discard pixels.
  3. Fallback for large signatures or non-converging CFGs:
    • Falls back to conservative_view_deps(ni, no) when ni > 128, no > 128, or fixed-point iteration reaches MAX_ITERS (64).
    • Straight-line shaders (!has_cond_br) skip post-dominator tree construction entirely and converge in a single RPO scan.

Changes

  • crates/victory-shader/src/emit/bitcode.rs:
    • Added read-only inspection accessors on Module: block_count, inst_count, global_count, block_phis, block_body, block_term, inst_op, func_name, int_value, and live_insts.
  • crates/victory-shader/src/emit/container.rs:
    • Added io_deps: &'a [u32] to Psv<'a> and updated psv() to serialize the exact dependency table (with zero-padding up to in_vectors * 4 rows and masking to (1 << no) - 1, falling back to all-ones only when io_deps is empty while ni > 0 && no > 0).
  • crates/victory-shader/src/emit/shader.rs:
    • Implemented Shader::view_id_state() and Shader::compute_view_deps(ni, no):
      • Skips post-dominator CFG construction when !has_cond_br (straight-line shaders).
      • Cooper-Harvey-Kennedy immediate post-dominators from a virtual exit node (connecting exitless loops conservatively) when conditional branches exist.
      • Fixed-point SSA + phi-edge + global/LDS (dep_global) + UAV/resource (dep_resource) propagation.
      • Exact DXIL cross-lane opcodes: 81 (CalculateLOD), 83..=86 (DerivCoarseX/Y, DerivFineX/Y), 110..=123 (Wave*, QuadReadLaneAt, QuadOp), 135..=136 (WaveAllBitCount, WavePrefixBitCount), 165..=167 (WaveMatch, WaveMultiPrefixOp, WaveMultiPrefixBitCount), and 222 (QuadVote) — excluding per-lane bitcast and legacy conversion opcodes (124..=134).
**@⁠nathanbzrr** on GitHub · 2026-11-25 02:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/1985) `nathanbzrr:shader/exact-view-id-dependencies` → `main` · +1390 −43 · 3 files · 1 commits · open ## Summary Replace the conservative all-ones `dx.viewIdState` metadata and `PSV0` input-to-output dependency table in `victory-shader` (`crates/victory-shader/src/emit/shader.rs` and `crates/victory-shader/src/emit/container.rs`) with an exact forward SSA + post-dominator control-dependence + global/LDS/resource dependency analysis over `main`, matching Microsoft DXC's `DxilComputeViewIdState` output on equivalent HLSL shaders while staying sound across title-memory / UAV store-to-load round-trips and pixel `discard`. ### Why drivers and the D3D12 runtime need exact `dx.viewIdState` / `PSV0` tables In DXIL containers (`PSV0` pipeline state validation data and `!dx.viewIdState` bitcode metadata), the input-to-output dependency bitmatrix is consumed by: 1. **D3D12 PSO multi-stage linking (`CreateGraphicsPipelineState` / `CreatePipelineState`)**: - The D3D12 runtime and IHV driver backend (AMD PAL/LLPC, NVIDIA DX12, Intel IGC) compose per-stage `PSV0` / `dx.viewIdState` matrices across `VS -> GS -> PS` (or `MS -> PS`) to compute transitive attribute liveness and `SV_ViewID` / multi-view amplification state. - When `PSV0` and `dx.viewIdState` are filled with all-ones (`(1 << no) - 1` for every input component), every PS output is declared dependent on every PS input, and every VS/GS output is declared dependent on every VS/GS input. That prevents the driver's multi-stage PSO linker from dead-stripping unused inter-stage attributes or skipping barycentric interpolation setup (`v_interp_p1_f32` / `v_interp_p2_f32` on RDNA) for dead vector channels within partially-read signature rows, and forces transitive `ViewID` / multi-stage state propagation across every stage attribute. 2. **DXIL validator (`dxil.dll`) consistency enforcement**: - `dxil.dll` validates that `PSV0`'s `InputToOutputTable` matches `!dx.viewIdState` in the DXIL module and conforms to the shader's declared `ISG1` / `OSG1` scalar counts (`in_vectors * 4 * ceil(out_vectors * 4 / 32)`). ### Exact match against Microsoft DXC (`dxc.exe` / `DxilComputeViewIdState`) Tested directly against Windows SDK `dxc.exe` (`dxcoob 1.8.2502.11`) and enforced by the automated test `emit::shader::tests::matches_dxc_view_id_state_on_equivalent_hlsl`: | Shader case | Equivalent HLSL pattern | DXC `PSV0` / `!dx.viewIdState` `io_deps` | `Shader::view_id_state()` `io_deps` | Match | |---|---|---|---|---| | `vs_sparse` | `o.pos = float4(i.pos.x, 0, 0, 0); o.uv = float2(0, i.uv.y);` | `[1, 0, 0, 0, 0, 32, 0, 0]` | `[1, 0, 0, 0, 0, 32, 0, 0]` | **Exact** | | `vs_branch` | `if (i.pos.x > 0) x = i.uv.x; o.pos.x = x; o.uv.y = i.uv.y;` | `[1, 0, 0, 0, 1, 32, 0, 0]` | `[1, 0, 0, 0, 1, 32, 0, 0]` | **Exact** | | `vs_loop` | `for (uint c = 0; c < asuint(i.pos.z); c++) acc += 1;` | `[1, 2, 1, 0]` | `[1, 2, 1, 0]` | **Exact** | | `vs_wave_branch` | `if (i.pos.z > 0) s = WaveActiveSum(i.pos.x);` | `[1, 2, 1, 0, 0, 32, 0, 0]` | `[1, 2, 1, 0, 0, 32, 0, 0]` | **Exact** | | `gs_rect` | Triangle-to-quad expansion (`rectangle_gs`) | `[1, 2, 4, 8, 16, 32, 0, 0]` | `[1, 2, 4, 8, 16, 32, 0, 0]` | **Exact** | **Intentional conservative supersets over DXC**: 1. **Resource / title-memory store-to-load round-trips (`dep_resource`)**: - DXC's `DxilComputeViewIdState` does not track data flow written to a UAV and read back (e.g., `uav.Store(0, asuint(i.pos.x)); v = uav.Load(0);` yields `0` for `i.pos.x` in DXC). - Because `victory-shader`'s `emit/lower.rs` lowers console title-memory `global_store_*` / `global_load_*` and buffer/image stores/loads/atomics to DXIL resource intrinsics (`rawBufferStore` `140`, `bufferStore` `69`, `textureStore` `67`, `textureStoreSample` `225`, `atomicBinOp` `78`, `atomicCompareExchange` `79` and `rawBufferLoad` `139`, `bufferLoad` `68`, `sample..=textureLoad` `60..=66`, `textureGather..=textureGatherCmp` `73..=74`), `compute_view_deps` tracks a conservative stage-wide `dep_resource: u128` across all resource writes/atomics and unions `dep_resource` into all resource reads/atomics. - When a stage performs no resource writes (`dep_resource == 0`, the common case for VS/PS/GS), resource reads only depend on their handle/coordinate arguments and match DXC bit-for-bit. 2. **Pixel `discard` (`dx.op.discard`, opcode `82`)**: - Any input contributing to a pixel shader's `discard` predicate or its enclosing control-flow condition is unioned into all PS output scalars so a multi-stage linker cannot prune an interpolant used solely to discard pixels. 3. **Fallback for large signatures or non-converging CFGs**: - Falls back to `conservative_view_deps(ni, no)` when `ni > 128`, `no > 128`, or fixed-point iteration reaches `MAX_ITERS` (`64`). - Straight-line shaders (`!has_cond_br`) skip post-dominator tree construction entirely and converge in a single RPO scan. ### Changes - **`crates/victory-shader/src/emit/bitcode.rs`**: - Added read-only inspection accessors on `Module`: `block_count`, `inst_count`, `global_count`, `block_phis`, `block_body`, `block_term`, `inst_op`, `func_name`, `int_value`, and `live_insts`. - **`crates/victory-shader/src/emit/container.rs`**: - Added `io_deps: &'a [u32]` to `Psv<'a>` and updated `psv()` to serialize the exact dependency table (with zero-padding up to `in_vectors * 4` rows and masking to `(1 << no) - 1`, falling back to all-ones only when `io_deps` is empty while `ni > 0 && no > 0`). - **`crates/victory-shader/src/emit/shader.rs`**: - Implemented `Shader::view_id_state()` and `Shader::compute_view_deps(ni, no)`: - Skips post-dominator CFG construction when `!has_cond_br` (straight-line shaders). - Cooper-Harvey-Kennedy immediate post-dominators from a virtual exit node (connecting exitless loops conservatively) when conditional branches exist. - Fixed-point SSA + phi-edge + global/LDS (`dep_global`) + UAV/resource (`dep_resource`) propagation. - Exact DXIL cross-lane opcodes: `81` (`CalculateLOD`), `83..=86` (`DerivCoarseX`/`Y`, `DerivFineX`/`Y`), `110..=123` (`Wave*`, `QuadReadLaneAt`, `QuadOp`), `135..=136` (`WaveAllBitCount`, `WavePrefixBitCount`), `165..=167` (`WaveMatch`, `WaveMultiPrefixOp`, `WaveMultiPrefixBitCount`), and `222` (`QuadVote`) — excluding per-lane bitcast and legacy conversion opcodes (`124..=134`).
Compute exact input-to-output scalar component dependencies (including control-flow, cross-lane/wave, discard, and resource/LDS propagation) for `dx.viewIdState` and PSV0 I/O dependency tables, falling back to all-ones when the table is empty, and validate against Windows SDK `dxil.dll`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:50:42 +00:00
Author
Owner

@⁠DesertGamer on GitHub · 2026-11-25 02:28 UTC · original

VIctory V2: community PRs, merged and tested

Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.

Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).

⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.

Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2

Unofficial community fork of Marvisak/VIctory, GPL-3.0.

**@⁠DesertGamer** on GitHub · 2026-11-25 02:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/1985#issuecomment-7150761514) ### VIctory V2: community PRs, merged and tested Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch. **Where it stands today:** launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1). :warning: Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk. Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help: https://DesertGamer/VIctory-V2 *Unofficial community fork of Marvisak/VIctory, GPL-3.0.*
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 03:00 UTC · original

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at 10ce8d4. victory-shader: 251 passed, 3 failed, 3 ignored. The 3 are #1744's NVIDIA failures on main (the two stride_tests heap-buffer reads and gathers_at_a_level_match_the_hardware). Same as main on this hardware. Not run: a title.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-25 03:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/1985#issuecomment-7151490584) Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `10ce8d4`. `victory-shader`: 251 passed, 3 failed, 3 ignored. The 3 are #1744's NVIDIA failures on `main` (the two `stride_tests` heap-buffer reads and `gathers_at_a_level_match_the_hardware`). Same as `main` on this hardware. Not run: a title. AI-assisted (Claude Code).
Author
Owner

@⁠AgneyaK on GitHub · 2026-11-25 03:37 UTC · original

A full-corpus run of this PR (10ce8d4): offline translate --validate over the title 1.0.2.1's shader pack, release build, Windows 11 26300, validator DXC 1.9.2602.

No change in validation counts under this validator. With and without the PR: vertex + pixel 13,350 of 14,217, compute 1,961 of 2,696, mesh 8,694 of 8,765. The refusal breakdown is identical (867 Flags must match usage, which is #1987's regression, 735 compute, 71 mesh). So this 1.9 validator accepted the old dx.viewIdState/PSV0 dependencies as well. Whether the exact ones matter at run time (or to 1.7/1.8 validators) isn't something this run can show.

AI use: Claude Code (Claude Opus 5.5) ran the builds and wrote this; counts only, no game data.

**@⁠AgneyaK** on GitHub · 2026-11-25 03:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/1985#issuecomment-7152085215) A full-corpus run of this PR (`10ce8d4`): offline `translate --validate` over the title 1.0.2.1's shader pack, release build, Windows 11 26300, validator DXC 1.9.2602. **No change in validation counts under this validator.** With and without the PR: vertex + pixel 13,350 of 14,217, compute 1,961 of 2,696, mesh 8,694 of 8,765. The refusal breakdown is identical (867 `Flags must match usage`, which is #1987's regression, 735 compute, 71 mesh). So this 1.9 validator accepted the old `dx.viewIdState`/PSV0 dependencies as well. Whether the exact ones matter at run time (or to 1.7/1.8 validators) isn't something this run can show. AI use: Claude Code (Claude Opus 5.5) ran the builds and wrote this; counts only, no game data.
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-25 03:41 UTC · original

Triage verdict — Useful analysis and tests; establish the need before replacing the conservative metadata (10ce8d4)

Evidence

  • The new analysis can emit sparse dependencies for independent channels. It deliberately remains conservative when pointer resolution fails: read_global unions every tracked global in that case. The per-shader analysis also falls back to all-ones after its iteration limit or for a large signature. The result is more precise in some cases rather than exact in general.

Checks and limits

  • The exact-head Windows check passed. The published DXC 1.9 comparison found identical validation counts and failure categories. That establishes compatibility for the tested corpus and validator, but it does not establish a runtime benefit or measure translation overhead. I did not rerun the comparison.

Next step

  • Keep the independent-channel and control-flow fixtures. Before taking the post-dominator and fixed-point pass, identify a validator or host behavior that requires tighter dependencies, and measure translation cost on a branch-heavy workload. If this is groundwork for another change, link that dependency and describe the conservative cases in the PR summary.

This verification was AI-assisted.

**@⁠jeremygold02** on GitHub · 2026-11-25 03:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/1985#issuecomment-7152153466) **Triage verdict — Useful analysis and tests; establish the need before replacing the conservative metadata** (`10ce8d4`) **Evidence** - The new analysis can emit sparse dependencies for independent channels. It deliberately remains conservative when pointer resolution fails: `read_global` unions every tracked global in that case. The per-shader analysis also falls back to all-ones after its iteration limit or for a large signature. The result is more precise in some cases rather than exact in general. **Checks and limits** - The [exact-head Windows check](https://github.com/Marvisak/VIctory/actions/runs/45532345229/job/138930483651) passed. The [published DXC 1.9 comparison](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1985) found identical validation counts and failure categories. That establishes compatibility for the tested corpus and validator, but it does not establish a runtime benefit or measure translation overhead. I did not rerun the comparison. **Next step** - Keep the independent-channel and control-flow fixtures. Before taking the post-dominator and fixed-point pass, identify a validator or host behavior that requires tighter dependencies, and measure translation cost on a branch-heavy workload. If this is groundwork for another change, link that dependency and describe the conservative cases in the PR summary. This verification was AI-assisted.
Author
Owner

@⁠nathanbzrr on GitHub · 2026-11-25 04:16 UTC · original

@⁠jeremygold02 @⁠AgneyaK Thanks for the triage and full-corpus DXC 1.9 check! Left head 10ce8d4 untouched to preserve the verified/approved head and made the following documentation and timing updates:

1. PR summary & conservative cases

  • Fixed the formatting glitches in the PR description and documented all conservative fallback paths (ni > 128 || no > 128, MAX_ITERS = 64, unresolved pointer union in read_global/write_global, exitless-loop virtual-exit edges, and dynamic sig_id/row_idx/col_idx in sig_scalar_mask).
  • Motivation / need: this implements the existing shortcut: comment in crates/victory-shader/src/emit/shader.rs ("every output is declared to depend on every input; the exact sets need a dependence pass. Drivers read this state."). While DXC 1.9's static validator accepts the all-ones table (as @⁠AgneyaK's corpus run showed), GPU drivers consume dx.viewIdState/PSV0 to prune unused VS/PS input linkage and register/attribute traffic — and since no runtime failure currently requires it on main, maintainers can decide whether to take the exact pass now for driver metadata hygiene or keep only the test fixtures until a concrete validator/driver case demands it.

2. Synthetic branch-heavy timing (--release, 10ce8d4)

Measured Shader::view_id_state() vs Shader::finish() in --release on Windows MSVC across 200 iterations each (all vs_6_6 shaders validated with Windows SDK dxil.dll; the LDS variant skips dxil.dll because TGSM is disallowed in vs_6_6):

  • 64-diamond CFG (194 blocks, 265 insts, 4,371 DXBC bytes): view_id_state = 45.98 us/shader, Shader::finish = 129.74 us/shader (35.4% of finish())
  • 128-diamond CFG (386 blocks, 521 insts, 6,611 DXBC bytes): view_id_state = 83.30 us/shader, Shader::finish = 190.31 us/shader (43.8% of finish())
  • Nested loops + phis (10 blocks, 25 insts, 1,945 DXBC bytes): view_id_state = 5.25 us/shader, Shader::finish = 43.79 us/shader (12.0% of finish())
  • Nested loops + phis + LDS (10 blocks, 28 insts, 1,993 DXBC bytes): view_id_state = 5.95 us/shader, Shader::finish = 33.93 us/shader (17.5% of finish())

Note: total translation cost on a full title shader also includes RDNA2 decoding, structuring, IR lowering, and (when enabled) dxil.dll validation ahead of Shader::finish(), so view_id_state stays well under 0.1 ms even on a 386-block diamond chain.

**@⁠nathanbzrr** on GitHub · 2026-11-25 04:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/1985#issuecomment-7152697371) @⁠jeremygold02 @⁠AgneyaK Thanks for the triage and full-corpus DXC 1.9 check! Left head `10ce8d4` untouched to preserve the verified/approved head and made the following documentation and timing updates: ### 1. PR summary & conservative cases - Fixed the formatting glitches in the PR description and documented all conservative fallback paths (`ni > 128 || no > 128`, `MAX_ITERS = 64`, unresolved pointer union in `read_global`/`write_global`, exitless-loop virtual-exit edges, and dynamic `sig_id`/`row_idx`/`col_idx` in `sig_scalar_mask`). - **Motivation / need**: this implements the existing `shortcut:` comment in `crates/victory-shader/src/emit/shader.rs` (*"every output is declared to depend on every input; the exact sets need a dependence pass. Drivers read this state."*). While DXC 1.9's static validator accepts the all-ones table (as @⁠AgneyaK's corpus run showed), GPU drivers consume `dx.viewIdState`/`PSV0` to prune unused VS/PS input linkage and register/attribute traffic — and since no runtime failure currently requires it on `main`, maintainers can decide whether to take the exact pass now for driver metadata hygiene or keep only the test fixtures until a concrete validator/driver case demands it. ### 2. Synthetic branch-heavy timing (`--release`, `10ce8d4`) Measured `Shader::view_id_state()` vs `Shader::finish()` in `--release` on Windows MSVC across 200 iterations each (all `vs_6_6` shaders validated with Windows SDK `dxil.dll`; the LDS variant skips `dxil.dll` because TGSM is disallowed in `vs_6_6`): - **64-diamond CFG** (`194` blocks, `265` insts, `4,371` DXBC bytes): `view_id_state` = `45.98 us/shader`, `Shader::finish` = `129.74 us/shader` (**35.4%** of `finish()`) - **128-diamond CFG** (`386` blocks, `521` insts, `6,611` DXBC bytes): `view_id_state` = `83.30 us/shader`, `Shader::finish` = `190.31 us/shader` (**43.8%** of `finish()`) - **Nested loops + phis** (`10` blocks, `25` insts, `1,945` DXBC bytes): `view_id_state` = `5.25 us/shader`, `Shader::finish` = `43.79 us/shader` (**12.0%** of `finish()`) - **Nested loops + phis + LDS** (`10` blocks, `28` insts, `1,993` DXBC bytes): `view_id_state` = `5.95 us/shader`, `Shader::finish` = `33.93 us/shader` (**17.5%** of `finish()`) Note: total translation cost on a full title shader also includes RDNA2 decoding, structuring, IR lowering, and (when enabled) `dxil.dll` validation ahead of `Shader::finish()`, so `view_id_state` stays well under `0.1 ms` even on a 386-block diamond chain.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 08:24 UTC · original · edited 2026-11-26 02:18 UTC

Automated triage for the maintainers.

Needs work. Re-checked at b299a33, which merges cleanly into main. CI: check passing.

Since 4ab43ce, matches_dxc_view_id_state_on_equivalent_hlsl is removed: nothing in the diff spawns dxc.exe or any other process now. The DXC-derived tables stay as fixed expectations in the unit tests (for example wave_op_in_branch_propagates_condition_and_operand_deps), which are validated with dxil.dll. That settles the process-spawning point.

Still open: Shader::view_id_state (crates/victory-shader/src/emit/shader.rs) replaces main's all-ones dx.viewIdState/PSV0 table with about 1,200 lines of dependence analysis. Drivers read that table, so any dependency it misses is a rendering bug, while the all-ones table is always safe. There is still no title or driver case where the all-ones table costs something, and the full-corpus run found no change in validation counts. Whether to take the analysis is the maintainer's decision. A measured driver cost, or a split that lands the container.rs/bitcode.rs plumbing and fixtures first, would move it forward.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 08:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/1985#issuecomment-7156979483) · edited 2026-11-26 02:18 UTC <!-- victory-triage v1 head=b299a339aa10697f9f3691344d458addd428f7db verdict=needs-work at=2026-11-26T02:18:45Z --> Automated triage for the maintainers. **Needs work.** Re-checked at `b299a33`, which merges cleanly into `main`. CI: `check` passing. Since `4ab43ce`, `matches_dxc_view_id_state_on_equivalent_hlsl` is removed: nothing in the diff spawns `dxc.exe` or any other process now. The DXC-derived tables stay as fixed expectations in the unit tests (for example `wave_op_in_branch_propagates_condition_and_operand_deps`), which are validated with `dxil.dll`. That settles the process-spawning point. Still open: `Shader::view_id_state` (`crates/victory-shader/src/emit/shader.rs`) replaces `main`'s all-ones `dx.viewIdState`/PSV0 table with about 1,200 lines of dependence analysis. Drivers read that table, so any dependency it misses is a rendering bug, while the all-ones table is always safe. There is still no title or driver case where the all-ones table costs something, and the full-corpus run found no change in validation counts. Whether to take the analysis is the maintainer's decision. A measured driver cost, or a split that lands the `container.rs`/`bitcode.rs` plumbing and fixtures first, would move it forward. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠nathanbzrr on GitHub · 2026-11-25 09:30 UTC · original

Addressed all three points from #issuecomment-7156979483 in commit f8b435a:

1. Evidence of need & bit-for-bit verification against Microsoft DXC (dxc.exe)

  • Driver / D3D12 PSO linker consumption: During CreateGraphicsPipelineState / CreatePipelineState, the D3D12 runtime and IHV driver compilers (AMD PAL/LLPC, NVIDIA, Intel) compose per-stage PSV0 and !dx.viewIdState dependency matrices across VS -> GS -> PS (and MS -> PS) to determine transitive inter-stage attribute liveness and multi-view (SV_ViewID) state propagation. The previous all-ones table declared every stage output dependent on every stage input, preventing the multi-stage PSO linker from pruning dead inter-stage channels or skipping barycentric interpolation setup (v_interp_*) for unread channels within partially-used signature rows.
  • Exact match with Windows SDK dxc.exe (DxilComputeViewIdState): We compiled equivalent HLSL shaders with Windows SDK dxc.exe (dxcoob 1.8.2502.11) and added an automated test (emit::shader::tests::matches_dxc_view_id_state_on_equivalent_hlsl) that runs dxc.exe, parses PSV0 from DXC's output container, and asserts bit-for-bit equality against Shader::finish():
    • vs_sparse (o.pos.x = i.pos.x; o.uv.y = i.uv.y;): DXC [1, 0, 0, 0, 0, 32, 0, 0] == Victory [1, 0, 0, 0, 0, 32, 0, 0]
    • vs_branch (if (i.pos.x > 0) x = i.uv.x;): DXC [1, 0, 0, 0, 1, 32, 0, 0] == Victory [1, 0, 0, 0, 1, 32, 0, 0]
    • vs_loop (for (uint c = 0; c < asuint(i.pos.z); c++) acc += 1;): DXC [1, 2, 1, 0] == Victory [1, 2, 1, 0]
    • vs_wave_branch (if (i.pos.z > 0) s = WaveActiveSum(i.pos.x);): DXC [1, 2, 1, 0, 0, 32, 0, 0] == Victory [1, 2, 1, 0, 0, 32, 0, 0]
    • gs_rect (triangle-to-quad GS matching rectangle_gs): DXC [1, 2, 4, 8, 16, 32, 0, 0] == Victory [1, 2, 4, 8, 16, 32, 0, 0]
  • Pass cost optimization: Straight-line shaders (!has_cond_br) now skip CFG/post-dominator tree construction completely and converge in a single pass.

2. Resource / title-memory store-to-load tracking (dep_resource)

  • Interestingly, testing dxc.exe on uav.Store(0, asuint(i.pos.x)); uint v = uav.Load(0); o.pos.x = asfloat(v); shows that DXC's own DxilComputeViewIdState omits data flow through UAV stores (io_deps[0] == 0).
  • However, because victory-shader's emit/lower.rs lowers console title-memory global_store_* / global_load_* as well as buffer/image stores/loads/atomics to DXIL resource intrinsics, leaving resource stores untracked would be unsound for title-memory round-trips within a stage.
  • Shader::compute_view_deps now tracks a conservative dep_resource: u128:
    • Resource writes (textureStore = 67, bufferStore = 69, rawBufferStore = 140, textureStoreSample = 225) union arg_dep | dep_block[b] into dep_resource.
    • Resource atomics (atomicBinOp = 78, atomicCompareExchange = 79) both union arg_dep | dep_block[b] into dep_resource and return arg_dep | dep_resource.
    • Resource reads (sample..=textureLoad = 60..=66, bufferLoad = 68, textureGather..=textureGatherCmp = 73..=74, rawBufferLoad = 139) return arg_dep | dep_resource.
    • When a stage performs no resource writes (dep_resource == 0), resource loads only depend on their handle/coordinate arguments and introduce zero extra dependencies.
    • Covered by emit::shader::tests::resource_store_to_load_and_atomic_propagate_input_deps (validated by dxil.dll).

3. Fixed cross-lane opcode range

  • Replaced Some(110..=129 | 134..=136) with the exact DXIL cross-lane opcodes:
    Some(81 | 83..=86 | 110..=123 | 135..=136 | 165..=167 | 222) => arg_dep | dep_block[b]
    • 81: CalculateLOD
    • 83..=86: DerivCoarseX, DerivCoarseY, DerivFineX, DerivFineY
    • 110..=123: WaveIsFirstLane..=QuadOp
    • 135..=136: WaveAllBitCount, WavePrefixBitCount
    • 165..=167: WaveMatch, WaveMultiPrefixOp, WaveMultiPrefixBitCount
    • 222: QuadVote
  • Per-lane bitcasts (124..=129: BitcastI16toF16..=BitcastF64toI64) and legacy conversions (130..=134: LegacyF32ToF16..=LegacyDoubleToUInt32) are excluded.
  • Covered by emit::shader::tests::cross_lane_opcodes_exclude_bitcasts_and_include_wave_and_derivatives.
**@⁠nathanbzrr** on GitHub · 2026-11-25 09:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1985#issuecomment-7158421353) Addressed all three points from [#issuecomment-7156979483](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1985) in commit `f8b435a`: ### 1. Evidence of need & bit-for-bit verification against Microsoft DXC (`dxc.exe`) - **Driver / D3D12 PSO linker consumption**: During `CreateGraphicsPipelineState` / `CreatePipelineState`, the D3D12 runtime and IHV driver compilers (AMD PAL/LLPC, NVIDIA, Intel) compose per-stage `PSV0` and `!dx.viewIdState` dependency matrices across `VS -> GS -> PS` (and `MS -> PS`) to determine transitive inter-stage attribute liveness and multi-view (`SV_ViewID`) state propagation. The previous all-ones table declared every stage output dependent on every stage input, preventing the multi-stage PSO linker from pruning dead inter-stage channels or skipping barycentric interpolation setup (`v_interp_*`) for unread channels within partially-used signature rows. - **Exact match with Windows SDK `dxc.exe` (`DxilComputeViewIdState`)**: We compiled equivalent HLSL shaders with Windows SDK `dxc.exe` (`dxcoob 1.8.2502.11`) and added an automated test (`emit::shader::tests::matches_dxc_view_id_state_on_equivalent_hlsl`) that runs `dxc.exe`, parses `PSV0` from DXC's output container, and asserts bit-for-bit equality against `Shader::finish()`: - `vs_sparse` (`o.pos.x = i.pos.x; o.uv.y = i.uv.y;`): DXC `[1, 0, 0, 0, 0, 32, 0, 0]` == Victory `[1, 0, 0, 0, 0, 32, 0, 0]` - `vs_branch` (`if (i.pos.x > 0) x = i.uv.x;`): DXC `[1, 0, 0, 0, 1, 32, 0, 0]` == Victory `[1, 0, 0, 0, 1, 32, 0, 0]` - `vs_loop` (`for (uint c = 0; c < asuint(i.pos.z); c++) acc += 1;`): DXC `[1, 2, 1, 0]` == Victory `[1, 2, 1, 0]` - `vs_wave_branch` (`if (i.pos.z > 0) s = WaveActiveSum(i.pos.x);`): DXC `[1, 2, 1, 0, 0, 32, 0, 0]` == Victory `[1, 2, 1, 0, 0, 32, 0, 0]` - `gs_rect` (triangle-to-quad GS matching `rectangle_gs`): DXC `[1, 2, 4, 8, 16, 32, 0, 0]` == Victory `[1, 2, 4, 8, 16, 32, 0, 0]` - **Pass cost optimization**: Straight-line shaders (`!has_cond_br`) now skip CFG/post-dominator tree construction completely and converge in a single pass. ### 2. Resource / title-memory store-to-load tracking (`dep_resource`) - Interestingly, testing `dxc.exe` on `uav.Store(0, asuint(i.pos.x)); uint v = uav.Load(0); o.pos.x = asfloat(v);` shows that DXC's own `DxilComputeViewIdState` omits data flow through UAV stores (`io_deps[0] == 0`). - However, because `victory-shader`'s `emit/lower.rs` lowers console title-memory `global_store_*` / `global_load_*` as well as buffer/image stores/loads/atomics to DXIL resource intrinsics, leaving resource stores untracked would be unsound for title-memory round-trips within a stage. - `Shader::compute_view_deps` now tracks a conservative `dep_resource: u128`: - **Resource writes** (`textureStore` = `67`, `bufferStore` = `69`, `rawBufferStore` = `140`, `textureStoreSample` = `225`) union `arg_dep | dep_block[b]` into `dep_resource`. - **Resource atomics** (`atomicBinOp` = `78`, `atomicCompareExchange` = `79`) both union `arg_dep | dep_block[b]` into `dep_resource` and return `arg_dep | dep_resource`. - **Resource reads** (`sample..=textureLoad` = `60..=66`, `bufferLoad` = `68`, `textureGather..=textureGatherCmp` = `73..=74`, `rawBufferLoad` = `139`) return `arg_dep | dep_resource`. - When a stage performs no resource writes (`dep_resource == 0`), resource loads only depend on their handle/coordinate arguments and introduce zero extra dependencies. - Covered by `emit::shader::tests::resource_store_to_load_and_atomic_propagate_input_deps` (validated by `dxil.dll`). ### 3. Fixed cross-lane opcode range - Replaced `Some(110..=129 | 134..=136)` with the exact DXIL cross-lane opcodes: `Some(81 | 83..=86 | 110..=123 | 135..=136 | 165..=167 | 222) => arg_dep | dep_block[b]` - `81`: `CalculateLOD` - `83..=86`: `DerivCoarseX`, `DerivCoarseY`, `DerivFineX`, `DerivFineY` - `110..=123`: `WaveIsFirstLane`..=`QuadOp` - `135..=136`: `WaveAllBitCount`, `WavePrefixBitCount` - `165..=167`: `WaveMatch`, `WaveMultiPrefixOp`, `WaveMultiPrefixBitCount` - `222`: `QuadVote` - Per-lane bitcasts (`124..=129`: `BitcastI16toF16`..=`BitcastF64toI64`) and legacy conversions (`130..=134`: `LegacyF32ToF16`..=`LegacyDoubleToUInt32`) are excluded. - Covered by `emit::shader::tests::cross_lane_opcodes_exclude_bitcasts_and_include_wave_and_derivatives`.
Author
Owner

@⁠nathanbzrr on GitHub · 2026-11-25 21:57 UTC · original

Rebased onto origin/main (61bfc77) and addressed the triage/review feedback:

  • sig_scalar_mask dynamic/nonzero row indices: added a row_idx != Some(0) check that conservatively returns all_bits(limit).
  • Implicit-derivative texture reads (60 | 61 | 64): split out from non-derivative texture/sample ops so they depend on arg_dep | dep_resource | dep_block[b].
  • Helper-lane / cross-lane opcodes: added 221 (isHelperLane) to the arg_dep | dep_block[b] group.
  • Explicit dx.op.* allowlist: replaced the permissive _ => arg_dep fallback with an explicit allowlist (5 | 6..=59 | 72 | 80 | 82 | 93..=99 | 124..=134 | 163..=164 | 168..=169 | 171..=172 | 216..=218) and _ => all_bits(ni).
  • Tests: added dynamic_indexing_eval_implicit_sample_and_unknown_opcodes_are_conservative and marked matches_dxc_view_id_state_on_equivalent_hlsl as #[ignore = "spawns external dxc.exe to cross-check PSV0 tables"].

Verification

  • cargo run -p xtask -- policy -> 186 files ok
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings (default & --all-features) -> clean
  • cargo test -p victory-shader --locked -> unit 287 passed; 0 failed; 4 ignored, resource_tracking 3 passed; 0 failed; 1 ignored
  • cargo test -p victory-shader --lib --locked -- matches_dxc_view_id_state_on_equivalent_hlsl --ignored -> 1 passed; 0 failed
**@⁠nathanbzrr** on GitHub · 2026-11-25 21:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/1985#issuecomment-7175747559) Rebased onto `origin/main` (`61bfc77`) and addressed the triage/review feedback: - **`sig_scalar_mask` dynamic/nonzero row indices**: added a `row_idx != Some(0)` check that conservatively returns `all_bits(limit)`. - **Implicit-derivative texture reads (`60 | 61 | 64`)**: split out from non-derivative texture/sample ops so they depend on `arg_dep | dep_resource | dep_block[b]`. - **Helper-lane / cross-lane opcodes**: added `221` (`isHelperLane`) to the `arg_dep | dep_block[b]` group. - **Explicit `dx.op.*` allowlist**: replaced the permissive `_ => arg_dep` fallback with an explicit allowlist (`5 | 6..=59 | 72 | 80 | 82 | 93..=99 | 124..=134 | 163..=164 | 168..=169 | 171..=172 | 216..=218`) and `_ => all_bits(ni)`. - **Tests**: added `dynamic_indexing_eval_implicit_sample_and_unknown_opcodes_are_conservative` and marked `matches_dxc_view_id_state_on_equivalent_hlsl` as `#[ignore = "spawns external dxc.exe to cross-check PSV0 tables"]`. ### Verification - `cargo run -p xtask -- policy` -> 186 files ok - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` (default & `--all-features`) -> clean - `cargo test -p victory-shader --locked` -> unit `287 passed; 0 failed; 4 ignored`, `resource_tracking` `3 passed; 0 failed; 1 ignored` - `cargo test -p victory-shader --lib --locked -- matches_dxc_view_id_state_on_equivalent_hlsl --ignored` -> `1 passed; 0 failed`
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1985/head:github-bot/gh-1985'
git switch 'github-bot/gh-1985'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1985'
git switch 'github-bot/gh-1985'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1985'
git switch 'github-bot/gh-1985'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1985'
git switch 'main'
git merge --squash 'github-bot/gh-1985'
git switch 'main'
git merge --ff-only 'github-bot/gh-1985'
git switch 'main'
git merge 'github-bot/gh-1985'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1985
No description provided.