WebGL builds fail when shader-graphs are compiled and stripped. There are vague C# index-out-of-range errors posted. When I disable shader stripping, it fails during variant compilation w/ the same posted errors.
So far, my solution has been to copy and paste the compiled shader-graph code into a separate shader file, which also causes build failures when certain shader-graph features aren’t exposed.
I initially saw the bug in Unity 2022 so stuck with 2021 LTS. Now the bug appears in 2021.3.15f1. Compilation happens successfully for 2021.3.14, although some shaders look different in builds vs in the editor, I do not consider that to be a major flaw.
I understand WebGL is not a common build target. I’m wondering if anyone else has seen this or cares.
Additional details:
WebGL 2 Graphics API specified
No compression
If any of you have suggestions, I’m all ears. I also want to know if you’ve seen this before and if a bug report is the right next step.
For reference, here’s the last valid console post, then the error.
STRIPPING: Shader Graphs/Gradient-Height (ShadowCaster pass) (Vertex) - Remaining shader variants = 4/4 = 100% - Total = 1963/8442 = 23.25278%
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:189)
ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: subshaderIndex
UnityEngine.Shader.FindSubshaderTagValue (System.Int32 subshaderIndex, UnityEngine.Rendering.ShaderTagId tagName) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Shaders/Shader.bindings.cs:98)
UnityEditor.Rendering.BuiltIn.ShaderPreprocessor.IsShaderGraphShader (UnityEngine.Shader shader, UnityEditor.Rendering.ShaderSnippetData snippetData) (at Library/PackageCache/com.unity.shadergraph@12.1.8/Editor/Generation/Targets/BuiltIn/Editor/ShaderPreprocessor.cs:114)
UnityEditor.Rendering.BuiltIn.ShaderPreprocessor.StripUnused (UnityEditor.Rendering.BuiltIn.ShaderFeatures features, UnityEngine.Shader shader, UnityEditor.Rendering.ShaderSnippetData snippetData, UnityEditor.Rendering.ShaderCompilerData compilerData) (at Library/PackageCache/com.unity.shadergraph@12.1.8/Editor/Generation/Targets/BuiltIn/Editor/ShaderPreprocessor.cs:284)
UnityEditor.Rendering.BuiltIn.ShaderPreprocessor.OnProcessShader (UnityEngine.Shader shader, UnityEditor.Rendering.ShaderSnippetData snippetData, System.Collections.Generic.IList`1[T] compilerDataList) (at Library/PackageCache/com.unity.shadergraph@12.1.8/Editor/Generation/Targets/BuiltIn/Editor/ShaderPreprocessor.cs:348)
UnityEditor.Build.BuildPipelineInterfaces.OnPreprocessShaders (UnityEngine.Shader shader, UnityEditor.Rendering.ShaderSnippetData snippet, UnityEditor.Rendering.ShaderCompilerData[] data) (at /Users/bokken/build/output/unity/unity/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:490)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:189)