Skip to content

Shaders: use validator 1.8 for compute derivatives - #1065

Open
Halfect wants to merge 1 commit into
Marvisak:mainfrom
Halfect:fix/cs-implicit-sample-dxil18
Open

Halfect wants to merge 1 commit into
Marvisak:mainfrom
Halfect:fix/cs-implicit-sample-dxil18

Conversation

@Halfect

@Halfect Halfect commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What

Validators before 1.8 reject gradient operations outside the pixel stage with Entry function performs some operation that is incompatible with the shader stage, although a compute shader using them is valid SM 6.x. The emitter declares every shader as validator 1.6, so those compute shaders are rejected even though they emit cleanly.

The emitter now derives the validator version from the module's written calls: Module::uses (the same liveness-filtered scan that feeds the shader-feature flags) reports a gradient operation, matching DXC's gradient classification — the implicit-derivative samples (Sample 60, SampleBias 61, SampleCmp 64), the LOD query (CalculateLOD 81), and the explicit derivatives (DerivCoarseX/Y, DerivFineX/Y, 83–86). Only a non-mesh compute shader with a live gradient op:

  • writes dx.valver 1.8 instead of 1.6;
  • emits the validator-1.8 PSV0 layout (runtime info version 3, 52 bytes, naming the entry point at strings offset 1) instead of the 1.6 layout (version 2, 48 bytes).

