Shaders: compute exact dx.viewIdState and PSV0 input-output dependencies #1985
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1985
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1985"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@nathanbzrr on GitHub · 2026-11-25 02:21 UTC · original
nathanbzrr:shader/exact-view-id-dependencies→main· +1390 −43 · 3 files · 1 commits · openSummary
Replace the conservative all-ones
dx.viewIdStatemetadata andPSV0input-to-output dependency table invictory-shader(crates/victory-shader/src/emit/shader.rsandcrates/victory-shader/src/emit/container.rs) with an exact forward SSA + post-dominator control-dependence + global/LDS/resource dependency analysis overmain, matching Microsoft DXC'sDxilComputeViewIdStateoutput on equivalent HLSL shaders while staying sound across title-memory / UAV store-to-load round-trips and pixeldiscard.Why drivers and the D3D12 runtime need exact
dx.viewIdState/PSV0tablesIn DXIL containers (
PSV0pipeline state validation data and!dx.viewIdStatebitcode metadata), the input-to-output dependency bitmatrix is consumed by:CreateGraphicsPipelineState/CreatePipelineState):PSV0/dx.viewIdStatematrices acrossVS -> GS -> PS(orMS -> PS) to compute transitive attribute liveness andSV_ViewID/ multi-view amplification state.PSV0anddx.viewIdStateare filled with all-ones ((1 << no) - 1for 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_f32on RDNA) for dead vector channels within partially-read signature rows, and forces transitiveViewID/ multi-stage state propagation across every stage attribute.dxil.dll) consistency enforcement:dxil.dllvalidates thatPSV0'sInputToOutputTablematches!dx.viewIdStatein the DXIL module and conforms to the shader's declaredISG1/OSG1scalar 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 testemit::shader::tests::matches_dxc_view_id_state_on_equivalent_hlsl:PSV0/!dx.viewIdStateio_depsShader::view_id_state()io_depsvs_sparseo.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]vs_branchif (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]vs_loopfor (uint c = 0; c < asuint(i.pos.z); c++) acc += 1;[1, 2, 1, 0][1, 2, 1, 0]vs_wave_branchif (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]gs_rectrectangle_gs)[1, 2, 4, 8, 16, 32, 0, 0][1, 2, 4, 8, 16, 32, 0, 0]Intentional conservative supersets over DXC:
dep_resource):DxilComputeViewIdStatedoes not track data flow written to a UAV and read back (e.g.,uav.Store(0, asuint(i.pos.x)); v = uav.Load(0);yields0fori.pos.xin DXC).victory-shader'semit/lower.rslowers console title-memoryglobal_store_*/global_load_*and buffer/image stores/loads/atomics to DXIL resource intrinsics (rawBufferStore140,bufferStore69,textureStore67,textureStoreSample225,atomicBinOp78,atomicCompareExchange79andrawBufferLoad139,bufferLoad68,sample..=textureLoad60..=66,textureGather..=textureGatherCmp73..=74),compute_view_depstracks a conservative stage-widedep_resource: u128across all resource writes/atomics and unionsdep_resourceinto all resource reads/atomics.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.discard(dx.op.discard, opcode82):discardpredicate 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.conservative_view_deps(ni, no)whenni > 128,no > 128, or fixed-point iteration reachesMAX_ITERS(64).!has_cond_br) skip post-dominator tree construction entirely and converge in a single RPO scan.Changes
crates/victory-shader/src/emit/bitcode.rs:Module:block_count,inst_count,global_count,block_phis,block_body,block_term,inst_op,func_name,int_value, andlive_insts.crates/victory-shader/src/emit/container.rs:io_deps: &'a [u32]toPsv<'a>and updatedpsv()to serialize the exact dependency table (with zero-padding up toin_vectors * 4rows and masking to(1 << no) - 1, falling back to all-ones only whenio_depsis empty whileni > 0 && no > 0).crates/victory-shader/src/emit/shader.rs:Shader::view_id_state()andShader::compute_view_deps(ni, no):!has_cond_br(straight-line shaders).dep_global) + UAV/resource (dep_resource) propagation.81(CalculateLOD),83..=86(DerivCoarseX/Y,DerivFineX/Y),110..=123(Wave*,QuadReadLaneAt,QuadOp),135..=136(WaveAllBitCount,WavePrefixBitCount),165..=167(WaveMatch,WaveMultiPrefixOp,WaveMultiPrefixBitCount), and222(QuadVote) — excluding per-lane bitcast and legacy conversion opcodes (124..=134).@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.
@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 onmain(the twostride_testsheap-buffer reads andgathers_at_a_level_match_the_hardware). Same asmainon this hardware. Not run: a title.AI-assisted (Claude Code).
@AgneyaK on GitHub · 2026-11-25 03:37 UTC · original
A full-corpus run of this PR (
10ce8d4): offlinetranslate --validateover 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 olddx.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.
@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
read_globalunions 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
Next step
This verification was AI-assisted.
@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
10ce8d4untouched to preserve the verified/approved head and made the following documentation and timing updates:1. PR summary & conservative cases
ni > 128 || no > 128,MAX_ITERS = 64, unresolved pointer union inread_global/write_global, exitless-loop virtual-exit edges, and dynamicsig_id/row_idx/col_idxinsig_scalar_mask).shortcut:comment incrates/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 consumedx.viewIdState/PSV0to prune unused VS/PS input linkage and register/attribute traffic — and since no runtime failure currently requires it onmain, 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()vsShader::finish()in--releaseon Windows MSVC across 200 iterations each (allvs_6_6shaders validated with Windows SDKdxil.dll; the LDS variant skipsdxil.dllbecause TGSM is disallowed invs_6_6):194blocks,265insts,4,371DXBC bytes):view_id_state=45.98 us/shader,Shader::finish=129.74 us/shader(35.4% offinish())386blocks,521insts,6,611DXBC bytes):view_id_state=83.30 us/shader,Shader::finish=190.31 us/shader(43.8% offinish())10blocks,25insts,1,945DXBC bytes):view_id_state=5.25 us/shader,Shader::finish=43.79 us/shader(12.0% offinish())10blocks,28insts,1,993DXBC bytes):view_id_state=5.95 us/shader,Shader::finish=33.93 us/shader(17.5% offinish())Note: total translation cost on a full title shader also includes RDNA2 decoding, structuring, IR lowering, and (when enabled)
dxil.dllvalidation ahead ofShader::finish(), soview_id_statestays well under0.1 mseven on a 386-block diamond chain.@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 intomain. CI:checkpassing.Since
4ab43ce,matches_dxc_view_id_state_on_equivalent_hlslis removed: nothing in the diff spawnsdxc.exeor any other process now. The DXC-derived tables stay as fixed expectations in the unit tests (for examplewave_op_in_branch_propagates_condition_and_operand_deps), which are validated withdxil.dll. That settles the process-spawning point.Still open:
Shader::view_id_state(crates/victory-shader/src/emit/shader.rs) replacesmain's all-onesdx.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 thecontainer.rs/bitcode.rsplumbing and fixtures first, would move it forward.Generated by Claude Code
@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)CreateGraphicsPipelineState/CreatePipelineState, the D3D12 runtime and IHV driver compilers (AMD PAL/LLPC, NVIDIA, Intel) compose per-stagePSV0and!dx.viewIdStatedependency matrices acrossVS -> GS -> PS(andMS -> 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.dxc.exe(DxilComputeViewIdState): We compiled equivalent HLSL shaders with Windows SDKdxc.exe(dxcoob 1.8.2502.11) and added an automated test (emit::shader::tests::matches_dxc_view_id_state_on_equivalent_hlsl) that runsdxc.exe, parsesPSV0from DXC's output container, and asserts bit-for-bit equality againstShader::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 matchingrectangle_gs): DXC[1, 2, 4, 8, 16, 32, 0, 0]== Victory[1, 2, 4, 8, 16, 32, 0, 0]!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)dxc.exeonuav.Store(0, asuint(i.pos.x)); uint v = uav.Load(0); o.pos.x = asfloat(v);shows that DXC's ownDxilComputeViewIdStateomits data flow through UAV stores (io_deps[0] == 0).victory-shader'semit/lower.rslowers console title-memoryglobal_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_depsnow tracks a conservativedep_resource: u128:textureStore=67,bufferStore=69,rawBufferStore=140,textureStoreSample=225) unionarg_dep | dep_block[b]intodep_resource.atomicBinOp=78,atomicCompareExchange=79) both unionarg_dep | dep_block[b]intodep_resourceand returnarg_dep | dep_resource.sample..=textureLoad=60..=66,bufferLoad=68,textureGather..=textureGatherCmp=73..=74,rawBufferLoad=139) returnarg_dep | dep_resource.dep_resource == 0), resource loads only depend on their handle/coordinate arguments and introduce zero extra dependencies.emit::shader::tests::resource_store_to_load_and_atomic_propagate_input_deps(validated bydxil.dll).3. Fixed cross-lane opcode range
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:CalculateLOD83..=86:DerivCoarseX,DerivCoarseY,DerivFineX,DerivFineY110..=123:WaveIsFirstLane..=QuadOp135..=136:WaveAllBitCount,WavePrefixBitCount165..=167:WaveMatch,WaveMultiPrefixOp,WaveMultiPrefixBitCount222:QuadVote124..=129:BitcastI16toF16..=BitcastF64toI64) and legacy conversions (130..=134:LegacyF32ToF16..=LegacyDoubleToUInt32) are excluded.emit::shader::tests::cross_lane_opcodes_exclude_bitcasts_and_include_wave_and_derivatives.@nathanbzrr on GitHub · 2026-11-25 21:57 UTC · original
Rebased onto
origin/main(61bfc77) and addressed the triage/review feedback:sig_scalar_maskdynamic/nonzero row indices: added arow_idx != Some(0)check that conservatively returnsall_bits(limit).60 | 61 | 64): split out from non-derivative texture/sample ops so they depend onarg_dep | dep_resource | dep_block[b].221(isHelperLane) to thearg_dep | dep_block[b]group.dx.op.*allowlist: replaced the permissive_ => arg_depfallback 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).dynamic_indexing_eval_implicit_sample_and_unknown_opcodes_are_conservativeand markedmatches_dxc_view_id_state_on_equivalent_hlslas#[ignore = "spawns external dxc.exe to cross-check PSV0 tables"].Verification
cargo run -p xtask -- policy-> 186 files okcargo clippy -p victory-shader --all-targets --locked -- -D warnings(default &--all-features) -> cleancargo test -p victory-shader --locked-> unit287 passed; 0 failed; 4 ignored,resource_tracking3 passed; 0 failed; 1 ignoredcargo test -p victory-shader --lib --locked -- matches_dxc_view_id_state_on_equivalent_hlsl --ignored->1 passed; 0 failedView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.