SHADER-659: a v_interp pair weighs with the barycentric its operand holds #509

Closed
github-bot wants to merge 1 commit from gh-pr/509/head into gh-pr/509/base
Owner

@⁠fiestorra on GitHub · 2026-11-24 06:36 UTC · original
fiestorra:carry/interp-pair-roles → main · +183 −70 · 7 files · 1 commits · closed without merging

Claimed in the coordination issue as: SHADER-659 (claim comment).

What this changes

A v_interp pair carries two barycentrics in one register pair, and the two ops of a site name which one they weigh with: v_interp_p1_* multiplies the value of P10 by its operand, v_interp_p2_* multiplies P20 by its operand. So the question at a site is not which slot the operand sits in but what the register holds. v0 holds I, v1 holds J, and a plain v_mov chain rooted at one of them holds that same coordinate (interp_copy_sources is what proves the single write and the unwritten root).

On main a source in the other role is refused rather than modelled: interp_pair_src (tools/rdna2spirv.py :14325-14339) accepts only v{want} for the op, want being 0 for p1 and 1 for p2, or a copy rooted at it, and anything else raises Unsupported("… only v{want} (or a plain v_mov copy of it) is modelled"). interp_ij_analysis hands those sources to it (:16709-16713). A program that reads the pair the other way round — p1 on v1, p2 on v0 — is therefore either refused or, if the analysis happened to treat it as computed, modelled with the weights of the coordinates it does not name.

This models the other-role case instead of refusing it: in interp_ij_analysis a site is marked computed when its operand provably holds the other coordinate (reaching_write, or a copy whose root is the other register), the pair's weights become the two barycentrics swapped — each axis weighted with its own operand, which is what the hardware computes from the registers the ops name — and the prologue seeds v0/v1 from BaryCoordKHR for such a pair. A source whose role matches, and a listing whose sources are the coordinates its ops weight, keep the existing path and their bit-identical .spv. A source whose value is unknown is still refused, naming the role. The contract row "v_interp operand guards" in docs/design.md says the rule and how it was confirmed.

One correction to my own claim comment: it mentioned a pair held in an SGPR pair. This PR does not cover that — an SGPR operand is still refused as an operand — and it is not in the diff. What is covered is a pair read as a VGPR pair with the roles swapped, and both ops reading the same coordinate.

Fixture and tests

runtime/test/shaders/ps_interp_pair_roles.asm (new, wired into runtime/test/shaders/check.py and scripts/run_gpu_tests.py) draws the test triangle the other fixtures use — vs_tri/vs_ids: (-1,-1), (3,-1), (-1,3) with attr0 = (0,0), (2,0), (0,2) — over a 64×64 frame, so i = (x + 0.5)/128 and j = (y + 0.5)/128, attr0.x interpolates to 2i and attr0.y to 2j. Four pairs each read one component:

register ops expected
v2 p1(v1)/p2(v0) on attr0.x 2j
v3 p1(v0)/p2(v1) on attr0.x (the standard pair, the control) 2i
v4 p1(v0)/p2(v0) on attr0.y 2i
v5 p1(v1)/p2(v1) on attr0.y 2j

so mrt0 = (2j, 2i, 2i, 2j) = ((y+0.5)/64, (x+0.5)/64, (x+0.5)/64, (y+0.5)/64). A model that used the hardware weights whatever register the op named would give (2i, 2i, 2j, 2j), and the two differ in three of the four components.

tests/semantic/test_interp_guards.py adds test_swapped_and_same_register_pairs_take_the_named_weights, test_opposite_role_read_without_its_partner_refused and test_copy_carries_the_coordinate_its_root_holds, and rewrites the expectations of the cases that used to assert a refusal. tests/semantic/test_interp_p1lv_f16.py is adjusted for the same rule on the f16 pair.

Evidence on ece4ba5b3

Head ae07e4118, one commit rebased cleanly onto ece4ba5b3, 7 files, +183/−70:

docs/design.md                                |  1 +  1 -
runtime/test/shaders/check.py                 | 32 +  1 -
runtime/test/shaders/ps_interp_pair_roles.asm | 22 +  0 -
scripts/run_gpu_tests.py                      | 14 +  1 -
tests/semantic/test_interp_guards.py          | 64 + 35 -
tests/semantic/test_interp_p1lv_f16.py        | 23 + 20 -
tools/rdna2spirv.py                           | 27 + 12 -

