]> git.tdb.fi Git - libs/gl.git/commitdiff
Keep track of the buffers of bound uniform blocks
authorMikko Rasa <tdb@tdb.fi>
Sat, 18 Dec 2021 22:00:32 +0000 (00:00 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 18 Dec 2021 22:02:36 +0000 (00:02 +0200)
ProgramData may recreate the buffer when creating new blocks, but existing
block objects will be retained.  As such, the block object alone isn't
enough to determine whether the binding has changed.

source/backends/opengl/pipelinestate_backend.cpp
source/backends/vulkan/pipelinestate_backend.cpp
source/core/pipelinestate.cpp
source/core/pipelinestate.h

index 78ba7978042dd84587480c7128a10d1df6fd1378..fb802995f6355e46a6794f07e6f4ec5d1b4e7593 100644 (file)
@@ -112,7 +112,7 @@ void OpenGLPipelineState::apply() const
                                {
                                        if(u.binding>=0)
                                        {
-                                               glBindBufferRange(GL_UNIFORM_BUFFER, u.binding, u.block->get_buffer()->id, u.block->get_offset(), u.block->get_data_size());
+                                               glBindBufferRange(GL_UNIFORM_BUFFER, u.binding, u.buffer->id, u.block->get_offset(), u.block->get_data_size());
                                                dev_state.bound_uniform_blocks[u.binding] = 1;
                                        }
                                        else if(u.binding==ReflectData::DEFAULT_BLOCK && self.shprog)
index a1a03d3d8fcb31d2646027036bb4936a237d4194..a6c9d8ce6754ce28d24002900b47511f21a16a33 100644 (file)
@@ -275,6 +275,7 @@ uint64_t VulkanPipelineState::compute_descriptor_set_hash(unsigned index) const
                {
                        result = hash_update<64>(result, b.binding);
                        result = hash_update<64>(result, reinterpret_cast<uintptr_t>(b.block));
+                       result = hash_update<64>(result, reinterpret_cast<uintptr_t>(b.buffer));
                }
        for(const PipelineState::BoundTexture &t: self.textures)
                if(t.used && (t.binding>>20)==index)
@@ -319,7 +320,7 @@ unsigned VulkanPipelineState::fill_descriptor_writes(unsigned index, vector<char
        for(const PipelineState::BoundUniformBlock &u: self.uniform_blocks)
                if(u.used && u.binding>=0 && static_cast<unsigned>(u.binding>>20)==index)
                {
-                       buffer_ptr->buffer = handle_cast<::VkBuffer>(u.block->get_buffer()->handle);
+                       buffer_ptr->buffer = handle_cast<::VkBuffer>(u.buffer->handle);
                        buffer_ptr->offset = u.block->get_offset();
                        buffer_ptr->range = u.block->get_data_size();
 
index 210a0703868035dc69572fc56cc50eaf67b9ff08..fd474d28f3f106d0dcdf1226a28d42755877b09d 100644 (file)
@@ -2,6 +2,7 @@
 #include <msp/core/algorithm.h>
 #include "error.h"
 #include "pipelinestate.h"
+#include "uniformblock.h"
 
 using namespace std;
 
@@ -44,9 +45,11 @@ void PipelineState::set_uniform_block(int binding, const UniformBlock *block)
        if(i==uniform_blocks.end() || i->binding!=binding)
                i = uniform_blocks.insert(i, BoundUniformBlock(binding));
        i->used = block;
-       if(block!=i->block || binding<0)
+       const Buffer *buffer = (block ? block->get_buffer() : 0);
+       if(block!=i->block || buffer!=i->buffer || binding<0)
        {
                i->block = block;
+               i->buffer = buffer;
                i->changed = true;
                changes |= UNIFORMS;
        }
index d0ff349069cee04e69992d2c94fa76233b9f6f0d..bc6087c780ea625d029bc5752c6fc80c3b4bdba0 100644 (file)
@@ -11,6 +11,7 @@ namespace Msp {
 namespace GL {
 
 class Blend;
+class Buffer;
 class DepthTest;
 class Framebuffer;
 class Program;
@@ -49,6 +50,7 @@ private:
                mutable bool changed = false;
                mutable bool used = false;
                const UniformBlock *block = 0;
+               const Buffer *buffer = 0;
 
                BoundUniformBlock(int b): binding(b) { }
        };