Search Unity

Feedback Are shaders being compiled efficiently?

Discussion in 'Shaders' started by yoonitee, Jan 17, 2021.

  1. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    I had a thought. Say you had some program "shadercompiler". Which could compile a shader like this from command prompt:

    Code (CSharp):
    1.  
    2. >shadercompiler myshader.shader
    Now an inefficient way of compiling 3 shaders would be:
    Code (CSharp):
    1. >shadercompiler shader1.shader
    2. >shadercompiler shader2.shader
    3. >shadercompiler shader3.shader
    Whereas an efficient way might be:

    Code (CSharp):
    1. >shadercompiler -batch shader1.shader shader2.shader shader3.shader
    Because it would only involve loading the program shadercompiler from the HD one time and running it.
    Thus if the program "shadercompiler" could compile 3 shaders one after another, would this be significantly faster?

    I have a feeling Unity is doing it the first way, seeing as how it is counting when it has done each shader which seems like it wouldn't be able to do in a batch compilation.

    That might be a problem if your IDE uses a lot of 3rd party tools.

    If the program "compileshader" couldn't do batch compilation there would be two solutions:
    • ask the 3rd party tool maker to support it
    • load the program onto a RAM disk if it is being run many times
    • have a built in shader compiler in the IDE
    These are just my thoughts about how a program like Unity might more efficiently compile hundreds of shaders. But perhaps they do this already.

    I suppose a bottleneck would also be writing the compiled shader to HD. But this might be done on a separate thread perhaps. Or saving all the shaders in RAM and then writing them all at once to HD in one big go.