# WarmUp

> Prewarms all shader variants in this collection using associated graphics states.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.Rendering](/engine/6000.7/script-reference/unityengine/rendering.md)
* **Assembly:** UnityEngine.CoreModule

## WarmUp(JobHandle)

Prewarms all shader variants in this collection using associated graphics states.

```csharp
public JobHandle WarmUp(JobHandle dependency = default)
```

### Parameters

**** (\[JobHandle]\(/engine/6000.7/script-reference/unity/jobs/jobhandle)): Job to wait for.

### Returns

| Type                                                                 | Description               |
| -------------------------------------------------------------------- | ------------------------- |
| [JobHandle](/engine/6000.7/script-reference/unity/jobs/jobhandle.md) | 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](/engine/6000.7/script-reference/unityengine/systeminfo/supportsparallelpsocreation.md) is true. Otherwise, behavior falls back to the legacy [ShaderVariantCollection.WarmUp](/engine/6000.7/script-reference/unityengine/shadervariantcollection/warmup.md).

If `traceCacheMisses` is set to `true`, then `cacheMissCollection` 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](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/cachemisscollection.md). 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.

You can use the [JobHandle](/engine/6000.7/script-reference/unity/jobs/jobhandle.md) 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](/engine/6000.7/script-reference/unity/jobs/jobhandle.md) will be empty.

The example below will perform the warm up asynchronously.

```csharp
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.

```csharp
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.

```csharp
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](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/warmupprogressively.md), [GraphicsStateCollection.isWarmedUp](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/iswarmedup.md), [ShaderVariantCollection.WarmUp](/engine/6000.7/script-reference/unityengine/shadervariantcollection/warmup.md).

## WarmUp(JobHandle, bool)

Prewarms all shader variants in this collection using associated graphics states.

```csharp
public JobHandle WarmUp(JobHandle dependency, bool traceCacheMisses)
```

### Parameters

**** (\[JobHandle]\(/engine/6000.7/script-reference/unity/jobs/jobhandle)): Job to wait for.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): If true, stores any graphics states used during runtime that were not prewarmed.

### Returns

| Type                                                                 | Description               |
| -------------------------------------------------------------------- | ------------------------- |
| [JobHandle](/engine/6000.7/script-reference/unity/jobs/jobhandle.md) | 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](/engine/6000.7/script-reference/unityengine/systeminfo/supportsparallelpsocreation.md) is true. Otherwise, behavior falls back to the legacy [ShaderVariantCollection.WarmUp](/engine/6000.7/script-reference/unityengine/shadervariantcollection/warmup.md).

If `traceCacheMisses` is set to `true`, then `cacheMissCollection` 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](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/cachemisscollection.md). 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.

You can use the [JobHandle](/engine/6000.7/script-reference/unity/jobs/jobhandle.md) 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](/engine/6000.7/script-reference/unity/jobs/jobhandle.md) will be empty.

The example below will perform the warm up asynchronously.

```csharp
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.

```csharp
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.

```csharp
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](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/warmupprogressively.md), [GraphicsStateCollection.isWarmedUp](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/iswarmedup.md), [ShaderVariantCollection.WarmUp](/engine/6000.7/script-reference/unityengine/shadervariantcollection/warmup.md).
