WarmUp
Prewarms all shader variants in this collection using associated graphics states.
Read time 4 minutesLast updated 5 days ago
Definition
- Type: Method
- Namespace: UnityEngine.Rendering
- Assembly: UnityEngine.CoreModule
WarmUp(JobHandle)
Prewarms all shader variants in this collection using associated graphics states.
public JobHandle WarmUp(JobHandle dependency = default)
Parameters
Job to wait for.
Returns
Type | Description |
|---|---|
| JobHandle | Handle to prewarming job. |
Remarks
This will result in the GPU representation of the stored shader variants being created. Except for the case of WebGPU, full graphics state collection warmup is only supported when SystemInfo.supportsParallelPSOCreation is true. Otherwise, behavior falls back to the legacy ShaderVariantCollection.WarmUp.
If is set to , then is created if it does not yet exist and then begins tracing. After the warmup job completes, any time a shader variant state permutation that does not exist in the current collection is used, it will be stored in this collection's GraphicsStateCollection.cacheMissCollection. If a prewarming a graphics state collection does not appear to reduce load times as expected, the cache miss collection is useful in investigating this issue.
traceCacheMissestruecacheMissCollectionYou can use the JobHandle this method returns to control if the creation of GPU representations occurs synchronously or asynchronously.
Note: On the Web platform, shader compilation is always performed synchronously and the returned JobHandle will be empty.
The example below will perform the warm up asynchronously.
using UnityEngine;using UnityEngine.Rendering;using Unity.Jobs;public class WarmUpExample : MonoBehaviour{ public GraphicsStateCollection graphicsStateCollection; void Start() { JobHandle handle = graphicsStateCollection.WarmUp(); }}
Below is an example of how to wait on the completion of the job handle in order to perform operations synchronously.
using UnityEngine;using UnityEngine.Rendering;using Unity.Jobs;public class WarmUpSynchronousExample : MonoBehaviour{ public GraphicsStateCollection graphicsStateCollection; void Start() { JobHandle handle = graphicsStateCollection.WarmUp(); handle.Complete(); }}
Prewarming can also be linked to other jobs using the input dependency and returned JobHandle.
using UnityEngine;using UnityEngine.Rendering;using Unity.Jobs;public class WarmUpSynchronousExample : MonoBehaviour{ struct PostWarmUpJob : IJob { public void Execute() { Debug.Log("WarmUp is complete"); } } public GraphicsStateCollection graphicsStateCollection; public JobHandle inputJobHandle; void Start() { JobHandle handle = graphicsStateCollection.WarmUp(inputJobHandle); var job = new PostWarmUpJob(); job.Schedule(handle); }}
Additional Resources: GraphicsStateCollection.WarmUpProgressively, GraphicsStateCollection.isWarmedUp, ShaderVariantCollection.WarmUp.
WarmUp(JobHandle, bool)
Prewarms all shader variants in this collection using associated graphics states.
public JobHandle WarmUp(JobHandle dependency, bool traceCacheMisses)
Parameters
Returns
Type | Description |
|---|---|
| JobHandle | Handle to prewarming job. |
Remarks
This will result in the GPU representation of the stored shader variants being created. Except for the case of WebGPU, full graphics state collection warmup is only supported when SystemInfo.supportsParallelPSOCreation is true. Otherwise, behavior falls back to the legacy ShaderVariantCollection.WarmUp.
If is set to , then is created if it does not yet exist and then begins tracing. After the warmup job completes, any time a shader variant state permutation that does not exist in the current collection is used, it will be stored in this collection's GraphicsStateCollection.cacheMissCollection. If a prewarming a graphics state collection does not appear to reduce load times as expected, the cache miss collection is useful in investigating this issue.
traceCacheMissestruecacheMissCollectionYou can use the JobHandle this method returns to control if the creation of GPU representations occurs synchronously or asynchronously.
Note: On the Web platform, shader compilation is always performed synchronously and the returned JobHandle will be empty.
The example below will perform the warm up asynchronously.
using UnityEngine;using UnityEngine.Rendering;using Unity.Jobs;public class WarmUpExample : MonoBehaviour{ public GraphicsStateCollection graphicsStateCollection; void Start() { JobHandle handle = graphicsStateCollection.WarmUp(); }}
Below is an example of how to wait on the completion of the job handle in order to perform operations synchronously.
using UnityEngine;using UnityEngine.Rendering;using Unity.Jobs;public class WarmUpSynchronousExample : MonoBehaviour{ public GraphicsStateCollection graphicsStateCollection; void Start() { JobHandle handle = graphicsStateCollection.WarmUp(); handle.Complete(); }}
Prewarming can also be linked to other jobs using the input dependency and returned JobHandle.
using UnityEngine;using UnityEngine.Rendering;using Unity.Jobs;public class WarmUpSynchronousExample : MonoBehaviour{ struct PostWarmUpJob : IJob { public void Execute() { Debug.Log("WarmUp is complete"); } } public GraphicsStateCollection graphicsStateCollection; public JobHandle inputJobHandle; void Start() { JobHandle handle = graphicsStateCollection.WarmUp(inputJobHandle); var job = new PostWarmUpJob(); job.Schedule(handle); }}
Additional Resources: GraphicsStateCollection.WarmUpProgressively, GraphicsStateCollection.isWarmedUp, ShaderVariantCollection.WarmUp.