Strict shader variant matching

Hello Unity alpha users!

By default, when a shader variant is not found in the player build, Unity silently picks a “close enough” variant from the available ones. This has a potential to hide bugs in the keyword setup.
Unity 2022.1 has a new checkbox in player settings, “Strict shader variant matching”, that can be used to alter this behaviour. If this setting is enabled and a variant is not found by the player, an error is printed in the console, specifying the shader, subshader index, pass and keywords that were used for variant search, and error shader is used for rendering.
This setting is intended as a simple validation layer that reveals keyword setup mistakes. By default it’s disabled.

Happy debugging! :slight_smile:

13 Likes

Hah! I discovered the ‘fallback’ earlier this year while tracking down a particularly nasty shader bug.
https://uninomicon.com/shaderkeyword

It’d be nice if the fallback mechanism were documented. How does it choose? Even better to have a warning like “Shader [Keywords] is missing. Falling back to Shader [Keywords]. Renderer [objectpath]”. As is it’s rather hard to identify when it happens.

2 Likes

That’s not a fallback, it’s a consequence of having global keywords.

This is the second keyword system improvement (the first one is here ). We want to introduce strict rules for resolving keyword conflicts, and make fixing keyword issues easier, but this will come later.

Great! Is there any plan to give this feature to 2020.3.x LTS?

No.

Here’s a thought - can we specify an “error shader” of our own? Having that control over default fallback is an even safer way to manage this new option. A use case scenario is that the developer wants to manage it strictly but one falls through the net. The dev can identify it but the gamer just thinks “oh, generic wall”.

Revenue unaffected, everyone happy and it’s silently fixed by the dev in the know.

2 Likes

I tried this recently for Hybrid… turns out it’s not as easy as it sounds :slight_smile:
Error shader is quite special, and is treated by the code as such.

1 Like

I am getting “not found” messages even when I don’t strip any shaders. What could cause that?

1 Like

For example:

Shader Standard, subshader 0, pass 2, stage vertex: variant <no keywords> not found.

@paulatwarp This often means the variant doesn’t exist at all.
In your particular case, are there any directives that don’t have an underscore? These need one of the keywords to be enabled. It can also happen if two keywords from the same directive are enabled simultaneously.

In the Standard shader?

Does that mean I have a malformed Material somewhere?

Okay, I’ve found the model / material. It’s an FBX file, imported with a default material and None set in the import settings. When that model is in the scene, the material set is Default-Material. And I get these errors in the console:

Shader Standard, subshader 0, pass 2, stage vertex: variant <no keywords> not found.
Shader Standard, subshader 0, pass 2, stage pixel: variant <no keywords> not found.

The only keyword set on the Material is _EMISSION as far as I can tell.

Scratch that. It’s simpler than that. Create a new project, add a cube and leave the default material on it. Then build. I get the same errors.

Also if I create a new Material using the standard shader. This new material does not have the _EMISSION keyword on it by default, but the result is the same two errors as above.

@aleksandrk should I report this as a bug?

Yes, please. It will be tracked properly in this case.
Thank you!

1 Like

IN-53232

Thanks

1 Like

Bug closed as won’t fix.

Unless there’s some workaround for this, I can’t see this being a useful feature.

URP and HDRP should work properly with this feature enabled.

Hello, I have a problem with this on Android device.

In some particular situation if I have it off, the GPU driver just crashes on some devices .

if I have it on, the game then works, ofc with a ton of pink shaders. And I get weird errors like

2023/11/08 18:52:39.488 2014 2111 Error Unity Shader Shader Graphs/UnityTerrain_simple_minSpec, subshader 0, pass 0, stage all: variant not found.

but I prewarm shaders from a shader collection that has:

please don’t tell me is a bug pleeeeeease.

I also don’t exactly get why it say that is not found instead than just compile a new variant