Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GLSL link error: Required uniform locations exceed MAX_UNIFORM_LOCATIONS

Discussion in 'General Graphics' started by btristan, Jan 14, 2021.

  1. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    I am seeing the following error frequently on OpenGL ES 3.1 on Android emulated on Windows 10. (Intel HD 620 graphics)

    Code (text):
    1. -------- GLSL link error: Required uniform locations exceed MAX_UNIFORM_LOCATIONS
    2. (Filename: ./Runtime/GfxDevice/opengles/ApiGLES.cpp Line: 687)
    3.  
    The latest Intel graphics driver is being used. OpenGL ES 3.1 is selected in the emulator settings.

    While the image appears to be rendered correctly, the frame rate is abysmal. This error does not occur if I try it on my Mac, which has a discrete graphics card.

    Any ideas what is causing this?
     
    Last edited: Jan 14, 2021
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
  3. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    Thanks for the info! Unfortunately I think all the shaders in-use are from LWRP so there probably isn't much we can do to fix it. :(


    Unfortunately we are stuck supporting an emulated system. We are also on 2019.2.21f1, the last Unity version to build Android x86, for that reason. :( FWIW, it works fine on everything else, just not Windows + this Intel graphics. (so far in our testing)
     
  4. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    Is there a way to see the value of MAX_UNIFORM_LOCATIONS and what shader is violating the limit?
     
  5. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    Seems you're a bit out of luck here - 2019.3.0a3 and newer has a checkbox to log, which shader variant is being compiled. Sorry :(
    GL_MAX_UNIFORM_LOCATIONS should be at least 1024 according to the spec, so search for a shader that uses something larger than that.
     
  6. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    Thanks, you have been super helpful! :)
     
    aleksandrk likes this.
  7. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    Sorry to keep pestering. This only happens during DrawMeshInstanced calls. Is there any interaction between Unity's instancing systems and global variables?
     
  8. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    Not global variables in general.
    Instanced arrays are a bit special, but they should not influence explicit locations.
     
  9. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    Did you figure out, which shader is causing trouble?
     
  10. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    Not yet - I am still testing various permutations. If I use DrawMeshInstanced with batches of 1023 or 511 I get that error. But if I use a batch size of one (inefficient I know, but for science) then the error does not appear.

    I'm trying to determine the highest batch count (there doesn't seem to be an easy API call to get the exact number) for the people depending on this now but I intent to start testing individual shaders after that.
     
  11. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    You can safely limit your testing to increments of 32 - there is no difference on the shader side between, say 256 and 287 instances.
     
  12. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    Thanks for the tip!

    FYI: The only shader I see used in the path of the code throwing the errors is the LWRP Unlit shader. Not sure if that satisfies your curiosity. There is a slim chance that it is a ShaderGraph shader (it would be using the Unlit output node) but the vast majority of the assets using instancing in the project are using LWRP unlit.
     
  13. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    I'd say that a shader with more input data (uniforms) has a higher chance to hit this. Idk if LWRP/Unlit uses more input data than this Shader Graph shader :)
     
  14. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    Final report in case it helps anyone else: 480 is the maximum batch size for this particular setup.

    Thanks again!
     
    aleksandrk likes this.
  15. yinono

    yinono

    Joined:
    Sep 15, 2010
    Posts:
    27
    Hi,
    I get this issue without calling DrawMeshInstanced directly. is it possible that just enabling GPU instancing cause this?
    if so how can I limit the number of instances used?