#🥝-shader-variant-explorer

📦 : https://github.com/needle-tools/shader-variant-explorer

hybridherbst

<@!784729418484547605> in case you have any questions / feedback, here would be the right place!

0x6c6c6968

I have yet to write anything that works with this tool because all my shaders that I tested were too big

hybridherbst

Oh, interesting. Would you mind sending me one of those shaders that didn't work? I'm aware some HDRP shaders might be too big, is it for HDRP?

hybridherbst

Nice. I've got some ideas on how to make it work with the Variant Explorer, might lose some convenience features but otherwise should be possible

0x6c6c6968

Those Billions of Variants are with “Skip unused shader_feature” unchecked right so the actual amount isn’t too big

hybridherbst

Most ops inside it are already "on-demand", that is, you compile the variant you want to see and just that (which is fast). What makes it slow right now for big shaders is a preprocessing step that attemps to figure out which keywords are part of the same define group

hybridherbst

Removing that step means you'll be able to debug if you know which keywords belong to each other, which you usually do as the author anyways

0x6c6c6968

Unity will still compile every combination of keywords for the following example

#if KEYWORD_A
    #if KEYWORD_B
    #endif
    #if KEYWORD_C
    #endif
#endif
hybridherbst

The compiler has all that info anyways, but there's no (good) way that exposes it. I'm using the bad one...

0x6c6c6968

If keyword A isn't set then B and C are irrelevant, but Unity will still generate variants with every combination of A, B, and C by default.

hybridherbst

If you do #pragma shader_feature_local A B C D it will not compile all combinations of these

hybridherbst

Yep, continuous movement in that area I started the Variant Explorer when the pass compile API was like a week old Immediately found 10 bugs and shader compiler crashes just by pressing random buttons 😄

hybridherbst

It does nothing more than turn "actual variants" into bool switches, but makes sense for e.g. the myriad of debugging variants they introduced for URP/HDRP

0x6c6c6968

at a certain point with the mess that is shader variants I feel like variants should be standardized and drivers should be able to handle "jitting" the variants for you

hybridherbst

actually SPIR-V has that - but a giant ship like Unity likely won't support special features that only work on some platforms

hybridherbst

unless they continue their tooling stuff and just make "everything is SPIR-V anyways" toolchains

hybridherbst

<@!784729418484547605> the shader that has these billions of variants isn't in the repo, right?

hybridherbst

OK 🙂 I just released a 0.3.0-pre, which should effectively remove any limits to how many variants your shaders have

hybridherbst

The "new stuff" (aka removing that limit) uses some 2021.2 APIs, so that's only available starting there

hybridherbst

New Release, 0.3.0-pre! ✨ This release leverages new shader APIs on Unity 2021.2+ that allow fine-grained control over variant compilation. In practice, it means that you can now explore the individual variants of huge shaders such as HDRP/Lit:

hybridherbst

Another new feature is that you can now select which pass you actually want to see, and log a list of valid keywords for that pass.

hybridherbst

Changelog:

## [0.3.0-exp] - 2021-11-23
- fixed: compiles on 2021.2
- added: support for 2020.3.16+ ShaderCompiler API
- changed: preprocessing now happens on demand only for selected variants (giant shaders can now be explored!)
- added: copy/paste shader variant combinations from the breadcrumb navigation
hybridherbst

Hey, please ask questions about Needle Engine in <#1024686103598477383> - thanks! This channel here is about a particular package

xeonzinc

Hi, I've just come across this tool, it's very useful. Unfortunately my specific problem is related to compute shader variants which doesn't seem supported. Do you think if I bodge the input to select .compute files instead of .shader it might just work? Or are the underlying unity mechanics likely to be significantly different between the two types?

darkyintheweb

Greetings, is there a shader collection which is compatible with Needle Engine? Specifically webxr image tracking unity scene. I am interested in axis based direction dissolve shader. Tried several but they didn't seem to work.