Shaders: evaluate centroid reads with evalCentroid when mixed with center #3160

Open
github-bot wants to merge 1 commit from github-bot/gh-3160 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 10:34 UTC · original
fuzeofficlal:fix/shader-input-center-and-centroid → main · +259 −57 · 2 files · 1 commits · open

Summary

Previously, Lower::interp rejected any pixel input read with two different interpolation modes ("one input interpolated two ways"), refusing valid pixel shaders that read the same float input at both center and centroid (EvaluateAttributeAtCentroid).

Fix

  • Pre-scan reachable io.interps in Lower::plan_interp_modes (reusing extracted interp_mode and interp_channels helpers).
  • When a float input (comp == 9) is read only at (PerspectiveCenter, PerspectiveCentroid) or (LinearCenter, LinearCentroid), declare its input signature element at center (2 or 4) and record it in centroid_inputs.
  • During lowering, emit dx.op.loadInput.f32 for center reads and dx.op.evalCentroid.f32 (opcode 89) for centroid reads regardless of instruction order, while preserving single-mode lowering (including centroid-only and sample-frequency inputs) and continuing to reject incompatible mode combinations (such as perspective+linear, perspective+sample, or interpolated+flat).

Verification

Added four synthetic tests in crates/victory-shader/src/emit/mod.rs covering 32-bit and FP16 mixed center+centroid reads (in both orders), centroid-only preservation, and rejection of incompatible mixes:

  • cargo test -p victory-shader --locked --lib emit::tests -- --test-threads=1: 21 passed, 0 failed (validated with dxil.dll and dxc -dumpbin)
  • cargo test -p victory-shader --locked --lib emit::lower::tests -- --test-threads=1: 33 passed, 0 failed
  • cargo test -p victory-shader --locked --lib emit::diff_tests -- --test-threads=1: 5 passed, 0 failed
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings (default and --no-default-features): clean
  • cargo test -p xtask --locked policy::tests::repository_passes_policy: passed (emit/lower.rs = 523,522 B < 524,288 B)
**@⁠fuzeofficlal** on GitHub · 2026-11-26 10:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/3160) `fuzeofficlal:fix/shader-input-center-and-centroid` → `main` · +259 −57 · 2 files · 1 commits · open ### Summary Previously, `Lower::interp` rejected any pixel input read with two different interpolation modes (`"one input interpolated two ways"`), refusing valid pixel shaders that read the same float input at both center and centroid (`EvaluateAttributeAtCentroid`). ### Fix - Pre-scan reachable `io.interps` in `Lower::plan_interp_modes` (reusing extracted `interp_mode` and `interp_channels` helpers). - When a float input (`comp == 9`) is read only at `(PerspectiveCenter, PerspectiveCentroid)` or `(LinearCenter, LinearCentroid)`, declare its input signature element at center (`2` or `4`) and record it in `centroid_inputs`. - During lowering, emit `dx.op.loadInput.f32` for center reads and `dx.op.evalCentroid.f32` (opcode `89`) for centroid reads regardless of instruction order, while preserving single-mode lowering (including centroid-only and sample-frequency inputs) and continuing to reject incompatible mode combinations (such as perspective+linear, perspective+sample, or interpolated+flat). ### Verification Added four synthetic tests in `crates/victory-shader/src/emit/mod.rs` covering 32-bit and FP16 mixed center+centroid reads (in both orders), centroid-only preservation, and rejection of incompatible mixes: - `cargo test -p victory-shader --locked --lib emit::tests -- --test-threads=1`: 21 passed, 0 failed (validated with `dxil.dll` and `dxc -dumpbin`) - `cargo test -p victory-shader --locked --lib emit::lower::tests -- --test-threads=1`: 33 passed, 0 failed - `cargo test -p victory-shader --locked --lib emit::diff_tests -- --test-threads=1`: 5 passed, 0 failed - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` (default and `--no-default-features`): clean - `cargo test -p xtask --locked policy::tests::repository_passes_policy`: passed (`emit/lower.rs` = 523,522 B < 524,288 B)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:09:03 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 10:49 UTC · original · approved these changes

