[PR #509] [CLOSED] SHADER-659: a v_interp pair weighs with the barycentric its operand holds #557

Closed
opened 2026-11-26 20:18:16 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/509
Author: @fiestorra
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: carry/interp-pair-roles


📝 Commits (1)

  • ae07e41 Interpolate a v_interp pair with the barycentric its registers name (SHADER-659)

📊 Changes

7 files changed (+183 additions, -70 deletions)

View changed files

📝 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)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/509 **Author:** [@fiestorra](https://github.com/fiestorra) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `carry/interp-pair-roles` --- ### 📝 Commits (1) - [`ae07e41`](https://github.com/ubiquitarianism/leonida/commit/ae07e4118e7736fdacadef55a9e0a163651a2e00) Interpolate a v_interp pair with the barycentric its registers name (SHADER-659) ### 📊 Changes **7 files changed** (+183 additions, -70 deletions) <details> <summary>View changed files</summary> 📝 `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) </details> ### 📄 Description Claimed in the coordination issue as: `SHADER-659` ([claim comment](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7122051420)). ### 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:18:16 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#557
No description provided.