ロギングとプロファイリングツールを使用して、Unity がコンパイルするシェーダーバリアントの数を確認できます。また、ビルド時間を短縮してメモリ使用量を削減するためにバリアントを削除 (ストリッピング) する方法を見つけることができます。以下を行うことが可能です。
エディターがシーンビューとゲームビューで使用する、シェーダーバリアントのリストを生成することができます。これは以下の手順で行えます。
プロジェクトをビルドした後で、Editor.log
ログファイルを開き、Compiling shader
を検索すると、Unity がどのバリアントをコンパイルおよび除去しているか確認できます。以下はその例です。
Compiling shader "Universal Render Pipeline/Lit" pass "ForwardLit" (fp)
320 / 786432 variants left after stripping, processed in 6.77 seconds
starting compilation...
finished in 29.72 seconds. Local cache hits 202 (0.24s CPU time), remote cache hits 0 (0.00s CPU time), compiled 118 variants (582.41s CPU time), skipped 0 variants
ユニバーサルレンダーパイプライン (URP) または HD レンダーパイプライン (HDRP) を使用している場合は、Unity がコンパイルおよび除去するバリアントの合計数をログに記録することも可能です。以下を開き、Shader Stripping > Shader Variant Log Level の下で、Disabled 以外のレベルを選択してください。
これにより、Editor.log
に Total
のログが追加されます。以下はその例です。
STRIPPING: Universal Render Pipeline/Lit (ForwardLit pass) (Fragment) - Remaining shader variants = 640/5760 = 11.11111% - Total = 2657/10169 = 26.12843%
Editor.log
の場所については、ログファイル を参照してください。
GPU 用にシェーダーをコンパイルすると、Console ウィンドウに Compiled shader
というメッセージが表示されます。
Memory プロファイラーモジュール または Memory Profiler パッケージ を使用して、シェーダーがランタイムで使用しているメモリの量を確認できます。シェーダーが大量のメモリを使用している場合は、そのバリアントを試しに除去してみることが可能です。
Unity 2022.2 以降では、欠落したシェーダーバリアントをマテリアルが使用しようとする場合に、Unity に強制的にランタイムでピンクのエラーシェーダーを表示させることができます。
C# スクリプトでこれを有効にするには strictShaderVariantMatching
を使用します。
これを行うと、Unity が、欠落したバリアントとそのキーワードを示す警告をコンソールに表示します。これを ストリッピング 中に使用することで、プロジェクトの必要とするシェーダーバリアントが除去されていないかどうか確認できます。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.