# BindingInfo

> Provides information about a shader resource binding.

## Definition

* **Type:** Struct
* **Namespace:** [UnityEngine.Shaders](/engine/7000.0/script-reference/unityengine/shaders.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public struct BindingInfo
```

## Remarks

This struct represents the read-only information about a single resource in a compiled rasterization or compute shader variant.

Additional Resources: [ShaderData.Pass.CompileVariant](/engine/7000.0/script-reference/unityeditor/shaderdata/pass/compilevariant.md), [ShaderData.ResourceBindingInfo](/engine/7000.0/script-reference/unityeditor/shaderdata/resourcebindinginfo.md), [ShaderData.TextureBindingInfo](/engine/7000.0/script-reference/unityeditor/shaderdata/texturebindinginfo.md).

## Examples

```csharp
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                                  |
| ----------------------------------------------------------------------------------------------------- | -------------------------------------------- |
| [ResourceOptions](/engine/7000.0/script-reference/unityengine/shaders/bindinginfo/resourceoptions.md) | The options of the shader resource.          |
| [ResourceType](/engine/7000.0/script-reference/unityengine/shaders/bindinginfo/resourcetype.md)       | The base type of the shader resource.        |
| [Set](/engine/7000.0/script-reference/unityengine/shaders/bindinginfo/set.md)                         | The set the shader resource is assigned to.  |
| [ShaderStages](/engine/7000.0/script-reference/unityengine/shaders/bindinginfo/shaderstages.md)       | The shader stages the resource is used in.   |
| [Slot](/engine/7000.0/script-reference/unityengine/shaders/bindinginfo/slot.md)                       | The slot the shader resource is assigned to. |
