From 80c394160a997768d2f8a1c868ef63441bec3c42 Mon Sep 17 00:00:00 2001 From: Lubos Lenco Date: Sat, 17 Sep 2016 14:33:16 +0200 Subject: [PATCH] Legacy GLES extensions. --- spirv_glsl.cpp | 39 ++++++++++++++++++++++++++++++++------- spirv_glsl.hpp | 5 +++++ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 34323ef..82f1f76 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -1059,6 +1059,9 @@ void CompilerGLSL::replace_fragment_output(SPIRVariable &var) if (location != 0) throw CompilerError("Arrayed output variable used, but location is not 0. " "This is unimplemented in SPIRV-Cross."); + + if (is_legacy_es()) + require_extension("GL_EXT_draw_buffers"); } else throw CompilerError("Array-of-array output variable used. This cannot be implemented in legacy GLSL."); @@ -1823,11 +1826,21 @@ string CompilerGLSL::legacy_tex_op(const std::string &op, const SPIRType &imgtyp if (op == "texture") return join("texture", type); else if (op == "textureLod") - return join("texture", type, "Lod"); + { + if (is_legacy_es()) + return join("texture", type, "LodEXT"); + else + return join("texture", type, "Lod"); + } else if (op == "textureProj") return join("texture", type, "Proj"); else if (op == "textureProjLod") - return join("texture", type, "ProjLod"); + { + if (is_legacy_es()) + return join("texture", type, "ProjLodEXT"); + else + return join("texture", type, "ProjLod"); + } else throw CompilerError(join("Unsupported legacy texture op: ", op)); } @@ -3719,14 +3732,20 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction) // Derivatives case OpDPdx: UFOP(dFdx); + if (is_legacy_es()) + require_extension("GL_OES_standard_derivatives"); break; case OpDPdy: UFOP(dFdy); + if (is_legacy_es()) + require_extension("GL_OES_standard_derivatives"); break; case OpFwidth: UFOP(fwidth); + if (is_legacy_es()) + require_extension("GL_OES_standard_derivatives"); break; // Bitfield @@ -3894,14 +3913,20 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction) break; // Textures - case OpImageSampleImplicitLod: case OpImageSampleExplicitLod: - case OpImageSampleProjImplicitLod: case OpImageSampleProjExplicitLod: - case OpImageSampleDrefImplicitLod: case OpImageSampleDrefExplicitLod: - case OpImageSampleProjDrefImplicitLod: case OpImageSampleProjDrefExplicitLod: + { + emit_texture_op(instruction); + if (is_legacy_es()) + require_extension("GL_EXT_shader_texture_lod"); + break; + } + case OpImageSampleImplicitLod: + case OpImageSampleProjImplicitLod: + case OpImageSampleDrefImplicitLod: + case OpImageSampleProjDrefImplicitLod: case OpImageFetch: case OpImageGather: case OpImageDrefGather: @@ -4481,7 +4506,7 @@ string CompilerGLSL::image_type_glsl(const SPIRType &type) if (type.image.arrayed) { if (!options.es && options.version < 130) - require_extension("GL_EXT_texture_array"); + require_extension("GL_EXT_texture_array"); res += "Array"; } if (type.image.depth) diff --git a/spirv_glsl.hpp b/spirv_glsl.hpp index 3e1eaf2..9c557bd 100644 --- a/spirv_glsl.hpp +++ b/spirv_glsl.hpp @@ -337,6 +337,11 @@ protected: return (options.es && options.version < 300) || (!options.es && options.version < 130); } + inline bool is_legacy_es() const + { + return (options.es && options.version < 300); + } + bool args_will_forward(uint32_t id, const uint32_t *args, uint32_t num_args, bool pure); void register_call_out_argument(uint32_t id); void register_impure_function_call();