Search Unity

Resolved Max number of Compute Buffers on mobile

Discussion in 'General Graphics' started by Opeth001, Jan 31, 2021.

  1. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    Hello everyone,
    i saw in the Unity documentation here that there is a limit of Compute Buffers count on GLES 3.1 and lower Platforms.

    Platform-specific differences
    • OpenGL ES 3.1 (for (Android, iOS, tvOS platforms) only guarantees support for 4 compute buffers at a time. Actual implementations typically support more, but in general if developing for OpenGL ES, you should consider grouping related data in structs rather than having each data item in its own buffer.
    but i dont see any information about this on device's SystemInfo, the only thing i can get is how many compute buffers are supported by a single Vertex/Fragment.. shader.

    does this mean some GLES 3.1 platform can only support 4+ Compute Buffers in total or per shader ?

    thank!
     
    Last edited: Feb 1, 2021
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,022
    Hi!
    The compute buffer limits are per stage (for example, on some theoretical hardware it can be that VS can support up to 8 compute buffers at the same time and FS can have up to 32). The total limit for all stages combined is the maximum of these, so in this example it would be 32 total.
    The example of the manual just says that the guaranteed total maximum is at least 4. This can mean, for example, 0 in VS and 4 in FS.
     
    Opeth001 likes this.
  3. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    thanks for the explanation!

    sorry but im new to shaders and GPU stuff.
    what do you mean by per stage ?
    let's say i have 3 fragment Shaders. A, B, C
    in your example there's a limit of 32 Compute buffers per stage, does this mean 32 for A, 32 for B and 32 for C. or 32 for all of them?

    also: does this mean 32 CB for all Compute Shaders or per Compute Shader ?
     
    Last edited: Feb 1, 2021
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,022
    Vertex shader, fragment shader, geometry shader and others are all stages.
    If you have a single shader variant that has a vertex and a fragment shader, the sum of compute buffers used by vertex shader and fragment shader should not be greater than this limit. At the same time, there are separate limit for individual stages, that is, there's a limit for the vertex shader and a (possibly different) limit for the fragment shader.

    Compute is separate, and usually has a separate limit. This is also per kernel variant.
     
    Opeth001 likes this.
  5. deep_deep

    deep_deep

    Joined:
    Aug 10, 2019
    Posts:
    16
    Necro, in case someone comes here looking for a problem related to their compute buffers not working in the vertex stage.

    Turns out, a lot of Mali GPUs using the OpenGL driver support 0 compute buffer (Structured Buffer) bindings to the vertex stage of the shader. AFAIK vulkan for the same GPUs has no such restriction.

    The variable you want to check at runtime is

    SystemInfo.maxComputeBufferInputsVertex
    .
    This will mostly come up if you're using DrawMeshInstancedIndirect. Based on this number, you would have to fallback on using float/vector constant buffers to read data in the vertex shader.
     
  6. CinnamonCereals

    CinnamonCereals

    Joined:
    Jan 19, 2022
    Posts:
    23
    Hi! I have a couple of what seem to me like newbie questions, doing my best to understand.
    • Is the limit set per shader or per material instance (all instances added together can have more than 4 but not individually)?
    • If i have 4 buffers that are declared in the whole shader and is only used in the vertex and not in the fragment, the buffers used count as 4 per stage and not 8?
    • I'm coding in a generated shader graph shader. It makes multiple passes and all passes have the same buffer (read only) included. Is this buffer a shared one or each pass makes a copy of it? In the case of 8 passes do the compute buffers count as 8 per stage?
    • Is there a limit for compute shaders that you can run on mobile? (where supported)
    Edit: i received a great answer here: https://forum.unity.com/threads/compatibility-buffer-newbie-questions.1291802/
     
    Last edited: Jun 7, 2022