- Home /
Does liberal use of #pragma shader_feature have an undocumented load time/parsing cost?
I have a shader that makes fairly liberal use of #pragma shader_feature (extending the standard shader), but the actual number of variations in use at runtime is very small.
The documentation states "Under all default settings, Unity loads the shaderlab Shader object into memory, but does not create the internal shader variants until they are actually needed.
This means that shader variants that are included into the game build can still potentially be used, but there’s no memory or load time cost paid until they are needed."
Contrary to my expectations after reading this, every time I add a new "#pragma shader_feature" to my shader and hit save, I have to wait an increasing amount of time for the editor to become responsive again. It appears that there might be a bunch of housekeeping going on that is related to the number of potential variations even if the compiler is not actually being invoked for all of them, since the delay appears to be increasing rapidly (possibly quadratic based on the number of features).
Is this expected behavior, or should I be able to make extensive use of #pragma shader_feature without large increases to load times? The load time is not dependent on the actual number of variations that are being used by the game, just the number that could potentially be used.
I'm going to have to merge a bunch of features into a few dedicated shaders if I'm pushing up against some limitation in the way that this feature is implemented. Please let me know if you have additional info on this.
Thank you.
Answer by Lex-DRL · Oct 08, 2015 at 04:09 PM
Same issue here. From docs, I'm pretty sure Unity should give no performance hit (or lag or any other "cost"). But in reality, seems like lag in the editor is linearly increases depending on total amount of possible variants. Since this behavior conflicts with what's told in docs, I'm assuming this is a bug.
what im getting on 940$$anonymous$$X preforms the same as my integrated graphics in the editor view but game view in massively improved. this is not the case if i use basic shader with less shader_feature's
Answer by scabnog · Jan 04, 2017 at 08:21 PM
I recently had a response from Unity, and apparently it has been fixed in Unity 5.6. Some lookup tables were being created ahead of time for all the potential shader permutations, not just the ones being compiled. I haven't checked the beta release yet, but hopefully this issue should be resolved.