Bfi and the dot products (53–56) are arithmetic and stay on 1.6; SampleGrad/SampleLevel (62/63) take explicit gradients and are already accepted in compute. Because the decision looks at the written calls, a dead call — a sample whose result nothing reads, dropped by the writer — does not bump the version, and a shader without live gradient ops declares 1.6 by reusing the dx.version metadata node: vertex, pixel, mesh and gradient-free compute shaders are byte-identical to before (the new byte-pin test matches main's exact containers).

Adds five Windows regressions: a compute shader with an implicit sample validates (and its forced-1.6 twin is rejected), a compute DerivCoarseX validates at 1.8 and is rejected at 1.6, a compute Dot3 keeps validator 1.6 and validates, a compute sample with a discarded result stays on 1.6 and validates, and the derivative-free pixel/compute containers are byte-pinned.

Host runtime note. A validator-1.8 container also needs a host runtime that accepts one. Current Windows 11 D3D12 and the SDK 10.0.26100 validator accept it, but an older host runtime would refuse such a compute pipeline at creation time rather than at translation. The bump is per shader, so only the gradient-using compute programs (24 measured below) are affected; every other shader stays a 1.6 container.

Offline title measurement

translate --validate --list --jobs 4 over the local 1.0.2.1 shader archive (26,503 containers, dxil.dll 10.0.26100), comparing main ffe310e with this head across 25,896 matched program labels:

  • Compute: 1,417 → 1,441 validated of 1,441 emitted. The only outcome transitions are the 24 compute programs that stopped at the incompatible with the shader stage validator error and now validate.
  • Vertex/pixel (12,231 emitted / 12,155 validated) and mesh (8,214 / 8,152) outcomes are identical; 0 regressions.

Checks

  • cargo test --locked -p victory-shader --lib, CPU-only suite skipping the GPU groups (diff_tests, valu_tests, waterfall_tests, stub_pipeline_is_created) and heap_direct_texture_reads_mark_their_heap_index: 230 passed, 3 failed, 3 ignored. The three failures (stride_tests pair, gathers_at_a_level_match_the_hardware) reproduce identically on unmodified 13f91ca on this machine, and the skipped heap test aborts the harness (STATUS_ACCESS_VIOLATION) identically on unmodified 13f91ca here — all pre-existing D3D12-device environment issues; this PR changes no code they exercise.
  • The six emit::shader tests pass with the SDK 10.0.26100 dxil.dll validator actually loaded (no skips), including the forced-1.6 negative controls.
  • cargo clippy --locked -p victory-shader --lib --tests -- -D warnings: clean.
  • cargo xtask policy: 184 files ok. git diff --check: clean.

Offline translation and DXIL validation only; no title executable or world run, and no shader contents or extracted data included. AI-assisted (Kimi).

JMAN730 pushed a commit to JMAN730/project-flamingo that referenced this pull request Nov 24, 2026

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validator 1.8 for compute derivatives — the detection is right for everything Victory emits today. I checked the DXIL opcodes the lowering actually produces in compute (sample.f32 60, sampleBias 61, sampleLevel 62, sampleGrad 63, sampleCmp 64/sampleCmpLevelZero 65, textureLoad 66, textureGather 73 at emit/lower.rs:5940-6070): the flagged set 53..=56 | 60 | 61 | 64 | 81 covers exactly the implicit-derivative forms (60/61/64) and correctly excludes the explicit-LOD/gradient ones (62/63/65) and derivative-free loads/gathers (66/73). The threads.is_some() && mesh.is_none() gate keeps pixel/vertex/mesh on 1.6, and the PSV runtime-info-3 layout (52 bytes, entry-point-name string offset at 48, \0main\0 prefix with semantic offsets shifted accordingly) matches the public D3D12 PSV spec.

Verified locally: test-merge with main (ffe310e) clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 96 passed / 0 failed / 1 ignored. Scope note: the new validator test is #[cfg(all(test, windows))], so the 1.8 PSV path itself is only exercised on Windows — the macOS run covers compilation and the unchanged 1.6 path. Approving on the strength of the spec match; the Windows validator run is the real gate.

@Halfect

Halfect commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @catminou4 for the close read of the flagged opcode set and the PSV0 layout. On the Windows gate: the new compute_implicit_sample_validates regression did run on Windows on this head (e8a046a2) with the SDK 10.0.26100 dxil.dll loaded, and the validator accepted the emitted 1.8 module; the CPU-only library suite there was 98 passed, 0 failed, 1 ignored. Agreed the macOS run only covers compilation plus the unchanged 1.6 path — the Windows validator result is the behavioral check for this change. Nothing further from my side; ready for review.

@hamdog0203

Copy link
Copy Markdown

Tested unmodified e8a046a independently on Windows 11 Build 26200, NVIDIA GeForce RTX 4060 (driver 621.35, 32-lane waves), Rust 1.98.1, and Windows SDK dxil.dll (10.0.26100.0):

Verification results

  • cargo clippy --workspace --all-targets --locked -- -D warnings: pass
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: pass
  • cargo test -p victory-shader --locked -- --nocapture compute_implicit_sample_validates: pass against dxil.dll (verified not skipped; forcing valver 1.6 as a negative control fails dxil.dll with Function uses features incompatible with the shader stage (cs))
  • cargo test --workspace --locked (RTX 4060): all workspace tests pass (victory-shader: 121 passed, 0 failed, 1 benchmark ignored)
  • VICTORY_WARP=1 cargo test -p victory-shader --locked: 121 passed, 0 failed, 1 ignored
  • cargo xtask policy: 154 files ok
  • Extra probe (Host::compute_pipeline on RTX 4060): CreateComputePipelineState succeeds with the validator-1.8 / PSVRuntimeInfo3 container for both [32, 1, 1] and [8, 8, 1] thread groups.

One code-review note (crates/victory-shader/src/emit/shader.rs)

In Shader::op:

matches!(opcode, 53..=56 | 60 | 61 | 64 | 81)

In DXIL, 53..=56 are UMsad / Dot2 / Dot3 / Dot4, whereas explicit derivatives (DerivCoarseX, DerivCoarseY, DerivFineX, DerivFineY) are 83..=86. Verified against dxil.dll with dx.op.unary.f32(83, ...) in a compute shader: dxil.dll still rejects it on e8a046a (because dx.valver stays 1.6), and accepts it when validator18 is enabled.

Synthetic tests + dxil.dll + RTX 4060 hardware only; no game data. AI-assisted.

@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 e8a046a: 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).

@Halfect
Halfect force-pushed the fix/cs-implicit-sample-dxil18 branch from e8a046a to 37f838d Compare November 24, 2026 16:33
@Halfect

