From f4dcad7b2472f803174c83c0af2e70b321cdd80c Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Fri, 2 Jul 2021 16:38:23 +0200 Subject: GPU: Sizecheck for push constants buffer. According to the specs platforms should at least support push constants of 128 bytes. As there are known platforms that have set this as their maximum (Mesa for example) we should use this as the maximum as well. --- source/blender/gpu/intern/gpu_shader.cc | 4 ++++ source/blender/gpu/intern/gpu_uniform_buffer_private.hh | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc index 1c66b43d93e..e108fb4a977 100644 --- a/source/blender/gpu/intern/gpu_shader.cc +++ b/source/blender/gpu/intern/gpu_shader.cc @@ -558,7 +558,11 @@ void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, cons void GPU_shader_uniform_push_constant(GPUShader *sh, GPUUniformBuf *ubo) { + /* According to the specification all platforms should at least support 128 bytes. We should + * support only upto the minimum size as some platforms have set this as their max. */ + static constexpr size_t MAX_PUSH_CONSTANTS_LEN = 128; UniformBuf *buf = unwrap(ubo); + BLI_assert(buf->size_in_bytes() < MAX_PUSH_CONSTANTS_LEN); unwrap(sh)->uniform_push_constant(buf); } diff --git a/source/blender/gpu/intern/gpu_uniform_buffer_private.hh b/source/blender/gpu/intern/gpu_uniform_buffer_private.hh index e8fc1343eaf..603af550d28 100644 --- a/source/blender/gpu/intern/gpu_uniform_buffer_private.hh +++ b/source/blender/gpu/intern/gpu_uniform_buffer_private.hh @@ -63,6 +63,11 @@ class UniformBuf { { data_ = data; } + + size_t size_in_bytes() const + { + return size_in_bytes_; + } }; /* Syntactic sugar. */ -- cgit v1.2.3