#What is the best way to solve this shader graph issue?

1 messages · Page 1 of 1 (latest)

brave tapir
#

maximum ps_5_0 sampler register index (16) exceeded
I have read that its maybe because of the target platform supports Shader Model 5.0, and the max Texture sampler number is 16, and if there are more Texture Sampler nodes are in the shader graph than 16, then the error will appear.
Is there a way to solve this without remaking the shader graph?
Can I make preprocessor directive-like nodes into the shader graph?

brave tapir
#

as I read, maybe the best solution is to create 1 Sampler State Node and connect that to all of the Sample Texture node's Sampler input, and that's all?

rigid spoke
marsh pelican
tall frost
#

and its not freezed out, its still ongoing

#

@rigid spoke

marsh pelican
#

haha wow, you need to remove some shader keywords

tall frost
marsh pelican
#

you added shader keywords yourself, did you not?

tall frost
marsh pelican
#

well, maybe you want to take a look at it anyway

tall frost
#

so there might be keywords, I have no idea

#

I mean I'm not pro at shaders, I'm mainly a gameplay programmer

marsh pelican
#

like, specify which shader stage(s) they are needed, and check shader feature vs. multi-compile depending on if you activate them through code or not

tall frost
#

so can you help me what to look for?

marsh pelican
#

yeah, you'll need to open it and look for parameters of the type "enum keyword" and/or "keyword"

marsh pelican
#

well, at that rate I guess it will go for another 42 hours..

#

so probably

tall frost
#

@marsh pelican okay, so I cancelled the compilation.
How to open it?

#

where should I find the "keyword" part?

marsh pelican
#

look for the shader graph in your project, I don't know it's name but i expect it's something like TerrainIce ?

#

you can filter by shader graph with t:ShaderGraph

tall frost
#

these are the keywords

marsh pelican
#

you need to open it

#

do you have knowledge about what kinds of features you need from this shader, in your project?

tall frost
#

absolutely zero

marsh pelican
#

what a joy to look at 🙈

tall frost
marsh pelican
#

it's not very different from regular programming, except that this is code that is executed for every vertex or pixel

tall frost
#

I know its probably a vertex and fragment shader

marsh pelican
#

right, so you need to try and look at the keywords and see what code is activated/deactived by them

tall frost
#

but my knowledge is almost ends here

marsh pelican
#

and see if you can identify keywords that have very little attached to them

#

those you can replace by a regular branch instead of a shader keyword branch

tall frost
#

and how to open the code?

marsh pelican
#

this is the code

tall frost
#

I thought you mean the generated code

marsh pelican
#

well, you can look at that, but that's much harder to read

#

do you have a lot of materials that use this shader?

#

and are you working alone on this or are there others that know more about this shader?

tall frost
marsh pelican
#

well, you need to figure this out, to be able to make changes you need to be able to update the materials that use the parameters

tall frost
marsh pelican
#

and you need to find out if there are places in the code where you set shader keywords on materials using this shader

#

you can see if a keyword can be overridden with a global keyword, if the Is Overridable option is checked

tall frost
#

so where should these keywords be in the shader graph?

#

as node names?

#

or what?

marsh pelican
#

they are inputs, like regular material parameters

#

you can see the type of input parameter next to the name

#

well, they're called Properties, officially

tall frost
marsh pelican
#

if you hover over them, it will highlight any nodes in the graph that are linked to the input

#

the keyword boolean and keyword enums are the ones you are interested in

#

