]> git.tdb.fi Git - libs/gl.git/commitdiff
Only set pipeline resources as used when the resource changes
authorMikko Rasa <tdb@tdb.fi>
Sun, 9 Jan 2022 13:38:54 +0000 (15:38 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 9 Jan 2022 13:38:54 +0000 (15:38 +0200)
This avoids an issue on Vulkan where invalid descriptor set writes were
generated if a resource unused by the current shader was set to the same
value it already had and the shader wasn't changed.

I'm not really sure if the flags should be set in the common part at all,
since the OpenGL bckend barely uses them.  But other approaches are not
clearly superior either.

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

index 65c98b94ffe69c485980c91f1528529bb5797ff5..84609ab03666370a0ce0793f3e6bdc4e9961daaf 100644 (file)
@@ -49,7 +49,8 @@ void VulkanPipelineState::update() const
                for(const PipelineState::BoundUniformBlock &u: self.uniform_blocks)
                        if(u.changed || changed_sets==~0U)
                        {
-                               u.used = self.shprog->uses_uniform_block_binding(u.binding);
+                               if(u.block)
+                                       u.used = self.shprog->uses_uniform_block_binding(u.binding);
                                if(u.binding>=0)
                                        changed_sets |= 1<<(u.binding>>20);
                                u.changed = false;
@@ -57,7 +58,8 @@ void VulkanPipelineState::update() const
                for(const PipelineState::BoundTexture &t: self.textures)
                        if(t.changed || changed_sets==~0U)
                        {
-                               t.used = self.shprog->uses_texture_binding(t.binding);
+                               if(t.texture && t.sampler)
+                                       t.used = self.shprog->uses_texture_binding(t.binding);
                                changed_sets |= 1<<(t.binding>>20);
                                if(t.texture && t.level>=0)
                                        t.texture->refresh_mip_views();
index fd474d28f3f106d0dcdf1226a28d42755877b09d..feb429a6eb126cc851f600c6e74144c698bcd5d9 100644 (file)
@@ -44,13 +44,13 @@ void PipelineState::set_uniform_block(int binding, const UniformBlock *block)
        auto i = lower_bound_member(uniform_blocks, binding, &BoundUniformBlock::binding);
        if(i==uniform_blocks.end() || i->binding!=binding)
                i = uniform_blocks.insert(i, BoundUniformBlock(binding));
-       i->used = block;
        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;
+               i->used = block;
                changes |= UNIFORMS;
        }
 }
@@ -70,13 +70,13 @@ void PipelineState::set_texture(unsigned binding, const Texture *tex, int level,
        auto i = lower_bound_member(textures, binding, &BoundTexture::binding);
        if(i==textures.end() || i->binding!=binding)
                i = textures.insert(i, BoundTexture(binding));
-       i->used = (tex && samp);
        if(tex!=i->texture || level!=i->level || samp!=i->sampler)
        {
                i->texture = tex;
                i->sampler = samp;
                i->level = level;
                i->changed = true;
+               i->used = (tex && samp);
                changes |= TEXTURES;
        }
 }