feat(shader): add opt-in perspective-center barycentric inputs #281

Closed
github-bot wants to merge 1 commit from gh-pr/281/head into gh-pr/281/base
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 02:01 UTC · original
jeremygold02:codex/pixel-barycentrics → main · +133 −7 · 4 files · 1 commits · closed without merging

What changes

A live read of the GFX10 perspective-center I or J register currently stops pixel-shader translation. With the new victory-shader/experimental-barycentrics Cargo feature, the emitter can assign the native triangle vertices D3D primitive order and load SV_Barycentrics.yz. This emits the unpacked float3 input, the DXIL entry-point flag and the separate SFI0 capability bit. The emitter retries with that input only if a direct read reaches an effect. An unused read and ordinary paired interpolation keep their previous requirements.

Why this is a draft

The chosen vertex order is explicit and opt-in. D3D defines barycentric component order in the API primitive, including odd triangles in a strip. AMD's raw I/J order can rotate relative to those vertices. The synthetic draw below verifies the D3D-order experiment. Matching the console's vertex order, or proving a given consumer is invariant to the permutation, is still open. D3D ordering · AMD raw-coordinate ordering

Local verification

Compared with main at d2a4bae on Windows 11 and an RTX 5070.

  • A hand-authored native pixel program exports I, J, 0 and 1. Stock refuses it. With the feature enabled, the emitted shader passes the Windows SDK DXIL validator. One hardware draw of a triangle with unequal clip-space W produced RGBA (0.26195815, 0.24601395, 0, 1) at the sampled pixel after fence completion. The CPU reference was (0.2619579, 0.24601403, 0, 1). A paired-interpolation control produced byte-identical validated DXIL in both builds.
  • Across 26,503 local shader containers, VS/PS emission rose from 12,272 to 12,278 of 14,001, and validation rose from 12,172 to 12,175. The other three new emissions used calculateLOD on 2D-array textures. With the feature enabled, all three failed SDK validation. Applying only the spatial-coordinate hunk from #136 at 8ae232f made the same three pass (0/3 to 3/3). Compute and mesh totals were identical. This comparison ran on the CPU.
  • Two pixel shaders associated with late loading on current main changed from refusal to SDK validation. In a separate comparison using #48, two more reached this path after the 64-bit atomic was translated. Within the 11-program set selected for those two diagnostics, 7 validated with #48 alone and 11 validated with both changes. The device watchdog remains unresolved.
  • cargo test -p victory-shader --lib direct_pixel_barycentrics passes with the feature off and on. The test covers a live center export, a dead read, rejection of the linear-center case, the SFI0 bit, and the input signature. The wider library run passed 59 tests in each configuration, with the WARP and differential GPU suites excluded. Shader formatting and Clippy passed.

To build the executable with this experiment, use cargo build -p victory --features victory-shader/experimental-barycentrics.

Refs #97. Related signature work is in #136.