I also recommend you make a backup of the graph (and the materials, if that's feasible), that way you can relatively easily go back if things go wrong

#

(and compare)

marsh pelican
#

yeah, but even then, you will want to be able to compare them

tall frost
#

oh never mind

#

they are here

#

some of them

marsh pelican
#

its possible some of them may exist only in the custom hlsl nodes

#

a lot of them are added by unity

tall frost
#

I can only see 3 keywords appearing in the left side

#

and if I hover them, I can see them in the graph

#

so that means all other keywords are unnecessary?

marsh pelican
#

no, it just means your shader does not use them itself, but they can still be used by the render pipeline and such

#

shader graph adds them for you

#

during build, any unused shader variants are usually stripped and not compiled

#

you can also customize this stripping process if you know certain keywords are unnecessary

#

these ones, I guess you are using HDRP?

tall frost
marsh pelican
#

I fidn it surprisng you have 62 thousand shader variants and only added 3 keywords in the graph yourself

#

are they enum keywords?

tall frost
#

_TESSELLATION_ENABLED, also boolean

#

_MATERIAL_QUALITY (built-in enum)

marsh pelican
#

how many quality settings do you have in your project?

tall frost
#

5 pieces

marsh pelican
#

that's not a lot of keywords in the blackboard indeed

#

okay, I suppose you use them and that you need the material quality

tall frost
#

yeah, these 3 keywords are being used in the graph

#

and about the qualities, yeah, those 5 are used

#

at least 3 of them for sure

#

but maybe all 5

marsh pelican
#

in the HDRP asset you should be able to find the quality level in the material section and verify they (material quality settings) are all three in use (low, med, high)

marsh pelican
# tall frost its _OTHERWORLD_MASK_ENABLED which is boolean

for this one, and the tesselation enabled one, you may want to check if they are shader features or multi-compile
also check if they enable/disable a lot of code

if its using shader feature, it will only compile the flag with the settings coming from your materials; if all materials use the same setting one, modifying this keyword will not do much for you

if its multi compile you need to see whether the keyword is set through code

otherwise you may be able to replace it by a regular branch

#

beyond this, i guess you would have to dig into the custom hlsl nodes, which may or may not be easier depending on the code

tall frost
#

so basically I should look for if our project is not using some of these

#

and those could be set to the suggested values here?

marsh pelican
#

indeed

#

that should help with all shader compilation times, not just this big one

tall frost
#

okay, thx. I'm not sure if anyone if the project would be able to answer which of these are being used

#

but I will try

#

the whole shader is more than a year old

#

probably 2-3 years old

marsh pelican
#

ah though for features that is a bit harder indeed

tall frost
#

@marsh pelican so if I look into the generated shader code

#

can't I just CTRL+F and search for the keywords one by one?

#

although if I would see a keyword not used in the generated shader anywhere, how could I remove that from the graph itself

marsh pelican
#

for this shader I think you first need to find all the custom HLSL nodes in the graph itself and see what code (and keywords) is added by them

marsh pelican
#

the problem is keywords that do something, but are not actually used by anything in the game

#

or dont do something useful

tall frost
#

if we can't do anything with it

marsh pelican
#

I don't think I said to look for unused keywords ? 🤔

tall frost
#

okay, maybe I misunderstood you then

marsh pelican
#

maybe, I may have phrased it poorly

#

unused features, maybe

tall frost
#

I got an info that maybe this shader is not even used anymore... 😄

marsh pelican
#

that should be possible to verify by traversing the references

#

but that would be great 😄

marsh pelican
tall frost
#

I tracked shaders with Project Settings

#

and it got found

tall frost
#

@marsh pelican can't I just set quality to low and disable all other qualities?

#

won't that speed up the compilation?

marsh pelican
#

I assume it will help yeah

#

but i figured you'd need them?

tall frost
#

I would, but for now I would just check everything else in the target platform

#

if other stuff works

#

I would honestly temporarily disable this whole shader

#

if I could

marsh pelican
#

if you just want to do it locally, you can always do find all references and change the shaders of the materials that use it
or simply delete it

tall frost
#

well, I could do it with this shader, but there's an another one, which is similarly bad

#

and that's being used by a lot of things

marsh pelican
#

well, I have to go unfortunately, but you have a lto more information now

#

so I think you can find a temporary solution at least

tall frost
marsh pelican
#

😆

#

if you just need to test you can open the shdaer graph and clear its contents 😄

tall frost
#

well, yeah, but I need to fix it primarily, or at least get it compiled in a bad quality

#

if it could got compiled in a worse quality, it would be enough for me for now

marsh pelican
#

I think you can remove all the other quality levels then

tall frost
#

already removed them

#

for target platform

marsh pelican
#

that didnt help?

tall frost
#

nope, still 62K variants

#

and still it was slow after 17k (the point it got compiled during 14 hours)

#

the weird is that this shader got compiled well for other platforms

#

I never had this issue before

#

with this shader

marsh pelican
#

strange, unfortunately I'm a little out of my depth here (and out of time)

tall frost
#

maybe because I added the Samplers?

#

okay, thx

#

this is the other one, even better

tall frost
#

@rigid spoke if I use shadervariants file (generated by tracking used shader variants), then for shader compilation, it would just received from that file?

rigid spoke
#

Not sure. What do the docs say?

#

Normally unity would strip variants that it decided would never be used. And compile any that might potentially be used. Based on different project settings.

tall frost
rigid spoke
tall frost
#

it says: "Check what shader variants you have to help you see which shader variants and keyword combinations Materials need at runtime."

#

well, based on the link it writes

#

no information is provided

#

and no info about how to set to include only the necessary ones

tall frost
#

when I start to compile the other shader called Lit/Actor, it says I have 100K variants... for the TerrainIce it says 62K

#

are those all variants really needed based on the project?

rigid spoke
tall frost
#

are these the correct settings?

rigid spoke
#

Reducing the amount of quality setting tiers, disabling features in the render pipeline settings could help

rigid spoke
# tall frost

There's not correct. It depends. And I've no clue what automatic does, or how it decides if to strip or not. Might need to look at the docs.

#

I'd start with these things that you can modify right away without introducing any breaking changes into the project

#

Another thing to consider is if the shader cache is used. Normally, only the first build should be heavy, while consequtive should skip shader compilation, unless there are new variants required.

tall frost
#

only 2 hours

rigid spoke
#

Then it uses way less variants. Or you already had some shader cache

tall frost
#

and these 2 shaders were not changed in the last 2 years

#

nope, variant number is the same

#

I just checked it

#

the whole shader graph is the exact same, and if I comple those, I also get 100K and 62K variants for them

rigid spoke
tall frost
rigid spoke
tall frost
#

just selected a different target platform

#

that's all

rigid spoke
#

Or rather, it generates the shader code, not compiles the variants

tall frost
#

but anyway... even if I created a build for the other platform for the first time, it took for 2 hours

#

not 10+ hours

#

even if we don't consider this "compile and show code" button

rigid spoke
tall frost
rigid spoke
tall frost
rigid spoke
#

It generates the shader code from nodes. Doesn't compile it.

tall frost
#

then what it does

#

okay

#

then how to compile shaders? only with creating build for target platform?

rigid spoke
#

Normally yes, because:

  1. It uses platform specific compiler.
  2. It uses platform specific configuration, keywords.
#

I think shader variant collections can be used to precompile them at will, but I don't know much about them

tall frost
#

but okay then

#

still the first build took 10+ hours instead of 2 for the other platform

rigid spoke
# tall frost

Customizing these might actually help quite a lot. If you know what is used or not used in the project.

tall frost
#

so that's not normal it differs

tall frost
rigid spoke
tall frost
#

NDA

#

both are NDA, but different NDA

rigid spoke
#

Well, then either they have a vastly different shader variant numbers, or the other platform shader compiler is fast fast, compared to this platform

#

Some platforms have several compilation passes too.

tall frost
#

"or the other platform shader compiler is fast fast, compared to this platform" maybe that will be the case

rigid spoke
#

Then it's probably fast fast

#

Could be the compiler settings too. Some could be spawning several compilation processes or threads to make use of all your cores. Other might be configured to be single threaded... Really hard to tell without actually investigating it.🤷‍♂️

tall frost
rigid spoke
#

There's also the other side to it where compiler optimizations are enabled