Verified against origin/main (63bcca4):

  • cargo test -p victory-shader --lib interpolation -- --test-threads=1: 9/9 passed (including mixed_input_interpolation_center_and_centroid, mixed_input_interpolation_center_and_centroid_f16, centroid_only_interpolation_uses_load_input, and mixed_input_interpolation_incompatible_modes_fail).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly uses evalCentroid when a pixel input mixes center and centroid reads while keeping loadInput for centroid-only inputs.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 10:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/3160#pullrequestreview-6072785355) · **approved these changes** Verified against `origin/main` (`63bcca4`): - `cargo test -p victory-shader --lib interpolation -- --test-threads=1`: 9/9 passed (including `mixed_input_interpolation_center_and_centroid`, `mixed_input_interpolation_center_and_centroid_f16`, `centroid_only_interpolation_uses_load_input`, and `mixed_input_interpolation_incompatible_modes_fail`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly uses `evalCentroid` when a pixel input mixes center and centroid reads while keeping `loadInput` for centroid-only inputs. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 11:24 UTC · original

I rendered 12 mixed center/centroid variants on 5b4f321 and compared each resolved RGBA32F pixel with a native HLSL shader using EvaluateAttributeCentroid on the same adapter. All 12 matched bit for bit on the RTX 5080, Windows WARP, and WARP 1.0.22. The parent (63bcca4) refused all 12 before creating a graphics pipeline with one input interpolated two ways.

Adapter Mismatched pixels Edge pixels changed by forcing center in each FP32 draw
RTX 5080, driver 621.40 0 / 12,288 72 / 72
Windows WARP 10.0.26100.10068 0 / 12,288 72 / 72
App-local WARP 1.0.22 0 / 12,288 72 / 72

The eight FP32 cases covered perspective and noperspective, both instruction orders, and the same or different channels of one attribute. The four FP16 cases covered both interpolation modes and both packing layouts, with explicit nearest-even rounding in the reference. Each 32×32 draw had 401 fully covered pixels and 72 partially covered pixels at 4× MSAA. On the RTX, for example, pixel (1,2) had two covered samples. The resolved center and centroid channels read 0.5057649 and 0.5169407; forcing both channels to center produced 0.5057649 twice.

The test-only commit keeps one FP32 regression with independent native, center-only, and coverage draws. Replacing the translated centroid read with a center load made the test fail at (1,2) on both the RTX and Windows WARP. To run it on this PR with the Windows SDK’s PC DXC:

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr3160-msaa-centroid
git cherry-pick 4212e48f02b9b67636dcd5a983bb571ea7cbe613
cargo test --locked -p victory-shader --lib mixed_input_matches_centroid_on_msaa_edges -- --nocapture --test-threads=1

Synthetic geometry and shader inputs. AI-assisted with Codex.

