diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 7ca4bd21e8..d6fab2a434 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -6404,7 +6404,8 @@ prepare_shader_buffer(ShaderBuffer *data) { _glObjectLabel(GL_SHADER_STORAGE_BUFFER, gbc->_index, name.size(), name.data()); } - uint64_t num_bytes = data->get_data_size_bytes(); + // Some drivers require the buffer to be padded to 16 byte boundary. + uint64_t num_bytes = (data->get_data_size_bytes() + 15u) & ~15u; if (_supports_buffer_storage) { _glBufferStorage(GL_SHADER_STORAGE_BUFFER, num_bytes, data->get_initial_data(), 0); } else { diff --git a/panda/src/gobj/shaderBuffer.I b/panda/src/gobj/shaderBuffer.I index 59d62d0171..ccbd160521 100644 --- a/panda/src/gobj/shaderBuffer.I +++ b/panda/src/gobj/shaderBuffer.I @@ -19,8 +19,7 @@ INLINE ShaderBuffer:: ShaderBuffer(const std::string &name, uint64_t size, UsageHint usage_hint) : Namable(name), _data_size_bytes(size), - _usage_hint(usage_hint), - _contexts(nullptr) { + _usage_hint(usage_hint) { } /** @@ -32,8 +31,13 @@ ShaderBuffer(const std::string &name, vector_uchar initial_data, UsageHint usage Namable(name), _data_size_bytes(initial_data.size()), _usage_hint(usage_hint), - _initial_data(initial_data), - _contexts(nullptr) { + _initial_data(std::move(initial_data)) { + + // Make sure it is padded to 16 bytes. Some drivers like that. + if ((_initial_data.size() & 15u) != 0) { + _initial_data.resize((_initial_data.size() + 15u) & ~15u, 0); + _data_size_bytes = _initial_data.size(); + } } /** diff --git a/panda/src/gobj/shaderBuffer.cxx b/panda/src/gobj/shaderBuffer.cxx index 971787f0e6..4e21319b49 100644 --- a/panda/src/gobj/shaderBuffer.cxx +++ b/panda/src/gobj/shaderBuffer.cxx @@ -193,7 +193,7 @@ fillin(DatagramIterator &scan, BamReader *manager) { if (scan.get_bool() && _data_size_bytes > 0) { nassertv_always(_data_size_bytes <= scan.get_remaining_size()); - _initial_data.resize(_data_size_bytes); + _initial_data.resize((_data_size_bytes + 15u) & ~15u); scan.extract_bytes(&_initial_data[0], _data_size_bytes); } else { _initial_data.clear(); diff --git a/panda/src/gobj/shaderBuffer.h b/panda/src/gobj/shaderBuffer.h index 69bdf985d9..bdf0538857 100644 --- a/panda/src/gobj/shaderBuffer.h +++ b/panda/src/gobj/shaderBuffer.h @@ -63,7 +63,7 @@ private: vector_uchar _initial_data; typedef pmap Contexts; - Contexts *_contexts; + Contexts *_contexts = nullptr; public: static void register_with_read_factory();