<commit_before>/*
 * GLSLExtensionAgent.cpp
 * 
 * This file is part of the XShaderCompiler project (Copyright (c) 2014-2017 by <NAME>)
 * See "LICENSE.txt" for license information.
 */

#include "GLSLExtensionAgent.h"
#include "AST.h"
#include "Exception.h"
#include <algorithm>


namespace Xsc
{


/*
 * Internal GL ARB extension descriptions
 */

static const GLSLExtension GLSLEXT_GL_EXT_gpu_shader4               { "GL_EXT_gpu_shader4",                 OutputShaderVersion::GLSL130 };
static const GLSLExtension GLSLEXT_GL_ARB_uniform_buffer_object     { "GL_ARB_uniform_buffer_object",       OutputShaderVersion::GLSL140 };
static const GLSLExtension GLSLEXT_GL_ARB_texture_multisample       { "GL_ARB_texture_multisample",         OutputShaderVersion::GLSL150 };
static const GLSLExtension GLSLEXT_GL_ARB_texture_query_lod         { "GL_ARB_texture_query_lod",           OutputShaderVersion::GLSL400 };
static const GLSLExtension GLSLEXT_GL_ARB_fragment_coord_conventions{ "GL_ARB_fragment_coord_conventions",  OutputShaderVersion::GLSL150 };
static const GLSLExtension GLSLEXT_GL_ARB_gpu_shader5               { "GL_ARB_gpu_shader5",                 OutputShaderVersion::GLSL330 };
static const GLSLExtension GLSLEXT_GL_ARB_derivative_control        { "GL_ARB_derivative_control",          OutputShaderVersion::GLSL450 };
static const GLSLExtension GLSLEXT_GL_ARB_shading_language_420pack  { "GL_ARB_shading_language_420pack",    OutputShaderVersion::GLSL420 };
static const GLSLExtension GLSLEXT_GL_ARB_shader_image_load_store   { "GL_ARB_shader_image_load_store",     OutputShaderVersion::GLSL420 };
static const GLSLExtension GLSLEXT_GL_ARB_arrays_of_arrays          { "GL_ARB_arrays_of_arrays",            OutputShaderVersion::GLSL430 };
static const GLSLExtension GLSLEXT_GL_ARB_enhanced_layouts          { "GL_ARB_enhanced_layouts",            OutputShaderVersion::GLSL430 };
static const GLSLExtension GLSLEXT_GL_ARB_gpu_shader_int64          { "GL_ARB_gpu_shader_int64",            OutputShaderVersion::GLSL450 };


/*
 * GLSLExtensionAgent class
 */

GLSLExtensionAgent::GLSLExtensionAgent()
{
    /* Establish intrinsic-to-extension map */
    intrinsicExtMap_ = std::map<Intrinsic, GLSLExtension>
    {
        { Intrinsic::AsDouble,                  GLSLEXT_GL_ARB_gpu_shader_int64   },
        { Intrinsic::AsFloat,                   GLSLEXT_GL_ARB_gpu_shader5        },
        { Intrinsic::AsInt,                     GLSLEXT_GL_ARB_gpu_shader5        },
        { Intrinsic::AsUInt_1,                  GLSLEXT_GL_ARB_gpu_shader5        },
        { Intrinsic::DDXCoarse,                 GLSLEXT_GL_ARB_derivative_control },
        { Intrinsic::DDXFine,                   GLSLEXT_GL_ARB_derivative_control },
        { Intrinsic::DDYCoarse,                 GLSLEXT_GL_ARB_derivative_control },
        { Intrinsic::DDYFine,                   GLSLEXT_GL_ARB_derivative_control },
        { Intrinsic::Texture_QueryLod,          GLSLEXT_GL_ARB_texture_query_lod  },
        { Intrinsic::Texture_QueryLodUnclamped, GLSLEXT_GL_ARB_texture_query_lod  },
    };
}

static OutputShaderVersion GetMinGLSLVersionForTarget(const ShaderTarget shaderTarget)
{
    switch (shaderTarget)
    {
        case ShaderTarget::Undefined:                       break;
        case ShaderTarget::VertexShader:                    return OutputShaderVersion::GLSL130; // actually 110, but this compiler does not support GLSL < 130
        case ShaderTarget::TessellationControlShader:       return OutputShaderVersion::GLSL400;
        case ShaderTarget::TessellationEvaluationShader:    return OutputShaderVersion::GLSL400;
        case ShaderTarget::GeometryShader:                  return OutputShaderVersion::GLSL150;
        case ShaderTarget::FragmentShader:                  return OutputShaderVersion::GLSL130; // actually 110, but this compiler does not support GLSL < 130
        case ShaderTarget::ComputeShader:                   return OutputShaderVersion::GLSL430; // actually 420, but only 430 supports local work group size
    }
    return OutputShaderVersion::GLSL130; // GLSL 110 and 120 are deprecated, so only output them when they are set explicitly
}

std::set<std::string> GLSLExtensionAgent::DetermineRequiredExtensions(
    Program& program, OutputShaderVersion& targetGLSLVersion,
    const ShaderTarget shaderTarget, bool allowExtensions, bool explicitBinding)<commit_msg>Added "GL_ARB_gpu_shader_fp64" to GLSL extensions (for "ldexp" intrinsic).<commit_after>/*
 * GLSLExtensionAgent.cpp
 * 
 * This file is part of the XShaderCompiler project (Copyright (c) 2014-2017 by <NAME>)
 * See "LICENSE.txt" for license information.
 */

#include "GLSLExtensionAgent.h"
#include "AST.h"
#include "Exception.h"
#include <algorithm>


namespace Xsc
{


/*
 * Internal GL ARB extension descriptions
 */

static const GLSLExtension GLSLEXT_GL_EXT_gpu_shader4               { "GL_EXT_gpu_shader4",                 OutputShaderVersion::GLSL130 };
static const GLSLExtension GLSLEXT_GL_ARB_uniform_buffer_object     { "GL_ARB_uniform_buffer_object",       OutputShaderVersion::GLSL140 };
static const GLSLExtension GLSLEXT_GL_ARB_texture_multisample       { "GL_ARB_texture_multisample",         OutputShaderVersion::GLSL150 };
static const GLSLExtension GLSLEXT_GL_ARB_fragment_coord_conventions{ "GL_ARB_fragment_coord_conventions",  OutputShaderVersion::GLSL150 };
static const GLSLExtension GLSLEXT_GL_ARB_gpu_shader5               { "GL_ARB_gpu_shader5",                 OutputShaderVersion::GLSL330 };
static const GLSLExtension GLSLEXT_GL_ARB_texture_query_lod         { "GL_ARB_texture_query_lod",           OutputShaderVersion::GLSL400 };
static const GLSLExtension GLSLEXT_GL_ARB_gpu_shader_fp64           { "GL_ARB_gpu_shader_fp64",             OutputShaderVersion::GLSL400 };
static const GLSLExtension GLSLEXT_GL_ARB_derivative_control        { "GL_ARB_derivative_control",          OutputShaderVersion::GLSL450 };
static const GLSLExtension GLSLEXT_GL_ARB_shading_language_420pack  { "GL_ARB_shading_language_420pack",    OutputShaderVersion::GLSL420 };
static const GLSLExtension GLSLEXT_GL_ARB_shader_image_load_store   { "GL_ARB_shader_image_load_store",     OutputShaderVersion::GLSL420 };
static const GLSLExtension GLSLEXT_GL_ARB_arrays_of_arrays          { "GL_ARB_arrays_of_arrays",            OutputShaderVersion::GLSL430 };
static const GLSLExtension GLSLEXT_GL_ARB_enhanced_layouts          { "GL_ARB_enhanced_layouts",            OutputShaderVersion::GLSL430 };
static const GLSLExtension GLSLEXT_GL_ARB_gpu_shader_int64          { "GL_ARB_gpu_shader_int64",            OutputShaderVersion::GLSL450 };


/*
 * GLSLExtensionAgent class
 */

GLSLExtensionAgent::GLSLExtensionAgent()
{
    /* Establish intrinsic-to-extension map */
    intrinsicExtMap_ = std::map<Intrinsic, GLSLExtension>
    {
        { Intrinsic::AsDouble,                  GLSLEXT_GL_ARB_gpu_shader_int64   },
        { Intrinsic::AsFloat,                   GLSLEXT_GL_ARB_gpu_shader5        },
        { Intrinsic::AsInt,                     GLSLEXT_GL_ARB_gpu_shader5        },
        { Intrinsic::AsUInt_1,                  GLSLEXT_GL_ARB_gpu_shader5        },
        { Intrinsic::DDXCoarse,                 GLSLEXT_GL_ARB_derivative_control },
        { Intrinsic::DDXFine,                   GLSLEXT_GL_ARB_derivative_control },
        { Intrinsic::DDYCoarse,                 GLSLEXT_GL_ARB_derivative_control },
        { Intrinsic::DDYFine,                   GLSLEXT_GL_ARB_derivative_control },
        { Intrinsic::Texture_QueryLod,          GLSLEXT_GL_ARB_texture_query_lod  },
        { Intrinsic::Texture_QueryLodUnclamped, GLSLEXT_GL_ARB_texture_query_lod  },
        { Intrinsic::LdExp,                     GLSLEXT_GL_ARB_gpu_shader_fp64    },
    };
}

static OutputShaderVersion GetMinGLSLVersionForTarget(const ShaderTarget shaderTarget)
{
    switch (shaderTarget)
    {
        case ShaderTarget::Undefined:                       break;
        case ShaderTarget::VertexShader:                    return OutputShaderVersion::GLSL130; // actually 110, but this compiler does not support GLSL < 130
        case ShaderTarget::TessellationControlShader:       return OutputShaderVersion::GLSL400;
        case ShaderTarget::TessellationEvaluationShader:    return OutputShaderVersion::GLSL400;
        case ShaderTarget::GeometryShader:                  return OutputShaderVersion::GLSL150;
        case ShaderTarget::FragmentShader:                  return OutputShaderVersion::GLSL130; // actually 110, but this compiler does not support GLSL < 130
        case ShaderTarget::ComputeShader:                   return OutputShaderVersion::GLSL430; // actually 420, but only 430 supports local work group size
    }
    return OutputShaderVersion::GLSL130; // GLSL 110 and 120 are deprecated, so only output them when they are set explicitly
}

std::set<std::string> GLSLExtensionAgent::DetermineRequiredExtensions(
    Program& program, OutputShaderVersion& targetGLSLVersion,
    const ShaderTarget shaderTarget, bool allowExtensions, bool explicitBinding)
{'fraction_non_alphanumeric': 0.0699031263760458, 'fraction_numerical': 0.025209158960810215, 'mean_word_length': 3.4317073170731707, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3826409', 'n_tokens_mistral': 2934, 'n_tokens_neox': 2767, 'n_words': 474}