From f537adf6e9970532e2f06276bd547bd9021cbecc Mon Sep 17 00:00:00 2001 From: Bas Zalmstra Date: Thu, 27 Oct 2016 12:51:22 +0200 Subject: [PATCH 1/4] Added all glsl reserved keywords to replace_illegal_names --- spirv_glsl.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index a2346e70..911022c3 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -18,6 +18,7 @@ #include "GLSL.std.450.h" #include #include +#include using namespace spv; using namespace spirv_cross; @@ -1109,6 +1110,8 @@ void CompilerGLSL::emit_specialization_constant(const SPIRConstant &constant) void CompilerGLSL::replace_illegal_names() { + std::array keywords = {"active","asm","atomic_uint","attribute","bool","break","bvec2","bvec3","bvec4","case","cast","centroid","class","coherent","common","const","continue","default","discard","dmat2","dmat2x2","dmat2x3","dmat2x4","dmat3","dmat3x2","dmat3x3","dmat3x4","dmat4","dmat4x2","dmat4x3","dmat4x4","do","double","dvec2","dvec3","dvec4","else","enum","extern","external","false","filter","fixed","flat","float","for","fvec2","fvec3","fvec4","goto","half","highp","hvec2","hvec3","hvec4","if","iimage1D","iimage1DArray","iimage2D","iimage2DArray","iimage2DMS","iimage2DMSArray","iimage2DRect","iimage3D","iimageBuffer","iimageCube","iimageCubeArray","image1D","image1DArray","image2D","image2DArray","image2DMS","image2DMSArray","image2DRect","image3D","imageBuffer","imageCube","imageCubeArray","in","inline","inout","input","int","interface","invariant","isampler1D","isampler1DArray","isampler2D","isampler2DArray","isampler2DMS","isampler2DMSArray","isampler2DRect","isampler3D","isamplerBuffer","isamplerCube","isamplerCubeArray","ivec2","ivec3","ivec4","layout","long","lowp","mat2","mat2x2","mat2x3","mat2x4","mat3","mat3x2","mat3x3","mat3x4","mat4","mat4x2","mat4x3","mat4x4","mediump","namespace","noinline","noperspective","out","output","packed","partition","patch","precision","public","readonly","resource","restrict","return","row_major","sample","sampler1D","sampler1DArray","sampler1DArrayShadow","sampler1DShadow","sampler2D","sampler2DArray","sampler2DArrayShadow","sampler2DMS","sampler2DMSArray","sampler2DRect","sampler2DRectShadow","sampler2DShadow","sampler3D","sampler3DRect","samplerBuffer","samplerCube","samplerCubeArray","samplerCubeArrayShadow","samplerCubeShadow","short","sizeof","smooth","static","struct","subroutine","superp","switch","template","this","true","typedef","uimage1D","uimage1DArray","uimage2D","uimage2DArray","uimage2DMS","uimage2DMSArray","uimage2DRect","uimage3D","uimageBuffer","uimageCube","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"}; + for (auto &id : ids) { if (id.get_type() == TypeVariable) @@ -1117,7 +1120,8 @@ void CompilerGLSL::replace_illegal_names() if (!is_hidden_variable(var)) { auto &m = meta[var.self].decoration; - if (m.alias.compare(0, 3, "gl_") == 0) + if (m.alias.compare(0, 3, "gl_") == 0 || + std::find(keywords.begin(), keywords.end(), m.alias) != keywords.end()) m.alias = join("_", m.alias); } } From e042eab551fe2c94b2f90fd0e325357df6f69199 Mon Sep 17 00:00:00 2001 From: Bas Zalmstra Date: Thu, 27 Oct 2016 13:48:15 +0200 Subject: [PATCH 2/4] Changed keywords to const static unordered_set and indented the keywords --- spirv_glsl.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 911022c3..6dec4ec8 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -18,7 +18,6 @@ #include "GLSL.std.450.h" #include #include -#include using namespace spv; using namespace spirv_cross; @@ -1110,7 +1109,28 @@ void CompilerGLSL::emit_specialization_constant(const SPIRConstant &constant) void CompilerGLSL::replace_illegal_names() { - std::array keywords = {"active","asm","atomic_uint","attribute","bool","break","bvec2","bvec3","bvec4","case","cast","centroid","class","coherent","common","const","continue","default","discard","dmat2","dmat2x2","dmat2x3","dmat2x4","dmat3","dmat3x2","dmat3x3","dmat3x4","dmat4","dmat4x2","dmat4x3","dmat4x4","do","double","dvec2","dvec3","dvec4","else","enum","extern","external","false","filter","fixed","flat","float","for","fvec2","fvec3","fvec4","goto","half","highp","hvec2","hvec3","hvec4","if","iimage1D","iimage1DArray","iimage2D","iimage2DArray","iimage2DMS","iimage2DMSArray","iimage2DRect","iimage3D","iimageBuffer","iimageCube","iimageCubeArray","image1D","image1DArray","image2D","image2DArray","image2DMS","image2DMSArray","image2DRect","image3D","imageBuffer","imageCube","imageCubeArray","in","inline","inout","input","int","interface","invariant","isampler1D","isampler1DArray","isampler2D","isampler2DArray","isampler2DMS","isampler2DMSArray","isampler2DRect","isampler3D","isamplerBuffer","isamplerCube","isamplerCubeArray","ivec2","ivec3","ivec4","layout","long","lowp","mat2","mat2x2","mat2x3","mat2x4","mat3","mat3x2","mat3x3","mat3x4","mat4","mat4x2","mat4x3","mat4x4","mediump","namespace","noinline","noperspective","out","output","packed","partition","patch","precision","public","readonly","resource","restrict","return","row_major","sample","sampler1D","sampler1DArray","sampler1DArrayShadow","sampler1DShadow","sampler2D","sampler2DArray","sampler2DArrayShadow","sampler2DMS","sampler2DMSArray","sampler2DRect","sampler2DRectShadow","sampler2DShadow","sampler3D","sampler3DRect","samplerBuffer","samplerCube","samplerCubeArray","samplerCubeArrayShadow","samplerCubeShadow","short","sizeof","smooth","static","struct","subroutine","superp","switch","template","this","true","typedef","uimage1D","uimage1DArray","uimage2D","uimage2DArray","uimage2DMS","uimage2DMSArray","uimage2DRect","uimage3D","uimageBuffer","uimageCube","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"}; + static const std::unordered_set keywords = {"active","asm","atomic_uint","attribute","bool","break", + "bvec2","bvec3","bvec4","case","cast","centroid","class","coherent","common","const","continue","default","discard", + "dmat2","dmat2x2","dmat2x3","dmat2x4","dmat3","dmat3x2","dmat3x3","dmat3x4","dmat4","dmat4x2","dmat4x3","dmat4x4", + "do","double","dvec2","dvec3","dvec4","else","enum","extern","external","false","filter","fixed","flat","float", + "for","fvec2","fvec3","fvec4","goto","half","highp","hvec2","hvec3","hvec4","if","iimage1D","iimage1DArray", + "iimage2D","iimage2DArray","iimage2DMS","iimage2DMSArray","iimage2DRect","iimage3D","iimageBuffer","iimageCube", + "iimageCubeArray","image1D","image1DArray","image2D","image2DArray","image2DMS","image2DMSArray","image2DRect", + "image3D","imageBuffer","imageCube","imageCubeArray","in","inline","inout","input","int","interface","invariant", + "isampler1D","isampler1DArray","isampler2D","isampler2DArray","isampler2DMS","isampler2DMSArray","isampler2DRect", + "isampler3D","isamplerBuffer","isamplerCube","isamplerCubeArray","ivec2","ivec3","ivec4","layout","long","lowp", + "mat2","mat2x2","mat2x3","mat2x4","mat3","mat3x2","mat3x3","mat3x4","mat4","mat4x2","mat4x3","mat4x4","mediump", + "namespace","noinline","noperspective","out","output","packed","partition","patch","precision","public","readonly", + "resource","restrict","return","row_major","sample","sampler1D","sampler1DArray","sampler1DArrayShadow", + "sampler1DShadow","sampler2D","sampler2DArray","sampler2DArrayShadow","sampler2DMS","sampler2DMSArray", + "sampler2DRect","sampler2DRectShadow","sampler2DShadow","sampler3D","sampler3DRect","samplerBuffer", + "samplerCube","samplerCubeArray","samplerCubeArrayShadow","samplerCubeShadow","short","sizeof","smooth","static", + "struct","subroutine","superp","switch","template","this","true","typedef","uimage1D","uimage1DArray","uimage2D", + "uimage2DArray","uimage2DMS","uimage2DMSArray","uimage2DRect","uimage3D","uimageBuffer","uimageCube", + "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"}; for (auto &id : ids) { @@ -1121,7 +1141,7 @@ void CompilerGLSL::replace_illegal_names() { auto &m = meta[var.self].decoration; if (m.alias.compare(0, 3, "gl_") == 0 || - std::find(keywords.begin(), keywords.end(), m.alias) != keywords.end()) + keywords.find(m.alias) != keywords.end()) m.alias = join("_", m.alias); } } From 48636b4af8d781659824edce9ed93d32a5535c2d Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Thu, 27 Oct 2016 13:55:47 +0200 Subject: [PATCH 3/4] Fix style nits from last merge. --- spirv_cross.cpp | 5 +++-- spirv_glsl.cpp | 51 ++++++++++++++++++++++++++----------------------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/spirv_cross.cpp b/spirv_cross.cpp index af348c9c..f29af87e 100644 --- a/spirv_cross.cpp +++ b/spirv_cross.cpp @@ -1106,8 +1106,9 @@ void Compiler::parse(const Instruction &instruction) case OpEntryPoint: { - auto itr = entry_points.insert(make_pair(ops[1], SPIREntryPoint(ops[1], static_cast(ops[0]), - extract_string(spirv, instruction.offset + 2)))); + auto itr = + entry_points.insert(make_pair(ops[1], SPIREntryPoint(ops[1], static_cast(ops[0]), + extract_string(spirv, instruction.offset + 2)))); auto &e = itr.first->second; // Strings need nul-terminator and consume the whole word. diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 6dec4ec8..7341b95e 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -1109,28 +1109,32 @@ void CompilerGLSL::emit_specialization_constant(const SPIRConstant &constant) void CompilerGLSL::replace_illegal_names() { - static const std::unordered_set keywords = {"active","asm","atomic_uint","attribute","bool","break", - "bvec2","bvec3","bvec4","case","cast","centroid","class","coherent","common","const","continue","default","discard", - "dmat2","dmat2x2","dmat2x3","dmat2x4","dmat3","dmat3x2","dmat3x3","dmat3x4","dmat4","dmat4x2","dmat4x3","dmat4x4", - "do","double","dvec2","dvec3","dvec4","else","enum","extern","external","false","filter","fixed","flat","float", - "for","fvec2","fvec3","fvec4","goto","half","highp","hvec2","hvec3","hvec4","if","iimage1D","iimage1DArray", - "iimage2D","iimage2DArray","iimage2DMS","iimage2DMSArray","iimage2DRect","iimage3D","iimageBuffer","iimageCube", - "iimageCubeArray","image1D","image1DArray","image2D","image2DArray","image2DMS","image2DMSArray","image2DRect", - "image3D","imageBuffer","imageCube","imageCubeArray","in","inline","inout","input","int","interface","invariant", - "isampler1D","isampler1DArray","isampler2D","isampler2DArray","isampler2DMS","isampler2DMSArray","isampler2DRect", - "isampler3D","isamplerBuffer","isamplerCube","isamplerCubeArray","ivec2","ivec3","ivec4","layout","long","lowp", - "mat2","mat2x2","mat2x3","mat2x4","mat3","mat3x2","mat3x3","mat3x4","mat4","mat4x2","mat4x3","mat4x4","mediump", - "namespace","noinline","noperspective","out","output","packed","partition","patch","precision","public","readonly", - "resource","restrict","return","row_major","sample","sampler1D","sampler1DArray","sampler1DArrayShadow", - "sampler1DShadow","sampler2D","sampler2DArray","sampler2DArrayShadow","sampler2DMS","sampler2DMSArray", - "sampler2DRect","sampler2DRectShadow","sampler2DShadow","sampler3D","sampler3DRect","samplerBuffer", - "samplerCube","samplerCubeArray","samplerCubeArrayShadow","samplerCubeShadow","short","sizeof","smooth","static", - "struct","subroutine","superp","switch","template","this","true","typedef","uimage1D","uimage1DArray","uimage2D", - "uimage2DArray","uimage2DMS","uimage2DMSArray","uimage2DRect","uimage3D","uimageBuffer","uimageCube", - "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"}; + // clang-format off + static const unordered_set keywords = { + "active", "asm", "atomic_uint", "attribute", "bool", "break", + "bvec2", "bvec3", "bvec4", "case", "cast", "centroid", "class", "coherent", "common", "const", "continue", "default", "discard", + "dmat2", "dmat2x2", "dmat2x3", "dmat2x4", "dmat3", "dmat3x2", "dmat3x3", "dmat3x4", "dmat4", "dmat4x2", "dmat4x3", "dmat4x4", + "do", "double", "dvec2", "dvec3", "dvec4", "else", "enum", "extern", "external", "false", "filter", "fixed", "flat", "float", + "for", "fvec2", "fvec3", "fvec4", "goto", "half", "highp", "hvec2", "hvec3", "hvec4", "if", "iimage1D", "iimage1DArray", + "iimage2D", "iimage2DArray", "iimage2DMS", "iimage2DMSArray", "iimage2DRect", "iimage3D", "iimageBuffer", "iimageCube", + "iimageCubeArray", "image1D", "image1DArray", "image2D", "image2DArray", "image2DMS", "image2DMSArray", "image2DRect", + "image3D", "imageBuffer", "imageCube", "imageCubeArray", "in", "inline", "inout", "input", "int", "interface", "invariant", + "isampler1D", "isampler1DArray", "isampler2D", "isampler2DArray", "isampler2DMS", "isampler2DMSArray", "isampler2DRect", + "isampler3D", "isamplerBuffer", "isamplerCube", "isamplerCubeArray", "ivec2", "ivec3", "ivec4", "layout", "long", "lowp", + "mat2", "mat2x2", "mat2x3", "mat2x4", "mat3", "mat3x2", "mat3x3", "mat3x4", "mat4", "mat4x2", "mat4x3", "mat4x4", "mediump", + "namespace", "noinline", "noperspective", "out", "output", "packed", "partition", "patch", "precision", "public", "readonly", + "resource", "restrict", "return", "row_major", "sample", "sampler1D", "sampler1DArray", "sampler1DArrayShadow", + "sampler1DShadow", "sampler2D", "sampler2DArray", "sampler2DArrayShadow", "sampler2DMS", "sampler2DMSArray", + "sampler2DRect", "sampler2DRectShadow", "sampler2DShadow", "sampler3D", "sampler3DRect", "samplerBuffer", + "samplerCube", "samplerCubeArray", "samplerCubeArrayShadow", "samplerCubeShadow", "short", "sizeof", "smooth", "static", + "struct", "subroutine", "superp", "switch", "template", "this", "true", "typedef", "uimage1D", "uimage1DArray", "uimage2D", + "uimage2DArray", "uimage2DMS", "uimage2DMSArray", "uimage2DRect", "uimage3D", "uimageBuffer", "uimageCube", + "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" + }; + // clang-format on for (auto &id : ids) { @@ -1140,8 +1144,7 @@ void CompilerGLSL::replace_illegal_names() if (!is_hidden_variable(var)) { auto &m = meta[var.self].decoration; - if (m.alias.compare(0, 3, "gl_") == 0 || - keywords.find(m.alias) != keywords.end()) + if (m.alias.compare(0, 3, "gl_") == 0 || keywords.find(m.alias) != end(keywords)) m.alias = join("_", m.alias); } } From 03abf6a534ad4125de861ba9bfac22d880868835 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Thu, 27 Oct 2016 16:27:15 +0200 Subject: [PATCH 4/4] Fix formatting after merge. --- spirv_msl.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spirv_msl.cpp b/spirv_msl.cpp index 281b92d5..d97d87c7 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -525,8 +525,9 @@ void CompilerMSL::emit_msl_defines() statement("#define dFdy dfdy"); statement("#define dFdx dfdy"); statement("#define atan(y,x) atan2((y),(x))"); - statement("#define greaterThan(a,b) ((a)>(b))"); - statement("inline uint2 imageSize(thread const texture2d& tex) { return uint2(tex.get_width(), tex.get_height()); }"); + statement("#define greaterThan(a,b) ((a)>(b))"); + statement("inline uint2 imageSize(thread const texture2d& tex) { return uint2(tex.get_width(), " + "tex.get_height()); }"); statement(""); }