[PR #2154] rdna2spirv: cache shader stages per carve root #2158

Open
opened 2026-11-26 21:20:14 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2154
Author: @whoalin1
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: shader-stage-cache-crossroot


📝 Commits (2)

  • c3ec925 rdna2spirv: cache shader stages per carve root
  • c5c367a rdna2spirv: do not cache a missing stage index

📊 Changes

2 files changed (+76 additions, -4 deletions)

View changed files

➕ tests/test_rdna2spirv_stage_cache.py (+67 -0)
📝 tools/rdna2spirv.py (+9 -4)

📄 Description

Claimed in the coordination issue as: SHADER-STAGE-CACHE-CROSS-ROOT (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7178575111)

What and why

rdna2spirv.stage_of cached the first carve index.json it read in process-global _STAGES and reused that one mapping for every later shader in the process. When one process translates listings from multiple carve roots, a shader in the second root can inherit the first root's stage, changing stage-dependent translation decisions. This is a concrete cross-shader mutable-state hazard in the area of jean-melikian's shard-only invalid-OpSelect report.

The process-local cache is kept, but is now keyed by the resolved index.json path. Existing tests that reset _STAGES = None remain compatible.

Regression test

tests/test_rdna2spirv_stage_cache.py builds two synthetic roots with the same shader stem but different stages. Before the fix it failed with:

AssertionError: 'ps' != 'cs'

After the fix the second root resolves to its own cs stage. It also checks that repeated lookups in one root still use the cache.

Tested

Windows 11, Python 3.14, under the machine coordination lock:

  • python -m compileall -q tools/rdna2spirv.py tests/test_rdna2spirv_stage_cache.py — pass.
  • python -I tests/test_rdna2spirv_stage_cache.py — 3 tests, OK.
  • python -I tests/test_bvh_shaders_stage.py — 13 tests, OK.
  • python -I tests/test_exe_shaders_stage.py — 11 tests, OK.
  • python -I tests/test_shader_library.py — 22 tests, OK (1 skipped).

No GPU or game data used. AI-assisted with Devin.

Consolidated follow-up

This branch now also contains the missing-index follow-up formerly opened as #2194: only successful index.json reads are cached, so an index created later in the same process is probed again instead of being hidden by a cached empty table. The added regression covers missing-then-created index.json; the branch head is exactly the previously reviewed #2194 head (c5c367a2a).


🔄 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/2154 **Author:** [@whoalin1](https://github.com/whoalin1) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `shader-stage-cache-crossroot` --- ### 📝 Commits (2) - [`c3ec925`](https://github.com/ubiquitarianism/leonida/commit/c3ec925623345b5ee2e923e2e83e887fbb68505b) rdna2spirv: cache shader stages per carve root - [`c5c367a`](https://github.com/ubiquitarianism/leonida/commit/c5c367a2a85e25e514a99107e66443d002257938) rdna2spirv: do not cache a missing stage index ### 📊 Changes **2 files changed** (+76 additions, -4 deletions) <details> <summary>View changed files</summary> ➕ `tests/test_rdna2spirv_stage_cache.py` (+67 -0) 📝 `tools/rdna2spirv.py` (+9 -4) </details> ### 📄 Description Claimed in the coordination issue as: SHADER-STAGE-CACHE-CROSS-ROOT (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7178575111) ### What and why `rdna2spirv.stage_of` cached the first carve `index.json` it read in process-global `_STAGES` and reused that one mapping for every later shader in the process. When one process translates listings from multiple carve roots, a shader in the second root can inherit the first root's stage, changing stage-dependent translation decisions. This is a concrete cross-shader mutable-state hazard in the area of jean-melikian's shard-only invalid-`OpSelect` report. The process-local cache is kept, but is now keyed by the resolved `index.json` path. Existing tests that reset `_STAGES = None` remain compatible. ### Regression test `tests/test_rdna2spirv_stage_cache.py` builds two synthetic roots with the same shader stem but different stages. Before the fix it failed with: ```text AssertionError: 'ps' != 'cs' ``` After the fix the second root resolves to its own `cs` stage. It also checks that repeated lookups in one root still use the cache. ### Tested Windows 11, Python 3.14, under the machine coordination lock: - `python -m compileall -q tools/rdna2spirv.py tests/test_rdna2spirv_stage_cache.py` — pass. - `python -I tests/test_rdna2spirv_stage_cache.py` — 3 tests, OK. - `python -I tests/test_bvh_shaders_stage.py` — 13 tests, OK. - `python -I tests/test_exe_shaders_stage.py` — 11 tests, OK. - `python -I tests/test_shader_library.py` — 22 tests, OK (1 skipped). No GPU or game data used. AI-assisted with Devin. ### Consolidated follow-up This branch now also contains the missing-index follow-up formerly opened as #2194: only successful `index.json` reads are cached, so an index created later in the same process is probed again instead of being hidden by a cached empty table. The added regression covers missing-then-created `index.json`; the branch head is exactly the previously reviewed #2194 head (`c5c367a2a`). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#2158
No description provided.