diff --git a/docs/launcher.md b/docs/launcher.md index 377fc245..9e4c5768 100644 --- a/docs/launcher.md +++ b/docs/launcher.md @@ -247,7 +247,11 @@ The stub swaps `python.next` in while no Python runs, then starts the new versio game files are already unpacked builds on from them as well (`jobs.InstallJob.args`). 7. **Prepare the Shaders** is skipped once shaders were prepared before (`shader-prepared.bin`): the game keeps using them and translates them again with the new translator in the background (`NX2NAVI_SHADER_CARRY`). With - `shader_carry = 0`, or nothing prepared yet, the step prepares them all as at the install. + `shader_carry = 0`, or nothing prepared yet, the step prepares them all as at the install. The step still builds + the prepared shaders into the graphics driver's cache again (`make_game.py` `warm_driver_cache`): seconds while + the driver has them, 20 minutes on a player's PC when the update changed what they are built with. Its bar + follows that count from 0 to 100 %, and the Updates row says an update takes from a few minutes to half an hour + or more (`launcher/ui/app.py` `UPDATE_TAKES`). 8. **Draw the Button Prompts**, with button art in the new version: only when the art, the prompt tools or the key bindings changed, or a prompt folder is missing (a first version with art draws them all). 9. Every version but the current and the previous one is deleted, except a staged release newer than the current diff --git a/launcher/ui/app.py b/launcher/ui/app.py index b01b4840..9527b044 100644 --- a/launcher/ui/app.py +++ b/launcher/ui/app.py @@ -159,6 +159,15 @@ def drop_partial_image(game_dir): pass +# How long an update's rebuild takes, for the Updates row. No single figure holds: a version that changed little +# compiles a few files and links, minutes; one that changed the lifter translates and compiles the game's code again, +# and one that changed what the shaders are built with builds all of them into the graphics driver's cache again +# (tools/make_game.py warm_driver_cache). Players' updates took 24, 34 and 45 minutes where the text said "a few +# minutes". +UPDATE_TAKES = ('That takes a few minutes when little changed, and half an hour or more when the game\'s code or ' + 'its shaders are built again.') + + def drive_of(path): return Path(path).anchor.rstrip('\\/') or str(Path(path).parent) @@ -1235,8 +1244,8 @@ class App: nv, mine = versions.display(r.version), versions.display(self.layout.version) notes = feed.plain_notes(r.notes, 6) return {'title': f'Version {nv} Is Ready', - 'text': [f'You have {mine}. Updating downloads the new version and rebuilds the game in a few ' - f'minutes. Your saves and settings stay as they are.'], + 'text': [f'You have {mine}. Updating downloads the new version and rebuilds the game. {UPDATE_TAKES} ' + f'Your saves and settings stay as they are.'], 'divider': bool(notes), 'subtitle': "What's New" if notes else '', 'bullets': notes} def staged_desc(self, m): @@ -1250,7 +1259,7 @@ class App: text = f'You have {mine}. Version {nv} is downloaded. Select this row to install it.' return {'title': f'Version {nv} Is Ready', 'text': [text], 'divider': bool(notes), 'subtitle': "What's New" if notes else '', 'bullets': notes, - 'note': 'Installing restarts the launcher and rebuilds the game in a few minutes. Your saves and ' + 'note': f'Installing restarts the launcher and rebuilds the game. {UPDATE_TAKES} Your saves and ' 'settings stay as they are.'} def staging_desc(self): diff --git a/tests/launcher_test.py b/tests/launcher_test.py index 3695adb2..8d50f9cb 100644 --- a/tests/launcher_test.py +++ b/tests/launcher_test.py @@ -1485,6 +1485,35 @@ class MakeGameTest(Tmp): self.assertTrue(any(d.startswith('Built 10 of 100') and 'still running' in d for d in details)) self.assertEqual([e['fraction'] for e in events if e['detail'] == 'Translated 50 of 100 shaders'][0], 0.25) + def test_a_build_only_run_fills_the_whole_bar(self): + """The driver cache warm-up after an update only builds: its count runs from 0 to 100% of the bar, where a + full preparation gives the build the second half after the translation.""" + p = self.mg.shader_progress + self.assertEqual(p('build', 0, 42142, 0, 1, build_only=True)['fraction'], 0.0) + self.assertEqual(p('build', 21071, 42142, 0, 600, build_only=True)['fraction'], 0.5) + self.assertEqual(p('build', 42142, 42142, 0, 1200, build_only=True)['fraction'], 1.0) + self.assertEqual(p('build', 21071, 42142, 0, 600)['fraction'], 0.75) + self.assertEqual(p('build', 21071, 42142, 0, 600, build_only=True)['detail'], + 'Built 21,071 of 42,142 shaders for your graphics card') + # warm_driver_cache runs the game's exe that way: a stand-in exe that prints the counts the game prints + self.out.mkdir() + (self.out / 'shader-prepared.bin').write_bytes(b'x') + exe = self.out / self.mg.EXE_NAME + exe.write_bytes(b'MZ') + script = self.tmp / 'warm.py' + script.write_text('for d in (0, 25, 100):\n print(f"prepare-shaders: progress build {d} 100", flush=True)\n') + real = self.mg.subprocess.Popen + + def popen(cmd, **kw): + self.assertEqual(cmd, [str(exe), '--warm-shaders']) + return real([sys.executable, str(script)], **kw) + buf = io.StringIO() + with mock.patch.object(self.mg, 'EVENTS', True), mock.patch.object(self.mg.subprocess, 'Popen', popen), \ + contextlib.redirect_stdout(buf): + self.mg.warm_driver_cache(self.out) + events = [json.loads(ln[2:]) for ln in buf.getvalue().splitlines() if ln.startswith('@@')] + self.assertEqual([e['fraction'] for e in events if e['detail'].startswith('Built')], [0.0, 0.25, 1.0]) + def test_shaders_step_packs_the_cache(self): """After the preparation the shaders step folds the loose files of the shader cache into shader-cache.pack (tools/pack_shader_cache.py), as the installer did; a kit without the tool leaves the cache as it is.""" @@ -1537,7 +1566,7 @@ class MakeGameTest(Tmp): fails is said and does not stop the build, and without a built game or a preparation nothing runs.""" calls = [] for name, value in (('shader_carry', lambda out: True), - ('shader_run', lambda cmd, cwd=None: calls.append((cmd, cwd)) or self.rc)): + ('shader_run', lambda cmd, cwd=None, build_only=False: calls.append((cmd, cwd)) or self.rc)): self.addCleanup(setattr, self.mg, name, getattr(self.mg, name)) setattr(self.mg, name, value) self.rc = 0 @@ -3405,6 +3434,21 @@ class BeginInstallTest(Tmp): self.assertIn('(31 GB free)', rows['Begin Installation'].desc[0]) +class UpdateTextTest(Tmp): + def test_the_updates_row_does_not_promise_a_few_minutes(self): + """An update's rebuild took players 24 to 45 minutes: the Updates row says what it depends on instead of + "in a few minutes".""" + from launcher.ui import app + App, a = mock_app(self, self.tmp / 'game') + a.release = mock.Mock(version='9.9.9', notes='') + texts = [' '.join(App.update_desc(a)['text']), App.staged_desc(a, {'version': '9.9.9', 'notes': ''})['note']] + for text in texts: + self.assertNotIn('in a few minutes', text) + self.assertIn(app.UPDATE_TAKES, text) + self.assertIn('saves and settings stay', text) + self.assertIn('half an hour or more', app.UPDATE_TAKES) + + class StartScriptTest(Tmp): """launcher/start.pyw when the version cannot be imported: with a version to go back to it ends with code 86 at once and shows no message box, so the stub's six-second wait sees the code and rolls back.""" diff --git a/tools/make_game.py b/tools/make_game.py index ec6d10d7..27c5d024 100644 --- a/tools/make_game.py +++ b/tools/make_game.py @@ -1535,19 +1535,24 @@ SHADER_STALL_S = 180 # no count moved for this long: the launcher says so (the SHADER_BEAT_S = 10 # a progress event at least this often while the step runs -def shader_progress(phase, done, total, quiet_s, elapsed_s): +def shader_progress(phase, done, total, quiet_s, elapsed_s, build_only=False): """The shaders step's progress event fields: the translation fills the first half of the bar, the build into the driver's cache the second (nx2navi.exe prints both counts, runtime/gfx_shader.c prepare_files and runtime/vk_pipeline.c lb_warm_prepared); before either count, reading the game's shaders. quiet_s: seconds since a count last moved, said once it passes SHADER_STALL_S, so a slow step never looks frozen without a word. The - detail ends without a full stop: the launcher adds one (launcher/ui/app.py).""" + detail ends without a full stop: the launcher adds one (launcher/ui/app.py). + build_only: a run that only builds (warm_driver_cache), whose count fills the whole bar: starting at one half, + the bar of a 20 minute build read 50% in its first second, and the launcher's time left, which follows the bar's + pace (launcher/jobs.py Job.eta), had half the bar to go by.""" clock = f'{int(elapsed_s) // 60}:{int(elapsed_s) % 60:02d}' if phase is None: fraction, detail = 0.0, f'Reading the game\'s shaders ({clock} so far)' elif phase == 'translate': fraction, detail = 0.5 * done / max(total, 1), f'Translated {done:,} of {total:,} shaders' else: - fraction, detail = 0.5 + 0.5 * done / max(total, 1), f'Built {done:,} of {total:,} shaders for your graphics card' + part = done / max(total, 1) + fraction = part if build_only else 0.5 + 0.5 * part + detail = f'Built {done:,} of {total:,} shaders for your graphics card' if quiet_s >= SHADER_STALL_S: detail += (f'. No change for {int(quiet_s) // 60} min, but it is still running: one large shader can take ' 'a while') @@ -1607,10 +1612,10 @@ def shader_carry(out): return (out / 'shader-prepared.bin').is_file() and bool(cache_identities(out)) -def shader_run(cmd, cwd=None): +def shader_run(cmd, cwd=None, build_only=False): """Runs a shader preparation command and returns its exit code. Its output is read as it comes: the counts nx2navi.exe prints become progress events, the other lines go on to the log, and while nothing moves an event - every few seconds keeps saying the step is running and for how long.""" + every few seconds keeps saying the step is running and for how long. build_only: shader_progress.""" proc = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, encoding='utf-8', errors='replace', bufsize=1) t0 = time.monotonic() @@ -1621,7 +1626,7 @@ def shader_run(cmd, cwd=None): def send(): now = time.monotonic() emit('progress', **shader_progress(state['phase'], state['done'], state['total'], now - state['moved'], - now - t0)) + now - t0, build_only)) def heartbeat(): while not stop.wait(SHADER_BEAT_S): @@ -1669,7 +1674,7 @@ def warm_driver_cache(out): say(" the prepared shaders are built into the graphics driver's cache again") t0 = time.monotonic() try: - rc = shader_run([str(exe), '--warm-shaders'], cwd=str(out)) + rc = shader_run([str(exe), '--warm-shaders'], cwd=str(out), build_only=True) except OSError as e: rc = str(e) if rc: @@ -1696,6 +1701,8 @@ def step_shaders(out, update=False): 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: + # minutes without a count (4 on a player's 328,000 files): the row says what runs meanwhile + emit('progress', step='shaders', fraction=0.0, detail='Folding the shader cache into one file') pack_shader_cache(out) warm_driver_cache(out) return