Fix: Vulkan: Compositor cryptomatte

When using cryptomatte the last identifier was never used due to a
memory alignment issue. Scalar types should not be aligned, but they
were.

Pull Request: https://projects.blender.org/blender/blender/pulls/133815
This commit is contained in:
Jeroen Bakker
2025-01-30 15:51:09 +01:00
parent 032feaf65f
commit 4dbb9b34c6
2 changed files with 33 additions and 1 deletions

View File

@@ -134,4 +134,16 @@ TEST(std430, simple_lighting)
EXPECT_EQ(offset, 112);
}
TEST(std430, compositor_cryptomatte_matte_compute)
{
uint32_t offset = 0;
def_attr<Std430>(shader::Type::VEC2, 0, 0, 8, &offset);
def_attr<Std430>(shader::Type::FLOAT, 0, 8, 12, &offset);
def_attr<Std430>(shader::Type::FLOAT, 32, 12, 140, &offset);
align_end_of_struct<Std430>(&offset);
EXPECT_EQ(offset, 144);
}
} // namespace blender::gpu

View File

@@ -22,7 +22,27 @@ uint32_t Std430::component_mem_size(const shader::Type /*type*/)
uint32_t Std430::element_alignment(const shader::Type type, const bool is_array)
{
if (is_array) {
return 16;
switch (type) {
case shader::Type::FLOAT:
case shader::Type::UINT:
case shader::Type::INT:
case shader::Type::BOOL:
return 4;
case shader::Type::VEC2:
case shader::Type::UVEC2:
case shader::Type::IVEC2:
case shader::Type::VEC3:
case shader::Type::UVEC3:
case shader::Type::IVEC3:
case shader::Type::VEC4:
case shader::Type::UVEC4:
case shader::Type::IVEC4:
case shader::Type::MAT3:
case shader::Type::MAT4:
return 16;
default:
BLI_assert_msg(false, "Type not supported in dynamic structs.");
}
}
switch (type) {
case shader::Type::FLOAT: