rdna2spirv: cache shader stages per carve root #2154
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2154"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-26T00:20:15Z.
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_ofcached the first carveindex.jsonit read in process-global_STAGESand 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-OpSelectreport.The process-local cache is kept, but is now keyed by the resolved
index.jsonpath. Existing tests that reset_STAGES = Noneremain compatible.Regression test
tests/test_rdna2spirv_stage_cache.pybuilds two synthetic roots with the same shader stem but different stages. Before the fix it failed with:After the fix the second root resolves to its own
csstage. 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.jsonreads 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-createdindex.json; the branch head is exactly the previously reviewed #2194 head (c5c367a2a).Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-26T00:28:43Z.
Full semantic verification on the PR head
c3ec92562under the machine lock:495 files, 6333 tests, 0 files failed(12 jobs). Focused compileall plus stage/cache/library unit tests were already green before opening. AI-assisted (Devin).Imported from ubiquitarianism/leonida. Originally posted by qhukz13 on 2026-11-26T00:40:41Z.
Checked at
c3ec92562on Linux (Python 3).rdna2spirv._STAGES(test_bvh_shaders_stage.py,test_exe_shaders_stage.py,test_shader_library.py) only resets it toNone, which still works; nothing reads or fills the old name -> stage form directly.test_rdna2spirv_stage_cache.py,test_bvh_shaders_stage.py,test_exe_shaders_stage.py,test_shader_library.py: all OK here.index.jsonis cached as an empty dict for its key, so if the carve writes it later in the same process,stage_offalls back to the name guess for that root until_STAGESis reset. Not needed for this PR's case; just noting it in case someone hits it with an in-process carve + translate.Looks right to me.
AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-26T09:19:06Z.
Thanks for the detailed check. The missing-index edge you called out is carried in the stacked follow-up #2194: it caches only successful index reads, so a root whose
index.jsonappears later in the same process is probed again instead of keeping the empty table until_STAGESis reset. The regression case is covered intests/test_rdna2spirv_stage_cache.py. AI-assisted with Devin.Imported from ubiquitarianism/leonida. Originally posted by real-rusher on 2026-11-26T10:20:14Z.
Verified on main
a73a57e1(Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. python -I tests/test_rdna2spirv_stage_cache.py: 2 tests OK with this PR; the same file against main's translator: 1 failure, so it fails on main and passes with the change. compileall clean.#2194 (do not cache a missing stage index) touches the same cache: the two merge together cleanly, and with both merged, each PR's version of tests/test_rdna2spirv_stage_cache.py passes.
AI-assisted: yes (Claude Code)
Imported from ubiquitarianism/leonida. Originally posted by wavehs on 2026-11-26T19:48:17Z.
Review: COMMENTED
macOS arm64 check of #2154 (rdna2spirv stage cache per carve root). A small tool change with a focused test; runs here without a GPU.
Tested head
c5c367a2amerged ontomainbdbc7e923as merge0a5f09382(clean, no conflicts).Environment: Apple M3 Pro arm64, macOS 27.2.1, CPython 3.15.2.
On the merge
python -I tests/test_rdna2spirv_stage_cache.py: 3 tests OK - two roots with the same shader name get their own stages (psthencs), the same root stays cached (deleting itsindex.jsonafterwards still answers), and a missing index is not cached (creating it later is picked up).500 files, 6367 tests, 0 files failed- no change, as expected.os.path.normcase(os.path.realpath(index.json)), so two spellings of one root share an entry on Windows and two carve roots cannot cross-contaminate. The bug was real in the in-process users (tools/image_bvh_census.py:753,tools/ptr_truncation_census.py:147,tools/wave32_pixel_scan.py:232,tools/wave64_graphics_scan.py:121): a census over several roots would answer the second root's same-named shaders from the first root's index.Negative control (new test kept,
tools/rdna2spirv.pyreverted tomain)FAILED (failures=2)in the new file: the second-root case and the missing-index case both fail on the old global cache, which is exactly the regression.Nits
index.jsonafter a firststage_ofcall, the answer stays stale. None of the current callers do that (they are one-shot census/scan tools, and_translatereads it once), so this is a note for future reuse rather than a defect; a comment on the function saying "the index is assumed immutable for the process lifetime" would make the assumption explicit.normcaseonly folds case on Windows. macOS's default filesystem is case-insensitive too, so two case-different spellings of the same root create two cached copies here; harmless (an extra parse), and folding it would need more thannormcase._STAGESreset in older tests (tests/test_bvh_shaders_stage.py:78,tests/test_exe_shaders_stage.py:87) still works because it is re-created as a dict; nothing to change.Not run: the game corpus (needs a copy), and the census tools over multiple real roots, which is the case the fix targets - the new test reproduces it synthetically with four files.
python -I scripts/check_no_game_data.pyon both changed files: clean.No game files. AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T11:09:08Z.
#2154 | head
c5c367a2a8(merged cleanly with main039870ea2) |python -I tests/test_rdna2spirv_stage_cache.py| red on main:FAILED (failures=2)('ps' != 'cs'across distinct carve roots and'?' != 'cs'after missingindex.json) | green on PR+main:3 tests OK| Windows 11, Python 3.12.10 | AI-assisted: yesAudited
stage_ofper-carve-root_STAGEScaching (os.path.normcase(os.path.realpath(idx))on Windows 11 NTFS, skipping_STAGES[key]assignment whenindex.jsonis absent) intools/rdna2spirv.pyandtests/test_rdna2spirv_stage_cache.py. Also verified0merge conflicts with #2011 and #2239, and passedtests/test_ci_registration.py(18 OK),tests/test_text_write_line_endings.py(3 OK),tests/test_runner_calls_all_tests.py(3 OK), andscripts/check_no_game_data.py.Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-29T02:12:46Z.
#2154 | head
b001cfa5ee(merged cleanly onto origin/main791899f652) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yesIndependent Verification (Windows 11 + NTFS)
b001cfa5eeacrosstools/rdna2spirv.py(keying_STAGESper carve root viaos.path.normcase(os.path.realpath(idx))and only caching whenos.path.isfile(idx)succeeds) andtests/test_rdna2spirv_stage_cache.py.python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/test_rdna2spirv_stage_cache.pypassed (rc=0).origin/main791899f652tools/rdna2spirv.py): Running#2154'stests/test_rdna2spirv_stage_cache.py -vagainst unpatchedtools/rdna2spirv.pyfailed2of3tests (FAILED (failures=2):test_a_missing_index_is_not_cachedandtest_second_root_does_not_reuse_the_first_roots_index,'ps' != 'cs').#2154 + origin/main):python -I tests/test_rdna2spirv_stage_cache.py -v->3/3passed (OK,0.024s)mklink /J) probe: Verified on Windows 11 NTFS that callingrdna2spirv.stage_of(...)through different letter-case spellings (listing.upper()) and through an NTFS junction (mklink /J) resolves to the exact sameos.path.normcase(os.path.realpath(idx))cache entry (len(rdna2spirv._STAGES) == 1) and continues returning'vs'afterindex.jsonis removed.python -I tests/test_ci_registration.py->18/18passed (OK).Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T15:44:08Z.
Merged. Tested by @zmasi on head
b001cfa5e(CPU only (Windows 11, Python 3.12)): test_rdna2spirv_stage_cache: red on main (2 of 3 fail, 'ps' != 'cs'); green 3/3 on head. The CI jobs that are red on this head were also red on main at the time of the run. Thanks @whoalin1!AI-assisted: yes