Fix: Memory Reserve Issue in Vulkan/Std140

This PR solves a memory reserve issue when a nvec3 was followed by
a int, bool, float.

Also adds a debug_print method to the push constants for checking
the structure against data in renderdoc.

Pull Request: https://projects.blender.org/blender/blender/pulls/111109
This commit is contained in:
Jeroen Bakker
2023-08-15 14:16:26 +02:00
parent ab3ae2be4d
commit d20f26aeb6
4 changed files with 28 additions and 0 deletions
@@ -99,4 +99,17 @@ TEST(std140, fl_vec2)
EXPECT_EQ(offset, 16);
}
TEST(std140, gpu_shader_2D_widget_base)
{
uint32_t offset = 0;
def_attr<Std140>(shader::Type::VEC4, 12, 0, 192, &offset);
def_attr<Std140>(shader::Type::MAT4, 0, 192, 256, &offset);
def_attr<Std140>(shader::Type::VEC3, 0, 256, 268, &offset);
def_attr<Std140>(shader::Type::BOOL, 0, 268, 272, &offset);
align_end_of_struct<Std140>(&offset);
EXPECT_EQ(offset, 272);
}
} // namespace blender::gpu
@@ -129,6 +129,7 @@ uint32_t Std140::element_components_len(const shader::Type type)
case shader::Type::VEC3:
case shader::Type::UVEC3:
case shader::Type::IVEC3:
return 3;
case shader::Type::VEC4:
case shader::Type::UVEC4:
case shader::Type::IVEC4:
@@ -102,6 +102,18 @@ const VKPushConstants::Layout::PushConstant *VKPushConstants::Layout::find(int32
return nullptr;
}
void VKPushConstants::Layout::debug_print() const
{
std::ostream &stream = std::cout;
stream << "VKPushConstants::Layout::debug_print()\n";
for (const PushConstant &push_constant : push_constants) {
stream << " - location:" << push_constant.location;
stream << ", offset:" << push_constant.offset;
stream << ", array_size:" << push_constant.array_size;
stream << "\n";
}
}
VKPushConstants::VKPushConstants() = default;
VKPushConstants::VKPushConstants(const Layout *layout) : layout_(layout)
{
@@ -147,6 +147,8 @@ class VKPushConstants : VKResourceTracker<VKUniformBuffer> {
* Location = ShaderInput.location.
*/
const PushConstant *find(int32_t location) const;
void debug_print() const;
};
private: