diff options
Diffstat (limited to 'src/3rdparty/angle/src/compiler/translator/ShaderLang.cpp')
-rw-r--r-- | src/3rdparty/angle/src/compiler/translator/ShaderLang.cpp | 234 |
1 files changed, 185 insertions, 49 deletions
diff --git a/src/3rdparty/angle/src/compiler/translator/ShaderLang.cpp b/src/3rdparty/angle/src/compiler/translator/ShaderLang.cpp index 608237860c..6a801eacfe 100644 --- a/src/3rdparty/angle/src/compiler/translator/ShaderLang.cpp +++ b/src/3rdparty/angle/src/compiler/translator/ShaderLang.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. +// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -11,11 +11,14 @@ #include "GLSLANG/ShaderLang.h" +#include "compiler/translator/Compiler.h" #include "compiler/translator/InitializeDll.h" -#include "compiler/preprocessor/length_limits.h" -#include "compiler/translator/ShHandle.h" +#include "compiler/translator/length_limits.h" #include "compiler/translator/TranslatorHLSL.h" #include "compiler/translator/VariablePacker.h" +#include "angle_gl.h" + +static bool isInitialized = false; // // This is the platform independent interface between an OGL driver @@ -43,14 +46,62 @@ static bool checkMappedNameMaxLength(const ShHandle handle, size_t expectedValue return (expectedValue == mappedNameMaxLength); } +template <typename VarT> +static const sh::ShaderVariable *ReturnVariable(const std::vector<VarT> &infoList, int index) +{ + if (index < 0 || static_cast<size_t>(index) >= infoList.size()) + { + return NULL; + } + + return &infoList[index]; +} + +static const sh::ShaderVariable *GetVariable(const TCompiler *compiler, ShShaderInfo varType, int index) +{ + switch (varType) + { + case SH_ACTIVE_ATTRIBUTES: + return ReturnVariable(compiler->getAttributes(), index); + case SH_ACTIVE_UNIFORMS: + return ReturnVariable(compiler->getExpandedUniforms(), index); + case SH_VARYINGS: + return ReturnVariable(compiler->getExpandedVaryings(), index); + default: + UNREACHABLE(); + return NULL; + } +} + +static ShPrecisionType ConvertPrecision(sh::GLenum precision) +{ + switch (precision) + { + case GL_HIGH_FLOAT: + case GL_HIGH_INT: + return SH_PRECISION_HIGHP; + case GL_MEDIUM_FLOAT: + case GL_MEDIUM_INT: + return SH_PRECISION_MEDIUMP; + case GL_LOW_FLOAT: + case GL_LOW_INT: + return SH_PRECISION_LOWP; + default: + return SH_PRECISION_UNDEFINED; + } +} + // // Driver must call this first, once, before doing any other compiler operations. // Subsequent calls to this function are no-op. // int ShInitialize() { - static const bool kInitialized = InitProcess(); - return kInitialized ? 1 : 0; + if (!isInitialized) + { + isInitialized = InitProcess(); + } + return isInitialized ? 1 : 0; } // @@ -58,7 +109,11 @@ int ShInitialize() // int ShFinalize() { - DetachProcess(); + if (isInitialized) + { + DetachProcess(); + isInitialized = false; + } return 1; } @@ -83,10 +138,17 @@ void ShInitBuiltInResources(ShBuiltInResources* resources) resources->ARB_texture_rectangle = 0; resources->EXT_draw_buffers = 0; resources->EXT_frag_depth = 0; + resources->EXT_shader_texture_lod = 0; // Disable highp precision in fragment shader by default. resources->FragmentPrecisionHigh = 0; + // GLSL ES 3.0 constants. + resources->MaxVertexOutputVectors = 16; + resources->MaxFragmentInputVectors = 15; + resources->MinProgramTexelOffset = -8; + resources->MaxProgramTexelOffset = 7; + // Disable name hashing by default. resources->HashFunction = NULL; @@ -99,7 +161,7 @@ void ShInitBuiltInResources(ShBuiltInResources* resources) // // Driver calls these to create and destroy compiler objects. // -ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec, +ShHandle ShConstructCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output, const ShBuiltInResources* resources) { @@ -128,8 +190,25 @@ void ShDestruct(ShHandle handle) DeleteCompiler(base->getAsCompiler()); } +void ShGetBuiltInResourcesString(const ShHandle handle, size_t outStringLen, char *outString) +{ + if (!handle || !outString) + { + return; + } + + TShHandleBase *base = static_cast<TShHandleBase*>(handle); + TCompiler *compiler = base->getAsCompiler(); + if (!compiler) + { + return; + } + + strncpy(outString, compiler->getBuiltInResourcesString().c_str(), outStringLen); + outString[outStringLen - 1] = '\0'; +} // -// Do an actual compile on the given strings. The result is left +// Do an actual compile on the given strings. The result is left // in the given compile object. // // Return: The return value of ShCompile is really boolean, indicating @@ -171,30 +250,30 @@ void ShGetInfo(const ShHandle handle, ShShaderInfo pname, size_t* params) *params = compiler->getInfoSink().obj.size() + 1; break; case SH_ACTIVE_UNIFORMS: - *params = compiler->getUniforms().size(); + *params = compiler->getExpandedUniforms().size(); break; case SH_ACTIVE_UNIFORM_MAX_LENGTH: - *params = 1 + MAX_SYMBOL_NAME_LEN; + *params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec()); break; case SH_ACTIVE_ATTRIBUTES: - *params = compiler->getAttribs().size(); + *params = compiler->getAttributes().size(); break; case SH_ACTIVE_ATTRIBUTE_MAX_LENGTH: - *params = 1 + MAX_SYMBOL_NAME_LEN; + *params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec()); break; case SH_VARYINGS: - *params = compiler->getVaryings().size(); + *params = compiler->getExpandedVaryings().size(); break; case SH_VARYING_MAX_LENGTH: - *params = 1 + MAX_SYMBOL_NAME_LEN; + *params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec()); break; case SH_MAPPED_NAME_MAX_LENGTH: // Use longer length than MAX_SHORTENED_IDENTIFIER_SIZE to // handle array and struct dereferences. - *params = 1 + MAX_SYMBOL_NAME_LEN; + *params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec()); break; case SH_NAME_MAX_LENGTH: - *params = 1 + MAX_SYMBOL_NAME_LEN; + *params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec()); break; case SH_HASHED_NAME_MAX_LENGTH: if (compiler->getHashFunction() == NULL) { @@ -203,12 +282,22 @@ void ShGetInfo(const ShHandle handle, ShShaderInfo pname, size_t* params) // 64 bits hashing output requires 16 bytes for hex // representation. const char HashedNamePrefix[] = HASHED_NAME_PREFIX; + (void)HashedNamePrefix; *params = 16 + sizeof(HashedNamePrefix); } break; case SH_HASHED_NAMES_COUNT: *params = compiler->getNameMap().size(); break; + case SH_SHADER_VERSION: + *params = compiler->getShaderVersion(); + break; + case SH_RESOURCES_STRING_LENGTH: + *params = compiler->getBuiltInResourcesString().length() + 1; + break; + case SH_OUTPUT_TYPE: + *params = compiler->getOutputType(); + break; default: UNREACHABLE(); } } @@ -250,7 +339,7 @@ void ShGetVariableInfo(const ShHandle handle, int index, size_t* length, int* size, - ShDataType* type, + sh::GLenum* type, ShPrecisionType* precision, int* staticUse, char* name, @@ -267,47 +356,32 @@ void ShGetVariableInfo(const ShHandle handle, if (compiler == 0) return; - const TVariableInfoList& varList = - varType == SH_ACTIVE_ATTRIBUTES ? compiler->getAttribs() : - (varType == SH_ACTIVE_UNIFORMS ? compiler->getUniforms() : - compiler->getVaryings()); - if (index < 0 || index >= static_cast<int>(varList.size())) + const sh::ShaderVariable *varInfo = GetVariable(compiler, varType, index); + if (!varInfo) + { return; - - const TVariableInfo& varInfo = varList[index]; - if (length) *length = varInfo.name.size(); - *size = varInfo.size; - *type = varInfo.type; - switch (varInfo.precision) { - case EbpLow: - *precision = SH_PRECISION_LOWP; - break; - case EbpMedium: - *precision = SH_PRECISION_MEDIUMP; - break; - case EbpHigh: - *precision = SH_PRECISION_HIGHP; - break; - default: - // Some types does not support precision, for example, boolean. - *precision = SH_PRECISION_UNDEFINED; - break; } - *staticUse = varInfo.staticUse ? 1 : 0; + + if (length) *length = varInfo->name.size(); + *size = varInfo->elementCount(); + *type = varInfo->type; + *precision = ConvertPrecision(varInfo->precision); + *staticUse = varInfo->staticUse ? 1 : 0; // This size must match that queried by // SH_ACTIVE_UNIFORM_MAX_LENGTH, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, SH_VARYING_MAX_LENGTH // in ShGetInfo, below. - size_t variableLength = 1 + MAX_SYMBOL_NAME_LEN; + size_t variableLength = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec()); ASSERT(checkVariableMaxLengths(handle, variableLength)); - strncpy(name, varInfo.name.c_str(), variableLength); + strncpy(name, varInfo->name.c_str(), variableLength); name[variableLength - 1] = 0; - if (mappedName) { + if (mappedName) + { // This size must match that queried by // SH_MAPPED_NAME_MAX_LENGTH in ShGetInfo, below. - size_t maxMappedNameLength = 1 + MAX_SYMBOL_NAME_LEN; + size_t maxMappedNameLength = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec()); ASSERT(checkMappedNameMaxLength(handle, maxMappedNameLength)); - strncpy(mappedName, varInfo.mappedName.c_str(), maxMappedNameLength); + strncpy(mappedName, varInfo->mappedName.c_str(), maxMappedNameLength); mappedName[maxMappedNameLength - 1] = 0; } } @@ -369,6 +443,18 @@ void ShGetInfoPointer(const ShHandle handle, ShShaderInfo pname, void** params) case SH_ACTIVE_UNIFORMS_ARRAY: *params = (void*)&translator->getUniforms(); break; + case SH_ACTIVE_INTERFACE_BLOCKS_ARRAY: + *params = (void*)&translator->getInterfaceBlocks(); + break; + case SH_ACTIVE_OUTPUT_VARIABLES_ARRAY: + *params = (void*)&translator->getOutputVariables(); + break; + case SH_ACTIVE_ATTRIBUTES_ARRAY: + *params = (void*)&translator->getAttributes(); + break; + case SH_ACTIVE_VARYINGS_ARRAY: + *params = (void*)&translator->getVaryings(); + break; default: UNREACHABLE(); } } @@ -379,12 +465,62 @@ int ShCheckVariablesWithinPackingLimits( if (varInfoArraySize == 0) return 1; ASSERT(varInfoArray); - TVariableInfoList variables; + std::vector<sh::ShaderVariable> variables; for (size_t ii = 0; ii < varInfoArraySize; ++ii) { - TVariableInfo var(varInfoArray[ii].type, varInfoArray[ii].size); + sh::ShaderVariable var(varInfoArray[ii].type, (sh::GLenum)0, "", varInfoArray[ii].size); variables.push_back(var); } VariablePacker packer; return packer.CheckVariablesWithinPackingLimits(maxVectors, variables) ? 1 : 0; } + +bool ShGetInterfaceBlockRegister(const ShHandle handle, + const char *interfaceBlockName, + unsigned int *indexOut) +{ + if (!handle || !interfaceBlockName || !indexOut) + { + return false; + } + + TShHandleBase* base = static_cast<TShHandleBase*>(handle); + TranslatorHLSL* translator = base->getAsTranslatorHLSL(); + if (!translator) + { + return false; + } + + if (!translator->hasInterfaceBlock(interfaceBlockName)) + { + return false; + } + + *indexOut = translator->getInterfaceBlockRegister(interfaceBlockName); + return true; +} + +bool ShGetUniformRegister(const ShHandle handle, + const char *uniformName, + unsigned int *indexOut) +{ + if (!handle || !uniformName || !indexOut) + { + return false; + } + + TShHandleBase* base = static_cast<TShHandleBase*>(handle); + TranslatorHLSL* translator = base->getAsTranslatorHLSL(); + if (!translator) + { + return false; + } + + if (!translator->hasUniform(uniformName)) + { + return false; + } + + *indexOut = translator->getUniformRegister(uniformName); + return true; +} |