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

Manually merged
github merged 1 commit from gh-pr/381/head into gh-pr/381/base 2026-11-26 04:01:51 +00:00
Owner

@⁠Dufftwt on GitHub · 2026-11-24 02:48 UTC · original
Dufftwt:fix/psv-sample-frequency → main · +85 −0 · 2 files · 1 commits · merged 2026-11-24 08:09 UTC

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 #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:

  • This PR: everything passes, and dxil.dll accepts both shaders. victory-shader has 70 passed, the other crates have 0 failed.
  • The new test alone on main: the check fails (left: 0, right: 1). For the sample-rate shader, dxil.dll reports:
    error: DXIL container mismatch for 'PSVRuntimeInfo' between 'PSV0' part:(… SampleFrequency=1 …) and DXIL module:(… SampleFrequency=0 …)
    error: Container part 'Pipeline State Validation' does not match expected for module.
    
  • I ran with --test-threads=1. With 4 threads, the shader crate's GPU tests sometimes crash on that runner (#181, #244).

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.

**@⁠Dufftwt** on GitHub · 2026-11-24 02:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/381) `Dufftwt:fix/psv-sample-frequency` → `main` · +85 −0 · 2 files · 1 commits · merged 2026-11-24 08:09 UTC ## 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 #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: - **This PR:** everything passes, and `dxil.dll` accepts both shaders. `victory-shader` has 70 passed, the other crates have 0 failed. - **The new test alone on `main`:** the check fails (`left: 0, right: 1`). For the sample-rate shader, `dxil.dll` reports: ``` error: DXIL container mismatch for 'PSVRuntimeInfo' between 'PSV0' part:(… SampleFrequency=1 …) and DXIL module:(… SampleFrequency=0 …) error: Container part 'Pipeline State Validation' does not match expected for module. ``` - I ran with `--test-threads=1`. With 4 threads, the shader crate's GPU tests sometimes crash on that runner (#181, #244). **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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:01:49 +00:00
github manually merged commit 404d7fd9bd into gh-pr/381/base 2026-11-26 04:01:51 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 04:19 UTC · original

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.

**@⁠jeremygold02** on GitHub · 2026-11-24 04:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/381#issuecomment-7121914675) 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.
Author
Owner

@⁠slint6614-dev on GitHub · 2026-11-24 07:47 UTC · original

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.

**@⁠slint6614-dev** on GitHub · 2026-11-24 07:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/381#issuecomment-7125370575) 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.
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!381
No description provided.