Shaders: pixel barycentrics through SV_Barycentrics (values and computed interpolation) #453
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!453
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/453/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@AntoninMichelq on GitHub · 2026-11-24 03:34 UTC · original
AntoninMichelq:up/pixel-barycentrics→main· +729 −72 · 6 files · 4 commits · closed without mergingRequested by 4nto · project thread
Summary
Pixel programs that use their barycentrics in other ways than plain
v_interp_*now translate, throughSV_Barycentrics.SV_Barycentricsinput. 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.v_interp_p1/p2(and the f16 forms) fed with an i or j that is not the loaded input VGPR failed with "an interpolation with computed barycentrics". Each half is now evaluated as the hardware does, from the vertex values read byattributeAtVertex.What changed
emit/lower.rs,emit/mod.rs,emit/shader.rs,emit/container.rs(commit 1):SV_Barycentricsis declared with the interpolation mode of its kind (perspective or linear; center, centroid or sample). There is one element per mode (semantic index 0 and 1), with the Barycentrics shader flag and SFI0 feature.v_interp_*declare nothing new.SV_Barycentricsrow (D3D name 23) is parsed and reused. Pull-model barycentrics stay unsupported.io.rs,emit/lower.rs(commit 2):Interp::Weighted: P0 + i (P1 - P0) for the first half, the old dst + j (P2 - P0) for the second.attributeAtVertexneeds the element declared constant, so every other interpolation of that attribute row is weighed from its vertices withSV_Barycentricsof its mode. Flat reads stayloadInputof the provoking vertex.v_interp_movof P10 and P20 reads P1 - P0 and P2 - P0 the same way when the program also interpolates the attribute. Alone it is still refused.apps/victory/src/translate.rs: the tally countsInterp::Weightedas interpolated.Open draft PR #281 also emits
SV_Barycentrics, but only for direct perspective-center reads and behind an opt-in build feature, because of a concern about the hardware's vertex order. This PR covers all six modes and computed barycentrics, on by default. The two touch the same code inlower.rs.How it was tested
cargo test -p victory-shader(Linux) passes: 65 tests, including 9 new ones (values read asSV_Barycentrics, two modes, interpolation alone, both together, computed barycentrics inioand in the emitter, constant weights, computed and loaded on one attribute, P10 of an interpolated attribute). On Windows these tests also run the DXIL validator when it is present.cargo check --tests -p victory-shader -p victory-gpuandcargo check -p victoryforx86_64-pc-windows-msvc(withCARGO_FEATURE_PURE=1) pass.Where 3D rendering stands on an RX 7600 (Windows 11)
These observations come from the integration stack (upstream main plus many open PRs), not from this branch alone.
🤖 Generated with Claude Code
https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
ffe310e) into up/pixel-barycentrics 3bc83d0d7bDXIL 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 <[email protected]> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66@DaviTostes on GitHub · 2026-11-24 03:42 UTC · original
Follow-up: this overlaps #442 (both emit
SV_Barycentricsfor pixel programs), and the two conflict textually —git merge-tree --write-tree pr442 pr453reportsCONFLICT (content)incrates/victory-shader/src/emit/lower.rs(plus auto-merges inmod.rs/shader.rs). Worth choosing one.Measured on Arch Linux x86_64 (rustc 1.98.1,
cargo test -p victory-shader):87e9d41): 65 passed, 0 failed.b6ccc95): 60 passed, 0 failed; it covers direct reads only, while this head also handles computed barycentrics and all six modes.Not covered here: DXIL validation on Windows (no SM 6.6 device in this Wine prefix) and title shaders (no game data).
@LocranKing on GitHub · 2026-11-24 04:18 UTC · original
Tested on Windows 11 + retail
shaders.rpf(1.0.2.1) usingvictory translate --validate.Tested
87e9d41(pr-453, clean tree)1.98.1(x86_64-pc-windows-msvc), Windows SDK10.0.26100.0dxil.dllcargo xtask policy:asset policy: 151 files okcargo test --workspace: 273 passed, 0 failed, 4 ignoredvictory translate <shaders.rpf> --validate(diagbuild) vsmain(d2a4bae):I/O: 14247 of 14247 vertex and pixel programs raised (up from14040 of 14247; all 207I/O: an interpolation with computed barycentricserrors cleared)DXIL(VS/PS): 12453 emitted of 14208; 12347 validated (up from12272 emitted/12172 validatedonmain: +181 emitted, +175 validated)DXIL(CS):1693emitted /1670validated;DXIL(MS):8191emitted /8129validated (unchanged)Not tested: Live gameplay / rendering with these shaders on GPU or WARP.
AI use: Antigravity (
Gemini 4 Hydrogen) ran the checks andvictory translate --validateand drafted this report from the command outputs.@marquezinii on GitHub · 2026-11-24 04:22 UTC · original
Ran
87e9d41on Windows 11 with the SDK'sdxil.dll(10.0.26100.0) loaded:cargo test -p victory-shaderpasses (78). The semantic mapping, the shader flag andSFI0bit, the element shape and the entry-block placement ofloadInput/attributeAtVertexall look right to me.One case emits a module the validator refuses.
barycentric()allows a secondSV_Barycentricselement for any second mode, but DXIL allows two only when one is perspective and the other linear. A pixel program that reads both perspective center and perspective centroid I/J as values (SPI_PS_INPUT_ADDRwith PERSP_CENTER and PERSP_CENTROID, thenv_add_f32 v4, v0, v3, built with the test module'spixelhelper) gives:two_barycentric_modes_get_two_elementspasses because it pairs perspective with linear. The computed-barycentrics path can reach the same state when per-vertex rows use center and centroid. ReturningVal::Missingfor a second element of the same perspective-ness would at least keep the module valid.Also, the tests'
validate()returns quietly whendxil.dlldoes not load, so on a machine without the SDK they pass without validating; a message (asconstant_color_validatesprints) would make that visible.@SantannaCarlos on GitHub · 2026-11-24 07:53 UTC · original
Tested on an RTX 4070 (Windows 11, driver 621.01) with
victory translate shaders.rpf --validate(1.0.2.1).main(d2a4bae)* #136 #173 #176 #164 #180 #179 #177 #138 #116 #145 #135 #100.
"an interpolation with computed barycentrics" goes 207 -> 0 and "barycentrics read directly" 6 -> 0 (29 -> 0 on the stack). A per-program diff of the
--listruns shows no program that validated before stops validating (+175 onmain, +200 on the stack), and no "Invalid record" appears.I also checked the interpolation on the GPU: full-screen triangles with known per-vertex values in all three vertex rotations, both windings, skewed and with varying w, comparing the hardware's own interpolation with v0 + i*(v1 - v0) + j*(v2 - v0) from
GetAttributeAtVertexandSV_Barycentrics. Worst difference 9.1e-8 on the 4070, 1.2e-7 on WARP with uniform w. With varying w WARP disagrees by up to 0.7, but a PC-only shader disagrees with itself the same way, so that is WARP's interpolation, not this lowering. That confirms the vertex order and i = y, j = z. A test like it would be a useful addition; note that a second drawing test module in victory-shader currently fails to resolve the#[cfg(test)]host helpers (Draw,Root) undercargo test --workspace, which is unrelated to this PR.A row read both per vertex and by hardware interpolation is handled well: rebuilding that row's hardware interpolations from the vertices means nothing emitted renders the provoking vertex by mistake.
@r4tedx on GitHub · 2026-11-24 09:12 UTC · original
This PR is in the tester tree now (
integration/testers, mergeda523faof87e9d41), so here is what merging and reviewing it there turned up. Three things, the first good news.1. What it gains in that tree. Measured on my own copy of the title's shader file, offline:
victory translate --host-lanes 32-32 --validate --listbefore and after the merge, compared program by program (25,889 programs; counts and reasons only):an interpolation with computed barycentricsand 26 that stopped atbarycentrics read directly.barycentrics read directlynow emit and fail validation without of bound coord must be undef. All three callcalculateLOD, so I read that as another lowering these programs reach now, not this PR's. I have not reproduced it with a synthetic program yet.That agrees with the counts on
mainposted above (207 and 6 cleared, +175 validated).2. Two cases where
87e9d41emits a moduledxil.dllrefuses. Both have a test in the tree that fails without the fix and passes with it (commit55c2938, 13 lines of code inemit/lower.rsandemit/mod.rs):SV_Barycentricselements of the same kind. DXIL takes one perspective and one linear. The limit inLower::barycentriccounts elements (index >= 2), not kinds. The fix refuses the second of a kind withbarycentrics of two sample positions.SV_Barycentricsrow. The row is carried over, packed, also under a program that only interpolates, and the validator refuses the module. The fix drops console rows of kind 28 before lowering, which declares what the program reads.By the same offline count, neither case occurs in the title's shader file: the fix changes the outcome of 0 of the 25,889 programs. So it is correctness for programs outside that file, not a gain. You are welcome to take the commit, or to tell me it is wrong.
3. One thing about drawing tests, now that CI runs on a machine without a GPU. In review here, a program with both a perspective and a linear
SV_Barycentricsdrew the expected values on an RTX 5070 and wrong ones on WARP, and so did DXC's own module for the same shader, so that is WARP's. A drawing test of that shape would fail in CI through no fault of the lowering. Programs with one kind drew correctly on both.Tested here on an RTX 5070:
cargo test --workspaceon the tree with this PR and the fix, 442 passed, 5 ignored. The title was not launched; point 1 used its shader file offline as described, and nothing from it is in the tree. AI-assisted.@slint6614-dev on GitHub · 2026-11-24 09:24 UTC · original
Measured on the full retail shader pack (26,503 containers) with
victory translate --validate --pipelines(pipelines created on an AMD RX 9070, Windows 11, dxil.dll from SDK 10.0.26100). Counts are emitted / validated / pipelines. This PR conflicts with current main (lower.rs), so it was measured on its own base, against main1f858b0before #612 (VS/PS 12272 / 12172, CS 1693 / 1670, MS 8191 / 8129).@MichaelSmithAI on GitHub · 2026-11-24 10:16 UTC · original · edited 2026-11-24 10:24 UTC
Follow-up on the three pixel programs that reached the
calculateLODvalidator error. We reproduced the same error on mainffe310ewith source-built pixel shaders using 1D-array and 2D-array textures. The emitter passes the array slice as a coordinate. DXIL expects only the spatial coordinates for this query, including the unclamped form. A plain 2D texture provided the control.The standalone fix and portable regression are in 26f915d. Microsoft DXV accepts all three generated modules with the fix. If you still have the same three programs locally, a before/after validator count on your #453 stack would tell us how many this covers. The synthetic inputs establish the array case; the resource dimensions in the three reported programs are still unknown.
On an RTX 4090 through Wine/vkd3d, both corrected array shaders and independent DXC HLSL returned clamped LOD 1 and unclamped LOD −32 in all 64 pixels with constant coordinates and sampler MinLOD 1.
AI-assisted implementation and verification.
@walterwallaceson on GitHub · 2026-11-24 10:56 UTC · original
A short in-game data point for this PR, from Windows 10 with an RTX 3070 on
main8e79c80plus a stack of open PRs (#439, #483, #493, #688, #704 and others; details on #392).In a captured frame in the world, every draw into one full-resolution
R32G32_UINTtarget is dropped: 35 draws, all from one pipeline, whose pixel program fails withbarycentrics read directly. That is the reason this PR addresses, so it should bring the whole pass back.I couldn't test it yet. This PR's head is on
mainffe310e, which includes #566, and that conflicts with #439's stack inemit/lower.rs,emit/mod.rsandstructure.rs. Once #439 is rebased past #566, I'll run the title with this PR and report whether the pass draws.I'm testing with Claude's help, and Claude drafted this comment.
@AntoninMichelq on GitHub · 2026-11-24 11:05 UTC · original
Thanks, that's a very useful data point. A full-resolution R32G32_UINT target written by 35 draws from one pipeline looks like a visibility-style pass, so getting it back could matter a lot.
Since your comment, the branch has main merged in (
3bc83d0). It also has88b34a4, which refuses a program that reads two perspective barycentric modes, so it no longer produces invalid DXIL. I understand you need #439 rebased past #566 before you can test. When you do, a before/after count of draws into that target would be great.@r4tedx on GitHub · 2026-11-24 14:30 UTC · original
@MichaelSmithAI the before/after count you asked for, on the three programs themselves.
The fix from your
26f915d(a level-of-detail query passes only its spatial coordinates) is in the tester tree now, as commit2a61b8eof update 7. Offline over my copy of the title's shader file (victory translate --host-lanes 32-32 --validate --list, 25,889 programs, compared program by program):out of bound coord must be undef;So it covers every case of it in that file. I cannot say from the count which array dimension the three use.
One thing about how it went in: your commit's test builds
Lower::new(&parts, &bad)directly, and that signature differs in the tree (the wave64 stack adds arguments), so the tree has its own test instead: a 1D-array and a 2D-arrayimage_get_lod, each run throughdxil.dll. It fails with the validator's message when the change is taken out. The commit message credits your commit for the fix.The title was not launched; this used its shader file offline as described. AI-assisted.
@Yaekai on GitHub · 2026-11-24 16:11 UTC · original
Independent test & review on Windows 11 + NVIDIA RTX 3070 (Rust 1.98.1) at head
88b34a4:cargo test -p victory-shader --lib -- --skip valu_tests --skip waterfall_tests: 112 passed, 0 failed.cargo clippy -p victory-shader -- -D warnings: 0 warnings.1.0.2.1,--console series-s, 19-min world run):barycentrics read directly is not supportedrefusals dropped to 0 with no regressions. Ready to merge!@Marvisak on GitHub · 2026-11-25 00:19 UTC · original
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-shader/src/emit/lower.rs,crates/victory-shader/src/io.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
@iGoldenNinja on GitHub · 2026-11-25 09:37 UTC · original
I checked
88b34a447350eeb1e747be84e4204dbb3955c58ctogether with the exact 64-bit atomics changee2624b3384813a444067fe9ba93dfd131473a63cfrom #2241. The cherry-pick onto this head applied without manual edits. Hardware was an RTX 5080, driver 617.14 and Windows 11 Pro 25H2 build 26200.9974, with Rust 1.98.1 MSVC anddxil.dll1.9.2609.5.In the same 168-program pixel set that I tested for #2241, six shaders still failed on
barycentrics read directlywith the atomics change alone. All six emitted, validated and created D3D12 pipelines with this PR added. A full rerun oftranslate --jobs 2 --validate --pipelines --listthen produced 168/168 emitted, validated and created pipelines, including all 162 from the earlier run. The combined test reached offline pipeline creation. Pinned results and tested revisionsPull request closed