Repository navigation
Shaders: pixel barycentrics through SV_Barycentrics (values and computed interpolation) - #453
AntoninMichelq 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
|
Follow-up: this overlaps #442 (both emit Measured on Arch Linux x86_64 (rustc 1.98.1,
Not covered here: DXIL validation on Windows (no SM 6.6 device in this Wine prefix) and title shaders (no game data). |
|
Tested on Windows 11 + retail Tested
Not tested: Live gameplay / rendering with these shaders on GPU or WARP. AI use: Antigravity ( |
|
Ran One case emits a module the validator refuses.
Also, the tests' |
|
Tested on an RTX 4070 (Windows 11, driver 621.01) with
* #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 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 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. |
…entrics) By AntoninMichelq. Conflicts and what was kept: - emit/lower.rs (the interpolation's packing): Marvisak#176's `half_inputs` lookup, with the PR's `total` closure after it. - io.rs: Marvisak#179's `Halves` made on demand (`halves.get_or_insert_with(|| Halves::new(p))`), with the PR's `push_pair`; both sides' tests. - emit/mod.rs (the PR's test helper `pixel`): Marvisak#566's per-lane argument of `resource::track` and Marvisak#223's `Target` argument of `emit`; the helper still fails on resources, then I/O, then structure. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… of the console's Two cases where Marvisak#453 emitted a module dxil.dll refuses, found in review: - A program that reads the barycentrics of two sample positions of one kind as values (centre and centroid, both perspective) declared two SV_Barycentrics of that kind. DXIL takes one perspective and one linear. It now stops with `barycentrics of two sample positions`; the old limit counted elements, not kinds. - A console input signature with an SV_Barycentrics row of its own kept that row, packed, also under a program that only interpolates. The row is dropped: lowering declares what the program reads. Tests (emit/mod.rs, barycentric_tests): the refusal by name; a console row under a program that interpolates and under one that reads i and j, each validated. Each fails with its half of the change taken out. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…out) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
This PR is in the tester tree now ( 1. What it gains in that tree. Measured on my own copy of the title's shader file, offline:
That agrees with the counts on 2. Two cases where
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 Tested here on an RTX 5070: |
|
Measured on the full retail shader pack (26,503 containers) with
|
|
Follow-up on the three pixel programs that reached the 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. |
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
|
A short in-game data point for this PR, from Windows 10 with an RTX 3070 on In a captured frame in the world, every draw into one full-resolution I couldn't test it yet. This PR's head is on I'm testing with Claude's help, and Claude drafted this comment. |
|
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 has 88b34a4, 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. |
… initialised, no group sync at a barrier only some lanes reach) By FibbS6. One textual conflict in emit/lower.rs (its `divergent_barriers` beside Marvisak#453's `interp_mode`; both kept). One change to the PR's behaviour, in `Lower::new`: its fence-only barriers are not applied in the console flow of the wave64 stack (Marvisak#233, Marvisak#320, Marvisak#439). There every lane of a wave runs every block, so the lanes come to a barrier together, and the stack relies on the group sync to order one wave's LDS accesses. Per lane, the PR's rule stands. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
catminou4
left a comment
There was a problem hiding this comment.
Substantial feature done carefully. What I verified in the diff:
Semantics. eval_channel with Eval::Weights computes P0 + i·(P1−P0) + j·(P2−P0) via fmad, matching the GFX10 barycentric interpolation the PR description documents (P0 = provoking vertex, i/j from SV_Barycentrics channels y/z). vertex_input reads the constant-declared element through attributeAtVertex and sets flags::BARYCENTRICS. The per_vertex/interpolated predicates correctly decide when an attribute row must be read per-vertex vs. left to the normal interpolated path, and Interp::Vertex still refuses non-provoking reads (vertex != 2 guard).
io.rs classification. Pair.barycentric becoming Option<Barycentric> is the right shape: computed i or j downgrades each half to Interp::Weighted independently, and push_pair records the first halves with a dedup guard so a half isn't registered twice. The kind.is_some_and(...) logic only keeps the paired kind when every first half reads the same kind's i — conservative in the right direction.
Validator constraints. The "one perspective + one linear SV_Barycentrics element max" errors match the DXIL rule quoted in the tests, and the element is deliberately left unpacked (packing location −1) with a comment explaining the validator refuses it in a row.
Tests. 9 new tests cover the matrix (values-as-barycentrics, two modes, interpolation alone, both together, computed barycentrics in io and emitter, constant weights); the computed_barycentrics_evaluate_each_half test pins the Weighted classification exactly.
Verified locally: test-merge with current main (ffe310e) clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 106 passed / 0 failed / 1 ignored. Actual barycentric values on hardware are Windows-gated (valu_tests), so the Windows lane should confirm the i=y/j=z mapping on real titles — but the lowering structure and classification are platform-independent and green here.
One triage note for the maintainer: open draft #281 touches the same lower.rs barycentrics code (opt-in, perspective-center only). This PR covers all six modes on by default and supersedes it functionally; whichever lands second will need a rebase.
`image_get_lod` of an array texture passed the array slice as a
coordinate; DXIL's CalculateLOD takes the spatial ones and wants the rest
undefined, and dxil.dll refused the module ("out of bound coord must be
undef"). Three of the title's pixel programs reached this once Marvisak#453 let
them past their barycentrics.
The fix is MichaelSmithAI's (commit 26f915d on their fork, reported on
Marvisak#453); its test there is written against main's
`Lower::new` and does not build in this tree, so the test here is one
for this tree's helpers: a 1D-array and a 2D-array query, each validated.
It fails with the validator's message when the change is taken out.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
@MichaelSmithAI the before/after count you asked for, on the three programs themselves. The fix from your
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 The title was not launched; this used its shader file offline as described. AI-assisted. |
…trics) Conflict in shader.rs: both feature flags kept (barycentrics, typed 64-bit atomics). Its test helper passes Target::ANY to emit (Marvisak#233). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent test & review on Windows 11 + NVIDIA RTX 3070 (Rust 1.98.1) at head
|
`image_get_lod` of an array texture passed the array slice as a
coordinate; DXIL's CalculateLOD takes the spatial ones and wants the rest
undefined, and dxil.dll refused the module ("out of bound coord must be
undef"). Three of the title's pixel programs reached this once Marvisak#453 let
them past their barycentrics.
The fix is MichaelSmithAI's (commit 26f915d on their fork, reported on
Marvisak#453); its test there is written against main's
`Lower::new` and does not build in this tree, so the test here is one
for this tree's helpers: a 1D-array and a 2D-array query, each validated.
It fails with the validator's message when the change is taken out.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…interpolation with its fix) Onto 6f1c30b (the tree's update 4, the black-scene branch and Marvisak#704). One conflict, emit/lower.rs, where inputs are loaded on first use: this branch's spill arguments (`Reg::Spill`, Marvisak#489) and Marvisak#453's barycentric VGPR inputs are both left for first use. `cargo test --workspace --no-fail-fast -- --test-threads=4`, run once on the RTX 5070 and WARP while offline translate runs shared the CPU: victory-shader 225 passed, 1 ignored; victory-gpu 97 passed, 1 ignored, 1 failed (frame::tests::waits_end_on_ticks_and_count_frames, a timing test that fails under load); every other crate passes. Not run in the title. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The tester tree (upstream main ffe310e plus its PRs, update 8; see its INTEGRATION.md) ran 11-25 minutes in the world on an RTX 5070 without a device removal. Where both sides carry the same PR (the wave64 stack #223/#233/#320 with #439 and #180, #454, #336, #259, #331 and others), the tester tree's newer head is taken; our own work and the PRs only we merged are kept. Conflicts, file by file: - descriptor/host.rs: the tester layout (`spare`, the guard slot after the dynamic slots, `free_table`, the capped sampler heap). A capped view heap keeps `capped_reserve()` dynamic slots, now 2^18 by default (the tester measurement, and our 91fed158), still `VICTORY_DYNAMIC_SLOTS` in diagnostics builds; uncapped hosts keep our 2^19. Our slot statistics (TAKEN/PEAK/SHORT), the bindless plan cache (`CommittedRegions`, `timed_valid_title_address`, `timed_find`, `title_bounds`) and the revision triple are kept beside the tester's `guard_slot`. - Buffer states: the tester tree's buffer-state tracker (#334: every list moves host copies of title memory between GENERIC_READ and UNORDERED_ACCESS and back to common before it closes) and depth twins (#469) are taken. #40's enhanced/legacy indirect barriers (the indirect prelude, `use_indirect_buffers`, the title buffer handoff mirrored in `host_barrier`) cannot share buffers with that tracker and are dropped; #40's argument checks (`byte_len`, exact spans, overflow-safe clamp shader, aligned counts) stay. `indirect::bound` and #282's `rectangles` go through `buffer_state`, and `indirect::execute` (#334) replaces `done`. #178's DXC fallback compiles both of our passes. Our segments (#387: `close` ends the segment, `close_native` closes a native list) carry the tracker: each native list returns its buffers to common and its twins to their depth targets, and each prelude also holds our texture uploads. - shadow.rs: our write flow (`queue_write`, one `snapshot` after the batch's refreshes, `finish_writes`, the unchanged-page cache) with #261's copy-back that also gives the snapshot the title's bytes; its tests run through our flow. - pipeline/make.rs: #275's per-frame budget and per-pipeline wake pair, with our compute waits (a dispatch waits for its pipeline, up to 20 s). - pipeline/library.rs: the tester version (#347, #275's saver thread); our concurrent-write test kept. shader_cache.rs: our byte-returning cache API with #358's "translated, only not kept". - draw.rs: #493's root SRV tables; where no table can stand in, our drop of a draw whose root view is unset or outside title buffers. Our refusal of a table offset past the capped heap stays. - resource.rs: `HostTexture` has both our `staged` generation and the depth twin. - Shaders: the tester's lower.rs for the wave64 stack, #160's image sampling (it covers our #73 and #136 sample forms) and #453/#587; kept from our side: #136's preference for an image or buffer use of a descriptor read as data and its `s_buffer_` arm, #422's nearest-even narrowing (also for #169's d16 loads and #453's interpolation), #452's spin-wait limit, #391's LDS limit, #302's spilled root arguments (now in `NativeProgram::translation_ir`), #136's PSV0 interpolation beside the tester's row harmonisation. split_tests.rs, lane_read_loop_tests.rs and docs/wave64-on-wave32.md are the tester versions (the same PRs at newer heads). - Tests: #483's heap guard dwords filled in our GPU tests of #200 (v_div_scale) and #437 (scalar loads from a raw view), which read through the guard slot otherwise; #334's debug-layer test passes an offset to our `indirect::bound`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ted interpolation) 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, one element per mode, 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; it is left unpacked, as the validator wants. A second perspective (or linear) mode is refused: DXIL allows one of each, and reusing the first would give centroid reads center weights. 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; alone it is still refused. Interpolations with operand modifiers (VOP3 abs/neg) are refused rather than lowered without them. XTP adaptation: the hunks of emit/lower.rs went to emit/lower/input.rs (S0b), merged with #592/#621's packed inputs (a padding half is the float 0 now that halves are evaluated as floats); the first-use hook went to `Lower::get` (emit/lower/operand.rs) and the join of a read phi to emit/lower/flow.rs (3 lines, granted for this port); emit/mod.rs and emit/container.rs get one line each for the system value; the upstream tests (emit/mod.rs there) are in input.rs's tests. Review: a plain 32-bit interpolation keeps its loaded bits as before (the upstream merge round-tripped them through a float, which changed 8,966 translations for nothing). Left as a shortcut, from upstream: triangles only (on lines and points the console's i and j are not checked against the host's weights). Survey (shaders.rpf, any host, every translation validated): 23,161 -> 23,371 translated, 210 new (175 with computed barycentrics, 35 reading them directly), 204 accepted by dxil.dll; the 6 others stop at errors of their own (3 "out of bound coord must be undef", 3 interpolation modes packed in one row); none lost, no validator verdict changed. 74 translations that existed change, all still accepted. 33 programs past these blockers stop at the next one (32 at an opaque lane mask). Without the flow.rs hook, 87 of them stopped at "a join of mismatched values". Ported from Marvisak/VIctory#453 (head 88b34a447350eeb1e747be84e4204dbb3955c58c) by AntoninMichelq Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…with the resolution of its conflicts with Marvisak#176 and Marvisak#1293 Marvisak#453 evaluates the halves of an interpolation on their own when i or j is computed (SV_Barycentrics, Interp::Weighted). Marvisak#1293 (in the stack) follows plain v_mov_b32 copies to find the barycentric of a pair, and Marvisak#176 (in the stack) pairs packed 16-bit pixel inputs through half_inputs. The conflicts were in io.rs (the pairing), emit/lower.rs (the interpolation lowering and two spots of the phi and helper code) and emit/shader.rs (the feature bits). See the pull request text for how each was resolved. Marvisak#1293's test interpolation_follows_agreeing_phis_and_rejects_mismatched_or_modified_copies asserted that a computed i (a phi of i and j, a negated copy) is refused; with Marvisak#453 it is supported as a Weighted pair, so those two assertions now expect Weighted halves. cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features, is clean and cargo test --workspace --locked passes (391 passed, 6 ignored; main has 342 passed, 6 ignored). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…with the resolution of its conflicts with Marvisak#176 and Marvisak#1293 Marvisak#453 evaluates the halves of an interpolation on their own when i or j is computed (SV_Barycentrics, Interp::Weighted). Marvisak#1293 (in the stack) follows plain v_mov_b32 copies to find the barycentric of a pair, and Marvisak#176 (in the stack) pairs packed 16-bit pixel inputs through half_inputs. The conflicts were in io.rs (the pairing), emit/lower.rs (the interpolation lowering and two spots of the phi and helper code) and emit/shader.rs (the feature bits). See the pull request text for how each was resolved. Marvisak#1293's test interpolation_follows_agreeing_phis_and_rejects_mismatched_or_modified_copies asserted that a computed i (a phi of i and j, a negated copy) is refused; with Marvisak#453 it is supported as a Weighted pair, so those two assertions now expect Weighted halves. cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features, is clean and cargo test --workspace --locked passes (391 passed, 6 ignored; main has 342 passed, 6 ignored). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. Needs rebase. This PR does not merge cleanly into current The content has not been reviewed yet; it will be once the branch is rebased onto Generated by Claude Code |
|
I checked In the same 168-program pixel set that I tested for #2241, six shaders still failed on |
Requested 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