Version: Unity 7.0 Alpha (7000.0)
LanguageEnglish
  • C#

ShaderResourceType

enumeration

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

Description

The base type of resource described by a BindingInfo.

Represents base resource types the shader compiler reports. The base type does not represent aspects such as whether the resource can be written to or what the underlying data format is.

Additional resources: ShaderData.Pass.CompileVariant, ResourceBindingInfo, TextureBindingInfo.

using UnityEditor;
using UnityEngine;
using UnityEngine.Shaders;

// Adds a new Editor menu item called Example.
// Select a shader asset in the Project window, then select
// Example > PrintVariantCompileInfoExample from the Editor menu.
// Information of a compiled variant will be printed as debug log.
public class PrintVariantCompileInfoExample
{
    [MenuItem("Example/PrintVariantCompileInfoExample")]
    static void MenuCallback()
    {
        if (Selection.activeObject is Shader selectedShader)
        {
            // Get the first pass of the the first subshader
            ShaderData shaderData = ShaderUtil.GetShaderData(selectedShader);
            ShaderData.Subshader subShader = shaderData.GetSubshader(0);
            ShaderData.Pass pass = subShader.GetPass(0);

            // Compile a vertex shader variant without any keywords
            var keywords = new string[] { };
            ShaderData.VariantCompileInfo info = pass.CompileVariant(UnityEditor.Rendering.ShaderType.Vertex, keywords, UnityEditor.Rendering.ShaderCompilerPlatform.D3D, BuildTarget.StandaloneWindows64);

            // Log the information Unity has about the compiled variant
            if (info.Success)
            {
                Debug.Log("Compiled size: " + info.ShaderData.Length + " bytes");

                string msg = "Vertex attributes: ";
                foreach (var a in info.Attributes)
                {
                    msg += a.ToString() + " ";
                }
                Debug.Log(msg);

                msg = "Texture bindings: ";
                foreach (var tex in info.TextureBindings)
                {
                    msg += tex.Name + "-" + tex.Binding.Set + ":" + tex.Binding.Slot;
                    msg += ", sampler " + tex.SamplerBinding.Set + ":" + tex.SamplerBinding.Slot;
                }
                Debug.Log(msg);

                msg = "Resource bindings: ";
                foreach (var resource in info.ResourceBindings)
                {
                    msg += resource.Name + " (" + resource.Binding.ResourceType + ")" + resource.Binding.Set + ":" + resource.Binding.Slot + "[";
                    if ((resource.Binding.ResourceOptions & ShaderResourceOptions.Readable) != 0)
                        msg += "R";
                    if ((resource.Binding.ResourceOptions & ShaderResourceOptions.Writable) != 0)
                        msg += "W";
                    msg += "]";
                }

                msg = "Constant buffers: ";
                foreach (var cb in info.ConstantBuffers)
                {
                    msg += cb.Name + "-" + cb.Size + "bytes ";
                }
                Debug.Log(msg);
            }
            else // If the compilation fails, Unity prints the errors
            {
                string failureMsg = "Compilation failed: ";
                foreach(var msg in info.Messages)
                {
                    failureMsg += msg.message + "\n";
                }
            }
        }
    }
}

Properties

Property Description
ConstantBufferThe shader resource is a constant buffer.
BufferThe shader resource is either a StructuredBuffer or a ByteAddressBuffer.
TypedBufferThe shader resource is a typed buffer.
TextureThe shader resource is a texture. The dimensionality of the resource, for example 2D or Cube, is not part of the base type.
CombinedTextureSamplerThe shader resource is a texture combined with a sampler.
SamplerThe shader resource is a separate sampler.
RayTracingAccelerationStructureThe shader resource is a ray tracing acceleration structure.
InputTargetThe shader resource is an input attachment.
UnknownThe shader resource type is unknown.