@@ -346,7 +346,9 @@ void CompilerMSL::emit_entry_point_declarations()
346346 for (uint32_t i = 0 ; i < type.array [0 ]; ++i)
347347 statement (name + " _" + convert_to_string (i) + " ," );
348348 end_scope_decl ();
349+ statement (" " );
349350 }
351+ // For some reason, without this, we end up emitting the arrays twice.
350352 buffer_arrays.clear ();
351353}
352354
@@ -3808,11 +3810,18 @@ string CompilerMSL::entry_point_args(bool append_comma)
38083810 break ;
38093811 if (!type.array .empty ())
38103812 {
3813+ if (type.array .size () > 1 )
3814+ SPIRV_CROSS_THROW (" Arrays of arrays of buffers are not supported." );
3815+
38113816 // Metal doesn't directly support this, so we must expand the
38123817 // array. We'll declare a local array to hold these elements
38133818 // later.
38143819 uint32_t array_size =
38153820 type.array_size_literal .back () ? type.array .back () : get<SPIRConstant>(type.array .back ()).scalar ();
3821+
3822+ if (array_size == 0 )
3823+ SPIRV_CROSS_THROW (" Unsized arrays of buffers are not supported in MSL." );
3824+
38163825 buffer_arrays.push_back (var_id);
38173826 for (uint32_t i = 0 ; i < array_size; ++i)
38183827 {
@@ -4004,6 +4013,8 @@ string CompilerMSL::argument_decl(const SPIRFunction::Parameter &arg)
40044013 // Arrays of images and samplers are special cased.
40054014 if (get<SPIRVariable>(name_id).storage == StorageClassUniform ||
40064015 get<SPIRVariable>(name_id).storage == StorageClassStorageBuffer)
4016+ // If an array of buffers, declare an array of pointers, since we
4017+ // can't have an array of references.
40074018 decl += " *" ;
40084019 decl += " (&" ;
40094020 decl += to_expression (name_id);
@@ -4130,7 +4141,8 @@ string CompilerMSL::to_member_reference(const SPIRVariable *var, const SPIRType
41304141 if (var && (var->storage == StorageClassUniform || var->storage == StorageClassStorageBuffer) &&
41314142 !get<SPIRType>(var->basetype ).array .empty ())
41324143 return join (" ->" , to_member_name (type, index));
4133- return join (" ." , to_member_name (type, index));
4144+ else
4145+ return join (" ." , to_member_name (type, index));
41344146}
41354147
41364148string CompilerMSL::to_qualifiers_glsl (uint32_t id)
@@ -4223,6 +4235,9 @@ std::string CompilerMSL::sampler_type(const SPIRType &type)
42234235 if (!msl_options.supports_msl_version (2 ))
42244236 SPIRV_CROSS_THROW (" MSL 2.0 or greater is required for arrays of samplers." );
42254237
4238+ if (type.array .size () > 1 )
4239+ SPIRV_CROSS_THROW (" Arrays of arrays of samplers are not supported in MSL." );
4240+
42264241 // Arrays of samplers in MSL must be declared with a special array<T, N> syntax ala C++11 std::array.
42274242 uint32_t array_size =
42284243 type.array_size_literal .back () ? type.array .back () : get<SPIRConstant>(type.array .back ()).scalar ();
@@ -4256,7 +4271,15 @@ string CompilerMSL::image_type_glsl(const SPIRType &type, uint32_t id)
42564271 minor = 2 ;
42574272 }
42584273 if (!msl_options.supports_msl_version (major, minor))
4259- SPIRV_CROSS_THROW (" MSL 2.0 or greater is required for arrays of textures." );
4274+ {
4275+ if (msl_options.is_ios ())
4276+ SPIRV_CROSS_THROW (" MSL 1.2 or greater is required for arrays of textures." );
4277+ else
4278+ SPIRV_CROSS_THROW (" MSL 2.0 or greater is required for arrays of textures." );
4279+ }
4280+
4281+ if (type.array .size () > 1 )
4282+ SPIRV_CROSS_THROW (" Arrays of arrays of textures are not supported in MSL." );
42604283
42614284 // Arrays of images in MSL must be declared with a special array<T, N> syntax ala C++11 std::array.
42624285 uint32_t array_size =
0 commit comments