**@⁠jeremygold02** on GitHub · 2026-11-24 02:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/281) `jeremygold02:codex/pixel-barycentrics` → `main` · +133 −7 · 4 files · 1 commits · closed without merging ## What changes A live read of the GFX10 perspective-center I or J register currently stops pixel-shader translation. With the new `victory-shader/experimental-barycentrics` Cargo feature, the emitter can assign the native triangle vertices D3D primitive order and load `SV_Barycentrics.yz`. This emits the unpacked float3 input, the DXIL entry-point flag and the separate SFI0 capability bit. The emitter retries with that input only if a direct read reaches an effect. An unused read and ordinary paired interpolation keep their previous requirements. ## Why this is a draft The chosen vertex order is explicit and opt-in. D3D defines barycentric component order in the API primitive, including odd triangles in a strip. AMD's raw I/J order can rotate relative to those vertices. The synthetic draw below verifies the D3D-order experiment. Matching the console's vertex order, or proving a given consumer is invariant to the permutation, is still open. [D3D ordering](https://github.com/microsoft/DirectXShaderCompiler/wiki/SV_Barycentrics) · [AMD raw-coordinate ordering](https://gpuopen.com/learn/stable-barycentric-coordinates/) ## Local verification Compared with main at `d2a4bae` on Windows 11 and an RTX 5070. - A hand-authored native pixel program exports I, J, 0 and 1. Stock refuses it. With the feature enabled, the emitted shader passes the Windows SDK DXIL validator. One hardware draw of a triangle with unequal clip-space W produced RGBA `(0.26195815, 0.24601395, 0, 1)` at the sampled pixel after fence completion. The CPU reference was `(0.2619579, 0.24601403, 0, 1)`. A paired-interpolation control produced byte-identical validated DXIL in both builds. - Across 26,503 local shader containers, VS/PS emission rose from 12,272 to 12,278 of 14,001, and validation rose from 12,172 to 12,175. The other three new emissions used `calculateLOD` on 2D-array textures. With the feature enabled, all three failed SDK validation. Applying only the spatial-coordinate hunk from [#136](https://git.gtahub.st/github/Marvisak--VIctory/pulls/136) at `8ae232f` made the same three pass (0/3 to 3/3). Compute and mesh totals were identical. This comparison ran on the CPU. - Two pixel shaders associated with late loading on current main changed from refusal to SDK validation. In a separate comparison using #48, two more reached this path after the 64-bit atomic was translated. Within the 11-program set selected for those two diagnostics, 7 validated with #48 alone and 11 validated with both changes. The device watchdog remains unresolved. - `cargo test -p victory-shader --lib direct_pixel_barycentrics` passes with the feature off and on. The test covers a live center export, a dead read, rejection of the linear-center case, the SFI0 bit, and the input signature. The wider library run passed 59 tests in each configuration, with the WARP and differential GPU suites excluded. Shader formatting and Clippy passed. To build the executable with this experiment, use `cargo build -p victory --features victory-shader/experimental-barycentrics`. Refs #97. Related signature work is in #136.
Emit the D3D barycentric system value when a perspective-center register reaches an effect. Gate the D3D vertex-order model behind a build feature while native ordering is investigated.

Refs: #97
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:57:46 +00:00
github-bot closed this pull request 2026-11-26 03:57:47 +00:00
Author
Owner

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

Tested PR #281 at head d9bbff571eabf7defe6b106349acda49d1eaa3f8 (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at d9bbff571eabf7defe6b106349acda49d1eaa3f8.

  • cargo test --locked -p victory-shader --features experimental-barycentrics direct_pixel_barycentrics_require_a_live_perspective_center_read — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 69 filtered out; finished in 0.00s ); cases: emit::lower::tests::direct_pixel_barycentrics_require_a_live_perspective_center_read.

Behavior covered: Checks feature-gated perspective-center barycentric input is emitted only when a live center read exists.
Code: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/shader.rs

**@⁠jeremygold02** on GitHub · 2026-11-24 04:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/281#issuecomment-7121860032) Tested PR #281 at head `d9bbff571eabf7defe6b106349acda49d1eaa3f8` (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at `d9bbff571eabf7defe6b106349acda49d1eaa3f8`. - `cargo test --locked -p victory-shader --features experimental-barycentrics direct_pixel_barycentrics_require_a_live_perspective_center_read` — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 69 filtered out; finished in 0.00s ); cases: emit::lower::tests::direct_pixel_barycentrics_require_a_live_perspective_center_read. Behavior covered: Checks feature-gated perspective-center barycentric input is emitted only when a live center read exists. Code: [crates/victory-shader/src/emit/lower.rs](https://github.com/Marvisak/VIctory/blob/d9bbff571eabf7defe6b106349acda49d1eaa3f8/crates/victory-shader/src/emit/lower.rs), [crates/victory-shader/src/emit/shader.rs](https://github.com/Marvisak/VIctory/blob/d9bbff571eabf7defe6b106349acda49d1eaa3f8/crates/victory-shader/src/emit/shader.rs)
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:01 UTC · original

Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #453. Draft: raw I/J reads as SV_Barycentrics.yz behind a new Cargo feature, with an assumed vertex order. #453 does the same and more without a feature; and the three pixel programs main still refuses for 'barycentrics read directly' are overwritten registers (#457), not real reads.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/281#issuecomment-7148046444) Automated triage for the maintainers. Closing because another open pull request covers the same change. See #453. Draft: raw I/J reads as SV_Barycentrics.yz behind a new Cargo feature, with an assumed vertex order. #453 does the same and more without a feature; and the three pixel programs main still refuses for 'barycentrics read directly' are overwritten registers (#457), not real reads. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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!281
No description provided.