Skip to content

Show and shorten the cold compile of the pipelines, and stop frames waiting behind speculative ones - #110

Closed
5hif7y wants to merge 3 commits into
mirai-engine:mainfrom
5hif7y:render/cold-start-shaders
Closed

5hif7y wants to merge 3 commits into
mirai-engine:mainfrom
5hif7y:render/cold-start-shaders

Conversation

@5hif7y

@5hif7y 5hif7y commented Nov 16, 2026

Copy link
Copy Markdown
Member

Closes #109.

On a cold driver cache the renderer compiled its pipelines synchronously for minutes behind a blank window that did not answer. Quitting waited for driver calls that cannot be cut. A single pipeline thread (with 4 cores) made frames wait behind speculative variants, so materials drew as their rows almost every frame, even with a warm store.

Changes

  • Start screen. The pipelines a renderer starts with compile on a thread. Meanwhile the window keeps answering (platform.window_wait) and shows Compiling shaders N/M with a clock, drawn without pipelines: a clear plus a copy of text painted on the CPU (ui.text_paint). The title says the same.
  • Instant exit. A window closed during that compile, or a quit while a pipeline is inside the driver (host.app_quit_compiling), writes the kept pipelines and ends the process at once. This is the one exception to the engine never ending the process, decided explicitly and written in the rendering skill.
  • Pipeline thread. The first thread takes no speculative job. Speculative jobs go cheapest first, and no frame waits for one, even after a setting selects it (pipeline_job_next).
  • Graphics_Settings.shaders. While_Playing (default) or Before_Playing: a frame waits for the pipelines that are not speculative.
  • Counters. Device_Stats counts pipelines made, read from the store and driver time. pipeline_store_load returns Read, Missing, Other_Device (a driver update) or Unreadable. On rebase this reuses Weigh the pipeline store's saves by the time measured around creation #107's CPU measurement of the creation call, so there is one measurement.
  • Telemetry. profile.load and the player log give each load its pipelines, with a note saying why they compiled.
  • mirai bench pipelines. Plays a cold start against a warm one with both caches emptied: the kept pipelines are set aside and restored, and the driver cache is pointed at an empty folder. It warns when the cold start may not have been cold.
  • project.user_folder. The user folder of a project moves out of platform, so the tools reach the kept pipelines without SDL.

Measurements (Radeon RX 580, no hardware RT, 4 cores, Windows)

Before After
Frames with materials as rows (ocean, warm store, 300 frames) 296 0
Closing the window during the cold start 165–176 s 0.35–0.48 s
Quitting with a pipeline in the driver 18 s 0.5 s
Before_Playing wait, cold (first draft waited for everything) 361 s 0.7 s

mirai bench pipelines demo --scene ocean/ocean.scene:

Cold Warm
Start of the renderer, ms 300808 1085
Compiled by the driver 108 0
Driver time, ms summed 599707 36
Frames late 2 0
Kept pipelines found Missing Read

mirai render check demo --views night against main: 5.86 → 5.86 ms, stability 0.001 → 0.001, no regressions.

What ran

  • mirai check: rhi, render, host, platform, project, ui, editor, tools/mirai, engine/render, engine/save.
  • mirai test --no-gpu: rhi 31, render 98, host 70, platform 46, project 38, ui 271, tools/mirai 82, editor (all pass after counting the new Shaders row).
  • mirai test with the GPU: rhi 31/31. render all pass but one, which also fails on origin/main (below).
  • mirai build editor demo, mirai play test demo (2/2), mirai scene check --project demo (no problems).
  • Cold runs with --validation: no Vulkan validation errors from the start screen.
  • Live checks: player cold, warm, closing and quitting; profile.load through mirai rpc in an editor session.

Fails on main too: render_far_from_the_centre_looks_as_at_it_and_a_jump_keeps_the_history ("a view 15 km from the origin is the one at it: mean 0.000117, most 0.137"). It fails identically on origin/main (4aae7bb), twice on each.

Not verified

  • NVIDIA, Intel, Linux and macOS. Metal code is written but not compiled here.
  • The instant exit with the multiplayer plugin: peers see the quit as a timeout.
  • Resizing the window during the start screen, and HDR swapchains (the screen shows the background only).

Open for review

  • The default of Graphics_Settings.shaders. Before_Playing now costs under a second, so it may be the better default.

🤖 Generated with Claude Code

5hif7y and others added 3 commits November 16, 2026 10:15
…with

On a cold driver cache the renderer compiled its pipelines synchronously
for minutes (4.5 to 7 on an RX 580 without hardware ray tracing) behind a
blank window that did not answer, and quitting waited for driver calls
that cannot be cut. With 4 cores a single pipeline thread made frames wait
behind speculative variants, so materials drew as their rows in almost
every frame even with a warm store.

- The start compiles on a thread while the window shows how many are
  made, with a screen drawn without pipelines (a clear and a copy of text
  painted on the CPU, ui.text_paint) and the title saying the same.
- A window closed meanwhile, or a quit while a pipeline is inside the
  driver (app_quit_compiling), writes the kept pipelines and ends the
  process at once: the one exception to the engine never ending it.
- The first pipeline thread takes no speculative job; speculative jobs go
  cheapest first and no frame waits for one.
- Graphics_Settings.shaders: While_Playing, or Before_Playing, where a
  frame waits for the pipelines that are not speculative.
- Device_Stats counts the pipelines made, those read from the store and
  the driver time; pipeline_store_load says what it found (Read, Missing,
  Other_Device after a driver update, Unreadable).
- profile.load and the player log give each load its pipelines, with a
  note on why they compiled.
- project.user_folder takes the user folder of a project out of platform,
  so the tools find the kept pipelines without SDL.

Refs mirai-engine#109

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It plays the project twice with a window and prints their table: the
start of the renderer, the pipelines the driver compiled and the frames
that lost them. Cold empties both caches: the kept pipelines go aside and
come back after, and the driver's own is pointed at an empty folder by
its variables. The table says when the cold start may not have been cold
(the kept pipelines were read, or the driver kept its own cache).

Refs mirai-engine#109

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Graphics_Settings.shaders is a tagged field of the machine settings, so the
popup has one row more.

Refs mirai-engine#109

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@5hif7y 5hif7y self-assigned this Nov 16, 2026
tomaszbk added a commit that referenced this pull request Nov 21, 2026
Port pull request #110 onto the expanded pipeline variant set. Keep the
window responsive during driver compilation and reserve a worker for
non-speculative work. Isolate the benchmark's cache from the project.

Ported-from: 4498ba7
Refs: #109, #110
Co-authored-by: 5hif7y <44300833+5hif7y@users.noreply.github.com>
@tomaszbk tomaszbk closed this Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cold-start shader compilation: progress screen, instant exit, pop-in priority fix, pipeline telemetry

2 participants