mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 22:19:57 -04:00
Read shaders from the disk cache off the render thread past a small budget, and pack the cache on carried updates.
A profiled traversal session had 9 of its 16 worst hitches (100 to 500 ms) inside the render thread's shader lookup, reading <key>.res.json and <key>.spv of shaders met for the first time: opening a loose file costs about 3 ms the first time on Windows. get_async_one now reads in place while those reads stay within 1/8 of the wall time (2 ms at once); past that three loader threads read them and the draws wait as for a translation. The perf line counts both. The launcher's updates carry the shaders over and never packed the cache, which held 44,000 loose translations in the test install. An update now packs it once it holds 1,000 loose ones, and the pack tool reads the loose files on 16 threads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1363,6 +1363,8 @@ def step_shaders(out, update=False):
|
||||
break
|
||||
if update and shader_carry(out):
|
||||
say(' the shaders prepared before this update stay in use; the game translates them again in the background')
|
||||
if loose_shaders(out) >= PACK_LOOSE_MIN:
|
||||
pack_shader_cache(out)
|
||||
return
|
||||
cmd = [sys.executable, '-u', str(KIT / 'tools' / 'prepare_shaders.py'), str(out), '--romfs', str(out / 'romfs'),
|
||||
'--exefs', str(out / 'exefs'), '--no-list', '--exe', EXE_NAME]
|
||||
@@ -1415,6 +1417,21 @@ def step_shaders(out, update=False):
|
||||
pack_shader_cache(out)
|
||||
|
||||
|
||||
# An update that carries the shaders over packs the cache when it has this many loose translations: the game writes
|
||||
# each translation it makes in play, and those of its background pass after a translator change (about 42,000), as loose
|
||||
# files, and reading one the first time cost 5.6 ms on Windows against a fraction of a millisecond from the pack.
|
||||
PACK_LOOSE_MIN = 1000
|
||||
|
||||
|
||||
def loose_shaders(out):
|
||||
"""The loose translations (<key>.spv) in the game's shader cache."""
|
||||
try:
|
||||
with os.scandir(out / 'shader-cache') as it:
|
||||
return sum(1 for e in it if e.name.endswith('.spv'))
|
||||
except OSError:
|
||||
return 0
|
||||
|
||||
|
||||
def pack_shader_cache(out):
|
||||
"""The prepared shader cache folded into shader-cache/shader-cache.pack (tools/pack_shader_cache.py): the
|
||||
preparation leaves four files per shader, about 175,000 for the whole game, which the game looks up one by one at
|
||||
|
||||
Reference in New Issue
Block a user