For MSL, use {} instead of constructors to init OpUndef values.

This commit is contained in:
Bill Hollings 2017-11-30 15:03:27 -05:00
parent a02b008ce0
commit c93d44ba3c
2 changed files with 11 additions and 27 deletions

View File

@ -3,8 +3,8 @@
using namespace metal;
constant float4 _38 = float4(0);
constant float4 _47 = float4(0);
constant float4 _38 = {};
constant float4 _47 = {};
struct main0_out
{

View File

@ -1042,7 +1042,7 @@ void CompilerMSL::emit_custom_functions()
}
// Undefined global memory is not allowed in MSL.
// Declare constant and init to zeros.
// Declare constant and init to zeros. Use {}, as global constructors can break Metal.
void CompilerMSL::declare_undefined_values()
{
bool emitted = false;
@ -1052,21 +1052,7 @@ void CompilerMSL::declare_undefined_values()
{
auto &undef = id.get<SPIRUndef>();
auto &type = get<SPIRType>(undef.basetype);
string arg_str;
switch (type.basetype)
{
case SPIRType::Struct:
arg_str = "";
break;
default:
arg_str = "0";
break;
}
string init_str = type_to_glsl(type) + "(" + arg_str + ")";
statement("constant ", variable_decl(type, to_name(undef.self), undef.self), " = ", init_str, ";");
statement("constant ", variable_decl(type, to_name(undef.self), undef.self), " = {};");
emitted = true;
}
}
@ -1546,7 +1532,7 @@ void CompilerMSL::emit_instruction(const Instruction &instruction)
emit_barrier(ops[0], ops[1], ops[2]);
break;
// OpOuterProduct
// OpOuterProduct
default:
CompilerGLSL::emit_instruction(instruction);
@ -1851,10 +1837,10 @@ void CompilerMSL::emit_glsl_op(uint32_t result_type, uint32_t id, uint32_t eop,
break;
}
// TODO:
// GLSLstd450InterpolateAtCentroid (centroid_no_perspective qualifier)
// GLSLstd450InterpolateAtSample (sample_no_perspective qualifier)
// GLSLstd450InterpolateAtOffset
// TODO:
// GLSLstd450InterpolateAtCentroid (centroid_no_perspective qualifier)
// GLSLstd450InterpolateAtSample (sample_no_perspective qualifier)
// GLSLstd450InterpolateAtOffset
default:
CompilerGLSL::emit_glsl_op(result_type, id, eop, args, count);
@ -2739,13 +2725,11 @@ string CompilerMSL::ensure_valid_name(string name, string pfx)
void CompilerMSL::replace_illegal_names()
{
static const unordered_set<string> keywords = {
"kernel",
"bias",
"kernel", "bias",
};
static const unordered_set<string> illegal_func_names = {
"main",
"saturate",
"main", "saturate",
};
for (auto &id : ids)