Halfect commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @hamdog0203 — you were right on both counts. Fixed in 37f838d:

  • The flagged set is now exactly DXC's gradient classification: 60 | 61 | 64 | 81 | 83..=86. 53..=56 (Bfi/Dot2/Dot3/Dot4) are arithmetic and no longer bump the validator version, so a derivative-free compute shader using them stays byte-identical to main. Explicit derivatives (DerivCoarseX/Y, DerivFineX/Y, 83–86) now trigger 1.8 as your probe showed they must.
  • New Windows regressions alongside the implicit-sample one: compute_explicit_derivative_validates (op 83 validates at 1.8; its forced-1.6 twin is rejected) and compute_dot3_stays_on_validator_1_6 (op 55 does not set the flag, and the resulting 1.6 module validates). The implicit-sample test also gained your forced-1.6 negative control.

Validation on this head (Windows, SDK 10.0.26100 dxil.dll): the three regressions pass with the validator actually loaded; the CPU-only library suite is 100 passed, 0 failed, 1 ignored; clippy -D warnings and cargo xtask policy (154 files) clean. No GPU execution was used.

I also reran the offline A/B against current main ffe310e (26,503 containers, 25,896 matched labels): compute 1,417 → 1,441 validated of 1,441 emitted; the only transitions are 24 × incompatible with the shader stage → validated; vertex/pixel and mesh outcomes are identical, 0 regressions. The PR body is updated with the corrected opcode set and this measurement. Ready for another look.

@adamdotpy

Copy link
Copy Markdown

Reviewed on Windows 11 / Rust 1.98.1, 37f838d on current main (ffe310e, merges as it stands), isolated target dir. Verified: cargo test -p victory-shader --lib 123 passed / 1 ignored, including the three new tests; clippy --all-targets --all-features --locked -D warnings clean; release build of victory fine.

The validation tests really ran here, and they are the decisive evidence. dxil.dll from SDK 10.0.26100 is present at the validator's default path on this machine, so with --nocapture there is no "no dxil.dll; skipped" line: compute_implicit_sample_validates builds a compute shader calling sample (opcode 60), validates the 1.8 container successfully, and asserts the same module declared 1.6 is rejected; compute_explicit_derivative_validates does the same for DerivCoarseX (83); compute_dot3_stays_on_validator_1_6 confirms dot products (55) do not bump the version and still validate at 1.6. That is exactly the check I asked #539 and #1127 to carry for their SFI0 bits — this PR is the template for it.

What checked out in the emitter. Detection happens in op() and is gated on threads.is_some() && mesh.is_none(), so pixel and mesh shaders are untouched and only compute shaders with a derivative-class opcode bump — minimal blast radius, and dx.valver is written in finish(), after every op, so the flag is complete by then. The opcode set matches the comment's reasoning (implicit-derivative samples 60/61/64, LOD 81, explicit derivatives 83..=86; SampleLevel/SampleGrad 62/63 excluded because they take explicit gradients). The PSV0 change is the validator 1.8 runtime-info-3 layout: 52-byte info with the entry-point string offset at 48, and the strings section starting "\0main\0" — consistent with the DXIL metadata change in the same commit.

Two notes, neither blocking.

  • The entry-point name is hard-coded "main" in the PSV0 strings. The emitter's entry is always main today, so it is correct, but an assert or comment tying the two would keep them from drifting if the entry name ever changes.
  • Validator 1.8 containers need a host runtime that accepts them. The SDK validator here accepts them and current Windows 11 D3D12 does too, but a host with an older runtime would fail pipeline creation at runtime rather than at translation — worth one line in the PR body so a "pipeline fails on my older Windows" report has the answer. Keeping the bump per-shader (only compute-with-derivatives) is what makes that rare.

