From 3229e6efb6164a95ebbccee7e46c236e04089db5 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Tue, 3 Apr 2018 15:36:35 +0200 Subject: [PATCH] Add more illegal name replacement in MSL. --- .../shaders-msl/frag/constant-composites.frag | 6 +++--- .../shaders-msl/frag/illegal-name-test-0.frag | 17 +++++++++++++++ .../shaders-msl/frag/constant-composites.frag | 6 +++--- .../shaders-msl/frag/illegal-name-test-0.frag | 21 +++++++++++++++++++ shaders-msl/frag/illegal-name-test-0.frag | 12 +++++++++++ spirv_glsl.cpp | 2 +- spirv_msl.cpp | 7 +++++++ 7 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 reference/opt/shaders-msl/frag/illegal-name-test-0.frag create mode 100644 reference/shaders-msl/frag/illegal-name-test-0.frag create mode 100644 shaders-msl/frag/illegal-name-test-0.frag diff --git a/reference/opt/shaders-msl/frag/constant-composites.frag b/reference/opt/shaders-msl/frag/constant-composites.frag index d216da6d..dfded3af 100644 --- a/reference/opt/shaders-msl/frag/constant-composites.frag +++ b/reference/opt/shaders-msl/frag/constant-composites.frag @@ -16,7 +16,7 @@ constant Foo _28[2] = {{10.0, 20.0}, {30.0, 40.0}}; struct main0_in { - int line [[user(locn0)]]; + int _line [[user(locn0)]]; }; struct main0_out @@ -43,8 +43,8 @@ fragment main0_out main0(main0_in in [[stage_in]]) main0_out out = {}; float lut[4] = {1.0, 4.0, 3.0, 2.0}; Foo foos[2] = {{10.0, 20.0}, {30.0, 40.0}}; - out.FragColor = float4(lut[in.line]); - out.FragColor += float4(foos[in.line].a * (foos[1 - in.line].a)); + out.FragColor = float4(lut[in._line]); + out.FragColor += float4(foos[in._line].a * (foos[1 - in._line].a)); return out; } diff --git a/reference/opt/shaders-msl/frag/illegal-name-test-0.frag b/reference/opt/shaders-msl/frag/illegal-name-test-0.frag new file mode 100644 index 00000000..81cd3b56 --- /dev/null +++ b/reference/opt/shaders-msl/frag/illegal-name-test-0.frag @@ -0,0 +1,17 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 FragColor [[color(0)]]; +}; + +fragment main0_out main0() +{ + main0_out out = {}; + out.FragColor = float4(40.0); + return out; +} + diff --git a/reference/shaders-msl/frag/constant-composites.frag b/reference/shaders-msl/frag/constant-composites.frag index d216da6d..dfded3af 100644 --- a/reference/shaders-msl/frag/constant-composites.frag +++ b/reference/shaders-msl/frag/constant-composites.frag @@ -16,7 +16,7 @@ constant Foo _28[2] = {{10.0, 20.0}, {30.0, 40.0}}; struct main0_in { - int line [[user(locn0)]]; + int _line [[user(locn0)]]; }; struct main0_out @@ -43,8 +43,8 @@ fragment main0_out main0(main0_in in [[stage_in]]) main0_out out = {}; float lut[4] = {1.0, 4.0, 3.0, 2.0}; Foo foos[2] = {{10.0, 20.0}, {30.0, 40.0}}; - out.FragColor = float4(lut[in.line]); - out.FragColor += float4(foos[in.line].a * (foos[1 - in.line].a)); + out.FragColor = float4(lut[in._line]); + out.FragColor += float4(foos[in._line].a * (foos[1 - in._line].a)); return out; } diff --git a/reference/shaders-msl/frag/illegal-name-test-0.frag b/reference/shaders-msl/frag/illegal-name-test-0.frag new file mode 100644 index 00000000..6b209b49 --- /dev/null +++ b/reference/shaders-msl/frag/illegal-name-test-0.frag @@ -0,0 +1,21 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 FragColor [[color(0)]]; +}; + +fragment main0_out main0() +{ + main0_out out = {}; + float4 fragment0 = float4(10.0); + float4 compute0 = float4(10.0); + float4 kernel0 = float4(10.0); + float4 vertex0 = float4(10.0); + out.FragColor = ((fragment0 + compute0) + kernel0) + vertex0; + return out; +} + diff --git a/shaders-msl/frag/illegal-name-test-0.frag b/shaders-msl/frag/illegal-name-test-0.frag new file mode 100644 index 00000000..8e6c11d1 --- /dev/null +++ b/shaders-msl/frag/illegal-name-test-0.frag @@ -0,0 +1,12 @@ +#version 450 + +layout(location = 0) out vec4 FragColor; + +void main() +{ + vec4 fragment = vec4(10.0); + vec4 compute = vec4(10.0); + vec4 kernel = vec4(10.0); + vec4 vertex = vec4(10.0); + FragColor = fragment + compute + kernel + vertex; +} diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 2b4680f8..78e4edba 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -1700,7 +1700,7 @@ void CompilerGLSL::replace_illegal_names() "uimageCubeArray", "uint", "uniform", "union", "unsigned", "usampler1D", "usampler1DArray", "usampler2D", "usampler2DArray", "usampler2DMS", "usampler2DMSArray", "usampler2DRect", "usampler3D", "usamplerBuffer", "usamplerCube", "usamplerCubeArray", "using", "uvec2", "uvec3", "uvec4", "varying", "vec2", "vec3", "vec4", "void", "volatile", "volatile", - "while", "writeonly", "texture" + "while", "writeonly", "texture", }; // clang-format on diff --git a/spirv_msl.cpp b/spirv_msl.cpp index eca47cc2..f9b34ffc 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -3262,8 +3262,13 @@ string CompilerMSL::ensure_valid_name(string name, string pfx) // Replace all names that match MSL keywords or Metal Standard Library functions. void CompilerMSL::replace_illegal_names() { + // FIXME: MSL and GLSL are doing two different things here. + // Agree on convention and remove this override. static const unordered_set keywords = { "kernel", + "vertex", + "fragment", + "compute", "bias", }; @@ -3318,6 +3323,8 @@ void CompilerMSL::replace_illegal_names() // Always write this because entry point might have been renamed earlier. meta[entry.first].decoration.alias = ep_name; } + + CompilerGLSL::replace_illegal_names(); } string CompilerMSL::to_qualifiers_glsl(uint32_t id)