From 7a7e210515c071438297e8b2187507760d22994e Mon Sep 17 00:00:00 2001 From: Chip Davis Date: Wed, 20 Feb 2019 20:23:02 -0600 Subject: [PATCH] MSL: Force unnamed array builtin attributes to have a name. That way, when we refer to them, they'll have the name that we're expecting. --- .../asm/tese/unnamed-builtin-array.asm.tese | 35 +++++++ .../asm/tese/unnamed-builtin-array.asm.tese | 35 +++++++ .../asm/tese/unnamed-builtin-array.asm.tese | 96 +++++++++++++++++++ spirv_msl.cpp | 7 ++ 4 files changed, 173 insertions(+) create mode 100644 reference/opt/shaders-msl/asm/tese/unnamed-builtin-array.asm.tese create mode 100644 reference/shaders-msl/asm/tese/unnamed-builtin-array.asm.tese create mode 100644 shaders-msl/asm/tese/unnamed-builtin-array.asm.tese diff --git a/reference/opt/shaders-msl/asm/tese/unnamed-builtin-array.asm.tese b/reference/opt/shaders-msl/asm/tese/unnamed-builtin-array.asm.tese new file mode 100644 index 00000000..3d4c2786 --- /dev/null +++ b/reference/opt/shaders-msl/asm/tese/unnamed-builtin-array.asm.tese @@ -0,0 +1,35 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 gl_Position [[position]]; +}; + +struct main0_patchIn +{ + float gl_TessLevelInner_0 [[attribute(0)]]; + float gl_TessLevelInner_1 [[attribute(1)]]; + float gl_TessLevelOuter_0 [[attribute(2)]]; + float gl_TessLevelOuter_1 [[attribute(3)]]; + float gl_TessLevelOuter_2 [[attribute(4)]]; + float gl_TessLevelOuter_3 [[attribute(5)]]; +}; + +[[ patch(quad, 0) ]] vertex main0_out main0(main0_patchIn patchIn [[stage_in]], float2 gl_TessCoord [[position_in_patch]]) +{ + main0_out out = {}; + float gl_TessLevelInner[2] = {}; + float gl_TessLevelOuter[4] = {}; + gl_TessLevelInner[0] = patchIn.gl_TessLevelInner_0; + gl_TessLevelInner[1] = patchIn.gl_TessLevelInner_1; + gl_TessLevelOuter[0] = patchIn.gl_TessLevelOuter_0; + gl_TessLevelOuter[1] = patchIn.gl_TessLevelOuter_1; + gl_TessLevelOuter[2] = patchIn.gl_TessLevelOuter_2; + gl_TessLevelOuter[3] = patchIn.gl_TessLevelOuter_3; + out.gl_Position = float4(((gl_TessCoord.x * as_type(gl_TessLevelInner[0])) * as_type(gl_TessLevelOuter[0])) + (((1.0 - gl_TessCoord.x) * as_type(gl_TessLevelInner[0])) * as_type(gl_TessLevelOuter[2])), ((gl_TessCoord.y * as_type(gl_TessLevelInner[1])) * as_type(gl_TessLevelOuter[1])) + (((1.0 - gl_TessCoord.y) * as_type(gl_TessLevelInner[1])) * as_type(gl_TessLevelOuter[3])), 0.0, 1.0); + return out; +} + diff --git a/reference/shaders-msl/asm/tese/unnamed-builtin-array.asm.tese b/reference/shaders-msl/asm/tese/unnamed-builtin-array.asm.tese new file mode 100644 index 00000000..3d4c2786 --- /dev/null +++ b/reference/shaders-msl/asm/tese/unnamed-builtin-array.asm.tese @@ -0,0 +1,35 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 gl_Position [[position]]; +}; + +struct main0_patchIn +{ + float gl_TessLevelInner_0 [[attribute(0)]]; + float gl_TessLevelInner_1 [[attribute(1)]]; + float gl_TessLevelOuter_0 [[attribute(2)]]; + float gl_TessLevelOuter_1 [[attribute(3)]]; + float gl_TessLevelOuter_2 [[attribute(4)]]; + float gl_TessLevelOuter_3 [[attribute(5)]]; +}; + +[[ patch(quad, 0) ]] vertex main0_out main0(main0_patchIn patchIn [[stage_in]], float2 gl_TessCoord [[position_in_patch]]) +{ + main0_out out = {}; + float gl_TessLevelInner[2] = {}; + float gl_TessLevelOuter[4] = {}; + gl_TessLevelInner[0] = patchIn.gl_TessLevelInner_0; + gl_TessLevelInner[1] = patchIn.gl_TessLevelInner_1; + gl_TessLevelOuter[0] = patchIn.gl_TessLevelOuter_0; + gl_TessLevelOuter[1] = patchIn.gl_TessLevelOuter_1; + gl_TessLevelOuter[2] = patchIn.gl_TessLevelOuter_2; + gl_TessLevelOuter[3] = patchIn.gl_TessLevelOuter_3; + out.gl_Position = float4(((gl_TessCoord.x * as_type(gl_TessLevelInner[0])) * as_type(gl_TessLevelOuter[0])) + (((1.0 - gl_TessCoord.x) * as_type(gl_TessLevelInner[0])) * as_type(gl_TessLevelOuter[2])), ((gl_TessCoord.y * as_type(gl_TessLevelInner[1])) * as_type(gl_TessLevelOuter[1])) + (((1.0 - gl_TessCoord.y) * as_type(gl_TessLevelInner[1])) * as_type(gl_TessLevelOuter[3])), 0.0, 1.0); + return out; +} + diff --git a/shaders-msl/asm/tese/unnamed-builtin-array.asm.tese b/shaders-msl/asm/tese/unnamed-builtin-array.asm.tese new file mode 100644 index 00000000..956d2a65 --- /dev/null +++ b/shaders-msl/asm/tese/unnamed-builtin-array.asm.tese @@ -0,0 +1,96 @@ +; SPIR-V +; Version: 1.3 +; Generator: Khronos Glslang Reference Front End; 7 +; Bound: 72 +; Schema: 0 + OpCapability Tessellation + %1 = OpExtInstImport "GLSL.std.450" + OpMemoryModel Logical GLSL450 + OpEntryPoint TessellationEvaluation %main "main" %_ %gl_TessCoord %gl_TessLevelInner %gl_TessLevelOuter + OpExecutionMode %main Quads + OpExecutionMode %main SpacingFractionalEven + OpExecutionMode %main VertexOrderCw + OpSource ESSL 310 + OpSourceExtension "GL_EXT_shader_io_blocks" + OpSourceExtension "GL_EXT_tessellation_shader" + OpMemberDecorate %gl_PerVertex 0 BuiltIn Position + OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize + OpDecorate %gl_PerVertex Block + OpDecorate %gl_TessCoord BuiltIn TessCoord + OpDecorate %gl_TessLevelInner Patch + OpDecorate %gl_TessLevelInner BuiltIn TessLevelInner + OpDecorate %gl_TessLevelOuter Patch + OpDecorate %gl_TessLevelOuter BuiltIn TessLevelOuter + %void = OpTypeVoid + %3 = OpTypeFunction %void + %float = OpTypeFloat 32 + %v4float = OpTypeVector %float 4 +%gl_PerVertex = OpTypeStruct %v4float %float +%_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex + %_ = OpVariable %_ptr_Output_gl_PerVertex Output + %int = OpTypeInt 32 1 + %int_0 = OpConstant %int 0 + %v3float = OpTypeVector %float 3 +%_ptr_Input_v3float = OpTypePointer Input %v3float +%gl_TessCoord = OpVariable %_ptr_Input_v3float Input + %uint = OpTypeInt 32 0 + %uint_0 = OpConstant %uint 0 +%_ptr_Input_float = OpTypePointer Input %float + %uint_2 = OpConstant %uint 2 +%_arr_float_uint_2 = OpTypeArray %float %uint_2 +%_ptr_Input__arr_float_uint_2 = OpTypePointer Input %_arr_float_uint_2 +%gl_TessLevelInner = OpVariable %_ptr_Input__arr_float_uint_2 Input + %uint_4 = OpConstant %uint 4 +%_arr_float_uint_4 = OpTypeArray %float %uint_4 +%_ptr_Input__arr_float_uint_4 = OpTypePointer Input %_arr_float_uint_4 +%gl_TessLevelOuter = OpVariable %_ptr_Input__arr_float_uint_4 Input + %float_1 = OpConstant %float 1 + %int_2 = OpConstant %int 2 + %uint_1 = OpConstant %uint 1 + %int_1 = OpConstant %int 1 + %int_3 = OpConstant %int 3 + %float_0 = OpConstant %float 0 +%_ptr_Output_v4float = OpTypePointer Output %v4float + %main = OpFunction %void None %3 + %5 = OpLabel + %19 = OpAccessChain %_ptr_Input_float %gl_TessCoord %uint_0 + %20 = OpLoad %float %19 + %25 = OpAccessChain %_ptr_Input_float %gl_TessLevelInner %int_0 + %26 = OpLoad %float %25 + %27 = OpFMul %float %20 %26 + %32 = OpAccessChain %_ptr_Input_float %gl_TessLevelOuter %int_0 + %33 = OpLoad %float %32 + %34 = OpFMul %float %27 %33 + %36 = OpAccessChain %_ptr_Input_float %gl_TessCoord %uint_0 + %37 = OpLoad %float %36 + %38 = OpFSub %float %float_1 %37 + %39 = OpAccessChain %_ptr_Input_float %gl_TessLevelInner %int_0 + %40 = OpLoad %float %39 + %41 = OpFMul %float %38 %40 + %43 = OpAccessChain %_ptr_Input_float %gl_TessLevelOuter %int_2 + %44 = OpLoad %float %43 + %45 = OpFMul %float %41 %44 + %46 = OpFAdd %float %34 %45 + %48 = OpAccessChain %_ptr_Input_float %gl_TessCoord %uint_1 + %49 = OpLoad %float %48 + %51 = OpAccessChain %_ptr_Input_float %gl_TessLevelInner %int_1 + %52 = OpLoad %float %51 + %53 = OpFMul %float %49 %52 + %54 = OpAccessChain %_ptr_Input_float %gl_TessLevelOuter %int_1 + %55 = OpLoad %float %54 + %56 = OpFMul %float %53 %55 + %57 = OpAccessChain %_ptr_Input_float %gl_TessCoord %uint_1 + %58 = OpLoad %float %57 + %59 = OpFSub %float %float_1 %58 + %60 = OpAccessChain %_ptr_Input_float %gl_TessLevelInner %int_1 + %61 = OpLoad %float %60 + %62 = OpFMul %float %59 %61 + %64 = OpAccessChain %_ptr_Input_float %gl_TessLevelOuter %int_3 + %65 = OpLoad %float %64 + %66 = OpFMul %float %62 %65 + %67 = OpFAdd %float %56 %66 + %69 = OpCompositeConstruct %v4float %46 %67 %float_0 %float_1 + %71 = OpAccessChain %_ptr_Output_v4float %_ %int_0 + OpStore %71 %69 + OpReturn + OpFunctionEnd diff --git a/spirv_msl.cpp b/spirv_msl.cpp index f75fb0c3..68b0f3b4 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -1185,6 +1185,13 @@ void CompilerMSL::add_composite_variable_to_interface_block(StorageClass storage while (is_array(*usable_type) || is_matrix(*usable_type)) usable_type = &get(usable_type->parent_type); + // If a builtin, force it to have the proper name. + if (is_builtin_variable(var)) + { + BuiltIn builtin = BuiltIn(get_decoration(var.self, DecorationBuiltIn)); + set_name(var.self, builtin_to_glsl(builtin, StorageClassFunction)); + } + entry_func.add_local_variable(var.self); // We need to declare the variable early and at entry-point scope.