diff --git a/reference/shaders-msl/asm/frag/undef-variable-store.asm.frag b/reference/shaders-msl/asm/frag/undef-variable-store.asm.frag index 16658ffc..2cefeb66 100644 --- a/reference/shaders-msl/asm/frag/undef-variable-store.asm.frag +++ b/reference/shaders-msl/asm/frag/undef-variable-store.asm.frag @@ -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 { diff --git a/spirv_msl.cpp b/spirv_msl.cpp index c6be0598..63515fc0 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -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(); auto &type = get(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 keywords = { - "kernel", - "bias", + "kernel", "bias", }; static const unordered_set illegal_func_names = { - "main", - "saturate", + "main", "saturate", }; for (auto &id : ids)