in tools/rdna2spirv.py across interp_pair_src and interp_ij_analysis.

  • py -3.13 -I -m unittest discover -s tests/semantic -p "test_interp_guards.py" — clean ece4ba5b3: Ran 14 tests / OK. This branch: Ran 15 tests / OK.
  • -p "test_interp_p1lv_f16.py" — clean ece4ba5b3: Ran 36 tests / OK. This branch: Ran 37 tests / OK.
  • Negative control, same tree with tools/rdna2spirv.py taken from ece4ba5b3 and my tests left in place: test_interp_guards.py Ran 15 tests / FAILED (failures=2, errors=5) and test_interp_p1lv_f16.py Ran 37 tests / FAILED (errors=1). Restoring the file returns both to OK, so the new cases only pass with the model change.
  • Whole game corpus, translated with --shard i/8 (8 parts) and validated with spirv-as/spirv-val from Vulkan SDK 1.4.363.0: the 26,503 listings disassembled from the 1.0.2.1 executable, run once with main's translator and once with mine into two separate output trees. Both produced 26,503 .spvasm and 26,503 .spv, and a byte-by-byte comparison of all 26,503 pairs on both kinds found 0 differences, with no file present on one side and missing on the other. So nothing in this game changes value, nothing that compiled stops compiling, and no listing is newly accepted or newly refused. The shape this PR models is one no shader in this game uses; what it changes is what happens at such a site instead of a refusal.
  • py -3.13 -I -m unittest discover -s tests -p "test_docs_*.py" on this branch: Ran 47 tests in 45.692s / OK. The same battery on clean ece4ba5b3 measured earlier in the same session: Ran 47 tests in 45.178s / OK. Same 47 tests, no failures either side.

What was measured on hardware, and when

The value rule itself was checked on this machine's gfx1036 iGPU (LEONIDA_HW_ARCH=gfx1036, Radeon 780M) on 2026-11-23, on the base that was current then: the fixture set ran green with the model change in, and the four pairs of ps_interp_pair_roles.asm produced mrt0 = (2j, 2i, 2i, 2j) as above. That device run has not been repeated on ece4ba5b3; the fixture is wired into runtime/test/shaders/check.py and scripts/run_gpu_tests.py so anyone with a device can run it, and I can re-run it on this machine if you want the number on this base. Everything in the list above is CPU-side — the translator, its tests, and the whole-corpus translation — and needed no runtime build and no GPU.

Written with an AI assistant.

Neighbour I read before claiming

The open draft #120 is SHADER-415 — computed I/J pairs under --bary-fallback, bary_fallback_input.per_vertex and Gen.pv_input(). It changes no pair-component ordering, and its v_interp_mov_f32 text is about array elements (p0 reading element 0, p10/p20 the deltas), which is a different thing from which coordinate a p1/p2 operand holds. But it edits the same neighbourhood of translate() and assemble(), so if it lands first I will rebase this on it rather than ask you to resolve anything.

