Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shader Uniform Array size limits #55674

Closed
clayjohn opened this issue Dec 6, 2021 · 3 comments
Closed

Shader Uniform Array size limits #55674

clayjohn opened this issue Dec 6, 2021 · 3 comments

Comments

@clayjohn
Copy link
Member

clayjohn commented Dec 6, 2021

Original Report:

I tried to use big (around 500 000 items) uniform arrays but they didn't seem to work. After narrowing down the problem it started to look like the total number of uniform items (including the items inside arrays) was limited to 4096. In addition to this, bigger types like mat4 seem to consume the available space quicker so that 1024 items already use all of it. This happens in both the editor and the running (ran from the editor) project.

Changing the sizes or contents of the arrays through "Shader Param" doesn't seem to affect anything

Tried to change setting "Rendering->Limits->Global Shader Variables->Buffer size" to see if it fixes the issue. Didn't help. Is there some other place to look for limits for these?

See attached video and sample project for more info.

If this is a (new) bug I can make an issue out of this(?)

System: Windows 10, RTX-2060(mobile), Godot v4.0.dev.custom_build [5f9e2fc], Vulkan renderer
(btw: After changing to opengl3-renderer godot stopped showing menus, the "3d-area" was grey, menus disappeared and after selecting a node it crashed so couldn't test the opengl-renderer).

2021-12-06.18-44-36.mp4

UniformArrayTest.zip

Originally posted by @GNSS-Stylist in #54657 (comment)

My response:

Most discrete GPUs have a maximum uniform buffer size of 65536 bytes (including yours) Which translates to 4096 vec4s or 1024 Mat4s (which are essentially 4 vec4s). Your GPU driver will pad most data types to vec4 when used in an array (some GPUs don't add padding, but many do).

There are two things we need to do in response:

Add a warning if a user tries to add more uniforms than can fit in 65536 bytes (long term we could automatically split the uniforms up into multiple UBOs internally, or use a SSBO internally)
add documentation about data padding and size limits to the documentation page.

@Chaosus
Copy link
Member

Chaosus commented Dec 7, 2021

Most discrete GPUs have a maximum uniform buffer size of 65536 bytes

I'm pretty sure on the mobile it's much less. Btw Godot has a function that retrieves that number from the system?

@clayjohn
Copy link
Member Author

clayjohn commented Dec 7, 2021

Most discrete GPUs have a maximum uniform buffer size of 65536 bytes

I'm pretty sure on the mobile it's much less. Btw Godot has a function that retrieves that number from the system?

Yes, most mobile support a size of only 16384. It looks like RenderingDevice has a function limit_get() which will allow you to check the limit using LIMIT_MAX_UNIFORM_BUFFER_SIZE as input

int RenderingDeviceVulkan::limit_get(Limit p_limit) {

case LIMIT_MAX_UNIFORM_BUFFER_SIZE:
return limits.maxUniformBufferRange;

@clayjohn
Copy link
Member Author

Closed by #56153

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants