Skip to content

Shaders: pixel barycentrics through SV_Barycentrics and live interpolation values (reopens #453, #1738) - #3588

Open
zed6000 wants to merge 12 commits into
Marvisak:mainfrom
zed6000:revive-barycentrics
Open

zed6000 wants to merge 12 commits into
Marvisak:mainfrom
zed6000:revive-barycentrics

Conversation

@zed6000

@zed6000 zed6000 commented Nov 27, 2026

Copy link
Copy Markdown

This reopens #1738 by @jaschinski97-ops (live interpolation values), which includes the pixel-barycentrics work of #453 by @AntoninMichelq that it builds on. Both were closed on 2026-11-26 without being merged. The change is still needed on main: one pixel program the title runs in the intro is refused with emit: barycentrics read directly.

The branch is #1738's last head (9d59892) merged onto main 63bcca4. The merge is clean, and all original commits and authors are kept.

Measured on an RX 7900 XTX (driver 32.0.32029.2010), Windows 11:

  • Shader census of the shipped shaders.rpf (translate --validate --list, 26,084 programs), compared with main 63bcca4 program by program: +1, 0 lost. The one is that "barycentrics read directly" refusal.
  • cargo test -p victory-shader --lib --locked: 325 passed, 0 failed.
  • In the game, as part of the tested set in Proposal: add one or more co-maintainers so main can take merges more often #3347, the intro runs with 0 dropped draws and faces drawn.

Merge notes for the open shader PRs touching the same code (#1924, #2978, #385, #2999) are in my comment on #1738.

I'm happy to hand this back if any of the original authors wants to continue it. AI-assisted (Claude Code); counts only, no game data.

claude and others added 11 commits November 24, 2026 03:22
Pixel programs that use the I/J VGPRs as plain values (custom
interpolation, math on the weights) failed with "barycentrics read
directly". They are now channels y and z of an SV_Barycentrics input
(SM 6.1+, the emitter targets 6.6) declared with the interpolation mode
of their kind (perspective/linear, center/centroid/sample), one element
per mode (semantic index 0 and 1), with the Barycentrics shader flag and
SFI0 feature. GFX10 interpolates P0 + i (P1 - P0) + j (P2 - P0) with P0
the provoking vertex, which the host's barycentrics weight as vertex 0,
so i = y and j = z.

The VGPRs are loaded on first use as a value, so programs that only feed
them to v_interp_* declare nothing new. A console signature's own
SV_Barycentrics row (D3D name 23) is parsed and reused. Pull-model
barycentrics stay unsupported.

SV_Barycentrics is left unpacked (no row, packing location -1), like
other non-packed system values: the DXIL validator refuses it in a row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
v_interp_p1/p2 (and the f16 forms) fed with an i or j that is not the
loaded input VGPR now evaluate each half as the hardware does: P0 + i
(P1 - P0) for the first, the old dst + j (P2 - P0) for the second, with
the vertex values read by attributeAtVertex. That needs the element
declared constant, so every other interpolation of the same attribute
row is weighed from its vertices with SV_Barycentrics of its mode, and
flat reads stay loadInput of the provoking vertex. v_interp_mov of P10
and P20 reads P1 - P0 and P2 - P0 the same way when the program also
interpolates the attribute (so the hardware holds the deltas); alone it
is still refused.

The translate command's tally counts Interp::Weighted as interpolated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
lower.rs: keep the PR's lazy barycentric VGPR inputs next to main's
`Reg::S(n)` arm for uninitialized SGPRs. mod.rs: the barycentric test
helper passes the structure to resource::track, which now takes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
DXIL allows at most two SV_Barycentrics input elements, one perspective
and one linear. A program reading both perspective center and centroid
I/J as values declared two perspective elements, which the validator
refuses ("There can only be up to two input attributes of
SV_Barycentrics with different perspective interpolation mode").

The second mode of the same kind is now an Unsupported reason rather
than a second element. Reusing the first element would hand centroid
reads center weights (or the reverse), which differ on edge pixels: a
silent wrong value. Before this PR such reads were refused anyway.

Test: center + centroid values are refused; centroid alone still
translates with one element.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
…polation values and pixel barycentrics
…wer.rs under the size limit)

The merged Marvisak#453 and Marvisak#1738 changes took emit/lower.rs to 533,630 bytes, over the
asset policy's 524,288-byte limit. Their methods (lazy_barycentric, barycentric,
interp, per_vertex, interpolated, eval_channel, vertex_input) and the two mode
helpers move unchanged to emit/lower/interp.rs, as the permlane code did in
Marvisak#3587. lower.rs is 518,013 bytes now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kilolimaVI

Copy link
Copy Markdown

Verified on AMD Radeon 780M (RDNA3, Ryzen 7 8845HS), Windows 11, head 6f32448.

case 780M WARP
x and y interpolated 95 px, 0 wrong 95 px, 0 wrong
I and J as values 95 px, 0 wrong 95 px, 0 wrong
x with a computed I 95 px, 0 wrong 95 px, 0 wrong
x interpolated, P0 of y (NEW-120) 95 px, 0 wrong 95 px, 0 wrong
x interpolated, P10 of x 95 px, 0 wrong 95 px, 0 wrong
P0 of x and y alone 95 px, 0 wrong 95 px, 0 wrong
  • Full suite (victory-shader + victory-gpu --features diagnostics): 575 passed, 0 failed.

This matches #3553's result on the same test, so the two PRs render identically here; the choice between them can be made on the code alone.

AI-assisted (Claude).

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.

4 participants