**@⁠steven-seagull27** on GitHub · 2026-11-26 11:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3160#issuecomment-7190690754) I rendered 12 mixed center/centroid variants on `5b4f321` and compared each resolved RGBA32F pixel with a native HLSL shader using `EvaluateAttributeCentroid` on the same adapter. All 12 matched bit for bit on the RTX 5080, Windows WARP, and WARP 1.0.22. The parent (`63bcca4`) refused all 12 before creating a graphics pipeline with `one input interpolated two ways`. | Adapter | Mismatched pixels | Edge pixels changed by forcing center in each FP32 draw | |---|---:|---:| | RTX 5080, driver 621.40 | 0 / 12,288 | 72 / 72 | | Windows WARP 10.0.26100.10068 | 0 / 12,288 | 72 / 72 | | App-local WARP 1.0.22 | 0 / 12,288 | 72 / 72 | The eight FP32 cases covered perspective and noperspective, both instruction orders, and the same or different channels of one attribute. The four FP16 cases covered both interpolation modes and both packing layouts, with explicit nearest-even rounding in the reference. Each 32×32 draw had 401 fully covered pixels and 72 partially covered pixels at 4× MSAA. On the RTX, for example, pixel `(1,2)` had two covered samples. The resolved center and centroid channels read `0.5057649` and `0.5169407`; forcing both channels to center produced `0.5057649` twice. The [test-only commit](https://github.com/steven-seagull27/VIctory/commit/4212e48f02b9b67636dcd5a983bb571ea7cbe613) keeps one FP32 regression with independent native, center-only, and coverage draws. Replacing the translated centroid read with a center load made the test fail at `(1,2)` on both the RTX and Windows WARP. To run it on this PR with the Windows SDK’s PC DXC: ```sh git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr3160-msaa-centroid git cherry-pick 4212e48f02b9b67636dcd5a983bb571ea7cbe613 cargo test --locked -p victory-shader --lib mixed_input_matches_centroid_on_msaa_edges -- --nocapture --test-threads=1 ``` Synthetic geometry and shader inputs. AI-assisted with Codex.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 11:28 UTC · original

WARP verification of #3160 at 5b4f321d (software adapter only; no physical GPU used). AI-assisted: Claude Code (Claude Sonnet 5.5).

Setup. The head is one commit on top of main 63bcca4 (merge-base = 63bcca4); I confirmed the head SHA matches before and after testing. Windows 11 (26100), rustc/cargo 1.98.1, VICTORY_D3D12_WARP=1 (WARP, d3d10warp.dll 10.0.26100.9818), VICTORY_DXIL = Windows SDK 10.0.26100.0 x64 dxil.dll 1.8.2502.11, and the same SDK's dxc.exe 1.8.2502.11 was present, so the dump_dxil assertions in the tests ran. Every cargo command used -j 4, --locked, a separate target dir.

Results

  • cargo test -p victory-shader --lib --locked mixed_input_interpolation -- --test-threads=1 -> 3 passed (..._center_and_centroid, ..._center_and_centroid_f16, ..._incompatible_modes_fail).
  • ... centroid_only_interpolation -> 1 passed (centroid_only_interpolation_uses_load_input, cfg(windows)).
  • Whole crate: cargo test -p victory-shader --lib --locked -- --test-threads=1 -> 306 passed, 0 failed, 3 ignored. Baseline main 63bcca4, same command and environment: 302 passed, 0 failed, 3 ignored. The difference is exactly the 4 new tests; no failure to attribute.
  • Fix reverted (lower.rs taken from 63bcca4, tests kept): mixed_input_interpolation_center_and_centroid and ..._f16 fail (panics at emit/mod.rs:1672 and :1713); the other interpolation tests (including centroid_only_... and ..._incompatible_modes_fail, which pin existing behaviour) still pass. So the two new behavioural tests do detect the change.

Diff review. I found no concrete defect. The planning pass (plan_interp_modes) declares a row that is read both at center and at centroid as center, and the centroid reads are then emitted as evalCentroid.f32 in the entry block; perspective-sample, linear-centroid and flat mixes are still refused with the old error (covered by the third test). The tests' dump file name is now unique per call (removes a race between parallel tests on the shared temp file). Observations, not defects: inputs read inside a lowered section (as plan_interp_modes skips) still fall back to the "one input interpolated two ways" refusal, and the tests check the signature read mask and the emitted DXIL text, not rendered output.

Not tested

  • Any physical GPU (RTX/AMD) or driver-specific behaviour of evalCentroid; WARP's rasterizer is not a stand-in for hardware centroid sampling.
  • Rendered pixel output / game content; no game files used.
  • Other crates (victory-gpu, victory), cargo clippy, cargo fmt --check, release profile, the ignored tests.
  • Non-Windows builds.
