Skip to content

Add GetMaxFragmentUniformComponents func to know when to split you shader draw calls into several passes #3200

@sedyh

Description

@sedyh

Operating System

  • Windows
  • macOS
  • Linux
  • FreeBSD
  • OpenBSD
  • Android
  • iOS
  • Nintendo Switch
  • PlayStation 5
  • Xbox
  • Web Browsers

What feature would you like to be added?

While working on efficiently drawing sprites in my game, I was faced with the fact that shader compilation could result in a panic that could not be controlled on my part.

0(6699) : error C5041: cannot locate suitable resource to bind variable "@l5.23-0029". Possibly large array.

This panic is due to the fact that some graphics backends do not have a minimum guaranteed number of uniform components in a shader (and if it exist, it varies very much between different gpus), but almost everywhere it is possible to find out their maximum number, which will solve the problem, but is not used by the engine.

I suggest to implement this function. This is how it looks like on each backend:

OpenGL counts uniform components (mostly floats):

GL_MAX_FRAGMENT_UNIFORM_COMPONENTS

DirectX counts vectors (float4):

D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT / <float_count_in_component>

Metal counts argument buffers (total size):

MTLDevice.maxBufferLength / <component_size>

It’s okay if the calculation will be inaccurate (or differs to a lesser extent), the main thing is that it provides a guarantee against hardware limitations so you can control that panic.

Why is this needed?

One way to avoid panic and closing the game by using this check and splitting your shader draw calls into several passes or choose predefined shaders with low/mid/high amount of uniforms based on this check.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions