diff --git a/source/blender/gpu/GPU_capabilities.hh b/source/blender/gpu/GPU_capabilities.hh index c55441ed3f5..4e85ba102d3 100644 --- a/source/blender/gpu/GPU_capabilities.hh +++ b/source/blender/gpu/GPU_capabilities.hh @@ -33,6 +33,7 @@ int GPU_max_varying_floats(); int GPU_max_shader_storage_buffer_bindings(); int GPU_max_compute_shader_storage_blocks(); int GPU_max_samplers(); +size_t GPU_max_uniform_buffer_size(); size_t GPU_max_storage_buffer_size(); /* Used when binding subrange of SSBOs. In bytes. * The start of the range must be aligned with this value. */ diff --git a/source/blender/gpu/intern/gpu_capabilities.cc b/source/blender/gpu/intern/gpu_capabilities.cc index 325591d79b8..5ade31b716c 100644 --- a/source/blender/gpu/intern/gpu_capabilities.cc +++ b/source/blender/gpu/intern/gpu_capabilities.cc @@ -191,6 +191,11 @@ int GPU_minimum_per_vertex_stride() return GCaps.minimum_per_vertex_stride; } +size_t GPU_max_uniform_buffer_size() +{ + return GCaps.max_uniform_buffer_size; +} + size_t GPU_max_storage_buffer_size() { return GCaps.max_storage_buffer_size; diff --git a/source/blender/gpu/intern/gpu_capabilities_private.hh b/source/blender/gpu/intern/gpu_capabilities_private.hh index e639f6d982d..8b17798851c 100644 --- a/source/blender/gpu/intern/gpu_capabilities_private.hh +++ b/source/blender/gpu/intern/gpu_capabilities_private.hh @@ -39,6 +39,7 @@ struct GPUCapabilities { int max_varying_floats = 0; int max_shader_storage_buffer_bindings = 0; int max_compute_shader_storage_blocks = 0; + size_t max_uniform_buffer_size = 0; size_t max_storage_buffer_size = 0; size_t storage_buffer_alignment = 256; int extensions_len = 0; diff --git a/source/blender/gpu/intern/gpu_uniform_buffer.cc b/source/blender/gpu/intern/gpu_uniform_buffer.cc index 61d67e3a858..f1ebdebfbbe 100644 --- a/source/blender/gpu/intern/gpu_uniform_buffer.cc +++ b/source/blender/gpu/intern/gpu_uniform_buffer.cc @@ -18,6 +18,7 @@ #include "gpu_backend.hh" #include "gpu_node_graph.hh" +#include "GPU_capabilities.hh" #include "GPU_context.hh" #include "GPU_material.hh" @@ -219,9 +220,12 @@ blender::gpu::UniformBuf *GPU_uniformbuf_create_from_list(ListBase *inputs, cons void *data = MEM_mallocN(buffer_size, __func__); buffer_fill_from_list(data, inputs); - UniformBuf *ubo = GPUBackend::get()->uniformbuf_alloc(buffer_size, name); - /* Defer data upload. */ - ubo->attach_data(data); + UniformBuf *ubo = nullptr; + if (buffer_size <= GPU_max_uniform_buffer_size()) { + ubo = GPUBackend::get()->uniformbuf_alloc(buffer_size, name); + /* Defer data upload. */ + ubo->attach_data(data); + } return ubo; } diff --git a/source/blender/gpu/metal/mtl_backend.mm b/source/blender/gpu/metal/mtl_backend.mm index dac9c3de31e..3bf194ba91f 100644 --- a/source/blender/gpu/metal/mtl_backend.mm +++ b/source/blender/gpu/metal/mtl_backend.mm @@ -534,6 +534,7 @@ void MTLBackend::capabilities_init(MTLContext *ctx) GCaps.max_shader_storage_buffer_bindings = 14; GCaps.max_compute_shader_storage_blocks = 14; GCaps.max_storage_buffer_size = size_t(ctx->device.maxBufferLength); + GCaps.max_uniform_buffer_size = size_t(ctx->device.maxBufferLength); GCaps.storage_buffer_alignment = 256; /* TODO(fclem): But also unused. */ GCaps.max_work_group_count[0] = 65535; diff --git a/source/blender/gpu/opengl/gl_backend.cc b/source/blender/gpu/opengl/gl_backend.cc index e432e940f49..1f8b0e472cc 100644 --- a/source/blender/gpu/opengl/gl_backend.cc +++ b/source/blender/gpu/opengl/gl_backend.cc @@ -529,7 +529,6 @@ static void detect_workarounds() GLint GLContext::max_cubemap_size = 0; GLint GLContext::max_ubo_binds = 0; -GLint GLContext::max_ubo_size = 0; GLint GLContext::max_ssbo_binds = 0; /** Extensions. */ @@ -588,7 +587,9 @@ void GLBackend::capabilities_init() glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 2, &GCaps.max_work_group_size[2]); glGetIntegerv(GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, &GCaps.max_shader_storage_buffer_bindings); glGetIntegerv(GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS, &GCaps.max_compute_shader_storage_blocks); - int64_t max_ssbo_size; + int64_t max_ssbo_size, max_ubo_size; + glGetInteger64v(GL_MAX_UNIFORM_BLOCK_SIZE, &max_ubo_size); + GCaps.max_uniform_buffer_size = size_t(max_ubo_size); glGetInteger64v(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_ssbo_size); GCaps.max_storage_buffer_size = size_t(max_ssbo_size); GLint ssbo_alignment; @@ -601,7 +602,6 @@ void GLBackend::capabilities_init() glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &GCaps.max_texture_3d_size); glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &GLContext::max_cubemap_size); glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_BLOCKS, &GLContext::max_ubo_binds); - glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &GLContext::max_ubo_size); GLint max_ssbo_binds; GLContext::max_ssbo_binds = 999999; glGetIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &max_ssbo_binds); diff --git a/source/blender/gpu/opengl/gl_context.hh b/source/blender/gpu/opengl/gl_context.hh index 89dc1aa49cc..9ccd8e76fc3 100644 --- a/source/blender/gpu/opengl/gl_context.hh +++ b/source/blender/gpu/opengl/gl_context.hh @@ -42,7 +42,6 @@ class GLContext : public Context { /** Capabilities. */ static GLint max_cubemap_size; - static GLint max_ubo_size; static GLint max_ubo_binds; static GLint max_ssbo_binds; diff --git a/source/blender/gpu/opengl/gl_storage_buffer.cc b/source/blender/gpu/opengl/gl_storage_buffer.cc index 0a221ffe770..2229fc5bae7 100644 --- a/source/blender/gpu/opengl/gl_storage_buffer.cc +++ b/source/blender/gpu/opengl/gl_storage_buffer.cc @@ -27,7 +27,7 @@ GLStorageBuf::GLStorageBuf(size_t size, GPUUsageType usage, const char *name) : StorageBuf(size, name) { usage_ = usage; - /* Do not create UBO GL buffer here to allow allocation from any thread. */ + /* Do not create SSBO GL buffer here to allow allocation from any thread. */ BLI_assert(size <= GPU_max_storage_buffer_size()); } diff --git a/source/blender/gpu/opengl/gl_uniform_buffer.cc b/source/blender/gpu/opengl/gl_uniform_buffer.cc index 1d826471437..0d018d49562 100644 --- a/source/blender/gpu/opengl/gl_uniform_buffer.cc +++ b/source/blender/gpu/opengl/gl_uniform_buffer.cc @@ -8,6 +8,8 @@ #include "BLI_string.h" +#include "GPU_capabilities.hh" + #include "gpu_context_private.hh" #include "gl_debug.hh" @@ -23,7 +25,7 @@ namespace blender::gpu { GLUniformBuf::GLUniformBuf(size_t size, const char *name) : UniformBuf(size, name) { /* Do not create ubo GL buffer here to allow allocation from any thread. */ - BLI_assert(size <= GLContext::max_ubo_size); + BLI_assert(size <= GPU_max_uniform_buffer_size()); } GLUniformBuf::~GLUniformBuf() diff --git a/source/blender/gpu/vulkan/vk_backend.cc b/source/blender/gpu/vulkan/vk_backend.cc index a3abc3509b7..7e3dab8a215 100644 --- a/source/blender/gpu/vulkan/vk_backend.cc +++ b/source/blender/gpu/vulkan/vk_backend.cc @@ -727,6 +727,7 @@ void VKBackend::capabilities_init(VKDevice &device) GCaps.max_varying_floats = min_uu(limits.maxVertexOutputComponents, INT_MAX); GCaps.max_shader_storage_buffer_bindings = GCaps.max_compute_shader_storage_blocks = min_uu( limits.maxPerStageDescriptorStorageBuffers, INT_MAX); + GCaps.max_uniform_buffer_size = size_t(limits.maxUniformBufferRange); GCaps.max_storage_buffer_size = size_t(limits.maxStorageBufferRange); GCaps.storage_buffer_alignment = limits.minStorageBufferOffsetAlignment;