diff options
Diffstat (limited to 'src/3rdparty/angle/src/compiler/translator/ShaderLang.cpp')
-rw-r--r-- | src/3rdparty/angle/src/compiler/translator/ShaderLang.cpp | 426 |
1 files changed, 310 insertions, 116 deletions
diff --git a/src/3rdparty/angle/src/compiler/translator/ShaderLang.cpp b/src/3rdparty/angle/src/compiler/translator/ShaderLang.cpp index e257f93e48..eeb13f2ec0 100644 --- a/src/3rdparty/angle/src/compiler/translator/ShaderLang.cpp +++ b/src/3rdparty/angle/src/compiler/translator/ShaderLang.cpp @@ -16,10 +16,13 @@ #include "compiler/translator/length_limits.h" #ifdef ANGLE_ENABLE_HLSL #include "compiler/translator/TranslatorHLSL.h" -#endif // ANGLE_ENABLE_HLSL +#endif // ANGLE_ENABLE_HLSL #include "compiler/translator/VariablePacker.h" #include "angle_gl.h" +namespace sh +{ + namespace { @@ -34,70 +37,109 @@ template <typename VarT> const std::vector<VarT> *GetVariableList(const TCompiler *compiler); template <> -const std::vector<sh::Uniform> *GetVariableList(const TCompiler *compiler) +const std::vector<Uniform> *GetVariableList(const TCompiler *compiler) { return &compiler->getUniforms(); } template <> -const std::vector<sh::Varying> *GetVariableList(const TCompiler *compiler) +const std::vector<Varying> *GetVariableList(const TCompiler *compiler) { - return &compiler->getVaryings(); + switch (compiler->getShaderType()) + { + case GL_VERTEX_SHADER: + return &compiler->getOutputVaryings(); + case GL_FRAGMENT_SHADER: + return &compiler->getInputVaryings(); + case GL_COMPUTE_SHADER: + ASSERT(compiler->getOutputVaryings().empty() && compiler->getInputVaryings().empty()); + return &compiler->getOutputVaryings(); + // Since geometry shaders have both input and output varyings, we shouldn't call GetVaryings + // on a geometry shader. + default: + return nullptr; + } } template <> -const std::vector<sh::Attribute> *GetVariableList(const TCompiler *compiler) +const std::vector<Attribute> *GetVariableList(const TCompiler *compiler) { return &compiler->getAttributes(); } template <> -const std::vector<sh::OutputVariable> *GetVariableList(const TCompiler *compiler) +const std::vector<OutputVariable> *GetVariableList(const TCompiler *compiler) { return &compiler->getOutputVariables(); } template <> -const std::vector<sh::InterfaceBlock> *GetVariableList(const TCompiler *compiler) +const std::vector<InterfaceBlock> *GetVariableList(const TCompiler *compiler) { return &compiler->getInterfaceBlocks(); } -template <typename VarT> -const std::vector<VarT> *GetShaderVariables(const ShHandle handle) +TCompiler *GetCompilerFromHandle(ShHandle handle) { if (!handle) { - return NULL; + return nullptr; } - TShHandleBase* base = static_cast<TShHandleBase*>(handle); - TCompiler* compiler = base->getAsCompiler(); + TShHandleBase *base = static_cast<TShHandleBase *>(handle); + return base->getAsCompiler(); +} + +template <typename VarT> +const std::vector<VarT> *GetShaderVariables(const ShHandle handle) +{ + TCompiler *compiler = GetCompilerFromHandle(handle); if (!compiler) { - return NULL; + return nullptr; } return GetVariableList<VarT>(compiler); } -TCompiler *GetCompilerFromHandle(ShHandle handle) -{ - if (!handle) - return NULL; - TShHandleBase *base = static_cast<TShHandleBase *>(handle); - return base->getAsCompiler(); -} - #ifdef ANGLE_ENABLE_HLSL TranslatorHLSL *GetTranslatorHLSLFromHandle(ShHandle handle) { if (!handle) - return NULL; + return nullptr; TShHandleBase *base = static_cast<TShHandleBase *>(handle); return base->getAsTranslatorHLSL(); } -#endif // ANGLE_ENABLE_HLSL +#endif // ANGLE_ENABLE_HLSL + +GLenum GetGeometryShaderPrimitiveTypeEnum(sh::TLayoutPrimitiveType primitiveType) +{ + switch (primitiveType) + { + case EptPoints: + return GL_POINTS; + case EptLines: + return GL_LINES; + case EptLinesAdjacency: + return GL_LINES_ADJACENCY_EXT; + case EptTriangles: + return GL_TRIANGLES; + case EptTrianglesAdjacency: + return GL_TRIANGLES_ADJACENCY_EXT; + + case EptLineStrip: + return GL_LINE_STRIP; + case EptTriangleStrip: + return GL_TRIANGLE_STRIP; + + case EptUndefined: + return GL_INVALID_VALUE; + + default: + UNREACHABLE(); + return GL_INVALID_VALUE; + } +} } // anonymous namespace @@ -105,7 +147,7 @@ TranslatorHLSL *GetTranslatorHLSLFromHandle(ShHandle handle) // Driver must call this first, once, before doing any other compiler operations. // Subsequent calls to this function are no-op. // -bool ShInitialize() +bool Initialize() { if (!isInitialized) { @@ -117,7 +159,7 @@ bool ShInitialize() // // Cleanup symbol tables // -bool ShFinalize() +bool Finalize() { if (isInitialized) { @@ -130,33 +172,38 @@ bool ShFinalize() // // Initialize built-in resources with minimum expected values. // -void ShInitBuiltInResources(ShBuiltInResources* resources) +void InitBuiltInResources(ShBuiltInResources *resources) { // Make comparable. memset(resources, 0, sizeof(*resources)); // Constants. - resources->MaxVertexAttribs = 8; - resources->MaxVertexUniformVectors = 128; - resources->MaxVaryingVectors = 8; - resources->MaxVertexTextureImageUnits = 0; + resources->MaxVertexAttribs = 8; + resources->MaxVertexUniformVectors = 128; + resources->MaxVaryingVectors = 8; + resources->MaxVertexTextureImageUnits = 0; resources->MaxCombinedTextureImageUnits = 8; - resources->MaxTextureImageUnits = 8; - resources->MaxFragmentUniformVectors = 16; - resources->MaxDrawBuffers = 1; + resources->MaxTextureImageUnits = 8; + resources->MaxFragmentUniformVectors = 16; + resources->MaxDrawBuffers = 1; // Extensions. - resources->OES_standard_derivatives = 0; - resources->OES_EGL_image_external = 0; - resources->ARB_texture_rectangle = 0; - resources->EXT_blend_func_extended = 0; - resources->EXT_draw_buffers = 0; - resources->EXT_frag_depth = 0; - resources->EXT_shader_texture_lod = 0; - resources->WEBGL_debug_shader_precision = 0; - resources->EXT_shader_framebuffer_fetch = 0; - resources->NV_shader_framebuffer_fetch = 0; - resources->ARM_shader_framebuffer_fetch = 0; + resources->OES_standard_derivatives = 0; + resources->OES_EGL_image_external = 0; + resources->OES_EGL_image_external_essl3 = 0; + resources->NV_EGL_stream_consumer_external = 0; + resources->ARB_texture_rectangle = 0; + resources->EXT_blend_func_extended = 0; + resources->EXT_draw_buffers = 0; + resources->EXT_frag_depth = 0; + resources->EXT_shader_texture_lod = 0; + resources->WEBGL_debug_shader_precision = 0; + resources->EXT_shader_framebuffer_fetch = 0; + resources->NV_shader_framebuffer_fetch = 0; + resources->ARM_shader_framebuffer_fetch = 0; + resources->OVR_multiview = 0; + resources->EXT_YUV_target = 0; + resources->OES_geometry_shader = 0; resources->NV_draw_buffers = 0; @@ -164,63 +211,125 @@ void ShInitBuiltInResources(ShBuiltInResources* resources) resources->FragmentPrecisionHigh = 0; // GLSL ES 3.0 constants. - resources->MaxVertexOutputVectors = 16; + resources->MaxVertexOutputVectors = 16; resources->MaxFragmentInputVectors = 15; - resources->MinProgramTexelOffset = -8; - resources->MaxProgramTexelOffset = 7; + resources->MinProgramTexelOffset = -8; + resources->MaxProgramTexelOffset = 7; // Extensions constants. resources->MaxDualSourceDrawBuffers = 0; + resources->MaxViewsOVR = 4; + // Disable name hashing by default. - resources->HashFunction = NULL; + resources->HashFunction = nullptr; resources->ArrayIndexClampingStrategy = SH_CLAMP_WITH_CLAMP_INTRINSIC; resources->MaxExpressionComplexity = 256; - resources->MaxCallStackDepth = 256; + resources->MaxCallStackDepth = 256; + resources->MaxFunctionParameters = 1024; + + // ES 3.1 Revision 4, 7.2 Built-in Constants + + // ES 3.1, Revision 4, 8.13 Texture minification + // "The value of MIN_PROGRAM_TEXTURE_GATHER_OFFSET must be less than or equal to the value of + // MIN_PROGRAM_TEXEL_OFFSET. The value of MAX_PROGRAM_TEXTURE_GATHER_OFFSET must be greater than + // or equal to the value of MAX_PROGRAM_TEXEL_OFFSET" + resources->MinProgramTextureGatherOffset = -8; + resources->MaxProgramTextureGatherOffset = 7; + + resources->MaxImageUnits = 4; + resources->MaxVertexImageUniforms = 0; + resources->MaxFragmentImageUniforms = 0; + resources->MaxComputeImageUniforms = 4; + resources->MaxCombinedImageUniforms = 4; + + resources->MaxUniformLocations = 1024; + + resources->MaxCombinedShaderOutputResources = 4; + + resources->MaxComputeWorkGroupCount[0] = 65535; + resources->MaxComputeWorkGroupCount[1] = 65535; + resources->MaxComputeWorkGroupCount[2] = 65535; + resources->MaxComputeWorkGroupSize[0] = 128; + resources->MaxComputeWorkGroupSize[1] = 128; + resources->MaxComputeWorkGroupSize[2] = 64; + resources->MaxComputeUniformComponents = 512; + resources->MaxComputeTextureImageUnits = 16; + + resources->MaxComputeAtomicCounters = 8; + resources->MaxComputeAtomicCounterBuffers = 1; + + resources->MaxVertexAtomicCounters = 0; + resources->MaxFragmentAtomicCounters = 0; + resources->MaxCombinedAtomicCounters = 8; + resources->MaxAtomicCounterBindings = 1; + + resources->MaxVertexAtomicCounterBuffers = 0; + resources->MaxFragmentAtomicCounterBuffers = 0; + resources->MaxCombinedAtomicCounterBuffers = 1; + resources->MaxAtomicCounterBufferSize = 32; + + resources->MaxUniformBufferBindings = 32; + resources->MaxShaderStorageBufferBindings = 4; + + resources->MaxGeometryUniformComponents = 1024; + resources->MaxGeometryUniformBlocks = 12; + resources->MaxGeometryInputComponents = 64; + resources->MaxGeometryOutputComponents = 64; + resources->MaxGeometryOutputVertices = 256; + resources->MaxGeometryTotalOutputComponents = 1024; + resources->MaxGeometryTextureImageUnits = 16; + resources->MaxGeometryAtomicCounterBuffers = 0; + resources->MaxGeometryAtomicCounters = 0; + resources->MaxGeometryShaderStorageBlocks = 0; + resources->MaxGeometryShaderInvocations = 32; + resources->MaxGeometryImageUniforms = 0; } // // Driver calls these to create and destroy compiler objects. // -ShHandle ShConstructCompiler(sh::GLenum type, ShShaderSpec spec, - ShShaderOutput output, - const ShBuiltInResources* resources) +ShHandle ConstructCompiler(sh::GLenum type, + ShShaderSpec spec, + ShShaderOutput output, + const ShBuiltInResources *resources) { - TShHandleBase* base = static_cast<TShHandleBase*>(ConstructCompiler(type, spec, output)); + TShHandleBase *base = static_cast<TShHandleBase *>(ConstructCompiler(type, spec, output)); if (base == nullptr) { return 0; } - TCompiler* compiler = base->getAsCompiler(); + TCompiler *compiler = base->getAsCompiler(); if (compiler == nullptr) { return 0; } // Generate built-in symbol table. - if (!compiler->Init(*resources)) { - ShDestruct(base); + if (!compiler->Init(*resources)) + { + Destruct(base); return 0; } - return reinterpret_cast<void*>(base); + return reinterpret_cast<void *>(base); } -void ShDestruct(ShHandle handle) +void Destruct(ShHandle handle) { if (handle == 0) return; - TShHandleBase* base = static_cast<TShHandleBase*>(handle); + TShHandleBase *base = static_cast<TShHandleBase *>(handle); if (base->getAsCompiler()) DeleteCompiler(base->getAsCompiler()); } -const std::string &ShGetBuiltInResourcesString(const ShHandle handle) +const std::string &GetBuiltInResourcesString(const ShHandle handle) { TCompiler *compiler = GetCompilerFromHandle(handle); ASSERT(compiler); @@ -234,11 +343,10 @@ const std::string &ShGetBuiltInResourcesString(const ShHandle handle) // Return: The return value of ShCompile is really boolean, indicating // success or failure. // -bool ShCompile( - const ShHandle handle, - const char *const shaderStrings[], - size_t numStrings, - int compileOptions) +bool Compile(const ShHandle handle, + const char *const shaderStrings[], + size_t numStrings, + ShCompileOptions compileOptions) { TCompiler *compiler = GetCompilerFromHandle(handle); ASSERT(compiler); @@ -246,23 +354,23 @@ bool ShCompile( return compiler->compile(shaderStrings, numStrings, compileOptions); } -void ShClearResults(const ShHandle handle) +void ClearResults(const ShHandle handle) { TCompiler *compiler = GetCompilerFromHandle(handle); ASSERT(compiler); compiler->clearResults(); } -int ShGetShaderVersion(const ShHandle handle) +int GetShaderVersion(const ShHandle handle) { - TCompiler* compiler = GetCompilerFromHandle(handle); + TCompiler *compiler = GetCompilerFromHandle(handle); ASSERT(compiler); return compiler->getShaderVersion(); } -ShShaderOutput ShGetShaderOutputType(const ShHandle handle) +ShShaderOutput GetShaderOutputType(const ShHandle handle) { - TCompiler* compiler = GetCompilerFromHandle(handle); + TCompiler *compiler = GetCompilerFromHandle(handle); ASSERT(compiler); return compiler->getOutputType(); } @@ -270,7 +378,7 @@ ShShaderOutput ShGetShaderOutputType(const ShHandle handle) // // Return any compiler log of messages for the application. // -const std::string &ShGetInfoLog(const ShHandle handle) +const std::string &GetInfoLog(const ShHandle handle) { TCompiler *compiler = GetCompilerFromHandle(handle); ASSERT(compiler); @@ -282,7 +390,7 @@ const std::string &ShGetInfoLog(const ShHandle handle) // // Return any object code. // -const std::string &ShGetObjectCode(const ShHandle handle) +const std::string &GetObjectCode(const ShHandle handle) { TCompiler *compiler = GetCompilerFromHandle(handle); ASSERT(compiler); @@ -291,58 +399,107 @@ const std::string &ShGetObjectCode(const ShHandle handle) return infoSink.obj.str(); } -const std::map<std::string, std::string> *ShGetNameHashingMap( - const ShHandle handle) +const std::map<std::string, std::string> *GetNameHashingMap(const ShHandle handle) { TCompiler *compiler = GetCompilerFromHandle(handle); ASSERT(compiler); return &(compiler->getNameMap()); } -const std::vector<sh::Uniform> *ShGetUniforms(const ShHandle handle) +const std::vector<Uniform> *GetUniforms(const ShHandle handle) { - return GetShaderVariables<sh::Uniform>(handle); + return GetShaderVariables<Uniform>(handle); } -const std::vector<sh::Varying> *ShGetVaryings(const ShHandle handle) +const std::vector<Varying> *GetInputVaryings(const ShHandle handle) { - return GetShaderVariables<sh::Varying>(handle); + TCompiler *compiler = GetCompilerFromHandle(handle); + if (compiler == nullptr) + { + return nullptr; + } + return &compiler->getInputVaryings(); } -const std::vector<sh::Attribute> *ShGetAttributes(const ShHandle handle) +const std::vector<Varying> *GetOutputVaryings(const ShHandle handle) { - return GetShaderVariables<sh::Attribute>(handle); + TCompiler *compiler = GetCompilerFromHandle(handle); + if (compiler == nullptr) + { + return nullptr; + } + return &compiler->getOutputVaryings(); } -const std::vector<sh::OutputVariable> *ShGetOutputVariables(const ShHandle handle) +const std::vector<Varying> *GetVaryings(const ShHandle handle) { - return GetShaderVariables<sh::OutputVariable>(handle); + return GetShaderVariables<Varying>(handle); } -const std::vector<sh::InterfaceBlock> *ShGetInterfaceBlocks(const ShHandle handle) +const std::vector<Attribute> *GetAttributes(const ShHandle handle) { - return GetShaderVariables<sh::InterfaceBlock>(handle); + return GetShaderVariables<Attribute>(handle); } -bool ShCheckVariablesWithinPackingLimits( - int maxVectors, ShVariableInfo *varInfoArray, size_t varInfoArraySize) +const std::vector<OutputVariable> *GetOutputVariables(const ShHandle handle) { - if (varInfoArraySize == 0) - return true; - ASSERT(varInfoArray); - std::vector<sh::ShaderVariable> variables; - for (size_t ii = 0; ii < varInfoArraySize; ++ii) - { - sh::ShaderVariable var(varInfoArray[ii].type, varInfoArray[ii].size); - variables.push_back(var); - } - VariablePacker packer; - return packer.CheckVariablesWithinPackingLimits(maxVectors, variables); + return GetShaderVariables<OutputVariable>(handle); } -bool ShGetInterfaceBlockRegister(const ShHandle handle, - const std::string &interfaceBlockName, - unsigned int *indexOut) +const std::vector<InterfaceBlock> *GetInterfaceBlocks(const ShHandle handle) +{ + return GetShaderVariables<InterfaceBlock>(handle); +} + +const std::vector<InterfaceBlock> *GetUniformBlocks(const ShHandle handle) +{ + ASSERT(handle); + TShHandleBase *base = static_cast<TShHandleBase *>(handle); + TCompiler *compiler = base->getAsCompiler(); + ASSERT(compiler); + + return &compiler->getUniformBlocks(); +} + +const std::vector<InterfaceBlock> *GetShaderStorageBlocks(const ShHandle handle) +{ + ASSERT(handle); + TShHandleBase *base = static_cast<TShHandleBase *>(handle); + TCompiler *compiler = base->getAsCompiler(); + ASSERT(compiler); + + return &compiler->getShaderStorageBlocks(); +} + +WorkGroupSize GetComputeShaderLocalGroupSize(const ShHandle handle) +{ + ASSERT(handle); + + TShHandleBase *base = static_cast<TShHandleBase *>(handle); + TCompiler *compiler = base->getAsCompiler(); + ASSERT(compiler); + + return compiler->getComputeShaderLocalSize(); +} + +int GetVertexShaderNumViews(const ShHandle handle) +{ + ASSERT(handle); + TShHandleBase *base = static_cast<TShHandleBase *>(handle); + TCompiler *compiler = base->getAsCompiler(); + ASSERT(compiler); + + return compiler->getNumViews(); +} + +bool CheckVariablesWithinPackingLimits(int maxVectors, const std::vector<ShaderVariable> &variables) +{ + return CheckVariablesInPackingLimits(maxVectors, variables); +} + +bool GetUniformBlockRegister(const ShHandle handle, + const std::string &uniformBlockName, + unsigned int *indexOut) { #ifdef ANGLE_ENABLE_HLSL ASSERT(indexOut); @@ -350,35 +507,72 @@ bool ShGetInterfaceBlockRegister(const ShHandle handle, TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle); ASSERT(translator); - if (!translator->hasInterfaceBlock(interfaceBlockName)) + if (!translator->hasUniformBlock(uniformBlockName)) { return false; } - *indexOut = translator->getInterfaceBlockRegister(interfaceBlockName); + *indexOut = translator->getUniformBlockRegister(uniformBlockName); return true; #else return false; -#endif // ANGLE_ENABLE_HLSL +#endif // ANGLE_ENABLE_HLSL } -bool ShGetUniformRegister(const ShHandle handle, - const std::string &uniformName, - unsigned int *indexOut) +const std::map<std::string, unsigned int> *GetUniformRegisterMap(const ShHandle handle) { #ifdef ANGLE_ENABLE_HLSL - ASSERT(indexOut); TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle); ASSERT(translator); - if (!translator->hasUniform(uniformName)) - { - return false; - } - - *indexOut = translator->getUniformRegister(uniformName); - return true; + return translator->getUniformRegisterMap(); #else - return false; -#endif // ANGLE_ENABLE_HLSL + return nullptr; +#endif // ANGLE_ENABLE_HLSL +} + +GLenum GetGeometryShaderInputPrimitiveType(const ShHandle handle) +{ + ASSERT(handle); + + TShHandleBase *base = static_cast<TShHandleBase *>(handle); + TCompiler *compiler = base->getAsCompiler(); + ASSERT(compiler); + + return GetGeometryShaderPrimitiveTypeEnum(compiler->getGeometryShaderInputPrimitiveType()); +} + +GLenum GetGeometryShaderOutputPrimitiveType(const ShHandle handle) +{ + ASSERT(handle); + + TShHandleBase *base = static_cast<TShHandleBase *>(handle); + TCompiler *compiler = base->getAsCompiler(); + ASSERT(compiler); + + return GetGeometryShaderPrimitiveTypeEnum(compiler->getGeometryShaderOutputPrimitiveType()); } + +int GetGeometryShaderInvocations(const ShHandle handle) +{ + ASSERT(handle); + + TShHandleBase *base = static_cast<TShHandleBase *>(handle); + TCompiler *compiler = base->getAsCompiler(); + ASSERT(compiler); + + return compiler->getGeometryShaderInvocations(); +} + +int GetGeometryShaderMaxVertices(const ShHandle handle) +{ + ASSERT(handle); + + TShHandleBase *base = static_cast<TShHandleBase *>(handle); + TCompiler *compiler = base->getAsCompiler(); + ASSERT(compiler); + + return compiler->getGeometryShaderMaxVertices(); +} + +} // namespace sh |