]> git.tdb.fi Git - libs/gl.git/commitdiff
Fix instance attribute description updates in VertexSetup on Vulkan
authorMikko Rasa <tdb@tdb.fi>
Thu, 17 Mar 2022 19:57:09 +0000 (21:57 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 17 Mar 2022 20:06:05 +0000 (22:06 +0200)
It was ignoring padding attributes when calculating which index to use
for the first instance attribute, resulting in a bogus description.

source/backends/vulkan/vertexsetup_backend.cpp
source/backends/vulkan/vertexsetup_backend.h

index 0d25181448caebe7ceb9ff14e4855f8daa4536a9..9579fd402af5eca57e21a279072822082253cdc0 100644 (file)
@@ -35,14 +35,14 @@ void VulkanVertexSetup::update(unsigned) const
        bindings[0].binding = 0;
        bindings[0].stride = self.vertex_format.stride();
        bindings[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
-       update_attributes(self.vertex_format, 0, attribs);
+       void *attrib_ptr = update_attributes(self.vertex_format, 0, attribs);
 
        if(!self.inst_format.empty())
        {
                bindings[1].binding = 1;
                bindings[1].stride = self.inst_format.stride();
                bindings[1].inputRate = VK_VERTEX_INPUT_RATE_INSTANCE;
-               update_attributes(self.inst_format, 1, attribs+self.vertex_format.size());
+               update_attributes(self.inst_format, 1, attrib_ptr);
        }
 
        input_state->sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
@@ -61,7 +61,7 @@ void VulkanVertexSetup::update(unsigned) const
        }
 }
 
-void VulkanVertexSetup::update_attributes(const VertexFormat &fmt, unsigned binding, void *buffer) const
+void *VulkanVertexSetup::update_attributes(const VertexFormat &fmt, unsigned binding, void *buffer) const
 {
        VkVertexInputAttributeDescription *attrib = reinterpret_cast<VkVertexInputAttributeDescription *>(buffer);
        unsigned offset = 0;
@@ -77,6 +77,8 @@ void VulkanVertexSetup::update_attributes(const VertexFormat &fmt, unsigned bind
                }
                offset += get_attribute_size(a);
        }
+
+       return attrib;
 }
 
 uint64_t VulkanVertexSetup::compute_hash() const
index 091056b8d64bb148532703673bf90a1c55ca00aa..87e780628d509db070c55c4481bfc97b5a648149 100644 (file)
@@ -28,7 +28,7 @@ protected:
 
        static void require_format(const VertexFormat &, bool) { }
        void update(unsigned) const;
-       void update_attributes(const VertexFormat &, unsigned, void *) const;
+       void *update_attributes(const VertexFormat &, unsigned, void *) const;
        std::uint64_t compute_hash() const;
 
        void unload() { }