From 4b27b458c56bcdad83ef8a50b1fdf446a3f4e09f Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Wed, 19 Jun 2024 12:22:16 +0200 Subject: [PATCH] MSL: Fix invalid packing for pointer-to-vector. Normally BDA is pointer to block, but there are use cases with OpPtrAccessChain. --- spirv_msl.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spirv_msl.cpp b/spirv_msl.cpp index 75d935d8..a0cb0601 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -4803,7 +4803,7 @@ bool CompilerMSL::validate_member_packing_rules_msl(const SPIRType &type, uint32 return false; } - if (!mbr_type.array.empty()) + if (is_array(mbr_type)) { // If we have an array type, array stride must match exactly with SPIR-V. @@ -17054,9 +17054,10 @@ uint32_t CompilerMSL::get_declared_struct_size_msl(const SPIRType &struct_type, uint32_t CompilerMSL::get_declared_type_size_msl(const SPIRType &type, bool is_packed, bool row_major) const { // Pointers take 8 bytes each + // Match both pointer and array-of-pointer here. if (type.pointer && type.storage == StorageClassPhysicalStorageBuffer) { - uint32_t type_size = 8 * (type.vecsize == 3 ? 4 : type.vecsize); + uint32_t type_size = 8; // Work our way through potentially layered arrays, // stopping when we hit a pointer that is not also an array. @@ -17131,9 +17132,10 @@ uint32_t CompilerMSL::get_declared_input_size_msl(const SPIRType &type, uint32_t // Returns the byte alignment of a type. uint32_t CompilerMSL::get_declared_type_alignment_msl(const SPIRType &type, bool is_packed, bool row_major) const { - // Pointers aligns on multiples of 8 bytes + // Pointers align on multiples of 8 bytes. + // Deliberately ignore array-ness here. It's not relevant for alignment. if (type.pointer && type.storage == StorageClassPhysicalStorageBuffer) - return 8 * (type.vecsize == 3 ? 4 : type.vecsize); + return 8; switch (type.basetype) {