diff --git a/docs/design.md b/docs/design.md index 6bb417340a..0c8d34b2c4 100644 --- a/docs/design.md +++ b/docs/design.md @@ -350,7 +350,7 @@ How the generated SPIR-V expects the runtime to work: | Ray tracing | `image_bvh_intersect_ray` / `image_bvh64_intersect_ray` (64 CS: RT shadows) are one traversal step against AMD's hardware BVH node format. The traversal loop lives in the game's shader. The step is emulated over buffer reads following Mesa RADV's software path (`radv_nir_rt_common.c`, `intersect_ray_amd_software_box/_tri`; node layouts from `bvh_defines.h`). Node id = address >> 3 \| type (0–3 triangle, 4 box16, 5 box32). Box nodes give the four child ids, with misses and NaN boxes = `0xFFFFFFFF`, sorted by entry distance when descriptor bit 63 (box_sort_enable) is set. **The box test is the native one, measured on RDNA2** (SHADER-650; RX 6900 XT, gfx1030, `tools/hw_oracle` raw kernels, 338 cases: BOX32 and BOX16, four rays including negative directions, NaN in every position, empty boxes, planes on the origin, and every tie order of four children; the translator now matches all 338 bit for bit, `main` before it 43, and all 811 rounding cases below): per axis, the near plane is min and the far plane max when the inverse direction (taken as given, not clamped) is ≥ 0, swapped otherwise; t = (plane − origin) × inverse direction, so `0 × inf` is NaN. **Both the subtraction and the multiply round toward zero** (811 more cases, 800 randomized slabs at origins 2^18 to 2^27 away plus 11 ties: round-to-nearest predicts 769 of them, round-toward-zero all 811; among the ties, a box with min.x = 1 > max.x = 0 at origin.x = −2^25 is a hit on hardware because both planes round to the same t). The translator emulates this exactly: the subtraction's error comes from TwoSum, the product's error sign from a Dekker split of the two mantissas scaled to [1, 2), and a result rounded away from zero steps one ulp back; a finite overflow gives ±FLT_MAX. tnear = max of the three near t, tfar = min of the three far t, **each skipping NaN**; all three near or all three far NaN is a miss. Hit when max(tnear, 0) ≤ tfar and tnear < extent (the extent boundary itself was not measured). So a lone NaN bound leaves its own plane open (a box with min.x = NaN is hit wherever x ≤ max.x), an empty box (min > max on any axis, ±inf or ±65504 included) is a miss without a separate check, and a plane exactly on the origin along a zero-direction axis is open. The sort key is max(tnear, 0), so boxes around the origin tie at 0, ordered by the network (0,2) (1,3) (0,1) (2,3) (1,2) with a strict `<` swap (all 88 measured tie orders). `tests/semantic/test_image_bvh_box_hw.py` holds measured words. Triangle nodes read their three vertices from the slots the node type picks: TRI0 (0,1,2), TRI1 (1,3,2), TRI2 (2,3,4), TRI3 (2,4,0), 12 bytes each. They use the watertight test with RADV's shared edge/vertex tie-breaks and give (t/\|det\|, sign(det), b_i/\|det\|, b_j/\|det\|), or (inf, 1, 0, 0) on a miss. The weights i and j are chosen by the node type's byte of the triangle-ID word at +60: bits [1:0] and [3:2], 0/1/2 = vertex 0/1/2 and 3 = vertex 0, bits [7:4] ignored; `0x09` gives RADV's (v, w). Vertex slots and remap follow AMD GPURT (`CalcTriangleCompressionVertexIndices`, `SwizzleBarycentrics`) and the public XDXR software path ([bvh.md](bvh.md) §7a), and the hardware agrees. **The triangle step is the native one, measured on RDNA2** (AMD Radeon RX 6800, gfx1030, AMD Windows driver 26.11.2, Windows 11, 2026-11-22; the `tools/hw_oracle` kernels `tools/bvh_tri_probe.py` builds, hand-built nodes and rays: 14 kernels, 308 single-lane cases and 7 cases on 64 lanes, 1,204 results, each in both forms; the 32-bit form with the descriptor base at the node and the 64-bit form with base 0, wave32 and wave64, NSA and contiguous operands all gave the same words). A NaN anywhere in t max, the origin, the direction or the inverse direction, or an infinite origin, returns (+inf, 1.0, +0, +0). Otherwise the watertight test runs with its shear taken from the direction (kz = the axis of the largest \|d\|, ties x, y, z; kx and ky swapped when d[kz] < 0; Sz = 1/d[kz]): **the supplied inverse direction is not used**. With the edge functions U, V, W, det = U + V + W, T = t·det and k = \|d[kz]\|³, a hit returns (k·T, k·det, k·b_i, k·b_j) and a miss (copysign(inf, k·det), k·det, k·b_i, k·b_j): numerators over the denominator k·det, and a miss keeps the plane's barycentric numerators. det = 0 is a miss with word 0 = +inf. The hit needs t ≥ 0 (t = 0 hits); there is no test against t max. Every zero word is +0 and every NaN word 0xFFC00000, so a NaN det gives word 0 = −inf. An edge function of 0 is inside when its edge passes RDNA2's tie rule, which is not RADV's: the edge from P to Q (U: B→C, V: C→A, W: A→B), with (tx, ty) = Q′ − P′ in the sheared frame with the d[kz] < 0 swap of kx and ky undone, passes when ty = 0 ? sign(det)·tx > 0 : sign(d[kz])·sign(det)·ty > 0, and every zero edge must pass. Every shared edge and shared vertex gave exactly one hit. How this rule was found: the first fit (ty = 0 ? tx < 0 : sign(det)·ty > 0, on the 49 tie rows of the first measurement, all z dominant) was confounded, because every one of those rows had det < 0 with d[kz] > 0 or det > 0 with d[kz] < 0, and it was wrong in the cells it never saw. A second measurement (2026-11-23, same part and driver; 8 more kernels, 256 rows: ties with x, y and z dominant, both windings, both signs of d[kz], every edge direction class in each of those cells, tilted triangles with oblique rays, equal \|d\| components) fitted none of the eight rules registered before it ran. The rule above was then read off its x/y rows (post hoc), and it predicted the z-dominant bridge kernel `tri_t8` before that ran: 32 of 32 cases, 10 of them rows where it and the first fit disagree. The translator computes these words without a division, with the shear multiplied through by \|d[kz]\| (a shear divided by d[kz] gives the same words on every measured row but d.z = +inf, and divides by zero at d = 0; this form gives d = 0 → (+inf, 0, 0, 0) and d.z = +inf → (−inf, NaN, −inf, −inf) as measured, a fit after the runs), and fixes zero signs and NaN bits with integer selects, so every measured input is defined SPIR-V. `tests/semantic/test_image_bvh_tri_hw.py` asserts all 308 rows and 84 lane results of the first measurement and the 256 rows of the second bit for bit (the translator before it: 129 of the first 308; the first fit: 210 of the 256); `tests/semantic/test_image_bvh_tri.py` runs every node type and remap byte on the interpreter. **A consumer that divides by word 1** (t = w0/w1, weights w2/w1 and w3/w1) gets t and the weights on a hit (k cancels; word 1 keeps det's sign); +inf for t on a miss of either winding, with the plane's weights; t = +inf/+0 = +inf and weights 0/0 on a zero-area triangle; t = NaN with a NaN or inf vertex, so a `t < t max` test fails as on a miss; t = +inf with a NaN in the ray or an infinite origin. It must compare t with t max itself. The translator's earlier normalised words (t/\|det\|, sign(det), b_i/\|det\|, b_j/\|det\|; a miss (inf, 1, 0, 0)) gave such a consumer the same t on every row and the same weights on every hit except on 14 shared-edge rows (RADV's tie rule), 3 rows whose inverse direction is not 1/d, 3 rows with a NaN in the ray (it reported a hit or other words), the v0.x = −inf and d.z = +inf rows, and 14 rows that were undefined SPIR-V there (zero area, a NaN or inf vertex, a NaN, inf or zero ray). **Not measured:** gfx1013 (the console); node types 6 and 7; the box extent boundary; descriptor words other than w2 = 0xFFFFFFFF, w3 = 0x81000000 (return mode 0 included); the dominant axis on equal \|d\| components except where a measured tie row tells the axes apart: x for \|dx\| = \|dy\| > \|dz\| (only with dx, dy > 0), x for \|dx\| = \|dz\| > \|dy\| (not with dx > 0 > dz), y for \|dy\| = \|dz\| > \|dx\| (only with dy, dz of the same sign) and x with all three equal (in the four of the eight sign patterns that ran), which is the translator's `>=` order (a non-tie row gives the same words whatever the choice, and every sign pattern could show it with the right tie); rounding-sensitive inputs (every input is dyadic, so the divided versus multiplied-through shear and fused versus separate rounding are not told apart); d = 0 and infinite d beyond one row each; the remap's high nibble on TRI1–TRI3. These two references agree; one real pack BLAS is now matched, rehydrated and traversed (§7b), though the rule has not been counted over the whole corpus. The triangle rule has not been measured on the native instruction yet: `tools/hw_oracle` can run it on RDNA2, and box32 nodes were measured that way (gfx1036, address = base × 256 + (node & ~7) × 8 in both instruction widths, §7b), so the triangle counterpart is a possible follow-up rather than an impossibility. These two references agree; no game BVH is decoded yet to count over. The triangle rule has not been run natively yet; the box rule above has (`tools/hw_oracle` on an AMD RDNA2 card runs the instruction itself). `tests/semantic/test_image_bvh_tri.py` runs every node type and remap byte on the interpreter, including the descriptor-base case. The game's code divides by `.y` exactly as for the hardware's numerator/denominator. Address = descriptor base + ((node & ~7) << 3). The descriptor's dword0 is the base in 256-byte units: the game passes `ptr >> 8` there, and the `\| 0x30` its shader ORs is only the temporary address it uses to load `rootNodePtr`, not the descriptor base. Measured at base 0 and at base 0x1000 (structure at VA 0x1000, dword0 `0x10`): the GPU returns the CPU walker's children in the same order at both, so the `<< 8` is correct and a nonzero base needs no masking. `tests/semantic/test_image_bvh_tri.py` runs the nonzero base (`0x10` → `0x1000`). Address = descriptor base + ((node & ~7) << 3), base = descriptor bits [39:0] in 256-byte units (measured on gfx1030: the 32-bit form with a non-zero base and the 64-bit form with base 0 and the full address gave the same words in 71 cases). **The runtime must build the game's acceleration structures in this AMD node format** (RADV's GPU BVH builder produces it) wherever the game's D3D12 calls build them. Far branches with `s_sub_u32`/`s_subb_u32` (backward) are folded too. GPU-checked with `runtime/test/shaders/cs_bvh.asm`: sorted box children and the triangle result are exact; its box with a NaN min.x is entered at t = 0 and sorts first (`0x68 0x48 0x40 0xffffffff`), as native gfx1030 returns for that scene. The 32-bit form (11 address dwords: the node id has no high dword) runs the same scene in `cs_bvh32.asm` and gives the same eight words. Corpus counts (`tools/image_bvh_census.py`, static, [bvh.md](bvh.md) §7): 716 sites, 638 32-bit and 78 64-bit; the descriptor has box_sort_en 1, big_page 1, size all ones and type 8 at every site; on every path from the call, 397 sites take `v_rcp_f32` of word 1, multiply word 0 (335 also words 2 and 3) by it and read `sext(w1[31:16])`, all 716 read the words as integers (397 through shifts and `v_and_or_b32`/`v_lshl_or_b32`/`v_or3_b32`, 319 through `v_cmp_eq_u32` only), and none reads a word undivided as a float; 633 sites also have reads on some paths only, which the census leaves unclassified. | | Coverage | Every shader in the corpus translates. The remaining fidelity gap is wave64 cross-half code on 32-wide subgroups in VS/PS/GS (tier C of the *Wave64 graphics* row; tiers A and B are exact); compute and mesh shaders are exact there with `--wave64-emulate` (see the wave-size and wave64 rows). | | Flat pixel inputs | A pixel input location read only by `v_interp_mov_f32` with the p0 select is declared `Flat` (a location a p10/p20 mov reads is `PerVertexKHR`, next row). A pixel input location read only by `v_interp_mov_f32` is declared `Flat`. Locations read with `v_interp_p1/p2` remain interpolated. The `ps_flat` GPU test passes integer IDs through the first vertex alongside interpolated UVs. On the CPU, `test_v_interp_mov_emits_flat_decoration` and `test_attribute_read_both_flat_and_interpolated_is_not_flat` in `tests/semantic/test_interp_mov_flat.py` check the Flat decoration of a p0-only location and that a location also read with p1/p2 is not decorated Flat. | -| v_interp operand guards (SHADER-177) | The single-lane model reads the attribute's own value for `v_interp_p1/p2`, which is only right when the VGPR source really holds the barycentric coordinate that op interpolates with — **p1 reads I = v0 and p2 reads J = v1, per op** — and `v_interp_mov_f32` p0 is the provoking vertex (p10/p20 are the deltas of the vertex-delta row above). A p1/p2 (f32 and f16 forms) whose source is not its own coordinate — v0 for p1, v1 for p2, each either the hardware register or a plain `v_mov_b32` copy rooted at it (the copy's single write in the whole shader, defined before the use, copy chains followed, and its source v0/v1 itself unwritten up to the copy: a copy of an already-overwritten v0/v1 carries a computed value — zeroing the source before copying renders (0,0) on hardware — while a write after the copy is fine, the copy saved the value) — is **Unsupported**, naming the register and the role, so a swapped p1(v1)/p2(v0) pair, a both-v0 pair, or a copy of an overwritten source is refused rather than silently mistranslated; `v_interp_mov_f32` with p10/p20 was **Unsupported** until the vertex-delta row above; any other select still is, naming it. `v_interp_mov_f32` with p10/p20 is **Unsupported**, naming the select. A **direct** v0/v1 read stays accepted even when the shader overwrites v0/v1 first (evaluate-at-offset/snapped barycentrics; up to 213 PS, #1218): modelling that computed value is the separate provenance follow-up. Zero corpus cost: over the 26,503-shader corpus every f32 I/J source is v0/v1 (117,001 / 116,997) except one PS whose four `v_interp_p2_f32` read J through `v_mov_b32 v14, v1` (its v1 unwritten up to the copy; the later overwrites are the saved-copy case), which the copy rule keeps translating (bit-identical .spv), every f16 source is v0/v1 (58,950 / 58,950), and all 6,926 `v_interp_mov_f32` use p0. Confirmed by `tests/semantic/test_interp_guards.py` (refusals name the operand and its role, including swapped and both-v0 pairs, a wrong-root copy, and a copy of an overwritten source; the copy, copy-chain, matching-role and saved-from-later-zero cases translate and compute; a second write or a dpp copy no longer qualifies; a mutation check that the guard consults the copy analysis) and by re-translating a 200-shader corpus slice plus that PS before and after: translated/valid counts and every .spv unchanged. | +| v_interp operand guards (SHADER-177) | The single-lane model reads the attribute's own value for `v_interp_p1/p2`, which is only right when the VGPR source really holds the barycentric coordinate that op interpolates with — **p1 reads I = v0 and p2 reads J = v1, per op** — and `v_interp_mov_f32` p0 is the provoking vertex (p10/p20 are the deltas of the vertex-delta row above). A p1/p2 (f32 and f16 forms) whose source is not its own coordinate — v0 for p1, v1 for p2, each either the hardware register or a plain `v_mov_b32` copy rooted at it (the copy's single write in the whole shader, defined before the use, copy chains followed, and its source v0/v1 itself unwritten up to the copy: a copy of an already-overwritten v0/v1 carries a computed value — zeroing the source before copying renders (0,0) on hardware — while a write after the copy is fine, the copy saved the value) — is **Unsupported**, naming the register and the role, so a copy of an overwritten source is refused rather than silently mistranslated. What the pair does when its two sources *are* barycentrics but not the ones its ops interpolate with is not a refusal but the interpolation with those values (**SHADER-659**): **a p1 multiplies P10 and a p2 multiplies P20 with the value the register it names holds**, so a swapped p1(v1)/p2(v0) pair, a pair that names one coordinate twice (both-v1, both-v0), and a copy rooted at the coordinate the other op does not use are modelled as the pair of weights they name — the attribute is read per-vertex (`PerVertexKHR`) and weighted with the two barycentrics, reusing the computed-I/J path below (its prologue seeds v0 and v1 from `BaryCoordKHR` whenever a pair reads them). Measured with `runtime/test/shaders/ps_interp_pair_roles.asm` over the test triangle (`vs_tri` in `scripts/run_gpu_tests.py`, `vs_ids` in `check.py`: attr0 = (0,0), (2,0), (0,2) at the vertices, so attr0.x interpolates to 2·i and attr0.y to 2·j): the four pairs of that listing — swapped, standard, both-v0, both-v1 — come out as (2j, 2i, 2i, 2j); taking the hardware weights whatever register the op named would give (2i, 2i, 2j, 2j). An opposite-role read with no partner op to take the other axis from stays **Unsupported** (`computed I/J pair: … without its p2 partner`). A matching-role source keeps the centre-interpolated read it had: every listing the rule does not touch translates byte for byte as before.; `v_interp_mov_f32` with p10/p20 was **Unsupported** until the vertex-delta row above; any other select still is, naming it. `v_interp_mov_f32` with p10/p20 is **Unsupported**, naming the select. A **direct** v0/v1 read stays accepted even when the shader overwrites v0/v1 first (evaluate-at-offset/snapped barycentrics; up to 213 PS, #1218): modelling that computed value is the separate provenance follow-up. Zero corpus cost: over the 26,503-shader corpus every f32 I/J source is v0/v1 (117,001 / 116,997) except one PS whose four `v_interp_p2_f32` read J through `v_mov_b32 v14, v1` (its v1 unwritten up to the copy; the later overwrites are the saved-copy case), which the copy rule keeps translating (bit-identical .spv), every f16 source is v0/v1 (58,950 / 58,950), and all 6,926 `v_interp_mov_f32` use p0. Counted again over all 26,503 listings for this change — no `v_interp_p1*` names v1 and no `v_interp_p2*` names v0 (the four `v14` reads are plain copies rooted at v1), so the new rule touches no listing the corpus has. Confirmed by `tests/semantic/test_interp_guards.py` (refusals name the operand and its role, including swapped and both-v0 pairs, a wrong-root copy, and a copy of an overwritten source; the copy, copy-chain, matching-role and saved-from-later-zero cases translate and compute; a second write or a dpp copy no longer qualifies; a mutation check that the guard consults the copy analysis) and by re-translating a 200-shader corpus slice plus that PS before and after: translated/valid counts and every .spv unchanged. **SHADER-659** the same way: `runtime/test/shaders/ps_interp_pair_roles.asm` judged by `interp_pair_roles_problem` (`runtime/test/shaders/check.py`, run by `scripts/run_gpu_tests.py`) — 4096/4096 pixels on a `gfx1036` iGPU (AMD Radeon Graphics, driver 31.0.24002.92) and on an RTX 4090 (driver 32.0.16.2124), with the standard pair in the same draw as the control; the role pairs and the two copy roots measured by value in `tests/semantic/test_interp_guards.py` and `tests/semantic/test_interp_p1lv_f16.py`; and the whole corpus re-translated before and after on the same flags — 26 503 translated both times, 26 503 byte-identical `.spv`, `index.json` unchanged. | | Pixel-shader interpolants | When a sidecar `fssm/.fssm` holds a pixel-input table (`tools/fssm_header.py`: 8-byte records from 0x138 while the first byte is 6; table position = `v_interp attr` number), every position 0..count−1 is declared as a fragment input at that Location, including positions the code never reads (the table overcounts the code's distinct `v_interp` attrs in 775 of 12,101 PS: 300 by one, 475 by two or more; only the 10 records starting with kind 7 undercount). A 32-bit `v_interp` read (`p1/p2/mov`) of a 16-bit-flagged position (flag bit 4; **measured natively on RDNA2**, AMD Radeon 680M `gfx1035` in wave32 and wave64 via `tools/vinterp_hw_probe.py --oracle both`, SHADER-430: the VINTRP unit reads the same LDS parameter-cache dwords at `M0 + 48·attr + {8·c, 8·c + 4, 32 + 4·c}` with no hidden 16-bit unpacking, so `v_interp_mov_f32` returns the raw 32-bit parameter word and `v_interp_p1_f32`/`v_interp_p2_f32` interpolate those 32-bit words as binary32), and reads past the table still declare an input (the value is undefined on hardware). 11,199 such inputs corpus-wide, matching the `*_f16` interpolation opcodes in 99.7%) sees the value rounded to f16 (round to nearest, f16 denormals flushed to signed zero, back to f32) via a single `OpQuantizeToF16` (a `PackHalf2x16`/`UnpackHalf2x16` round-trip is folded to a no-op by at least one Vulkan driver, RTX 5080); reads through the `*_f16` opcodes already narrow and are unchanged (on a location an f16 op also reads, the f32 read is of the per-vertex raw word, "16-bit interpolation"; on gfx1036 a 32-bit `p1/p2_f32` read of a packed channel takes the raw LDS words as f32 bits, one fma each (SHADER-430, `tools/interp_hw_probe.py`); what P10/P20 words the SPI stores for such a channel is unverified), and reads past the table still declare an input (the value is undefined on hardware). Without a sidecar, or with an empty table, the output is byte-identical to the code-driven path. Confirmed by synthetic fixtures plus mini-interpreter agreement (`tests/test_rdna2spirv_pixelinput.py`: an f32 read of a flagged slot with input 1.1 yields the f16-rounded 1.099609375; unflagged and table-less controls yield exact 1.1) and `tests/test_vinterp_hw_probe.py`. The `index.json` entry records `ps_interpolants` (count) and `ps_fp16_interpolants` (flagged positions). | | PS interpolation modes (SHADER-181) | Every interpolated generic pixel input in this build is **perspective-correct at the pixel center**, and every other input is flat, so the single v0/v1 pair the code reads is `PERSP_CENTER`. The translator models exactly these two: Flat for `v_interp_mov_f32`, plain (perspective, center) inputs and `BaryCoordKHR` for `v_interp_p1/p2` and the f16 forms. Two records describe each input, and they state **different facts**: PSV0 (DXBC) stores the interpolation **mode**; the FSSM input record's flags byte (byte 7) stores the **read method** — bit 0 (0x01) marks `v_interp_mov_f32` (4,600 records), bit 1 (0x02) 32-bit `v_interp_p1/p2` (51,191; values 0 and 3 never occur), bit 3 (0x08) a Float16-typed parameter (11,619), bit 4 (0x10) the `*_f16` opcodes (11,199; 24 f16-read records lack it). The flag/usage cross-table over all 55,791 records has no contradiction: every bit-0 position the code reads is read only by `v_interp_mov_f32` (4,295 positions), every bit-1 position only by `v_interp_p1/p2` or the f16 forms (49,594), and no position is read both ways (1,902 positions are unread, and 88 reads fall past the table). **The mode is in PSV0, not the FSSM**: `tools/ps_interp_modes.py` decodes it from the PSV0 signature elements (`DXIL::InterpolationMode`, "must match D3D_INTERPOLATION_MODE": 1 Constant, 2 Linear, 3 LinearCentroid, 4 LinearNoperspective, 5 LinearNoperspectiveCentroid, 6 LinearSample, 7 LinearNoperspectiveSample; the 16-byte elements carry row, cols, semantic kind, component type and the mode — layout in the Pixel-shader inputs section) and maps the modes onto the `SPI_PS_INPUT_ENA` barycentric-pair bits (Mesa `gfx103.json` register type SPI_PS_INPUT_ENA: PERSP_SAMPLE/CENTER/CENTROID = bits 0/1/2, LINEAR_SAMPLE/CENTER/CENTROID = bits 4/5/6; the same type serves `SPI_PS_INPUT_ADDR`). **No FSSM word stores ENA/ADDR**: every u16 in bytes 0x00–0x138 of all 12,101 PS was compared against the signature-reconstructed ENA and only constant coincidences matched, and the register addresses (0x286CC/0x286D0, or 0xA1B3/0xA1B4 as context-register indices) appear in no PS blob, so the v2.. position layout of "PS system inputs" (one enabled pair) is the only ENA witness. The #2735 packed-component census matched PSV0, FSSM and disassembly for all 12,101 indexed PS. Of 101,024 declared input rows, 77,245 have a nonzero read mask. Census (12,101 PS; 101,024 declared / 77,245 read inputs): every arbitrary, clip and cull input is Constant (6,333 rows, 4,529 read) or Linear = perspective-centre (81,385 rows, attributes plus 1,806 `SV_ClipDistance` and 2 `SV_CullDistance`); zero centroid, sample or noperspective generics; per shader 6,350 linear only, 4,507 linear and constant, 6 constant only, 1,238 no interpolated input. 101,024 declared / 76,215 read inputs): every arbitrary, clip and cull input is Constant (6,333 rows, 3,652 read) or Linear = perspective-centre (81,385 rows, attributes plus 1,806 `SV_ClipDistance` and 2 `SV_CullDistance`); zero centroid, sample or noperspective generics; per shader 6,350 linear only, 4,507 linear and constant, 6 constant only, 1,238 no interpolated input. ISG1 has no mode field, and the DXIL part carries no bitcode. SV_Position is mode 4 (11,295 rows) or mode 5 (27), both noperspective by the D3D rule. With packed-component read masks, the classifier assigns 10,260 shaders to the perspective-centre pair and 1,841 to no pair. None classify as linear-centre. Hardware delivery of SV_Position is outside the scope of the census. Front face is a system input (1,984 rows, 345 read, at most one per shader). It assigns none to a linear pair. This count measures input classification; it does not directly measure how the hardware delivers SV_Position; front face is a system input (1,984 rows, 345 read, at most one per shader). SV_Position is mode 4 (11,295 rows) or mode 5 (27) — noperspective by the D3D rule — and is delivered through the system VGPRs in every shader except **4**, which interpolate it through the parameter cache with the *linear* pair (`FragCoord` stays at the pixel center, which only differs at partly covered MSAA pixels); front face is a system input (1,984 rows, 345 read, at most one per shader). The code reads **at most one** barycentric pair per shader: v0/v1 in 10,259, none in 1,841, and one shader reads J from v14 (a copy of v1), so the perspective-centre assumption holds for every interpolated generic input. **Mode and read method disagree in thousands of rows** — the residual surface for modelling is: those 4 linear-pair position shaders, Constant rows read via `p1/p2` or `*_f16` (2,190 records at the matching table position; flat semantics in hardware, not modelled), and Linear rows read only by `v_interp_mov_f32` (3,197; already declared `Flat`). The translator's table check (`check_read_methods`, the row below) compares each read's opcode against the record's read-method bits (`fssm_header.read_methods`) — since the bits restate the read method, it rejects 0 of 12,101 PS: a consistency check between the two encodings of the read, not a mode check (a centroid/sample/noperspective input would still read `v_interp_p1/p2` and pass; that every interpolated generic input is perspective-centre is the PSV0 census result above, so keying a refusal on genuinely unmodelled modes means decoding PSV0, not reading these bits). Counted with `tools/ps_interp_modes.py` (stdlib; PSV0, FSSM and disassembly in one pass; #1301 removed the earlier #1246 census tool in favour of it) on the 1.0.2.1 corpus; tests `tests/test_ps_interp_modes.py`, `tests/test_fssm_header.py` and `tests/test_rdna2spirv_pixelinput.py` (synthetic). No GPU test: no shader needs centroid or sample interpolation. **Not covered:** bit 3 (0x08) is set in 11,619 records (all 11,199 16-bit ones, 396 flat, 24 linear). The 213 PS that overwrite v0/v1 before a `v_interp` (SHADER-178) compute their own barycentrics in code; PSV0 gives them no other mode. | | `v_interp_mov_f32` p10 / p20 | The VINTRP mov returns one of the three values the hardware keeps per attribute for the p1/p2 pair, {P10, P20, P0}[S] (RDNA2 ISA, VINTRP; P = P0 + i·P10 + j·P20). p0 stays the provoking vertex (`Flat`, exact bits). p10 and p20 read the location `PerVertexKHR` (the per-vertex path the `*_f16` interps use, so the PS needs `fragmentShaderBarycentric`) and return P1 − P0 and P2 − P0 as one f32 `OpFSub` of the producer's words, vertices ordered as in the f16 row (BaryCoordKHR .y/.z weight vertices 1/2). Refused (`Unsupported`) under `--bary-fallback` and `--f16-interp-fallback` (no per-vertex inputs) and on a 16-bit-flagged interpolant (FSSM table), where whether the hardware forms the delta in f16 is unmeasured. Until 2026-11-22 both selects were refused; all 6,926 `v_interp_mov_f32` in the corpus use p0, so the corpus translation is unchanged. Confirmed on the CPU by `tests/semantic/test_interp_mov_delta.py` (distinct per-vertex words give the deltas, and P0 + i·P10 + j·P20 from the three movs matches the p1/p2 pair bit for bit). **Unverified:** a GPU run, and AMD's rounding of P10/P20 for denormal or NaN words. | diff --git a/runtime/test/shaders/check.py b/runtime/test/shaders/check.py index 7b37772874..ffc63c3d80 100644 --- a/runtime/test/shaders/check.py +++ b/runtime/test/shaders/check.py @@ -1706,11 +1706,40 @@ def nan_payload_problem(px, out): return "" +def interp_pair_roles_problem(px: list[tuple[float, float, float, float]], abs_tol: float) -> str: + """Check ps_interp_pair_roles over the 64-by-64 frame covered by the vs_ids triangle. + + A p1 weights P10 and a p2 weights P20 with the value the register it names holds. The fixture is drawn + with the test triangle (vs_tri in scripts/run_gpu_tests.py, vs_ids in check.py: the same (-1,-1), + (3,-1), (-1,3) triangle with attr0 = (0,0), (2,0), (0,2) at the vertices), and the 64-by-64 frame + covers the [-1,1] square of it, so its barycentrics at pixel (x,y) are i = (x + 0.5) / 128, + j = (y + 0.5) / 128: attr0.x interpolates to 2*i = (x + 0.5) / 64 and attr0.y to 2*j = + (y + 0.5) / 64. The fixture's four pairs — swapped, standard, both-I, both-J — therefore come out as + (2j, 2i, 2i, 2j) = (v, u, u, v) with u, v those two values. A model that used the hardware weights + whatever register the op named would give (u, u, v, v): the first channel would not read the J its op + named, and the third would read J instead of the I it names.""" + if len(px) != 64 * 64: + return f"expected 4096 pixels, got {len(px)}" + for index, pixel in enumerate(px): + if not all(math.isfinite(v) for v in pixel): + return "interpolated values contain non-finite values" + y, x = divmod(index, 64) + u, v = (x + 0.5) / 64, (y + 0.5) / 64 + expected = (v, u, u, v) + if any(abs(got - want) > abs_tol for got, want in zip(pixel, expected)): + return f"at ({x},{y}): got {pixel}, expected {expected}" + return "" + + def pixel_test(tools, spirv, name): path = os.path.join(spirv, name + ".spv") if name == "ps_ij_computed" and (BARY_FALLBACK or F16_HALVES): # Before the .spv check: without PerVertexKHR inputs the translator refuses a computed I/J pair (no .spv). return Skip("SKIP (computed I/J pairs need PerVertexKHR inputs: no --bary-fallback / --f16-interp-fallback)") + if name == "ps_interp_pair_roles" and BARY_FALLBACK: + # A pair that names the coordinates the other way round is weighted with those values too, and needs + # the same per-vertex inputs (tools/rdna2spirv.py, interp_ij_analysis). + return Skip("SKIP (swapped I/J pairs need PerVertexKHR inputs: no --bary-fallback)") if not os.path.isfile(path): return f"missing {name}.spv" if name == "ps_cbv_modulate": @@ -1719,7 +1748,7 @@ def pixel_test(tools, spirv, name): return texoff_test(tools, spirv, name) if name == "ps_interp_f16_high" and BARY_FALLBACK and not F16_HALVES: # with F16_HALVES it reads decoded halves return Skip("SKIP (per-vertex interpolants need VK_KHR_fragment_shader_barycentric)") - fmt = "<4f" if name in ("ps_bary", "ps_persp_bary") else "<2I2f" if name in ("ps_flat", "ps_uniform_branch", "ps_scc_mask32") else "<4I" + fmt = "<4f" if name in ("ps_bary", "ps_persp_bary", "ps_interp_pair_roles") else "<2I2f" if name in ("ps_flat", "ps_uniform_branch", "ps_scc_mask32") else "<4I" px, out = pixels(tools, spirv, name, fmt, PIXEL_VERTEX.get(name, "vs_ids")) if isinstance(px, Skip): # exit 77: the device cannot run this shader (e.g. no barycentrics) m = re.search(r"unsupported: .*", out) @@ -1749,6 +1778,8 @@ def pixel_test(tools, spirv, name): return barycentric_problem(px, 1e-6) if name == "ps_persp_bary": return bary_persp_problem(px) + if name == "ps_interp_pair_roles": + return interp_pair_roles_problem(px, 1e-6) if name == "ps_flat": if any(not math.isfinite(v) for p in px for v in p[2:]): return "UVs contain non-finite values" diff --git a/runtime/test/shaders/ps_interp_pair_roles.asm b/runtime/test/shaders/ps_interp_pair_roles.asm new file mode 100644 index 0000000000..9264d92114 --- /dev/null +++ b/runtime/test/shaders/ps_interp_pair_roles.asm @@ -0,0 +1,22 @@ +; Pair weights are the values the named registers hold (SHADER-659). Drawn with the test triangle +; (vs_tri / vs_ids: (-1,-1), (3,-1), (-1,3) with attr0 = (0,0), (2,0), (0,2) at the vertices), whose +; barycentrics over the 64-by-64 frame are i = (x + 0.5) / 128, j = (y + 0.5) / 128: attr0.x interpolates +; to 2*i = (x + 0.5) / 64 and attr0.y to 2*j = (y + 0.5) / 64. Each pair here reads one of the two +; components, so its value is 2 * (the weight its p1 names) on attr0.x and 2 * (the weight its p2 names) +; on attr0.y. Expected mrt0 = (2j, 2i, 2i, 2j) = ((y + 0.5) / 64, (x + 0.5) / 64, (x + 0.5) / 64, +; (y + 0.5) / 64): +; v2: p1(v1)/p2(v0) on attr0.x - the pair named the other way round +; v3: p1(v0)/p2(v1) on attr0.x - the standard pair, the control +; v4: p1(v0)/p2(v0) on attr0.y - both ops read I +; v5: p1(v1)/p2(v1) on attr0.y - both ops read J +; A model that used the hardware weights whatever register the op named would give (2i, 2i, 2j, 2j). +v_interp_p1_f32_e32 v2, v1, attr0.x +v_interp_p2_f32_e32 v2, v0, attr0.x +v_interp_p1_f32_e32 v3, v0, attr0.x +v_interp_p2_f32_e32 v3, v1, attr0.x +v_interp_p1_f32_e32 v4, v0, attr0.y +v_interp_p2_f32_e32 v4, v0, attr0.y +v_interp_p1_f32_e32 v5, v1, attr0.y +v_interp_p2_f32_e32 v5, v1, attr0.y +exp mrt0 v2, v3, v4, v5 done vm +s_endpgm diff --git a/scripts/run_gpu_tests.py b/scripts/run_gpu_tests.py index 483287fbd3..118fb86b5f 100644 --- a/scripts/run_gpu_tests.py +++ b/scripts/run_gpu_tests.py @@ -46,7 +46,7 @@ from check import (WAVE32_LANE_DUMPS, WAVE32_LANE_ENV, bitmask_perm_narrow_skip, narrow_subgroup_skip, unpinned_subgroup_skip, vcmpx_forms_narrow_skip, wave32_lane_skip) # as in check.py from check import PIXEL_VERTEX, VINT_ENV, interp_f16_high_problem, ij_computed_problem, mandelbrot_problem # pixel producers and checks -from check import barycentric_problem +from check import barycentric_problem, interp_pair_roles_problem from check import NAN_PAYLOAD_TEST, nan_payload_problem from check import GET_LOD_TESTS, STORE_WORDS, get_lod_test, store_words_problem # TEST-184: image atomics and queries from check import wide_pixel_skip # ps_w64x_readlane: judged only where the fragment stage was required 64-wide @@ -452,6 +452,11 @@ def check_bary(raw_path: str) -> tuple[bool, str]: return not problem, problem or "4096/4096 pixels match" +def check_interp_pair_roles(raw_path: str) -> tuple[bool, str]: + problem = interp_pair_roles_problem(read_raw_rgba32f(raw_path), 1e-4) + return not problem, problem or "4096/4096 pixels weight each axis with the register its op names" + + def check_bitmask_perm(raw_path: str, msg: str = "") -> tuple[bool | None, str]: px = read_raw_u32(raw_path) if skip := bitmask_perm_narrow_skip(msg, px): @@ -964,6 +969,12 @@ def run_suite(a, work: str) -> int: results.append((name, None, "SKIP (computed I/J pairs need PerVertexKHR inputs: " "no --bary-fallback / --f16-interp-fallback)")) continue + if name == "ps_interp_pair_roles" and (bary_fallback() or f16_interp_fallback()): + # A pair that names the coordinates the other way round is modelled as a computed I/J pair + # (tools/rdna2spirv.py, interp_ij_analysis): the same per-vertex inputs are needed. + results.append((name, None, "SKIP (swapped I/J pairs need PerVertexKHR inputs: " + "no --bary-fallback / --f16-interp-fallback)")) + continue if not os.path.isfile(spv): results.append((name, False, "missing .spv (translation failed)")) continue @@ -1519,6 +1530,8 @@ def run_suite(a, work: str) -> int: elif name == "ps_persp_bary": problem = bary_persp_problem(read_raw_rgba32f(raw)) ok, detail = not problem, problem or "perspective-correct on every covered pixel" + elif name == "ps_interp_pair_roles": + ok, detail = check_interp_pair_roles(raw) elif name == "ps_bitmask_perm": m = re.search(r"subgroup \d+\.\.(\d+)", msg) if m and int(m.group(1)) < 32: diff --git a/tests/semantic/test_interp_guards.py b/tests/semantic/test_interp_guards.py index 08da4156dd..37ce3fd512 100644 --- a/tests/semantic/test_interp_guards.py +++ b/tests/semantic/test_interp_guards.py @@ -1,26 +1,34 @@ """SHADER-177: v_interp reads the barycentric pair through its VGPR source (I = v0, J = v1), and v_interp_mov_f32 names the vertex with p0 (p10/p20 would be the other two vertices). The single-lane -model returns the attribute's own value, which is only that when the operand really holds the pair, -so anything else is refused instead of silently translating wrong (docs/design.md, PS system inputs): - -* v_interp_p1/p2 (f32 and f16 forms) must read their OWN coordinate of the pair — p1 reads I = v0, - p2 reads J = v1, per op — as the hardware register or a qualifying copy: anything else, including a - swapped p1(v1)/p2(v0) pair or both-v0, -> Unsupported naming the register and the role (the corpus - has none: 117,001 v0 and 116,997 v1 over 26,503 shaders); -* v_interp_mov_f32 with p10/p20 was refused here; it is now modelled as P1 - P0 / P2 - P0 - (test_interp_mov_delta.py; all 6,926 in the corpus are p0); +model returns the attribute's own value, which is only that when the operand really holds a coordinate of +the pair, so a source with no provable value is refused instead of silently translating wrong +(docs/design.md, PS system inputs): + +* v_interp_p1/p2 (f32 and f16 forms) interpolate with the value their VGPR source holds: p1 weights P10 and + p2 weights P20, and a source qualifies when it provably holds a coordinate of the pair — the hardware + register v0 (I) or v1 (J), or a qualifying copy rooted at one. A pair that names them in the other order, + p1(v1)/p2(v0), or with both ops naming the same one, is modelled with the values those registers hold + (SHADER-659: measured with runtime/test/shaders/ps_interp_pair_roles.asm on a gfx1036 iGPU and an RTX 4090, + docs/design.md "v_interp operand guards"). A source whose value is nothing provable — v4, v9, an unwritten + register — is still Unsupported naming the register and the role (the corpus has none: 117,001 v0 and 116,997 + v1 over 26,503 shaders, and no read names the other role); +* an opposite-role read with no partner op to take the other axis from is Unsupported: the model needs both + weights of the pair; +* v_interp_mov_f32 with p10/p20 is modelled as P1 - P0 / P2 - P0 (test_interp_mov_delta.py; all 6,926 in the + corpus are p0); any other select is Unsupported, naming it; * a plain v_mov_b32 copy of the op's coordinate (rooted at v0 for p1, at v1 for p2) is still accepted, including a chain of copies: its single write in the whole shader is the mov, and its source v0/v1 is itself unwritten up to the copy (a copy of an already-overwritten v0/v1 carries a computed value — the zero-before-copy measurement renders (0,0) on hardware — while zeroing after the copy is fine, the copy saved the value). One corpus shader reads its J through a copy of v1 and must keep - translating (bit-identical .spv); + translating (bit-identical .spv); a copy in the role its coordinate fits keeps the centre-interpolated + read and that bit-identical .spv; a copy of the *other* coordinate is weighted with that value; * a register written twice (the mov, then anything else) no longer qualifies — and since the computed-I/J model landed, a written-again register, a copy of an already-overwritten v0/v1, or a modified (dpp) mov is no longer refused but modelled: the operand is a value the program wrote, and the model weights the interpolation with the value loaded from %vgpr (Vonsek's zero-before-copy - row renders P0, which is exactly those loads' result). A pristine copy in the wrong role stays - refused: it carries no computed value to model; + row renders P0, which is exactly those loads' result). A copy in either role is + modelled with the barycentric its root holds, like the pairs above; * the standard forms (v0/v1 pairs, p0 mov) translate and compute exactly as before. On main (before the guards) the refused cases translated silently and passed spirv-val: the operand @@ -114,33 +122,54 @@ def test_copy_with_modifiers_is_computed(self): self.assertIn("OpEntryPoint Fragment", spv) self.assertIn("PerVertexKHR", spv) - def test_swapped_and_same_register_roles_refused(self): - # The roles are per op — p1 interpolates with I = v0, p2 with J = v1 — so a swapped pair - # (p1(v1), p2(v0)) and a both-v0 pair are refused, not silently exchanged (review: kapitche). - cases = {(1, 0): "v_interp_p1_f32 I source v1", - (1, 1): "v_interp_p1_f32 I source v1", - (0, 0): "v_interp_p2_f32 J source v0"} - for (i, j), msg in cases.items(): - with self.subTest(i=i, j=j): + def test_swapped_and_same_register_pairs_take_the_named_weights(self): + # SHADER-659: p1 weights P10 and p2 weights P20 with the value their source holds, so naming the + # pair the other way round (or naming one coordinate twice) is the interpolation with those + # weights, not a refusal (measured on gfx1036 with runtime/test/shaders/ps_interp_swapped_pair.asm). + # attr0.z is (1, 3, 5) at the three vertices: P10 = 2, P20 = 4, and with BARY = (.25, .25, .5) + # the four role pairs give four different numbers. + bary = {"i": BARY[1], "j": BARY[2]} + for role in ((0, 1), (1, 0), (1, 1), (0, 0)): + with self.subTest(p1=role[0], p2=role[1]): + w1, w2 = (bary["i"] if role[0] == 0 else bary["j"], + bary["i"] if role[1] == 0 else bary["j"]) + want = VERTS0[0][2] + w1 * (VERTS0[1][2] - VERTS0[0][2]) + w2 * (VERTS0[2][2] - VERTS0[0][2]) + spv = support.translate_lines("ps_role", [f"v_interp_p1_f32_e32 v2, v{role[0]}, attr0.z", + f"v_interp_p2_f32_e32 v2, v{role[1]}, attr0.z", + "exp mrt0 v2, v2, v2, v2 done vm", + "s_endpgm"]) + words = support.mrt0_words(spv, inputs=support.varyings(spv, {0: WORDS0}, BARY)) + self.assertEqual(words, [f32_bits(want)] * 4) + # Only the pair that reads the coordinates through the registers the hardware seeded needs + # the per-vertex read; the standard pair keeps the interpolated input as it always did. + self.assertEqual("PerVertexKHR" in spv, role != (0, 1)) + + def test_opposite_role_read_without_its_partner_refused(self): + # One op of the pair alone has no weight for the other axis, so it stays a refusal (SHADER-659 + # models pairs; unpaired reads are a separate item). + for op, other, msg in (("v_interp_p1_f32_e32", "p2", "v_interp_p1_f32 without its p2 partner"), + ("v_interp_p2_f32_e32", "p1", "v_interp_p2_f32 without its p1 partner")): + src = 1 if op.startswith("v_interp_p1") else 0 + with self.subTest(op=op): with self.assertRaises(rdna2spirv.Unsupported) as cm: - support.translate_lines("ps_role", [f"v_interp_p1_f32_e32 v2, v{i}, attr0.x", - f"v_interp_p2_f32_e32 v2, v{j}, attr0.x", - "exp mrt0 v2, v2, v2, v2 done vm", - "s_endpgm"]) + support.translate_lines("ps_lonely", [f"{op} v2, v{src}, attr0.z", + "exp mrt0 v2, v2, v2, v2 done vm", + "s_endpgm"]) self.assertIn(msg, str(cm.exception)) - def test_copy_root_role_enforced(self): - # A copy only stands in for the coordinate it is rooted at: v6 = v0 cannot feed p2's J, and - # v6 = v1 cannot feed p1's I (the other op of the pair reads the register it should). - for chain, p1, p2, msg in ((["v_mov_b32_e32 v6, v0"], "v0", "v6", "v_interp_p2_f32 J source v6"), - (["v_mov_b32_e32 v6, v1"], "v6", "v1", "v_interp_p1_f32 I source v6")): + def test_copy_carries_the_coordinate_its_root_holds(self): + # A copy of the pair stands for the coordinate its root holds, in either role: v6 = v1 gives the + # p1 the J weight, v6 = v0 gives the p2 the I weight (the other op of the pair still reads v1/v0). + for chain, p1, p2, w1, w2 in ((["v_mov_b32_e32 v6, v1"], "v6", "v1", BARY[2], BARY[2]), + (["v_mov_b32_e32 v6, v0"], "v0", "v6", BARY[1], BARY[1])): with self.subTest(root=chain[0]): - with self.assertRaises(rdna2spirv.Unsupported) as cm: - support.translate_lines("ps_rolc", chain + [f"v_interp_p1_f32_e32 v2, {p1}, attr0.x", - f"v_interp_p2_f32_e32 v2, {p2}, attr0.x", - "exp mrt0 v2, v2, v2, v2 done vm", - "s_endpgm"]) - self.assertIn(msg, str(cm.exception)) + want = VERTS0[0][2] + w1 * (VERTS0[1][2] - VERTS0[0][2]) + w2 * (VERTS0[2][2] - VERTS0[0][2]) + spv = support.translate_lines("ps_rolc", chain + [f"v_interp_p1_f32_e32 v2, {p1}, attr0.z", + f"v_interp_p2_f32_e32 v2, {p2}, attr0.z", + "exp mrt0 v2, v2, v2, v2 done vm", + "s_endpgm"]) + words = support.mrt0_words(spv, inputs=support.varyings(spv, {0: WORDS0}, BARY)) + self.assertEqual(words, [f32_bits(want)] * 4) def test_copy_in_matching_roles_translates_and_computes(self): # Vonsek measurement row 1: copies of untouched v0/v1, one as a chain, feed p1's I and p2's diff --git a/tests/semantic/test_interp_p1lv_f16.py b/tests/semantic/test_interp_p1lv_f16.py index e13f9c761b..543fb8dc8c 100644 --- a/tests/semantic/test_interp_p1lv_f16.py +++ b/tests/semantic/test_interp_p1lv_f16.py @@ -511,28 +511,10 @@ def test_p1lv_and_p1ll_i_source_guards(self): "exp mrt0 v2, v2, v2, v2 done vm", "s_endpgm", ]), - ("v_interp_p1lv_f16 I source v1", [ - "v_mov_b32_e32 v10, 0", - "v_interp_p1lv_f16 v2, v1, attr0.x, v10", - "v_interp_p2_f16 v2, v1, attr0.x, v2", - "exp mrt0 v2, v2, v2, v2 done vm", - "s_endpgm", - ]), - ("v_interp_p1ll_f16 I source v1", [ - "v_interp_p1ll_f16 v2, v1, attr0.x", - "v_interp_p2_f16 v2, v1, attr0.x, v2", - "exp mrt0 v2, v2, v2, v2 done vm", - "s_endpgm", - ]), # An I source holding a zeroed v0 ("v_mov v0, 0; v_mov v6, v0") is a computed I of 0, which the translator # models since #1545 (computed I/J barycentrics) instead of rejecting; it is no longer a bad case here. - ("v_interp_p2_f16 J source v0", [ - "v_mov_b32_e32 v10, 0", - "v_interp_p1lv_f16 v2, v0, attr0.x, v10", - "v_interp_p2_f16 v2, v0, attr0.x, v2", - "exp mrt0 v2, v2, v2, v2 done vm", - "s_endpgm", - ]), + # v1 for a p1 and v0 for a p2 are modelled too since SHADER-659 (the weight is the value the named + # register holds) — see test_opposite_role_f16_pairs_weight_with_their_registers. ] for msg, lines in bad_cases: with self.subTest(msg=msg): @@ -540,6 +522,27 @@ def test_p1lv_and_p1ll_i_source_guards(self): translate_with_flags("ps_guard_bad", lines, dxbc=PS_ATTR01_DXBC) self.assertIn(msg, str(cm.exception)) + def test_opposite_role_f16_pairs_weight_with_their_registers(self): + # SHADER-659: the f16 forms weight each axis with the value their own op's source holds, so a pair + # that names the coordinates the other way round, or names one of them twice, is the interpolation + # with those weights. attr0.x is (0, 1, 4) at the three vertices (low half), exact in f16: + # P10 = 1, P20 = 4, and with BARY = (.25, .25, .5) the four role pairs give 2.25, 1.5, 2.5, 1.25. + forms = (("v_interp_p1ll_f16", "v_interp_p2_f16", ""), + ("v_interp_p1lv_f16", "v_interp_p2_f16", "v_mov_b32_e32 v10, 0")) + for (p1_op, p2_op, setup), roles in zip(forms, ((0, 1), (1, 0), (1, 1), (0, 0))): + with self.subTest(op=p1_op, roles=roles): + w1, w2 = (BARY[1] if roles[0] == 0 else BARY[2], BARY[1] if roles[1] == 0 else BARY[2]) + want = w1 * 1.0 + w2 * 4.0 + p1 = (f"v_interp_p1lv_f16 v2, v{roles[0]}, attr0.x, v10" if p1_op == "v_interp_p1lv_f16" + else f"v_interp_p1ll_f16 v2, v{roles[0]}, attr0.x") + lines = ([setup] if setup else []) + [p1, + f"v_interp_p2_f16 v2, v{roles[1]}, attr0.x, v2", + "exp mrt0 v2, v2, v2, v2 done vm", "s_endpgm"] + spv, _ = translate_with_flags("ps_pair_roles", lines, dxbc=PS_ATTR01_DXBC) + attrs = {0: [(pack_f16(v, 0.0), 0, 0, 0) for v in (0.0, 1.0, 4.0)]} + words = support.mrt0_words(spv, inputs=support.varyings(spv, attrs, BARY)) + self.assertEqual(words[0] & 0xFFFF, f16_bits(want)) + def test_p1lv_accepts_saved_copy_of_v0_even_if_v0_later_zeroed(self): lines = [ "v_mov_b32_e32 v6, v0", diff --git a/tools/rdna2spirv.py b/tools/rdna2spirv.py index 67b2fa225c..f0b732025b 100644 --- a/tools/rdna2spirv.py +++ b/tools/rdna2spirv.py @@ -14325,9 +14325,10 @@ def interp_pair_src(self, op, a, ins): with — p1 reads I = v0, p2 reads J = v1, per op. The model returns the attribute's interpolated value, which is only that when the register really holds that coordinate: the hardware register, or a plain v_mov copy rooted at it (self.v_interp_copy, from interp_copy_sources, which tracks each copy's root). - Anything else — the other coordinate, a copy rooted at the other one — is refused, not guessed at. - A computed-I/J site (ins["ij"], interp_ij_analysis) is exempt: its operand is a value the program - wrote, and attribute() weights the interpolation with that value.""" + A source in the other role — v1 for p1, v0 for p2, or a copy rooted at the other one — is modelled by + interp_ij_analysis with the value the register holds (SHADER-659); a source whose value is unknown is + refused here, not guessed at. A computed-I/J site (ins["ij"], interp_ij_analysis) is exempt: its + operand is a value the program wrote, and attribute() weights the interpolation with that value.""" if ins.get("ij") is not None: return # computed-I/J site: the analysis vetted the source; attribute() weights with it want, role = (0, "I") if op.startswith("v_interp_p1") else (1, "J") @@ -16708,9 +16709,13 @@ def interp_ij_analysis(insns, g): and the p2 loads its J fresh; the p1's own full-sum value is dead unless something reads the partial between the ops. - A source that is neither v0/v1 nor written is left to interp_pair_src (#1224), which refuses it at - emission naming the role; a plain v_mov copy of the pair (g.v_interp_copy) stays #1224's to model, - keeping its bit-identical .spv. Refused here (Unsupported, naming the pattern): a computed pair + A source whose value is unknown — neither v0/v1 nor written nor a copy rooted at one of them — is left + to interp_pair_src (#1224), which refuses it at emission naming the role. A source in the role its own + coordinate fits (v0 or a copy rooted at v0 for p1, v1 or a copy rooted at v1 for p2) also stays + #1224's to model, keeping its bit-identical .spv. A source that provably holds the *other* coordinate + (SHADER-659) is modelled here: the pair's weights are the two barycentrics swapped, which is what the + hardware computes from the registers the ops name (docs/design.md, "v_interp operand guards"), and the + prologue seeds v0/v1 from BaryCoordKHR for such a pair. Refused here (Unsupported, naming the pattern): a computed pair whose ops are not in one basic block (the captured I would not dominate the p2), whose shared partial register -- the f32 vdst, or the f16 p2's fourth operand naming the p1's vdst -- is written between the ops, or read between them by anything but a p2's partial operand, any computed site @@ -16813,14 +16818,24 @@ def reaching_write(reg, s): return False for s in sites: + # SHADER-659: the operand names the weight of one axis — p1 multiplies P10 with it, p2 multiplies + # P20 — so the question is what the register holds, not which slot it sits in. v0 holds I, v1 holds + # J, and a plain copy chain rooted at one of them holds that same coordinate (interp_copy_sources + # guarantees the single write and an unwritten root). A site whose operand holds the *other* + # coordinate is a weights-of-the-coordinates site: the computed model already loads the value the + # register holds and weights each axis with its own operand, and the prologue seeds v0/v1 from + # BaryCoordKHR when a pair reads them (below). A matching-role source is left exactly as before, + # so a listing whose sources are the coordinates its ops weight keeps its bit-identical .spv. + want = 0 if s["op"] in P1 else 1 + c = g.v_interp_copy.get(s["src"]) if s["src"] in (0, 1): + s["computed"] = reaching_write(s["src"], s) or s["src"] != want + elif c is not None: + s["computed"] = c[0] != want and c[1] < s["n"] # a copy carrying the other coordinate + else: s["computed"] = reaching_write(s["src"], s) - elif reaching_write(s["src"], s) and s["src"] not in g.v_interp_copy: - s["computed"] = True - # any other source is pristine: interp_pair_src (#1224) accepts it only as the op's own - # coordinate (v0 for p1, v1 for p2) or a plain v_mov copy rooted there — which - # interp_copy_sources already vetted, so such a copy keeps #1224's centre-interpolated - # read and its bit-identical .spv — and refuses the rest at emission, naming the role + # any other source is pristine: interp_pair_src (#1224) accepts it only as a coordinate it can + # prove the register holds, and refuses the rest at emission, naming the role if s["computed"] and s["op"].endswith("_f32") and g.pixel_interpolants is not None and \ (g.pixel_interpolants[1] >> s["attr"]) & 1: raise Unsupported("computed I/J on 16-bit interpolant through v_interp_*_f32")