diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index 5c9b26fc39e..43f7d04e88f 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -59,6 +59,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - 2D shaders now use half-precision floats whenever precise results are not necessary. ### Fixed +- Fixed a performance problem with ShaderPreprocessor with large amount of active shader variants in the project - Fixed an issue where linear to sRGB conversion occurred twice on certain Android devices. - Fixed an issue where there were 2 widgets showing the outer angle of a spot light. - Fixed an issue where Unity rendered fullscreen quads with the pink error shader when you enabled the Stop NaN post-processing pass. diff --git a/com.unity.render-pipelines.universal/Editor/ShaderPreprocessor.cs b/com.unity.render-pipelines.universal/Editor/ShaderPreprocessor.cs index 7080d6472a3..554b7da9477 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderPreprocessor.cs +++ b/com.unity.render-pipelines.universal/Editor/ShaderPreprocessor.cs @@ -212,14 +212,23 @@ public void OnProcessShader(Shader shader, ShaderSnippetData snippetData, IList< return; int prevVariantCount = compilerDataList.Count; - - for (int i = 0; i < compilerDataList.Count; ++i) + + var inputShaderVariantCount = compilerDataList.Count; + for (int i = 0; i < inputShaderVariantCount;) { - if (StripUnused(ShaderBuildPreprocessor.supportedFeatures, shader, snippetData, compilerDataList[i])) - { + bool removeInput = StripUnused(ShaderBuildPreprocessor.supportedFeatures, shader, snippetData, compilerDataList[i]); + if (removeInput) + compilerDataList[i] = compilerDataList[--inputShaderVariantCount]; + else + ++i; + } + + if(compilerDataList is List inputDataList) + inputDataList.RemoveRange(inputShaderVariantCount, inputDataList.Count - inputShaderVariantCount); + else + { + for(int i = compilerDataList.Count -1; i >= inputShaderVariantCount; --i) compilerDataList.RemoveAt(i); - --i; - } } if (urpAsset.shaderVariantLogLevel != ShaderVariantLogLevel.Disabled)