Skip to content

Shaders: PSV0 says a pixel shader runs per sample when an input does - #381

Merged
Marvisak merged 1 commit into
Marvisak:mainfrom
Dufftwt:fix/psv-sample-frequency
Nov 24, 2026
Merged

Marvisak merged 1 commit into
Marvisak:mainfrom
Dufftwt:fix/psv-sample-frequency

Conversation

@Dufftwt

@Dufftwt Dufftwt commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

What's wrong

Every translated shader carries a PSV0 (pipeline state validation) part. Its runtime info for a pixel shader starts with PSInfo { DepthOutput, SampleFrequency }. container::psv sets DepthOutput (byte 0) but always leaves SampleFrequency (byte 1) at 0.

DXC sets SampleFrequency = 1 whenever a pixel shader input is interpolated per sample (interpolation mode 6 LinearSample or 7 LinearNoperspectiveSample) or is SV_SampleIndex (DxilPipelineStateValidation.cpp, SetShaderProps, pixel case). Our lowering does produce such inputs: barycentrics from PERSP_SAMPLE / LINEAR_SAMPLE (SPI_PS_INPUT_ADDR bits 0 and 3) get modes 6 and 7 (lower.rs).

For those shaders the part contradicts the module:

  • The DXIL validator compares the whole runtime info with what it derives from the module, so it rejects them ("Pipeline State Validation does not match"). This adds to the validation failures counted in Corpus census: 185 emitted DXIL modules fail dxil.dll validation #201.
  • The runtime and driver are told the shader runs per pixel when it needs to run per sample.

What the fix does

For a pixel shader, psv sets SampleFrequency to 1 when any input element has interpolation mode 6 or 7, or is SV_SampleIndex (semantic kind 12), as DXC does. It's 0 otherwise.

How it behaves after the fix

Pixel shaders that interpolate at sample positions declare it in PSV0, so they match what DXC would produce. Every other shader's PSV0 is byte-for-byte unchanged.

Tests

The new test sample_interpolated_inputs_set_psv_sample_frequency (in emit/mod.rs) translates a pixel shader that interpolates one input (v_interp_p1/p2_f32) twice:

  • with center barycentrics (SPI_PS_INPUT_ADDR bit 1), where SampleFrequency must be 0;
  • with sample barycentrics (bit 0), where it must be 1.

Where dxil.dll is available, as on GitHub's Windows runner, the test also passes the shader through the validator, as stub_pipeline_is_created and constant_color_validates already do.

I ran cargo test --workspace on GitHub's windows-latest with Rust 1.98.1 from rust-toolchain.toml, and the shader crate's tests on Linux:

Not tested: a title's sample-rate pixel shaders on a GPU.

Related: #136 and #306 edit psv() elsewhere, and neither sets this field. This PR merges cleanly with both.

The pipeline state validation part left PSInfo.SampleFrequency at 0.
DXC sets it when a pixel input is interpolated per sample (modes 6 and
7, which our lowering gives to PERSP_SAMPLE and LINEAR_SAMPLE
barycentrics) or is SV_SampleIndex, and the validator compares the
whole runtime info with what it derives from the module.

The flag is now set for such pixel shaders.
muhammed-aksoy pushed a commit to muhammed-aksoy/VIctory that referenced this pull request Nov 24, 2026
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
… an input does

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

Copy link
Copy Markdown
Contributor

Thanks @Dufftwt for this PSV0 metadata fix. I tested head 404d7fd9bd9ee4f1d1a54eca9e8fed369ae29f83 with:

cargo test --locked -p victory-shader --lib sample_interpolated_inputs_set_psv_sample_frequency -- --test-threads=1

Result: 1 passed, 0 failed (69 filtered out). The test emits a shader with sample-interpolated inputs and verifies the PSV0 sample-frequency flag. It checks container metadata generation, not pixel execution on a GPU.

@slint6614-dev

Copy link
Copy Markdown

Measured on the full retail shader pack (26,503 containers) with victory translate --validate, against main d2a4bae (emitted / validated). Windows 11, dxil.dll from SDK 10.0.26100.

VS/PS MS validator failures changed
main 12272 / 12172 8191 / 8129
#554 12272 / 12214 8191 / 8130 clears all 49 "interpolation mode that differs from another element packed into the same row"; "Program Input Signature does not match" 21 → 23, "Program Output Signature does not match" 25 → 29
#565 12272 / 12186 8191 / 8129 clears the 14 "Interpolation mode for PS input position must be linear_noperspective_centroid…"
#381 12272 / 12172 8191 / 8129 none on this pack
#306 12316 / 12316 8191 / 8138 clears both kinds above and the signature mismatches (all VS/PS that emit validate)

cargo test -p victory-shader passes on all four.

@Marvisak
Marvisak merged commit c30fc99 into Marvisak:main Nov 24, 2026
suirentakamura pushed a commit to suirentakamura/VIctory that referenced this pull request Nov 24, 2026
Shaders: PSV0 says a pixel shader runs per sample when an input does
itsonlysimbo pushed a commit to itsonlysimbo/VIctory that referenced this pull request Nov 24, 2026
Shaders: PSV0 says a pixel shader runs per sample when an input does
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants