Possible for Shader.CreateGPUProgram to report instigating variants?

Is it possible to get Unity to report which shader variant instigated a call to Shader.CreateGPUProgram? We are already using a ShaderVariantCollection to warm up shaders. If we were able to get the device to report which variant caused a new GPU program it would allow us to make sure the proper variants are included in the collection.

Thanks!

A weird aside I noticed is that the Shader class doesn’t even contain a definition for CreateGPUProgram…weird.

@thebarryman A checkbox “Log shader compilation” in Graphics settings is available in 2019.3.0a3, 2019.2.7f2 and 2018.4.6f1.

1 Like

Wow, incredible! Thanks @aleksandrk .

EDIT: Though, I am unable to find the setting in graphics settings. I’m assuming it should be there in 2018.4.9f1?

I downloaded 2018.4.6f1 and it wasn’t showing up in the Editor either. However I checked the text of the actual asset file and it’s showing up there. Will test in build to see if it’s working - thanks again! EDIT - it works!!

Huh…so after diagnosing the shader hitches we’ve been experiencing, some of them make perfect sense, but the majority of them should have already been warmed up by the ShaderVariantCollection!

The scene I was testing with is part of an AssetBundle, so duplication is a potential issue. However, our shader and ShaderVariantCollection assets are part of their own bundle that gets loaded on startup, so I would think that the assets wouldn’t be subject to duplication in this particular case.

Additionally, our project is set to never unload shader assets.

For anyone curious as to what was causing those bad re-compilations - changing all shader keywords to use “shader_feature” and not using any “multicompile” seemed to do the trick.

Even though shaders with the correct list of keywords had already been warmed up, for some reason Unity seems to think that it hasn’t been warmed up if you enable a global multicompiled keyword. Since I already put the logic in place to build the variants we need, simply switching to shader_feature got rid of this issue.

@thebarryman Can you please report this bug with multi compile vs shader feature? Thanks!

1 Like

I think I’m experiencing a similiar issue. I created a ShaderVariantCollection and yet I’m seeing a huge CreateGPUProgram spike (~72 ms) on device upon spawning some impact effects for the very first time.

I enabled the shader compilation log and it reported:

However my ShaderVariantCollection for Sprite/Diffuse looks like this:

It looks like those variants are included except for the STEREO_MULTIVIEW_ON that seems to be missing and I cannot find on any entry in the ShaderVariantCollection. Unfortunately I’m not too experienced with shaders but should the STEREO_MULTIVIEW_ON be included to fix the issue?

Unity 2018.4.12f1

EDIT: Tested it and the missing STEREO_MULTIVIEW_ON is definitely the culprit.

2 Likes

I enabled the shader compilation log, but i can’t find the log or file.
Where should I look? Thanks

Unity 2019.3.0f6

@tietie it should be in the regular player log

I selected the “use player log” check box, and i found the file “Player.log”, but i can’t see anything about shader compilation.:frowning:
@aleksandrk you know why? Thank you

did you run the player after checking the checkbox? :slight_smile:

I published it as PC as debug, and i got it.
Can’t it run under editor?:slight_smile:

Why should it?
The intention here is to provide information on when actual shader compilation happens in the player. I don’t see any value for this info about the editor :slight_smile:

Maybe editor has compiled completely when the shader is modified.
Is it possible?

If a shader is modified, it will be recompiled. I still don’t see any value for this option to work for the editor.