**@⁠fiestorra** on GitHub · 2026-11-24 06:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/509) `fiestorra:carry/interp-pair-roles` → `main` · +183 −70 · 7 files · 1 commits · closed without merging Claimed in the coordination issue as: `SHADER-659` ([claim comment](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14)). ### What this changes A `v_interp` pair carries two barycentrics in one register pair, and the two ops of a site name which one they weigh with: `v_interp_p1_*` multiplies the value of `P10` by its operand, `v_interp_p2_*` multiplies `P20` by its operand. So the question at a site is not which slot the operand sits in but **what the register holds**. `v0` holds `I`, `v1` holds `J`, and a plain `v_mov` chain rooted at one of them holds that same coordinate (`interp_copy_sources` is what proves the single write and the unwritten root). On `main` a source in the other role is refused rather than modelled: `interp_pair_src` (`tools/rdna2spirv.py` :14325-14339) accepts only `v{want}` for the op, `want` being 0 for `p1` and 1 for `p2`, or a copy rooted at it, and anything else raises `Unsupported("… only v{want} (or a plain v_mov copy of it) is modelled")`. `interp_ij_analysis` hands those sources to it (:16709-16713). A program that reads the pair the other way round — `p1` on `v1`, `p2` on `v0` — is therefore either refused or, if the analysis happened to treat it as computed, modelled with the weights of the coordinates it does not name. This models the other-role case instead of refusing it: in `interp_ij_analysis` a site is marked computed when its operand provably holds the other coordinate (`reaching_write`, or a copy whose root is the other register), the pair's weights become the two barycentrics swapped — each axis weighted with its own operand, which is what the hardware computes from the registers the ops name — and the prologue seeds `v0`/`v1` from `BaryCoordKHR` for such a pair. A source whose role matches, and a listing whose sources are the coordinates its ops weight, keep the existing path and their bit-identical `.spv`. A source whose value is unknown is still refused, naming the role. The contract row "v_interp operand guards" in `docs/design.md` says the rule and how it was confirmed. One correction to my own claim comment: it mentioned a pair held in an **SGPR** pair. This PR does not cover that — an SGPR operand is still refused as an operand — and it is not in the diff. What is covered is a pair read as a VGPR pair with the roles swapped, and both ops reading the same coordinate. ### Fixture and tests `runtime/test/shaders/ps_interp_pair_roles.asm` (new, wired into `runtime/test/shaders/check.py` and `scripts/run_gpu_tests.py`) draws the test triangle the other fixtures use — `vs_tri`/`vs_ids`: `(-1,-1), (3,-1), (-1,3)` with `attr0 = (0,0), (2,0), (0,2)` — over a 64×64 frame, so `i = (x + 0.5)/128` and `j = (y + 0.5)/128`, `attr0.x` interpolates to `2i` and `attr0.y` to `2j`. Four pairs each read one component: | register | ops | expected | | --- | --- | --- | | `v2` | `p1(v1)/p2(v0)` on `attr0.x` | `2j` | | `v3` | `p1(v0)/p2(v1)` on `attr0.x` (the standard pair, the control) | `2i` | | `v4` | `p1(v0)/p2(v0)` on `attr0.y` | `2i` | | `v5` | `p1(v1)/p2(v1)` on `attr0.y` | `2j` | so `mrt0 = (2j, 2i, 2i, 2j) = ((y+0.5)/64, (x+0.5)/64, (x+0.5)/64, (y+0.5)/64)`. A model that used the hardware weights whatever register the op named would give `(2i, 2i, 2j, 2j)`, and the two differ in three of the four components. `tests/semantic/test_interp_guards.py` adds `test_swapped_and_same_register_pairs_take_the_named_weights`, `test_opposite_role_read_without_its_partner_refused` and `test_copy_carries_the_coordinate_its_root_holds`, and rewrites the expectations of the cases that used to assert a refusal. `tests/semantic/test_interp_p1lv_f16.py` is adjusted for the same rule on the f16 pair. ### Evidence on `ece4ba5b3` Head `ae07e4118`, one commit rebased cleanly onto `ece4ba5b3`, 7 files, +183/−70: ``` docs/design.md | 1 + 1 - runtime/test/shaders/check.py | 32 + 1 - runtime/test/shaders/ps_interp_pair_roles.asm | 22 + 0 - scripts/run_gpu_tests.py | 14 + 1 - tests/semantic/test_interp_guards.py | 64 + 35 - tests/semantic/test_interp_p1lv_f16.py | 23 + 20 - tools/rdna2spirv.py | 27 + 12 - ``` in `tools/rdna2spirv.py` across `interp_pair_src` and `interp_ij_analysis`. * `py -3.13 -I -m unittest discover -s tests/semantic -p "test_interp_guards.py"` — clean `ece4ba5b3`: `Ran 14 tests / OK`. This branch: `Ran 15 tests / OK`. * `-p "test_interp_p1lv_f16.py"` — clean `ece4ba5b3`: `Ran 36 tests / OK`. This branch: `Ran 37 tests / OK`. * Negative control, same tree with `tools/rdna2spirv.py` taken from `ece4ba5b3` and my tests left in place: `test_interp_guards.py` `Ran 15 tests / FAILED (failures=2, errors=5)` and `test_interp_p1lv_f16.py` `Ran 37 tests / FAILED (errors=1)`. Restoring the file returns both to OK, so the new cases only pass with the model change. * Whole game corpus, translated with `--shard i/8` (8 parts) and validated with `spirv-as`/`spirv-val` from Vulkan SDK 1.4.363.0: the 26,503 listings disassembled from the 1.0.2.1 executable, run once with `main`'s translator and once with mine into two separate output trees. Both produced 26,503 `.spvasm` and 26,503 `.spv`, and a byte-by-byte comparison of all 26,503 pairs on both kinds found **0 differences**, with no file present on one side and missing on the other. So nothing in this game changes value, nothing that compiled stops compiling, and no listing is newly accepted or newly refused. The shape this PR models is one no shader in this game uses; what it changes is what happens at such a site instead of a refusal. * `py -3.13 -I -m unittest discover -s tests -p "test_docs_*.py"` on this branch: `Ran 47 tests in 45.692s / OK`. The same battery on clean `ece4ba5b3` measured earlier in the same session: `Ran 47 tests in 45.178s / OK`. Same 47 tests, no failures either side. ### What was measured on hardware, and when The value rule itself was checked on this machine's gfx1036 iGPU (`LEONIDA_HW_ARCH=gfx1036`, Radeon 780M) on 2026-11-23, on the base that was current then: the fixture set ran green with the model change in, and the four pairs of `ps_interp_pair_roles.asm` produced `mrt0 = (2j, 2i, 2i, 2j)` as above. That device run has **not** been repeated on `ece4ba5b3`; the fixture is wired into `runtime/test/shaders/check.py` and `scripts/run_gpu_tests.py` so anyone with a device can run it, and I can re-run it on this machine if you want the number on this base. Everything in the list above is CPU-side — the translator, its tests, and the whole-corpus translation — and needed no runtime build and no GPU. Written with an AI assistant. ### Neighbour I read before claiming The open draft #120 is SHADER-415 — computed I/J pairs under `--bary-fallback`, `bary_fallback_input.per_vertex` and `Gen.pv_input()`. It changes no pair-component ordering, and its `v_interp_mov_f32` text is about array elements (`p0` reading element 0, `p10`/`p20` the deltas), which is a different thing from which coordinate a `p1`/`p2` operand holds. But it edits the same neighbourhood of `translate()` and `assemble()`, so if it lands first I will rebase this on it rather than ask you to resolve anything.
A p1 multiplies P10 and a p2 multiplies P20 with the value the register its op names. A pair written the
other way round, one that names the same coordinate twice, and one that reads a plain v_mov copy rooted at
the other coordinate are therefore modelled as the pair of weights they name - the attribute read per-vertex
and weighted with those two values, on the computed-I/J path that already seeds v0/v1 from BaryCoordKHR -
instead of refused. Sources whose value the model cannot name are still refused, as is an opposite-role read
with no partner op to take the other axis from. A matching-role source keeps the centre-interpolated read it
had: re-translating the 26503-listing corpus with main 902358c8 and with this change translated 26503 both
times, every .spv byte-identical and index.json identical, which is what the source census says - no listing
in the corpus names the other role.

Confirmed by runtime/test/shaders/ps_interp_pair_roles.asm (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; the standard pair in the same draw as
the control), by the role-pair and copy-root cases measured by value in tests/semantic/test_interp_guards.py
and tests/semantic/test_interp_p1lv_f16.py, and by the whole-corpus runs above. docs/design.md records the
rule and how it was checked.

Coordinated as SHADER-659 in #4571.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:04:53 +00:00
github-bot closed this pull request 2026-11-26 09:04:53 +00:00
Author
Owner

@⁠fiestorra on GitHub · 2026-11-24 12:19 UTC · original

Closing this. I am moving my work to a different project and will not continue here. The pair-role reading in this branch was my best local understanding at the time and it did not land; I am leaving it unlanded rather than rebasing it. The branch will be deleted shortly.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-24 12:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/509#issuecomment-7131276120) Closing this. I am moving my work to a different project and will not continue here. The pair-role reading in this branch was my best local understanding at the time and it did not land; I am leaving it unlanded rather than rebasing it. The branch will be deleted shortly. Written with an AI assistant.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.