Check how many shader variants you have
Use the shader logging and profiling tools in Unity.
읽는 시간 3분최근 업데이트: 7일 전
You can use logging and profiling tools to check how many shader variants Unity compiles, and identify ways you can remove (strip) variants to improve build times and reduce memory usage. You can do the following:
- Get a list of shader variants the Editor uses
- Get a list of shader variants Unity creates at build time
- Get a list of shader variants Unity compiles at runtime
- Check how much memory shaders use at runtime
- Highlight missing shaders at runtime
Get a list of shader variants Unity creates at build time
After you build your project, open the log file and search for to see which variants Unity compiles and strips. For the location of , refer to log files.
Editor.logCompiling shaderEditor.logFor example:
Compiling shader "Sprites/Default" pass "" (vp) Full variant space: 8 After settings filtering: 8 After built-in stripping: 4 After scriptable stripping: 4 Processed in 0.00 seconds starting compilation... finished in 0.03 seconds. Local cache hits 0 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 4 variants (0.09s CPU time), skipped 0 variants Prepared data for serialisation in 0.00s
If you use the Universal Render Pipeline (URP) or the High Definition Render Pipeline (HDRP), refer to the following:
Get a list of shader variants Unity compiles at runtime
To get a list of shader variants Unity compiles at runtime, record which pipeline state objects (PSOs) your application uses with the experimental API. For more information, refer to Trace and manage PSO data collections.
GraphicStateCollectionYou can also log compiled shader variants in the Console window and in a log file. Follow these steps:
- Go to Edit > Project Settings > Graphics.
- Under Shader Loading, enable Log Shader Compilation.
- When you build your project, enable in the build settings.Development Build
?
- In the Console Window, select Editor and enable Full Log [Developer Mode Only].
- Start the application you built.
Unity prints a message in the Console Window when it compiles a shader for the GPU.
Compiled shaderCheck how much memory shaders use at runtime
Use the Memory Profiler module or the Memory Profiler package to check how much memory shaders are using at runtime. If a shader uses a lot of memory, you can experiment with stripping its variants.
Highlight missing shaders at runtime
In Unity 2022.3 and above, you can force Unity to show a pink error shader during runtime, when a Material tries to use a missing shader variant.
- Go to Edit > Project Settings > Player.
- Under Other Settings, in the Shader Settings section, select Strict shader variant matching.
You can also enable this in C# scripts using .
strictShaderVariantMatchingWhen you do this, Unity shows a warning in the console with the missing variant and its keywords. You can use this during stripping to check you don't remove shader variants your project needs.