Warm up PSO collections on the GPU at runtime.
Important: GraphicsStateCollection is an experimental API and might be changed or removed in the future.
To reduce stuttering, compile shadersA program that runs on the GPU. More info
See in Glossary 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 sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary.
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.
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 markersPlaced in code to describe a CPU or GPU event that is then displayed in the Unity Profiler window. Added to Unity code by default, or you can use ProfilerMarker API to add your own custom markers. More info
See in Glossary 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.