Repository navigation
Shaders: pixel barycentrics through SV_Barycentrics (rebased #453) - #3335
kotekompotek wants to merge 4 commits into
Conversation
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
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
Dukestar69
left a comment
There was a problem hiding this comment.
Tested on RTX 5090 (Windows / D3D12) against origin/main (63bcca4).
Tests and clippy pass cleanly:
cargo test -p victory-shader --lib io:: -- --test-threads=1: 5 passed, 0 failed.cargo test -p victory-shader --lib emit::tests:: -- --test-threads=1: 17 passed, 0 failed.cargo clippy -p victory-shader -p victory --all-targets -- -D warnings: clean.
However, cargo xtask policy fails because crates/victory-shader/src/emit/lower.rs grows to 534,321 bytes, exceeding the 524,288-byte (512 KiB) file-size limit by 10,033 bytes:
POLICY: crates/victory-shader/src/emit/lower.rs: 534321 bytes exceeds the 524288-byte limit
Error: 1 asset-policy violation(s). Nothing from the game may be committed; see docs/asset-policy.md
Moving the new barycentrics lowering code into a submodule under crates/victory-shader/src/emit/lower/ will bring lower.rs back under the limit.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
|
WARP/CPU verification of head Environment: Windows 11, WARP only (
AI disclosure: run by Claude Code (Claude Sonnet 5.5), coordinated by Antigravity. |
|
The failed CI job reports one repository-policy failure on The failing kotekompotek, please consider applying the module split and rerunning CI. If you fold it into another commit, please preserve its Git author or add |
|
Full-pack validation on the retail shaders.rpf (v1.0.2.1, 26 084 programs), dxil.dll from SDK 10.0.26100.0:
Side discovery from the same run, not caused by this PR: 748 emitted compute programs fail validation with 'incompatible with the shader stage' and 71 mesh with 'vertex plus primitive output size is greater than 32768' — pre-existing on main, worth its own census entry. |
fuzeofficlal
left a comment
There was a problem hiding this comment.
The split into crates/victory-shader/src/emit/lower/barycentric.rs cleanly brings emit/lower.rs back under the size limit (504,649 bytes), and the DXIL SV_Barycentrics constants/modes (SFI0 1 << 17, flags 1 << 22, semantic kind 28 -> 23, (1 - i - j, i, j) triangle weights) and tests (emit::barycentric_tests 9/9, emit::tests 17/17 with dxil.dll, io:: 5/5, emit::lower 33/33, apps/victory 18/18, clippy, xtask policy) all pass locally at e495d2dd.
However, there are a few issues at e495d2dd that need to be addressed before merge:
-
Corrupted UTF-8 comments in
crates/victory-shader/src/emit/lower.rs(starting at line366):- The rebase/split rewrote non-ASCII symbols (
×,π,→,²,−,±,≤) in unrelatedlower.rsdoc comments as mojibake (Г—,ПЂ,в†’,ВІ,в€’,В±,≤) across 14+ lines. Please restore the original UTF-8 text.
- The rebase/split rewrote non-ASCII symbols (
-
P1 — Dead per-vertex reads can leave
flags::BARYCENTRICSset without any usage (barycentric.rs:602,bitcode.rs:513-515,shader.rs:578-586):vertex_inputsetsself.s.flags |= flags::BARYCENTRICSwhen emitting aReadNonedx.op.attributeAtVertexcall (137). If the interpolated output is never exported/consumed,bitcode::Module::writedrops deadReadNonecalls (rooted()returnsfalse), whileShader::finishnever recomputesflags::BARYCENTRICSfromself.m.uses(). DXC validation rejects a module whoseSFI0/entry flags advertise barycentrics with neither anSV_Barycentricsinput nor a liveattributeAtVertexcall ("Flags must match usage").
-
P1 — Imported
SV_Barycentricssignature elements can emit invalid DXIL signatures (mod.rs:455, 627,barycentric.rs:230-266):signature()+emit()initialize importedSV_Barycentricsrows withrow: Some(register)andinterp: 2. If an imported element goes unread, it stays packed (row.is_some()) without settingflags::BARYCENTRICS. Additionally, ifSV_Barycentrics1is already declared and another interpolation family is added,barycentric.rs:238setsindex = count() as u32(1), producing a duplicateSV_Barycentrics1element.
Non-blocking notes:
- P2 (FP16 coefficient precision):
barycentric.rs:425, 575computesvk - v0inf32for computed-weight FP16 interpolations instead of narrowingP10/P20coefficients tof16as RDNA2v_interp_p1ll_f16/v_interp_p2_f16do. - P3 (
v_interp_mov_f32):barycentric.rs:365should maskVSRCwith& 3per RDNA2 ISA (VSRC[1:0]). - Diagnostic count (
apps/victory/src/translate.rs:709-710): counting eachInterp::Weightedsite incrementst.interpolatedtwice for a split first/second half pair. - Formatting:
rustfmt --edition 2024 --checkpasses ontranslate.rsandio.rs, with 5 small line-wrap diffs incrates/victory-shader/src/emit/lower/barycentric.rs(366, 374, 383, 467, 652).
|
Hardware run of head Environment: NVIDIA GeForce RTX 3070 8 GB (Ampere, wave32 only), driver 616.56, Windows 11, SM 6.6, Windows SDK 10.0.26100.0 PR's tests, head, 3 runs,
(9 Negative control: the PR's test hunks ( Full lib,
No game files used. |
|
I ran a D3D12 raster readback on head The guest shader exports Unequal clip w (1, 2, 4), pixels differing from the analytic weights out of 16
On both WARP runtimes the dual-mode programs missed 32/64 components. All 32 screen-linear components matched. At pixel (2,1) the expected RGBA was The PR’s original nine translation/validator tests also passed. The same guest export on base The opt-in test and three HLSL references are in this test-only commit. To reproduce from this PR head with Windows SDK DXC installed, run the following. git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/test/pr3335-dual-barycentric-readback
git cherry-pick c0c39ce3246583f784fbc7935bbd3d0df2000c7d
cargo test --locked -p victory-shader --lib raw_center_weights_match_native_rasterization -- --ignored --nocapture --test-threads=1 |
Revival of #453 (itself grown from #442), rebased onto current main. Both earlier PRs closed unmerged — #442 yielded to the broader #453, and #453 hit needs-rebase with no one picking it up. Original authorship is preserved in the commits; the design is theirs, the rebase and one integration fix are mine.
What
A pixel program receives its barycentric pairs (i, j) in input VGPRs as
SPI_PS_INPUT_ADDRenables them. When it uses them only inv_interp_*, that already translates. When it reads them as data — arithmetic, an export, a join — lowering stopped withbarycentrics read directly(one program in the retail pack:PS_SampleFromHigherResGrid). Such reads are now channels ofSV_Barycentrics(SM 6.1):SV_Barycentrics.y, j is.z; the element is rowless and unpacked, declared only when a barycentric is actually read as data — programs that only interpolate keep their signatures and need no new device feature.noperspectiveforms 4/5/7 — one shared mode table forv_interpand the direct reads.noperspectiveelement; a program reading two same-family pairs as data is refused by name.v_interp_p1/p2whose i/j are not the loaded inputs evaluatesP0 + i(P1-P0) + j(P2-P0)from the vertex values throughattributeAtVertex(opcode 137), with the element forced to constant interpolation.What the rebase changed beyond conflict resolution
Main's counted-
v_movreldproof (#457) recognized raw barycentric inputs because they were unrepresentable (Val::Missing). With direct barycentrics representable, the proof now recognizes raw barycentric input values directly; malformed/partial counted fills keep the input value instead of failing.indexed_move_initializes_an_input_before_its_first_usewas updated to the new correct behavior: complete fills declare noSV_Barycentrics, partial fills preserve the input and do.Verification
cargo test -p victory-shader --lib: 224 passed / 88 failed — the 88 are byte-identical to theorigin/mainbaseline on the same machine (GTX 1050, SM 6.5 ceiling; most want SM 6.6). The 10 new tests all pass.cargo clippy -p victory-shader --all-targets: clean.Test plan
emit::barycentric_tests— 9 tests: direct reads, two-element split, same-family refusal, no-declaration for pure interpolation, computed weights, constant weightsio::tests::computed_barycentrics_evaluate_each_halfGenerated with Devin