Version: Unity 6.6 Alpha (6000.6)
LanguageEnglish
  • C#

VariantsUploadedToGpuLastFrame.UploadData.shader

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public Shader shader;

Description

The shader the uploaded shader variant belongs to.

using UnityEngine;
using UnityEngine.Shaders;

/*
    Attach this script to a GameObect. When run in the player, it reports shader variants sent to the
    GPU driver for compilation during the last frame in the console.
*/
public class VariantsUploadedToGpuLogger : MonoBehaviour
{
    void Update()
    {
        uint variantCount = VariantsUploadedToGpuLastFrame.count;
        if (variantCount > 0)
        {
            Debug.Log("Sent " + variantCount + " variants to the GPU.");
            for (uint variantIndex = 0; variantIndex < variantCount; ++variantIndex)
            {
                VariantsUploadedToGpuLastFrame.UploadData d;
                if (!VariantsUploadedToGpuLastFrame.TryGetUploadData(variantIndex, out d))
                    continue;

                string keywords = "'";
                for (uint keywordIndex = 0; keywordIndex < d.keywords.Length; ++keywordIndex)
                {
                    if (keywordIndex != 0)
                        keywords += " ";
                    keywords += d.keywords[keywordIndex].name;
                }
                keywords += "'";
                string passId = "subshader " + (d.passIdentifier.SubshaderIndex + 1) + " pass " + (d.passIdentifier.PassIndex + 1);
                string description = "Shader " + d.shader.name + " " + passId + " stages " + d.stages;
                Debug.Log(description + " keywords " + keywords + " uploaded in " + d.uploadTimeInMilliseconds + " ms.");
            }
        }
    }
}