using System.Diagnostics.CodeAnalysis; using UnityEngine; using UnityEngine.Rendering; namespace UnityEditor.Rendering { /// /// Collection of extensions for /// static class ShaderExtensions { private static readonly ShaderTagId s_RenderPipelineShaderTagId = new ShaderTagId("RenderPipeline"); /// /// Tries to find the "RenderPipeline" on the shader by the given /// /// The shader to look for the tag /// /// containing the value of the tag "RenderPipeline" /// true if the tag is found and has a value public static bool TryGetRenderPipelineTag([DisallowNull] this Shader shader, ShaderSnippetData snippetData, [NotNullWhen(true)] out string renderPipelineTag) { renderPipelineTag = string.Empty; var shaderData = ShaderUtil.GetShaderData(shader); if (shaderData == null) return false; int subshaderIndex = (int)snippetData.pass.SubshaderIndex; if (subshaderIndex < 0 || subshaderIndex >= shader.subshaderCount) return false; var subShader = shaderData.GetSerializedSubshader(subshaderIndex); if (subShader == null) return false; var shaderTag = subShader.FindTagValue(s_RenderPipelineShaderTagId); if (string.IsNullOrEmpty(shaderTag.name)) return false; renderPipelineTag = shaderTag.name; return true; } } }