From: Mikko Rasa Date: Thu, 17 Mar 2022 19:57:09 +0000 (+0200) Subject: Fix instance attribute description updates in VertexSetup on Vulkan X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=bb82b949ff134b07618c02bcd6d40e97fdecbf1a;p=libs%2Fgl.git Fix instance attribute description updates in VertexSetup on Vulkan It was ignoring padding attributes when calculating which index to use for the first instance attribute, resulting in a bogus description. --- diff --git a/source/backends/vulkan/vertexsetup_backend.cpp b/source/backends/vulkan/vertexsetup_backend.cpp index 0d251814..9579fd40 100644 --- a/source/backends/vulkan/vertexsetup_backend.cpp +++ b/source/backends/vulkan/vertexsetup_backend.cpp @@ -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(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 diff --git a/source/backends/vulkan/vertexsetup_backend.h b/source/backends/vulkan/vertexsetup_backend.h index 091056b8..87e78062 100644 --- a/source/backends/vulkan/vertexsetup_backend.h +++ b/source/backends/vulkan/vertexsetup_backend.h @@ -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() { }