MSL: Don't use native arrays for tess level inputs.
authorHans-Kristian Arntzen <post@arntzen-software.no>
Fri, 16 Apr 2021 13:02:26 +0000 (15:02 +0200)
committerHans-Kristian Arntzen <post@arntzen-software.no>
Mon, 19 Apr 2021 10:10:49 +0000 (12:10 +0200)
reference/shaders-msl/tese/read-tess-level-in-func.msl2.tese
spirv_msl.cpp

index 1dc3be3..ec9017d 100644 (file)
@@ -55,7 +55,7 @@ struct main0_patchIn
 };
 
 static inline __attribute__((always_inline))
-float4 read_tess_levels(thread float (&gl_TessLevelOuter)[4])
+float4 read_tess_levels(thread spvUnsafeArray<float, 4>& gl_TessLevelOuter)
 {
     return float4(gl_TessLevelOuter[0], gl_TessLevelOuter[1], gl_TessLevelOuter[2], gl_TessLevelOuter[3]);
 }
index 5019841..cc42686 100644 (file)
@@ -12433,12 +12433,20 @@ string CompilerMSL::argument_decl(const SPIRFunction::Parameter &arg)
        else if (builtin)
        {
                // Only use templated array for Clip/Cull distance when feasible.
-               // In other scenarios, we need need to override array length for tess levels,
+               // In other scenarios, we need need to override array length for tess levels (if used as outputs),
                // or we need to emit the expected type for builtins (uint vs int).
-               if (builtin_type != BuiltInClipDistance && builtin_type != BuiltInCullDistance)
+               auto storage = get<SPIRType>(var.basetype).storage;
+
+               if (storage == StorageClassInput &&
+                   (builtin_type == BuiltInTessLevelInner || builtin_type == BuiltInTessLevelOuter))
+               {
+                       is_using_builtin_array = false;
+               }
+               else if (builtin_type != BuiltInClipDistance && builtin_type != BuiltInCullDistance)
+               {
                        is_using_builtin_array = true;
+               }
 
-               auto storage = get<SPIRType>(var.basetype).storage;
                if (storage == StorageClassOutput && variable_storage_requires_stage_io(storage) &&
                    !is_stage_output_builtin_masked(builtin_type))
                        is_using_builtin_array = true;