Repository navigation
Conversation
A pixel program gets its barycentric pairs (i, j) in VGPRs, as SPI_PS_INPUT_ADDR enables them. Programs that use them only in v_interp_* translate; one that also reads them as data (arithmetic, an export, a join) stopped with "barycentrics read directly", one of the common reasons pixel shaders do not translate (Marvisak#97). Such a read is now a channel of SV_Barycentrics (SM 6.1) with the pair's interpolation mode: perspective or linear (noperspective), center, centroid or sample. The hardware's i and j weight vertices 1 and 2 (P0 + i P10 + j P20); D3D gives the provoking vertex's weight in x and the other two in y and z in winding order, so i is y and j is z when P0 is the provoking vertex. The hardware may rotate a primitive's vertices cyclically; the host has no such rotation, and gives the unrotated weights. D3D allows one perspective-correct and one linear SV_Barycentrics, so a program reading two perspective (or two linear) pairs as data still stops, as does the pull model. The element is declared on first read, so programs that only interpolate keep their signatures. A console SV_Barycentrics row (system value 23, refused as an unknown system value until now) is left out and declared again from the pair read: a signature has no interpolation modes. The barycentrics shader flag and SFI0 bit are set with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Verified Not covered: the emitted barycentric signature on a real host (no D3D12 execution here) and title behaviour (no game data). |
|
Follow-up: this overlaps #453 (both emit Measured on Arch Linux x86_64 (rustc 1.98.1,
#453 describes itself as the broader version of the same fix (it also notes draft #281). Not covered here: DXIL validation on Windows (no SM 6.6 device in this Wine prefix) and title shaders (no game data). |
|
Thanks for testing and for spotting the overlap. You're right: #453 does everything this PR does, plus computed barycentrics in Two things from here that #453 may want:
|
…out) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Measured on the full retail shader pack (26,503 containers) with VS/PS 12237 / 12158 (+10 validated): the 13 "barycentrics read directly" refusals are gone, but 3 of those programs fail the validator with "out of bound coord must be undef.". CS and MS unchanged. For comparison, #453 (measured on its base, since it conflicts with main) also clears the 207 "interpolation with computed barycentrics" and validates +175 pixel programs. |
|
Thanks @slint6614-dev for the full-pack numbers. They confirm #453 is the one to take. It clears the same 13 refusals plus the 207 computed-barycentric ones (+175 validated, against +10 here), and 3 of the programs this PR emits fail the validator ("out of bound coord must be undef"). I'm closing this in favour of #453. The GPU draw test and the vertex-rotation note in my comment above remain available to #453. |
|
Tester result: +2 of 339 previously failing world programs now emit (vertex/pixel 0 → 2 of 25; the two that logged How measured: 339 shader containers from my own 1.0.2.1 copy, the distinct programs that logged |
What
A pixel program gets its barycentric pairs (i, j) in VGPRs, as
SPI_PS_INPUT_ADDRenables them. When it usesthem only in
v_interp_*, it translates already. When it also reads them as data (arithmetic, an export, ajoin), lowering stopped with
barycentrics read directly. Such a read is now a channel ofSV_Barycentrics(SM 6.1):
lower.rs: i isSV_Barycentrics.yand j is.z,loadInputfrom an element declared on first read with thepair's interpolation mode: perspective center, centroid and sample become
linear,linear centroidandlinear sample(DXIL modes 2, 3, 6); the linear pairs become thenoperspectiveforms (4, 5, 7). The modetable
v_interp_*already used is now one function (interp_mode) for both.their signatures and need no new device feature. A barycentric that reaches its reader through a join (a phi)
is loaded for the join too.
noperspectiveSV_Barycentrics(indices 0 and 1). A programthat reads two perspective pairs as data (say center and centroid), or two linear ones, still stops, now with
barycentrics of two sample positions read directly. The pull-model triple (i/w, j/w, 1/w) still stops too.mod.rs: anISG1row with system value 23 (SV_Barycentrics) is parsed; until now it stopped thetranslation as
a system value in the signature. That row is left out and declared again from the pair theprogram reads, because a signature carries no interpolation mode.
container.rswrites kind 28 as systemvalue 23.
shader.rssets the barycentrics shader flag (bit 22) and itsSFI0bit (0x20000), which thevalidator expects whenever the input signature has
SV_Barycentrics.emit/barycentric_tests.rs(below).Why
#97 lists
barycentrics read directlyamong the most common reasons pixel shaders do not translate.The vertex order is the part that has to be right. Here is what I checked, and how:
v_interp_p1_f32takes i,
v_interp_p2_f32takes j). Mesa's ACO does exactly that: it passes channel 0 of the barycentric pairto
v_interp_p1_f32and channel 1 tov_interp_p2_f32(aco_isel_helpers.cpp). So i is the weight ofvertex 1, j the weight of vertex 2, and P0 gets 1 − i − j.
v_interp_mov_f32from P0 (vertex_id = 0; /* P0 */). This translator already maps P0 tonointerpolation. RADV implementsVK_KHR_fragment_shader_barycentricin
radv_nir_lower_fs_barycentric.c(MIT). It builds the API-order weights as (1 − i − j, i, j) when a per-quadhardware value (
load_provoking_vtx, GFX10.3 and later) is 0. For 1 and 2 it uses the two cyclic rotations ofthat. So the hardware's P0, P1, P2 are the API vertices rotated, never mirrored. The rotation can differ per
primitive: AMD's GPUOpen article on stable barycentrics says the driver picks the first vertex by the
triangle's screen orientation.
SV_Barycentricsdocumentation says the provoking vertex's weight is always in x.The others follow in the primitive's order, flipped on every other strip triangle to keep the winding (strip
triangle 1 is [1, 3, 2]).
and j is symmetric (an edge distance, say) gets the console's result on every primitive. A program that
un-rotates with the hardware's per-quad value reads an SGPR this translator does not model, so it still
stops. A program that uses raw i and j unsymmetrically gets the API-order weights, which are one of the orders
the console itself can show.
SV_Barycentricsin a pixel input isNotPacked(SM 6.1), so itgets no register (row and column −1, PSV0 start 0 without the allocated bit). It must be a float3. Its mode must
be one of the six above. There are at most two, with different perspective, at semantic index 0 or 1. The
shader flag is computed from the input signature for validator 1.6 and newer (our
dx.valver).vertices 0, 1 and 2 at each pixel. Perspective-correct and screen-linear both match, on the RTX 5080 and on
WARP (test below).
What I could not check: which rotation the console hardware uses for a given primitive. Lines: D3D's z is exactly 0 on a line, so j reads 0 and i reads the
whole weight. RADV builds the line weight as i + j, so the hardware may split it between the two. A program
that uses i and j separately on lines could differ. This is marked
shortcut:.SV_BarycentricsneedsD3D12_FEATURE_DATA_D3D12_OPTIONS3::BarycentricsSupportedon the host. These programs didnot translate before, so no device loses anything. On a device without the feature, creating their pipeline
fails.
Overlap: #281 (open, opened while this was being written) makes the same mapping (i = y, j = z) for the
perspective-center pair only, behind an opt-in feature because of the rotation question above. This branch
covers all six pairs and two elements, a console
SV_Barycentricsrow and reads through a join, and it is on bydefault. #136 (open) adds the same one-line
23 => 28mapping inmod.rssignature()and takes interpolationmodes from the console's
PSV0. It does not lower barycentric reads. If both land, the conflict is that oneline. The row this PR leaves out is dropped before #136's mode loop, so the two do not fight.
Tested
Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1; also WARP.
New tests in
crates/victory-shader/src/emit/barycentric_tests.rs. They use synthetic GFX10 programs throughir::build→resource::track→io::raise→structure→emit. The checks read the container'sISG1,PSV0andSFI0:barycentrics_read_as_data_are_sv_barycentrics_y_and_z: a program exporting (1 − i − j, i, j, 1). It runs foreach of the six pairs, and once with a console
SV_Barycentricsrow inISG1. Checks: oneSV_Barycentricsrow (system value 23, no register, float, mask xyz, y and z read), the pair's mode in
PSV0, and theSFI0bit.a_perspective_and_a_linear_pair_are_two_elements: perspective center plus linear center gives indices 0 and1 with modes 2 and 4. Center plus centroid is refused with the new message.
interpolation_alone_declares_no_barycentrics: av_interp_p1/p2program keeps only its TEXCOORD row anddoes not set the
SFI0bit.a_barycentric_joined_at_a_branch_is_loaded_for_the_join: i, or 0.5 behind a uniform branch, joined in a phi.drawn_weights_are_the_hosts_vertex_weights(host GPU): a triangle with w = 1, 2, 4 and a pass-through vertexshader, drawn at 32×32. In each of the 292 pixels well inside the triangle, the output must match the weights
of vertices 0, 1, 2 to within 2e-3. For the perspective-center pair those are the perspective-correct weights.
For the linear-center pair they are the screen-linear ones (the two differ by up to about 0.3 here). It skips
when the device lacks barycentrics. It ran on both.
Results:
barycentrics read directly(the GPU test at translation). Onlyinterpolation_alone_declares_no_barycentricspasses. Branch:all 5 pass, and the draw matches on the RTX 5080 and on WARP.
cargo test --workspace -- --test-threads=1,cargo clippy --workspace --all-targets,cargo xtask policy): main 264 passed, 0 failed, 4 ignored; branch269 passed (the five new tests), 0 failed, 4 ignored; clippy reports the same warnings on both (none in the
changed files); policy ok on both. A first run with
--test-threads=4hung in the existing
emit::valu_tests::bfe_signed_and_unsigned_match_rdna2, which uses WARP from paralleltest threads (Tests: victory-shader tests crash (0xC0000005) when several tests use WARP devices in parallel #181). Every crate before
victory-shaderpassed, as did 73 of its 74 tests, the new onesincluded.
cargo clippy -p victory-shader --all-targets: no warnings, on main or on the branch.dxil.dllwas not available on the test machine, so the validator step of these tests (and of the existingones) was skipped. The DXIL checks above are structural, plus pipeline creation and the draw on two drivers.
Not tested
dxil.dll), as above.AI-assisted (Claude Code, Claude Opus 5.5). No game files were used.