Side note for the two 64-bit-atomic PRs (#539, #1127): the open question I left them — which SFI0 flags dxil.dll demands for atomicBinOp.i64 — is settled the same way this PR settles the validator version: emit the op, validate at each candidate flag set, keep the one that passes and assert the other fails. Neither PR has that yet.

@Halfect

Halfect commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @adamdotpy for the careful review — especially for confirming the three regressions really validated rather than skipped, and for checking the gating and PSV0 layout against the DXIL rules.

Both notes addressed:

  • Host runtime: added a "Host runtime note" to the PR body, with your framing — a 1.8 container fails at pipeline creation on an older host runtime, not at translation, and the per-shader bump keeps that to the 24 measured compute programs.
  • Hard-coded "main": agreed. Shader::finish always names the entry main today; I'll tie the PSV0 string to it with a comment/assert on the next push, if one is needed. I'd rather keep the reviewed head 37f838d stable than churn it for a comment-only change.

One disclosure for the maintainer's choice, since you reviewed this closely: #306 bundles an equivalent compute-derivative change (same dx.valver 1.8 + runtime-info-3 mechanism) alongside four other fixes. The differences here: this PR's flagged set additionally covers the explicit derivatives (83–86, after @hamdog0203's DXC classification correction; #306 flags only 60/61/64/81), the detection sits in Shader::op so any emission path is covered, and it carries the forced-1.6 negative controls. Both clear the same observed census group (all 24 failing programs call sample); this one is the focused single-purpose version.

Nothing further from my side; ready for review.

@rafaconvaitis

Copy link
Copy Markdown

I independently tested the host-runtime question on 37f838d using two synthetic shaders, without game data. On Windows 11 build 26300, both the NVIDIA GeForce RTX 4070 (driver 32.0.16.1664, adapter confirmed by device LUID) and inbox WARP created the signed DXIL 1.8 compute PSOs and executed one four-thread group.

Instruction shape Readback on each backend
DerivCoarseX(float(SV_GroupThreadID.x)) [1.0, 1.0, 1.0, 1.0]
Implicit sample of a constant 1×1 RGBA32F texture [7.25, 7.25, 7.25, 7.25]

The equivalent forced-1.6 controls were rejected by Microsoft's dxil.dll 1.8.2502.8 validator before PSO creation, as expected. This confirms execution and readback for the two instruction shapes on this host. Older D3D12 runtimes and the title's actual shaders are outside this result. The fixture also passed focused Clippy with warnings as errors.

AI-assisted test fixture and reporting.

@adamdotpy

Copy link
Copy Markdown

Thanks for the independent confirmation @rafaconvaitis — RTX 4070 + WARP both creating and executing the signed DXIL 1.8 compute PSOs with the 1.6 controls rejected by dxil.dll 1.8.2502.8 matches what I measured on 37f838d here (validator really ran, not skipped). That closes the host-runtime question on current hardware/driver; noted on the thread.

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
@zed6000

zed6000 commented Nov 24, 2026

Copy link
Copy Markdown

Measured on the new main 70564ae, the largest remaining gap there. With dxil.dll 1.8.2502, 735 compute programs emit on 70564ae but fail validation with "Entry function performs some operation that is incompatible with the shader stage". This PR clears all of them.

This PR conflicts with 70564ae in two hunks, because main added geometry shaders in the same places. I merged it onto 70564ae and resolved both by keeping both sides:

  • emit/container.rs, psv(): main's if let Some(max) = p.gs { ... } block stays. Your if p.validator18 { info[48..52] ... } block follows it, and the final line is your out.extend(&info[..info_size as usize]), not main's out.extend(info).
  • emit/shader.rs, dx.valver: your 1.6/1.8 selection from self.compute_derivatives, with main's updated comment (0 pixel, 1 vertex, 2 geometry, 5 compute, 13 mesh).

The result, measured with victory translate --validate --list on shaders.rpf (1.0.2.1) and compared program by program with 70564ae:

Validated Compute validated
main 70564ae 24,785 1,886 of 2,621
70564ae + this PR 25,520 (+735, 0 lost) 2,621 of 2,621

On the merged tree, cargo test -p victory-shader --lib gives 212 passed and 0 failed on an RX 7900 XTX (RDNA3). Clippy with -D warnings is clean with and without --all-features.

Offline counts only; no program names or data, per the asset policy.

@alessiodeia

Copy link
Copy Markdown
Contributor

Independent confirmation of @zed6000's merge onto 70564ae, on NVIDIA (RTX 2070 SUPER, Turing, driver 621.40). I resolved the two hunks the same way, independently: main's p.gs block followed by validator18, then out.extend(&info[..info_size as usize]), and the 1.6/1.8 dx.valver selection with main's geometry comment. The branch is alessiodeia:rebase/1065-on-70564ae (6e26c67) if anyone wants it.

Same counts, program by program over shaders.rpf with dxil.dll 1.9.2609: validated 24,785 → 25,520 (+735, 0 lost), compute 1,886 → 2,621 of 2,621. The only validator failure left on the merged tree is the 71 mesh programs with vertex plus primitive output size is greater than 32768, which 70564ae has as well.

Workspace clippy -D warnings is clean. On this card cargo test -p victory-shader has 3 failures: stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros and synthetic_tests::gathers_at_a_level_match_the_hardware. All 3 fail identically on clean 70564ae here (dispatch failed: E_INVALIDARG on the hardware device), so they're NVIDIA-side issues on main, not this PR.

AI-assisted (Claude Code). Offline counts only.

@zed6000

zed6000 commented Nov 24, 2026

Copy link
Copy Markdown

@alessiodeia thanks for the independent confirmation. On the three test failures: on clean 70564ae all three pass on AMD (RX 7900 XTX, RDNA3, hardware device, no WARP):

  • stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride
  • stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros
  • synthetic_tests::gathers_at_a_level_match_the_hardware

That run gives 209 passed, 0 failed, 2 ignored (the opt-in bitcode bench and the documented fused-multiply-add defect). Your dispatch failed: E_INVALIDARG on Turing therefore looks NVIDIA-specific, as you suspected, and unrelated to this PR.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work. Needs the maintainer's decision. Since cbd152c the only change is the requested comment at the validator-1.8 decision in Shader::finish (emit/shader.rs), explaining that in multi-row groups the host forms quads from 2x2 tiles while the console's quads are four lanes of one row. The decision itself is open: with this PR, 2D compute groups validate but take their implicit level from the host's tiling (RX 6750 XT and RX 7900 XTX read level 3 where the console gives level 1), and #2999 handles the quad layout for multi-row groups. Whether to take 1.8 now, right only for one-row groups, or to wait for that approach is the maintainer's call.

CI: passing.


Generated by Claude Code

@Halfect

Halfect commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main 13f91ca and pushed d22149a; the emit/shader.rs conflict resolved by keeping both sides (main's UAV-declaration test alongside this PR's derivative tests). The branch merges cleanly again.

One fixture fix the rebase exposed: main's writer now drops a call nothing reads ("a phi or a value nothing reads is dropped"), and these tests called the sample/derivative ops with dead results — so the emitted modules no longer contained a gradient op and the forced-1.6 negative controls were vacuously accepted (caught locally: both negative controls failed after the plain rebase). The fixtures now branch on the operations' results (extract + compare + conditional branch), which keeps the calls live; the negative controls reject again.

Validation on d22149a (Windows, CPU-only, SDK 10.0.26100 dxil.dll really loaded):

  • cargo test --locked -p victory-shader --lib emit::shader: 4 passed / 0 failed — including both forced-1.6 negative controls rejecting and main's uavs_outside_pixel_and_compute_programs_are_declared.
  • Full library suite (skipping heap_direct_texture_reads_mark_their_heap_index, which aborts the harness with an access violation on this machine, identically on unmodified main): 269 passed, 3 failed — the same three D3D12-device dispatch tests (stride_tests pair, gathers_at_a_level_match_the_hardware) that fail on clean main here.
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings: clean. cargo xtask policy: 184 files ok. git diff --check: clean.

No GPU, no game data. AI-assisted (Kimi).

@zed6000

zed6000 commented Nov 25, 2026

Copy link
Copy Markdown

Measured on current main. The rebased head d22149a, merged onto main 13f91ca (a clean merge), with the same method as before (victory translate --validate --list, shaders.rpf 1.0.2.1, dxil.dll 1.8.2502, program by program):

Validated "Entry function ... incompatible with the shader stage"
main 13f91ca 24,846 748
13f91ca + d22149a 25,594 (+748, 0 lost) 0

The count is 748 now rather than 735: since 940d32f, 13 more compute programs reach emission on main and then hit the same validator error, and this PR clears them too. cargo test -p victory-shader --lib on the merged tree gives 273 passed and 0 failed on an RX 7900 XTX. This is the largest single remaining gap on main. Offline counts only; no program names or data.

@Halfect

Halfect commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @zed6000 for the fresh A/B on the rebased head. The numbers line up with the change's intent: 748 compute programs move from incompatible with the shader stage to validated, 0 lost, vertex/pixel and mesh identical — and the 735 → 748 delta is explained by the 13 compute programs that started reaching emission on main since 940d32f and hit the same validator error. Good to also have the merged tree green on the RX 7900 XTX (273 passed). Nothing further from my side; ready for review.

@brainbudt

Copy link
Copy Markdown

Note

🤖 Gemini 4 Neon (with GPT-6.2 Astra, Mistral Large 4, and DeepSeek V4.1 Flash) responding on behalf of brainbudt

Independently tested d22149ae merged with 13f91cae (Windows 11 + Microsoft dxil.dll 1.8.2505.32 + WARP, Linux x86-64, and Windows MSVC cargo check --tests). All four focused Windows emitter tests passed with dxil.dll 1.8.2505.32 loaded, including both forced-1.6 negative controls, and WARP created the live derivative pipeline.

Two issues found before merge:

  1. Dead image_sample still declares validator 1.8 (crates/victory-shader/src/emit/shader.rs:250): When a synthetic GFX10 compute shader discards its image_sample result, dxc -dumpbin shows zero sample calls on both main and this PR, yet this PR still emits validator 1.8. Microsoft validator 1.7 accepts main's output and rejects this PR's output (Validator version in metadata (1.8) is not supported; maximum: (1.7)). Deriving the 1.8 selection from live emitted calls in Module::uses() (with a dead-sample regression test) avoids this regression.
  2. Extra metadata node changes DXIL bytes on the 1.6 path (crates/victory-shader/src/emit/shader.rs:922): Plain vertex (+8 B), pixel (+8 B), and compute (+4 B) shaders change DXIL bytes and container hashes on the 1.6 path. Reusing the existing version metadata node on the 1.6 path restores the base hashes (verified on pixel and Dot3 compute controls).

@gmankab

gmankab commented Nov 25, 2026

Copy link
Copy Markdown

I adapted this commit to the native Linux branch and ran the three derivative regressions with Microsoft's Linux libdxil 1.9.2609. All three executed and passed. The implicit-sample and explicit-derivative controls with validator 1.6 were rejected as expected, and the arithmetic control kept validator 1.6.

In a separate native RX 6800 test, both descriptor paths hit a GPUVM invalid read in the same compute-indirect breadcrumb range. The translated shader in that range contains implicit samples and the Linux validator rejects its original 1.6 container with the stage error described here. That identifies a validation defect in the suspect shader. The patched hardware run will test whether the GPU fault persists.

Tested-on: Fedora Linux 45, Microsoft Linux DXIL validator 1.9.2609
Assisted-by: gpt-6.2 sol xhigh

@Halfect

Halfect commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @brainbudt — both findings were real, fixed in cbd152c.

1. Dead image_sample declaring 1.8. The eager flag in Shader::op is gone. Module::uses — the liveness-filtered scan that already feeds the SFI0 feature flags — now also reports gradient operations, reading a live dx.op call's opcode (its first argument); finish derives the decision as uses.derivatives && compute && !mesh, so a call the writer drops declares nothing. Your regression exists as a_dead_sample_stays_on_validator_1_6: a compute image_sample with a discarded result declares 1.6 and validates with the SDK 10.0.26100 dxil.dll.

2. Extra metadata node on the 1.6 path. dx.valver now reuses the dx.version node unless 1.8 is actually declared. Pinned by a_shader_without_derivatives_reuses_the_version_node (len + FNV of a minimal pixel and a minimal compute container); I also verified those pins against unmodified 13f91ca in a scratch test — pixel (1268, 0x0cf4762f4d364c15), compute (1252, 0xe811e2546d1c9513), identical on both — so the 1.6 path is byte-identical to before this PR.

The forced-1.6 negative controls survive through a test-only override (force_validator18), since the live-call derivation would otherwise re-derive 1.8 for the control module.

@gmankab Thanks for the native-Linux run — good to have all three regressions passing with the Linux libdxil 1.9.2609, and the 1.6 controls rejected as expected.

Validation on cbd152c (Windows, CPU-only): the six emit::shader tests pass with dxil.dll actually loaded; the CPU-only library suite is 230 passed, 3 failed — the same three pre-existing D3D12-device failures (stride_tests pair, gathers_at_a_level_match_the_hardware) that fail identically on unmodified 13f91ca on this machine, and the heap_direct_texture_reads_mark_their_heap_index harness abort also reproduces on unmodified 13f91ca; clippy -D warnings clean; cargo xtask policy 184 files ok; git diff --check clean. The PR body is updated to match.

AI-assisted: Kimi.

@zed6000

zed6000 commented Nov 25, 2026

Copy link
Copy Markdown

Re-measured the new head cbd152c on main 13f91ca (a clean merge), with the same method (shaders.rpf 1.0.2.1, dxil.dll 1.8.2502, program by program): +748, 0 lost (25,594). These are exactly the same 748 programs as d22149a, so the narrower 1.8 detection changes no program's outcome on this title. cargo test -p victory-shader --lib gives 275 passed and 0 failed on an RX 7900 XTX. Offline counts only; no program names or data.

@Halfect

Halfect commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @zed6000 for the quick re-measure on cbd152c — the same 748 programs at +748 / 0 lost confirms the liveness-based detection (and the reused dx.version node on the 1.6 path) changed no program's outcome, which is exactly what @brainbudt's two findings required. CI is green on this head as well (check passed in run 45702073311). Nothing further from my side; ready for review.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
@fuzeofficlal

Copy link
Copy Markdown
Contributor

Code review and Windows SDK 10.0.26100.0 dxil.dll + RTX 5090 + WARP verification at head cbd152cc1d92 merged cleanly onto main (63bcca43c6a0; emit/lower.rs untouched):

  • Code review (emit/bitcode.rs:528-558, emit/shader.rs:914-925, emit/container.rs:169-251):
    • Module::uses() scans only live emitted instructions (plan.live) for DXIL derivative/implicit-sample ops (60 | 61 | 64 | 81 | 83..=86), so dead samples eliminated before writing do not bump the validator version.
    • Only non-mesh compute shaders with live derivatives declare dx.valver = (1, 8) and PSV0 RuntimeInfo v3 (52 B with entry name offset 1); all other shaders stay byte-for-byte on validator 1.6 and PSV0 v2 (48 B).
  • Verified (Windows 11, Windows SDK 10.0.26100.0 dxil.dll, NVIDIA RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy (default + --features diagnostics): 0 warnings
    • emit::shader::tests (6/6, including live dxil.dll validation of compute implicit sample & explicit derivatives and 1.6 preservation on dead/non-derivative shaders), emit::container:: (1/1), emit::bitcode:: (12/12, 1 ignored), and emit::semantics_tests (34/34 on both RTX 5090 and WARP, 1 ignored) all passed.

LGTM.

@Halfect

Halfect commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @fuzeofficlal for the careful code review and the RTX 5090 + WARP verification — especially for confirming the liveness-based detection in Module::uses (dead samples no longer bump the version) and the byte-identical 1.6 path for non-derivative shaders. Good to have the six emitter tests validating with the SDK dxil.dll really loaded on another machine. Nothing further from my side; ready for review.

@wwwwwwww3333333

Copy link
Copy Markdown
Contributor

For comparison: #2999 (on top of #1237) has a GPU test with an [8, 8, 1] group whose lane quads give level 1 and whose 2x2 tiles give level 3. With this PR rebased onto main 63bcca4 it read 3 on an RX 6750 XT, since the host's compute derivatives use 2x2 tiles of threads in a two-dimensional group, while the console's quad is four threads of one row. In one-row groups the two agree, as the earlier comparisons found.

@zed6000

zed6000 commented Nov 26, 2026

Copy link
Copy Markdown

The same on RDNA3, to go with the RX 6750 XT result above. I applied #2999's synthetic_tests.rs (only the test, none of its lowering) to this PR's head cbd152c merged onto main 63bcca4 and ran compute_samples_take_derivatives_from_lane_quads on an RX 7900 XTX: it fails with wave32 hardware: thread (0, 0) sampled level 3, the lane quads give 1 (2x2 tiles give 3). So RDNA3 also forms compute quads from 2x2 tiles in an [8, 8, 1] group. On #2999 itself the same test reads level 1 on every lane, in Wave32 and Wave64, on hardware and WARP.

On this title's census the two tie: #1065 and #2999 each gain exactly the same 748 programs on 63bcca4, 0 lost (measured on #2999 and in #1247). The difference is which mip 2D compute groups sample on the host. Offline tests only; no program names or data.

Validators before 1.8 reject gradient operations outside the pixel
stage; declare 1.8 for a compute shader that uses them, with the PSV0
runtime-info-3 layout that requires. The regression fixtures branch on
the operations' results so the writer keeps the calls (a call nothing
reads is dead).
@Halfect
Halfect force-pushed the fix/cs-implicit-sample-dxil18 branch from cbd152c to b96509e Compare November 26, 2026 04:05
@Halfect

Halfect commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the triage's needs-work point in b96509e (comment-only change; the declaration logic is untouched).

The 1.8 decision in Shader::finish now states the limitation in place: declaring 1.8 makes a derivative-using compute program accepted, but the host's derivative semantics are not the console's — console compute lanes are x-major, so a quad of a multi-row group is four lanes of one row, while the host forms 2x2 tiles; an implicit level (and DerivCoarseY/FineY) of a multi-row group therefore comes from the host's tiling, not the console's row. One-row groups agree either way, which is why the earlier one-row measurements showed no difference. Reproducing the console's quad layout for multi-row groups (the #2999 direction) is noted as future work that does not gate this declaration.

That framing also matches the measurement position: this PR is the validation step — it moves the 748 measured compute programs from incompatible with the shader stage to validated with 0 losses; the quad-layout correctness question applies to what those programs then compute and belongs to the follow-up work.

Validation on b96509e (Windows, CPU-only, SDK 10.0.26100 dxil.dll really loaded): the six emit::shader tests pass, including both forced-1.6 negative controls; cargo clippy --locked -p victory-shader --lib --tests -- -D warnings clean; cargo xtask policy 184 files ok; git diff --check clean. No GPU, no game data. AI-assisted (Kimi).

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
Steenax6 added a commit to Steenax6/VIctory-NVID that referenced this pull request Nov 26, 2026
…f lanes

image_sample and image_sample_b in compute programs read level 0 (a bias:
that level): DXIL before validator 1.8 has no derivatives outside pixel
shaders. The console takes the level from each quad of lanes (lanes
4n..4n+3, coarse: lane 1 less lane 0 across, lane 2 less lane 0 down).
Those differences are now read with waveReadLaneAt and passed to
sampleGrad; a bias scales them by 2^bias, which selects the same level
for isotropic filtering. The programs are the sky, fog and
in-scattering, the ray-traced shadow denoisers, the irradiance cache and
light probes and the ray-tracing resolves (upstream counted 535 compute
programs). They count as reading other lanes now (console lane order and
wave size), as quad swizzles do; a wave64 program still runs in host
waves of 32, since a quad never crosses a half. Cubes take the
gradients of the direction, as a pixel shader's implicit sample does.
Vertex and mesh programs keep level 0.

From Marvisak/VIctory PR Marvisak#1237 (felicienradio), with the bias scale and
the cube case as Belobug/VIctory-Belobug-AMD c78056c has them; the
alternative Marvisak#1065 (validator 1.8, DXIL derivatives) is not taken: it
changes the container layout and needs a newer validator on the player's
machine. New test: four lanes on a cube with levels read log2 of the
quad's step on the RTX 4070 Ti (WARP has no waves of 32 and is skipped).

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.