[PR #658] [MERGED] rdna2spirv: v_writelane_b32 keeps its destination's other lanes in read_before_write_vgprs (OLD-9910, SHADER-768) #698

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/658
Author: @LouisRiverstone
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @ubiquitarianism

Base: main ← Head: carry-old-9910


📝 Commits (1)

  • f05bc53 read_before_write_vgprs: v_writelane_b32 keeps its destination's other lanes (SHADER-768)

📊 Changes

2 files changed (+112 additions, -12 deletions)

View changed files

➕ tests/semantic/test_writelane_read_before_write.py (+82 -0)
📝 tools/rdna2spirv.py (+30 -12)

📄 Description

Claimed in the coordination issue as: OLD-9910 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7129736114)

Replaces the carried-over draft #175. I'm the original author of old upstream PR 9910.

What and why

SHADER-768: read_before_write_vgprs in tools/rdna2spirv.py treated v_writelane_b32 as a full write of its destination.

v_writelane_b32 vD, sSRC, sLANE writes one lane of vD and leaves the other lanes as they were. The translator's own emission already loads the old vD and selects per lane. So when a shader's first touch of a VGPR is a writelane and it reads that register later, the value from shader entry is read in the lanes that weren't written.

Treating every writelane destination as a read goes too far the other way. On the old PR, shdann showed a VS that spills an SGPR into one lane of v40 around the fetch call and reads it back with v_readlane; that VS would be rejected with fetch mapping. So the kept lanes are now carried: they count as a read only when something other than v_readlane_b32 reads the register before a full write. reg_reads_writes (per slice) counts the destination as read. DST_ALSO_READ holds the accumulating ops that both functions used to list separately.

Known approximation, also written in the docstring: a v_readlane of a lane the writelane didn't write reads the entry value, and that read isn't counted.

Diff: the old branch's final tree diff applied on current main (21625bca8), one commit. It applied cleanly. main's v_swap_b32 entry and the d16 format exclusion are kept.

Tested

  • python -I tests/semantic/test_writelane_read_before_write.py: 9 tests OK (carried vs used lanes, the readlane spill, a full write ending the carry, shdann's VS spill and PS v0 barycentric cases translated end to end).
  • python -I scripts/run_semantic_tests.py tests/semantic: 466 files, 6117 tests, 0 files failed (Linux, Python 3.14.4).
  • python -m compileall -q make_game.py tools tests: OK.

GPUs tested: n/a (CPU-only change, no GPU fixture)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: this fixes a register-use analysis, not a translation rule)

🔄 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/658 **Author:** [@LouisRiverstone](https://github.com/LouisRiverstone) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@ubiquitarianism](https://github.com/ubiquitarianism) **Base:** `main` ← **Head:** `carry-old-9910` --- ### 📝 Commits (1) - [`f05bc53`](https://github.com/ubiquitarianism/leonida/commit/f05bc53865332bc59f320449d9e26522dfcc7e1d) read_before_write_vgprs: v_writelane_b32 keeps its destination's other lanes (SHADER-768) ### 📊 Changes **2 files changed** (+112 additions, -12 deletions) <details> <summary>View changed files</summary> ➕ `tests/semantic/test_writelane_read_before_write.py` (+82 -0) 📝 `tools/rdna2spirv.py` (+30 -12) </details> ### 📄 Description Claimed in the coordination issue as: OLD-9910 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7129736114) Replaces the carried-over draft #175. I'm the original author of old upstream PR 9910. ### What and why SHADER-768: `read_before_write_vgprs` in `tools/rdna2spirv.py` treated `v_writelane_b32` as a full write of its destination. `v_writelane_b32 vD, sSRC, sLANE` writes one lane of `vD` and leaves the other lanes as they were. The translator's own emission already loads the old `vD` and selects per lane. So when a shader's first touch of a VGPR is a writelane and it reads that register later, the value from shader entry is read in the lanes that weren't written. Treating every writelane destination as a read goes too far the other way. On the old PR, shdann showed a VS that spills an SGPR into one lane of `v40` around the fetch call and reads it back with `v_readlane`; that VS would be rejected with `fetch mapping`. So the kept lanes are now *carried*: they count as a read only when something other than `v_readlane_b32` reads the register before a full write. `reg_reads_writes` (per slice) counts the destination as read. `DST_ALSO_READ` holds the accumulating ops that both functions used to list separately. Known approximation, also written in the docstring: a `v_readlane` of a lane the writelane didn't write reads the entry value, and that read isn't counted. Diff: the old branch's final tree diff applied on current `main` (21625bca8), one commit. It applied cleanly. `main`'s `v_swap_b32` entry and the d16 `format` exclusion are kept. ### Tested - `python -I tests/semantic/test_writelane_read_before_write.py`: 9 tests OK (carried vs used lanes, the readlane spill, a full write ending the carry, shdann's VS spill and PS `v0` barycentric cases translated end to end). - `python -I scripts/run_semantic_tests.py tests/semantic`: 466 files, 6117 tests, 0 files failed (Linux, Python 3.14.4). - `python -m compileall -q make_game.py tools tests`: OK. GPUs tested: n/a (CPU-only change, no GPU fixture) AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: this fixes a register-use analysis, not a translation rule) --- <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:45 +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#698
No description provided.