Skip to content

Commit b7433c0

Browse files
committed
Minor cleanups.
Throw an error for cases we don't support. Add a blank line after each local array declaration.
1 parent 2506046 commit b7433c0

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

reference/opt/shaders-msl/vert/resource-arrays-leaf.ios.vert

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ vertex void main0(device storage_block* storage_0 [[buffer(0)]], device storage_
2222
storage_0,
2323
storage_1,
2424
};
25+
2526
constant constant_block* constants[] =
2627
{
2728
constants_0,
2829
constants_1,
2930
constants_2,
3031
constants_3,
3132
};
33+
3234
storage[0]->baz = uint4(constants[3]->foo);
3335
storage[1]->quux = images[2].read(uint2(int2(constants[1]->bar))).xy;
3436
}

reference/opt/shaders-msl/vert/resource-arrays.ios.vert

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ vertex void main0(device storage_block* storage_0 [[buffer(0)]], device storage_
2222
storage_0,
2323
storage_1,
2424
};
25+
2526
constant constant_block* constants[] =
2627
{
2728
constants_0,
2829
constants_1,
2930
constants_2,
3031
constants_3,
3132
};
33+
3234
storage[0]->baz = uint4(constants[3]->foo);
3335
storage[1]->quux = images[2].read(uint2(int2(constants[1]->bar))).xy;
3436
}

reference/shaders-msl/vert/resource-arrays-leaf.ios.vert

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ vertex void main0(device storage_block* storage_0 [[buffer(0)]], device storage_
3030
storage_0,
3131
storage_1,
3232
};
33+
3334
constant constant_block* constants[] =
3435
{
3536
constants_0,
3637
constants_1,
3738
constants_2,
3839
constants_3,
3940
};
41+
4042
doWork(storage, constants, images);
4143
}
4244

reference/shaders-msl/vert/resource-arrays.ios.vert

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ vertex void main0(device storage_block* storage_0 [[buffer(0)]], device storage_
2222
storage_0,
2323
storage_1,
2424
};
25+
2526
constant constant_block* constants[] =
2627
{
2728
constants_0,
2829
constants_1,
2930
constants_2,
3031
constants_3,
3132
};
33+
3234
storage[0]->baz = uint4(constants[3]->foo);
3335
storage[1]->quux = images[2].read(uint2(int2(constants[1]->bar))).xy;
3436
}

spirv_msl.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

41364148
string 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

Comments
 (0)