Warm up PSO collections on the GPU at runtime.
To reduce stuttering, compile shaders and create PSOs before they’re first needed, so that the graphics driver caches them to disk. This is called warming up, prewarming, or precooking graphics states. You usually warm up during a loading screen, either when your application starts or while loading a scene.
Once you’ve traced a PSO data collection, you can warm up the cached PSOs to disk.
Note: The recommended best practice is to prewarm your collection during application or scene loading sequences.
To warm up a PSO data collection, you can use two API methods:
The GraphicsStateCollection.WarmUp and GraphicsStateCollection.WarmUpProgressively prewarm methods return a job handle, which you can use to set whether Unity performs the warming synchronously or asynchronously.
Unity can also start warming PSOs from graphics state collections automatically before or after the first scene loads in your application. For more information, refer to Shader loading (Graphics Settings).
Tip: To trace any PSOs used by your application that weren’t created during the collection warmup, enable the traceCacheMisses option when you call GraphicsStateCollection.WarmUp or GraphicsStateCollection.WarmUpProgressively. This creates a separate cacheMissCollection to store the new PSOs, which you can manage as its own collection, or Append to an existing collection.
Unity creates PSOs and caches them to disk. The next time the GPU needs a PSO, it loads the PSO directly from the cache.
To check when Unity and the graphics driver compile shaders and create PSOs, search for the following profiler markers in the ProfilerA window that helps you to optimize your game. It shows how much time is spent in the various areas of your game. For example, it can report the percentage of time spent rendering, animating, or in your game logic. More info
See in Glossary:
Shader.CreateGPUProgram for Unity creating a GPU-specific version of a shader variant.CreateGraphicsGraphicsPipelineImpl for Unity creating a PSO.