**@⁠oni-swr** on GitHub · 2026-11-26 11:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/3160#issuecomment-7190779077) **WARP verification of #3160 at `5b4f321d`** (software adapter only; no physical GPU used). AI-assisted: Claude Code (Claude Sonnet 5.5). **Setup.** The head is one commit on top of `main` `63bcca4` (merge-base = `63bcca4`); I confirmed the head SHA matches before and after testing. Windows 11 (26100), rustc/cargo 1.98.1, `VICTORY_D3D12_WARP=1` (WARP, `d3d10warp.dll` 10.0.26100.9818), `VICTORY_DXIL` = Windows SDK 10.0.26100.0 x64 `dxil.dll` 1.8.2502.11, and the same SDK's `dxc.exe` 1.8.2502.11 was present, so the `dump_dxil` assertions in the tests ran. Every cargo command used `-j 4`, `--locked`, a separate target dir. **Results** - `cargo test -p victory-shader --lib --locked mixed_input_interpolation -- --test-threads=1` -> 3 passed (`..._center_and_centroid`, `..._center_and_centroid_f16`, `..._incompatible_modes_fail`). - `... centroid_only_interpolation` -> 1 passed (`centroid_only_interpolation_uses_load_input`, `cfg(windows)`). - Whole crate: `cargo test -p victory-shader --lib --locked -- --test-threads=1` -> **306 passed, 0 failed, 3 ignored**. Baseline `main` `63bcca4`, same command and environment: **302 passed, 0 failed, 3 ignored**. The difference is exactly the 4 new tests; no failure to attribute. - Fix reverted (`lower.rs` taken from `63bcca4`, tests kept): `mixed_input_interpolation_center_and_centroid` and `..._f16` **fail** (panics at `emit/mod.rs:1672` and `:1713`); the other interpolation tests (including `centroid_only_...` and `..._incompatible_modes_fail`, which pin existing behaviour) still pass. So the two new behavioural tests do detect the change. **Diff review.** I found no concrete defect. The planning pass (`plan_interp_modes`) declares a row that is read both at center and at centroid as center, and the centroid reads are then emitted as `evalCentroid.f32` in the entry block; perspective-sample, linear-centroid and flat mixes are still refused with the old error (covered by the third test). The tests' dump file name is now unique per call (removes a race between parallel tests on the shared temp file). Observations, not defects: inputs read inside a lowered section (as `plan_interp_modes` skips) still fall back to the "one input interpolated two ways" refusal, and the tests check the signature read mask and the emitted DXIL text, not rendered output. **Not tested** - Any physical GPU (RTX/AMD) or driver-specific behaviour of `evalCentroid`; WARP's rasterizer is not a stand-in for hardware centroid sampling. - Rendered pixel output / game content; no game files used. - Other crates (`victory-gpu`, `victory`), `cargo clippy`, `cargo fmt --check`, release profile, the ignored tests. - Non-Windows builds.
github-bot force-pushed github-bot/gh-3160 from 5b4f321d17 to cb96b3a249 2026-11-26 11:51:34 +00:00 Compare
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 11:48 UTC · original

Re-pushed identical tree (5b4f321d -> cb96b3a2) to re-trigger CI after an unrelated flaky failure in frame::tests::waits_end_on_ticks_and_count_frames.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 11:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/3160#issuecomment-7191201649) Re-pushed identical tree (`5b4f321d` -> `cb96b3a2`) to re-trigger CI after an unrelated flaky failure in `frame::tests::waits_end_on_ticks_and_count_frames`.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3160/head:github-bot/gh-3160'
git switch 'github-bot/gh-3160'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3160'
git switch 'github-bot/gh-3160'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3160'
git switch 'github-bot/gh-3160'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3160'
git switch 'main'
git merge --squash 'github-bot/gh-3160'
git switch 'main'
git merge --ff-only 'github-bot/gh-3160'
git switch 'main'
git merge 'github-bot/gh-3160'
git push origin 'main'
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!3160
No description provided.