From 7693656d68fbecb997f60ab9dc7b587c56a52dce Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Sat, 13 Aug 2016 00:14:52 +0200 Subject: [PATCH 1/3] Change variable names beginning with gl_ in GLSL Using old-school GLSL as input containing code ala "gl_FragColor = whatever" resulted in illegal declarations ala "out vec4 gl_FragColor;". --- spirv_glsl.cpp | 23 +++++++++++++++++++++++ spirv_glsl.hpp | 2 ++ 2 files changed, 25 insertions(+) diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index cfb652b2..2f7469a6 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -1017,6 +1017,27 @@ void CompilerGLSL::emit_uniform(const SPIRVariable &var) statement(layout_for_variable(var), "uniform ", variable_decl(var), ";"); } +void CompilerGLSL::replace_illegal_names() +{ + for (auto &id : ids) + { + if (id.get_type() == TypeVariable) + { + auto &var = id.get(); + auto &type = get(var.basetype); + + if (!is_builtin_variable(var)) + { + auto &m = meta[var.self].decoration; + if (m.alias.compare(0, 3, "gl_") == 0) + { + m.alias = join("_", m.alias); + } + } + } + } +} + void CompilerGLSL::replace_fragment_output(SPIRVariable &var) { auto &m = meta[var.self].decoration; @@ -1101,6 +1122,8 @@ void CompilerGLSL::emit_resources() { auto &execution = get_entry_point(); + replace_illegal_names(); + // Legacy GL uses gl_FragData[], redeclare all fragment outputs // with builtins. if (execution.model == ExecutionModelFragment && is_legacy()) diff --git a/spirv_glsl.hpp b/spirv_glsl.hpp index 524b30b0..a5afaacb 100644 --- a/spirv_glsl.hpp +++ b/spirv_glsl.hpp @@ -308,6 +308,8 @@ protected: // and force recompile. bool check_atomic_image(uint32_t id); + void replace_illegal_names(); + void replace_fragment_output(SPIRVariable &var); void replace_fragment_outputs(); std::string legacy_tex_op(const std::string &op, const SPIRType &imgtype); From 866cb014d10cadbc196fa0b32bf174089f9a20dd Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Sat, 13 Aug 2016 22:56:08 +0200 Subject: [PATCH 2/3] Never try to rename remapped variables Because remapping is used to map to builtins. --- spirv_glsl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 2f7469a6..1e0b1d80 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -1026,7 +1026,7 @@ void CompilerGLSL::replace_illegal_names() auto &var = id.get(); auto &type = get(var.basetype); - if (!is_builtin_variable(var)) + if (!is_builtin_variable(var) && !var.remapped_variable) { auto &m = meta[var.self].decoration; if (m.alias.compare(0, 3, "gl_") == 0) From 3a408608693964c75a8fdb29dd075fd5d155cdec Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Sat, 13 Aug 2016 22:56:53 +0200 Subject: [PATCH 3/3] Remove unused variable in replace_illegal_names --- spirv_glsl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 1e0b1d80..dd47b169 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -1024,7 +1024,6 @@ void CompilerGLSL::replace_illegal_names() if (id.get_type() == TypeVariable) { auto &var = id.get(); - auto &type = get(var.basetype); if (!is_builtin_variable(var) && !var.remapped_variable) {