rdna2spirv: cache shader stages per carve root #2154
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2154
Loading…
Reference in a new issue
No description provided.
Delete branch "shader-stage-cache-crossroot"
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?
Pull request successfully merged and closed
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).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).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).
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.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)
#2154 | head c5c367a2a85e25e514a99107e66443d002257938 (merged cleanly with main 039870ea2) |
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.#2154 | head b001cfa5ee78c2ba55c3e896c8f49e5eb976827b (merged cleanly onto origin/main 791899f652) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yes
Independent 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).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