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

Merged
Dufftwt merged 1 commit from upstream-pr/381 into main 2026-11-24 08:09:12 +00:00
Dufftwt commented 2026-11-24 02:48:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dufftwt on 2026-11-24T02:48:21Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6573483871 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/381). Originally posted by [Dufftwt](https://github.com/Dufftwt) on 2026-11-24T02:48:21Z. --- ## 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.
jeremygold02 commented 2026-11-24 06:55:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:19:33Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121914675 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/381#issuecomment-7121914675). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:19:33Z. --- 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 commented 2026-11-24 08:02:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by slint6614-dev on 2026-11-24T07:47:15Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7125370575 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/381#issuecomment-7125370575). Originally posted by [slint6614-dev](https://github.com/slint6614-dev) on 2026-11-24T07:47:15Z. --- 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.
upstream-sync closed this pull request 2026-11-24 09:05:26 +00:00
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!381
No description provided.