Skip to content

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

Closed
jeremygold02 wants to merge 1 commit into
Marvisak:mainfrom
jeremygold02:codex/pixel-barycentrics
Closed

jeremygold02 wants to merge 1 commit into
Marvisak:mainfrom
jeremygold02:codex/pixel-barycentrics

Conversation

@jeremygold02

@jeremygold02 jeremygold02 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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 Translate 64-bit texture atomics and follow proven shader branches #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 Translate 64-bit texture atomics and follow proven shader branches #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: Marvisak#97
@jeremygold02

Copy link
Copy Markdown
Contributor Author

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

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested d9bbff5 on Windows 11, RTX 5070, MSVC: cargo test -p victory-shader -- --test-threads=1 70 passed, both by default and with --features experimental-barycentrics, including direct_pixel_barycentrics_require_a_live_perspective_center_read. cargo clippy -p victory-shader --all-targets is clean. victory translate --validate --pipelines on the local title executable reports 12 of 12 programs, the same as main, so default builds are unchanged.

  • The default build can't change behaviour. Val::Missing(DIRECT_CENTER) is only produced in the cfg!(feature = "experimental-barycentrics") arm, so the retry branch in lower is unreachable without the feature, and a perspective-centre read still fails as before.
  • With the feature, SV_Barycentrics is added, and BARYCENTRICS set in the flags and SFI0, only when a direct I/J read reaches a live effect. An unused read doesn't force the capability. The test checks both cases through SFI0.
  • As the Cargo comment says, D3D's vertex order versus the console's possibly rotated order is the open risk, so keeping it opt-in is right.

AI-assisted (Claude Code).

@Marvisak

Copy link
Copy Markdown
Owner

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 Marvisak closed this Nov 25, 2026
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.

3 participants