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

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 records when a non-mesh compute shader calls a gradient op — 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 for those shaders it:

  • 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. Vertex, pixel, mesh and gradient-free compute shaders are byte-identical to before.

Adds three 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, and a compute Dot3 keeps validator 1.6 and validates.

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 37f838d 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): 100 passed, 0 failed, 1 ignored, including the three regressions above with their Windows DXIL validations (SDK 10.0.26100 dxil.dll).
  • cargo clippy --locked -p victory-shader --lib --tests -- -D warnings: clean.
  • cargo xtask policy: 154 files ok.

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
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
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
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.

Merge candidate. Recommending a look, not approving. The head is the same as at the earlier note, and it still merges cleanly onto main.

  • Shader::op in emit/shader.rs flags non-mesh compute shaders that call a gradient op (60/61/64/81, 83..=86). For those shaders alone, finish writes dx.valver 1.8, and psv in emit/container.rs emits runtime info 3 (52 bytes, with the entry name at string offset 1). Every other shader keeps the 1.6 layout byte for byte. main still declares 1.6 for every shader, and lower.rs still emits sample/sample_b in compute.
  • The Windows 10 measurement in the thread (Agility runtime, which SM 6.6 needs anyway) shows the 1.8 compute containers getting pipelines just as on main. That answers the host-runtime caveat in the PR body.
  • Overlap: Shaders: implicit-level samples in compute take their gradients from the quad #1237 fixes the same validator rejections a different way (quad gradients in lower.rs). It does not merge cleanly at present, and the thread measures both as equal on the title's shaders. Which approach to take is the maintainer's call.

CI: check passing.

On your reply: noted. Nothing in it changes the verdict.


Generated by Claude Code

@zed6000

zed6000 commented Nov 25, 2026

Copy link
Copy Markdown

For the "needs rebase" triage above: a rebase onto current main exists and is measured. This PR merged onto 70564ae with the two-hunk resolution described above (the same resolution as alessiodeia's rebase/1065-on-70564ae) merges cleanly onto main 4118f33. Measured there:

Validated Compute validated
main 4118f33 24,785 1,886 of 2,621
4118f33 + the rebased PR 25,520 (+735, 0 lost) 2,621 of 2,621

cargo test -p victory-shader --lib on the merged tree gives 249 passed, 0 failed on an RX 7900 XTX. The 137 merges between 70564ae and 4118f33 don't change any program's outcome on this data, so the earlier numbers still hold. All 735 are the "Entry function performs some operation that is incompatible with the shader stage" rejections, the largest remaining gap on main. Offline counts only; no program names or data.

Flag exactly DXC's gradient-op classification in non-mesh compute:
the implicit-derivative samples (60/61/64), the LOD query (81), and
the explicit derivatives (83..=86). Validators before 1.8 reject all
of these outside the pixel stage. 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.
@Halfect
Halfect force-pushed the fix/cs-implicit-sample-dxil18 branch from 37f838d to e198449 Compare November 25, 2026 01:20
@Halfect

Halfect commented Nov 25, 2026

Copy link
Copy Markdown
Author

Rebased onto current main ccfb029 and pushed e198449. Both conflict resolutions keep main's geometry-shader handling alongside the validator-1.8 behavior; the PR still changes only emit/container.rs and emit/shader.rs (+155/-10).

Validation on macOS with the project toolchain (Rust 1.98.1):

  • cargo test --locked -p victory-shader --lib -- --skip diff_tests --skip valu_tests --skip waterfall_tests --skip stub_pipeline_is_created: 144 passed, 0 failed, 2 ignored.
  • cargo xtask policy: 182 files ok.
  • cargo clippy --locked -p victory-shader --lib --tests -- -D warnings stops on five warnings that reproduce identically on clean main ccfb029 (checked in a separate worktree). They are in emit/mod.rs / emit/lower.rs, which this PR does not change.

Windows dxil.dll validation was not rerun on macOS; the earlier Windows validation and independent rebased A/B measurements are in the thread above.

@zed6000

zed6000 commented Nov 25, 2026

Copy link
Copy Markdown

@Halfect confirmed on the title's shaders. Your rebased head e198449, merged onto main ccfb029 (a clean merge), measured with the same method (victory translate --validate --list, shaders.rpf 1.0.2.1, dxil.dll 1.8.2502, program by program):

Validated Compute validated
main ccfb029 24,785 1,886 of 2,621
ccfb029 + e198449 25,520 (+735, 0 lost) 2,621 of 2,621

cargo test -p victory-shader --lib on the merged tree gives 249 passed and 0 failed on an RX 7900 XTX (RDNA3). All 735 are the "Entry function performs some operation that is incompatible with the shader stage" rejections, the largest remaining gap on main. Offline counts only; no program names or data.

@hadrianhola

Copy link
Copy Markdown

#1065 and #1237 on Windows 10 (the "older host runtime" case), program by program. I'm not the author of either.

Host: Windows 10 22H2 (19045), RTX 4060, driver 610.88, dxil.dll 1.8.2502. The D3D12 Agility SDK 1.620 runtime sits beside victory.exe (the #175/#362 exports). The in-box runtime stops at SM 6.5, so without it Host::new refuses the device and nothing gets a pipeline.

Both PRs are merged onto main 940d32f. #1065 (e198449) merges cleanly. #1237 (a3346f9) has one conflict in lower.rs, which I resolved by keeping quad_gradients and helpers_read/helper_reads_own side by side, as @wildheathen did. Measured with victory translate --validate --pipelines --list over shaders.rpf (1.0.2.1) and compared program by program:

compute validated compute pipelines the 735 "incompatible with the shader stage"
940d32f 1,886 of 2,621 2,226 723 get a pipeline, 12 E_INVALIDARG
+ #1065 2,621 2,226 the same 723 / 12
+ #1237 2,621 2,226 the same 723 / 12

Counts only; no shader names, hashes or data. AI-assisted (Claude Code).

@Halfect

Halfect commented Nov 25, 2026

Copy link
Copy Markdown
Author

Thanks @hadrianhola for the Windows 10 run — that directly closes the host-runtime caveat in the PR body: with the Agility 1.620 runtime beside the executable (which SM 6.6 needs anyway), Windows 10 accepts all 723 of this PR's validator-1.8 containers with the same pipeline outcomes as main, and the 12 E_INVALIDARG refusals are identical on all three trees. Good to have the equivalence with #1237 measured on the older-runtime host as well. Nothing further from my side; ready for review.

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.

10 participants