translator: Put ShaderLang APIs in "sh" namespace.
Working with glslang in Vulkan means we are static linking libANGLE
with functions that have the same name as our translator APIs. We
can fix this by scoping our APIs. We don't need to scope the types
of the file, since they don't conflict.
This will require a follow-up patch to remove the unscoped APIs
once we switch over Chromium.
We also scope TCompiler and some related classes to avoid multiply
defined link errors with glslang.
BUG=angleproject:1576
Change-Id: I729b19467d2ff7d374a82044b16dbebdf2dc8f16
Reviewed-on: https://chromium-review.googlesource.com/408337
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/fuzz/translator_fuzzer.cpp b/src/compiler/fuzz/translator_fuzzer.cpp
index 5185522..b772b4a 100644
--- a/src/compiler/fuzz/translator_fuzzer.cpp
+++ b/src/compiler/fuzz/translator_fuzzer.cpp
@@ -14,6 +14,8 @@
#include "compiler/translator/Compiler.h"
#include "angle_gl.h"
+using namespace sh;
+
struct TranslatorCacheKey
{
bool operator==(const TranslatorCacheKey &other) const
diff --git a/src/compiler/translator/CodeGen.cpp b/src/compiler/translator/CodeGen.cpp
index f099bcc..6bf6dc5 100644
--- a/src/compiler/translator/CodeGen.cpp
+++ b/src/compiler/translator/CodeGen.cpp
@@ -16,6 +16,9 @@
#include "compiler/translator/TranslatorHLSL.h"
#endif // ANGLE_ENABLE_HLSL
+namespace sh
+{
+
//
// This function must be provided to create the actual
// compile object used by higher level code. It returns
@@ -29,10 +32,10 @@
#ifdef ANGLE_ENABLE_ESSL
return new TranslatorESSL(type, spec);
#else
- // This compiler is not supported in this
- // configuration. Return NULL per the ShConstructCompiler API.
- return nullptr;
-#endif // ANGLE_ENABLE_ESSL
+ // This compiler is not supported in this configuration. Return NULL per the
+ // sh::ConstructCompiler API.
+ return nullptr;
+#endif // ANGLE_ENABLE_ESSL
case SH_GLSL_130_OUTPUT:
case SH_GLSL_140_OUTPUT:
case SH_GLSL_150_CORE_OUTPUT:
@@ -47,23 +50,23 @@
#ifdef ANGLE_ENABLE_GLSL
return new TranslatorGLSL(type, spec, output);
#else
- // This compiler is not supported in this
- // configuration. Return NULL per the ShConstructCompiler API.
- return nullptr;
-#endif // ANGLE_ENABLE_GLSL
+ // This compiler is not supported in this configuration. Return NULL per the
+ // sh::ConstructCompiler API.
+ return nullptr;
+#endif // ANGLE_ENABLE_GLSL
case SH_HLSL_3_0_OUTPUT:
case SH_HLSL_4_1_OUTPUT:
case SH_HLSL_4_0_FL9_3_OUTPUT:
#ifdef ANGLE_ENABLE_HLSL
return new TranslatorHLSL(type, spec, output);
#else
- // This compiler is not supported in this
- // configuration. Return NULL per the ShConstructCompiler API.
- return nullptr;
-#endif // ANGLE_ENABLE_HLSL
+ // This compiler is not supported in this configuration. Return NULL per the
+ // sh::ConstructCompiler API.
+ return nullptr;
+#endif // ANGLE_ENABLE_HLSL
default:
- // Unknown format. Return NULL per the ShConstructCompiler API.
- return nullptr;
+ // Unknown format. Return NULL per the sh::ConstructCompiler API.
+ return nullptr;
}
}
@@ -74,3 +77,5 @@
{
delete compiler;
}
+
+} // namespace sh
diff --git a/src/compiler/translator/Compiler.cpp b/src/compiler/translator/Compiler.cpp
index c1be552..7689a03 100644
--- a/src/compiler/translator/Compiler.cpp
+++ b/src/compiler/translator/Compiler.cpp
@@ -35,6 +35,9 @@
#include "compiler/translator/VariablePacker.h"
#include "third_party/compiler/ArrayBoundsClamper.h"
+namespace sh
+{
+
namespace
{
@@ -80,24 +83,17 @@
bool IsGLSL130OrNewer(ShShaderOutput output)
{
- return (output == SH_GLSL_130_OUTPUT ||
- output == SH_GLSL_140_OUTPUT ||
- output == SH_GLSL_150_CORE_OUTPUT ||
- output == SH_GLSL_330_CORE_OUTPUT ||
- output == SH_GLSL_400_CORE_OUTPUT ||
- output == SH_GLSL_410_CORE_OUTPUT ||
- output == SH_GLSL_420_CORE_OUTPUT ||
- output == SH_GLSL_430_CORE_OUTPUT ||
- output == SH_GLSL_440_CORE_OUTPUT ||
- output == SH_GLSL_450_CORE_OUTPUT);
+ return (output == SH_GLSL_130_OUTPUT || output == SH_GLSL_140_OUTPUT ||
+ output == SH_GLSL_150_CORE_OUTPUT || output == SH_GLSL_330_CORE_OUTPUT ||
+ output == SH_GLSL_400_CORE_OUTPUT || output == SH_GLSL_410_CORE_OUTPUT ||
+ output == SH_GLSL_420_CORE_OUTPUT || output == SH_GLSL_430_CORE_OUTPUT ||
+ output == SH_GLSL_440_CORE_OUTPUT || output == SH_GLSL_450_CORE_OUTPUT);
}
bool IsGLSL420OrNewer(ShShaderOutput output)
{
- return (output == SH_GLSL_420_CORE_OUTPUT ||
- output == SH_GLSL_430_CORE_OUTPUT ||
- output == SH_GLSL_440_CORE_OUTPUT ||
- output == SH_GLSL_450_CORE_OUTPUT);
+ return (output == SH_GLSL_420_CORE_OUTPUT || output == SH_GLSL_430_CORE_OUTPUT ||
+ output == SH_GLSL_440_CORE_OUTPUT || output == SH_GLSL_450_CORE_OUTPUT);
}
size_t GetGlobalMaxTokenSize(ShShaderSpec spec)
@@ -106,10 +102,10 @@
// size undefined. ES3 defines a max size of 1024 characters.
switch (spec)
{
- case SH_WEBGL_SPEC:
- return 256;
- default:
- return 1024;
+ case SH_WEBGL_SPEC:
+ return 256;
+ default:
+ return 1024;
}
}
@@ -155,18 +151,18 @@
{
switch (spec)
{
- case SH_GLES2_SPEC:
- case SH_WEBGL_SPEC:
- return 100;
- case SH_GLES3_SPEC:
- case SH_WEBGL2_SPEC:
- return 300;
- case SH_GLES3_1_SPEC:
- case SH_WEBGL3_SPEC:
- return 310;
- default:
- UNREACHABLE();
- return 0;
+ case SH_GLES2_SPEC:
+ case SH_WEBGL_SPEC:
+ return 100;
+ case SH_GLES3_SPEC:
+ case SH_WEBGL2_SPEC:
+ return 300;
+ case SH_GLES3_1_SPEC:
+ case SH_WEBGL3_SPEC:
+ return 310;
+ default:
+ UNREACHABLE();
+ return 0;
}
}
@@ -534,21 +530,21 @@
TPublicType floatingPoint;
floatingPoint.initializeBasicType(EbtFloat);
- switch(shaderType)
+ switch (shaderType)
{
- case GL_FRAGMENT_SHADER:
- symbolTable.setDefaultPrecision(integer, EbpMedium);
- break;
- case GL_VERTEX_SHADER:
- symbolTable.setDefaultPrecision(integer, EbpHigh);
- symbolTable.setDefaultPrecision(floatingPoint, EbpHigh);
- break;
- case GL_COMPUTE_SHADER:
- symbolTable.setDefaultPrecision(integer, EbpHigh);
- symbolTable.setDefaultPrecision(floatingPoint, EbpHigh);
- break;
- default:
- assert(false && "Language not supported");
+ case GL_FRAGMENT_SHADER:
+ symbolTable.setDefaultPrecision(integer, EbpMedium);
+ break;
+ case GL_VERTEX_SHADER:
+ symbolTable.setDefaultPrecision(integer, EbpHigh);
+ symbolTable.setDefaultPrecision(floatingPoint, EbpHigh);
+ break;
+ case GL_COMPUTE_SHADER:
+ symbolTable.setDefaultPrecision(integer, EbpHigh);
+ symbolTable.setDefaultPrecision(floatingPoint, EbpHigh);
+ break;
+ default:
+ assert(false && "Language not supported");
}
// Set defaults for sampler types that have default precision, even those that are
// only available if an extension exists.
@@ -581,60 +577,60 @@
// clang-format off
strstream << ":MaxVertexAttribs:" << compileResources.MaxVertexAttribs
- << ":MaxVertexUniformVectors:" << compileResources.MaxVertexUniformVectors
- << ":MaxVaryingVectors:" << compileResources.MaxVaryingVectors
- << ":MaxVertexTextureImageUnits:" << compileResources.MaxVertexTextureImageUnits
- << ":MaxCombinedTextureImageUnits:" << compileResources.MaxCombinedTextureImageUnits
- << ":MaxTextureImageUnits:" << compileResources.MaxTextureImageUnits
- << ":MaxFragmentUniformVectors:" << compileResources.MaxFragmentUniformVectors
- << ":MaxDrawBuffers:" << compileResources.MaxDrawBuffers
- << ":OES_standard_derivatives:" << compileResources.OES_standard_derivatives
- << ":OES_EGL_image_external:" << compileResources.OES_EGL_image_external
- << ":OES_EGL_image_external_essl3:" << compileResources.OES_EGL_image_external_essl3
- << ":NV_EGL_stream_consumer_external:" << compileResources.NV_EGL_stream_consumer_external
- << ":ARB_texture_rectangle:" << compileResources.ARB_texture_rectangle
- << ":EXT_draw_buffers:" << compileResources.EXT_draw_buffers
- << ":FragmentPrecisionHigh:" << compileResources.FragmentPrecisionHigh
- << ":MaxExpressionComplexity:" << compileResources.MaxExpressionComplexity
- << ":MaxCallStackDepth:" << compileResources.MaxCallStackDepth
- << ":MaxFunctionParameters:" << compileResources.MaxFunctionParameters
- << ":EXT_blend_func_extended:" << compileResources.EXT_blend_func_extended
- << ":EXT_frag_depth:" << compileResources.EXT_frag_depth
- << ":EXT_shader_texture_lod:" << compileResources.EXT_shader_texture_lod
- << ":EXT_shader_framebuffer_fetch:" << compileResources.EXT_shader_framebuffer_fetch
- << ":NV_shader_framebuffer_fetch:" << compileResources.NV_shader_framebuffer_fetch
- << ":ARM_shader_framebuffer_fetch:" << compileResources.ARM_shader_framebuffer_fetch
- << ":MaxVertexOutputVectors:" << compileResources.MaxVertexOutputVectors
- << ":MaxFragmentInputVectors:" << compileResources.MaxFragmentInputVectors
- << ":MinProgramTexelOffset:" << compileResources.MinProgramTexelOffset
- << ":MaxProgramTexelOffset:" << compileResources.MaxProgramTexelOffset
- << ":MaxDualSourceDrawBuffers:" << compileResources.MaxDualSourceDrawBuffers
- << ":NV_draw_buffers:" << compileResources.NV_draw_buffers
- << ":WEBGL_debug_shader_precision:" << compileResources.WEBGL_debug_shader_precision
- << ":MaxImageUnits:" << compileResources.MaxImageUnits
- << ":MaxVertexImageUniforms:" << compileResources.MaxVertexImageUniforms
- << ":MaxFragmentImageUniforms:" << compileResources.MaxFragmentImageUniforms
- << ":MaxComputeImageUniforms:" << compileResources.MaxComputeImageUniforms
- << ":MaxCombinedImageUniforms:" << compileResources.MaxCombinedImageUniforms
- << ":MaxCombinedShaderOutputResources:" << compileResources.MaxCombinedShaderOutputResources
- << ":MaxComputeWorkGroupCountX:" << compileResources.MaxComputeWorkGroupCount[0]
- << ":MaxComputeWorkGroupCountY:" << compileResources.MaxComputeWorkGroupCount[1]
- << ":MaxComputeWorkGroupCountZ:" << compileResources.MaxComputeWorkGroupCount[2]
- << ":MaxComputeWorkGroupSizeX:" << compileResources.MaxComputeWorkGroupSize[0]
- << ":MaxComputeWorkGroupSizeY:" << compileResources.MaxComputeWorkGroupSize[1]
- << ":MaxComputeWorkGroupSizeZ:" << compileResources.MaxComputeWorkGroupSize[2]
- << ":MaxComputeUniformComponents:" << compileResources.MaxComputeUniformComponents
- << ":MaxComputeTextureImageUnits:" << compileResources.MaxComputeTextureImageUnits
- << ":MaxComputeAtomicCounters:" << compileResources.MaxComputeAtomicCounters
- << ":MaxComputeAtomicCounterBuffers:" << compileResources.MaxComputeAtomicCounterBuffers
- << ":MaxVertexAtomicCounters:" << compileResources.MaxVertexAtomicCounters
- << ":MaxFragmentAtomicCounters:" << compileResources.MaxFragmentAtomicCounters
- << ":MaxCombinedAtomicCounters:" << compileResources.MaxCombinedAtomicCounters
- << ":MaxAtomicCounterBindings:" << compileResources.MaxAtomicCounterBindings
- << ":MaxVertexAtomicCounterBuffers:" << compileResources.MaxVertexAtomicCounterBuffers
- << ":MaxFragmentAtomicCounterBuffers:" << compileResources.MaxFragmentAtomicCounterBuffers
- << ":MaxCombinedAtomicCounterBuffers:" << compileResources.MaxCombinedAtomicCounterBuffers
- << ":MaxAtomicCounterBufferSize:" << compileResources.MaxAtomicCounterBufferSize;
+ << ":MaxVertexUniformVectors:" << compileResources.MaxVertexUniformVectors
+ << ":MaxVaryingVectors:" << compileResources.MaxVaryingVectors
+ << ":MaxVertexTextureImageUnits:" << compileResources.MaxVertexTextureImageUnits
+ << ":MaxCombinedTextureImageUnits:" << compileResources.MaxCombinedTextureImageUnits
+ << ":MaxTextureImageUnits:" << compileResources.MaxTextureImageUnits
+ << ":MaxFragmentUniformVectors:" << compileResources.MaxFragmentUniformVectors
+ << ":MaxDrawBuffers:" << compileResources.MaxDrawBuffers
+ << ":OES_standard_derivatives:" << compileResources.OES_standard_derivatives
+ << ":OES_EGL_image_external:" << compileResources.OES_EGL_image_external
+ << ":OES_EGL_image_external_essl3:" << compileResources.OES_EGL_image_external_essl3
+ << ":NV_EGL_stream_consumer_external:" << compileResources.NV_EGL_stream_consumer_external
+ << ":ARB_texture_rectangle:" << compileResources.ARB_texture_rectangle
+ << ":EXT_draw_buffers:" << compileResources.EXT_draw_buffers
+ << ":FragmentPrecisionHigh:" << compileResources.FragmentPrecisionHigh
+ << ":MaxExpressionComplexity:" << compileResources.MaxExpressionComplexity
+ << ":MaxCallStackDepth:" << compileResources.MaxCallStackDepth
+ << ":MaxFunctionParameters:" << compileResources.MaxFunctionParameters
+ << ":EXT_blend_func_extended:" << compileResources.EXT_blend_func_extended
+ << ":EXT_frag_depth:" << compileResources.EXT_frag_depth
+ << ":EXT_shader_texture_lod:" << compileResources.EXT_shader_texture_lod
+ << ":EXT_shader_framebuffer_fetch:" << compileResources.EXT_shader_framebuffer_fetch
+ << ":NV_shader_framebuffer_fetch:" << compileResources.NV_shader_framebuffer_fetch
+ << ":ARM_shader_framebuffer_fetch:" << compileResources.ARM_shader_framebuffer_fetch
+ << ":MaxVertexOutputVectors:" << compileResources.MaxVertexOutputVectors
+ << ":MaxFragmentInputVectors:" << compileResources.MaxFragmentInputVectors
+ << ":MinProgramTexelOffset:" << compileResources.MinProgramTexelOffset
+ << ":MaxProgramTexelOffset:" << compileResources.MaxProgramTexelOffset
+ << ":MaxDualSourceDrawBuffers:" << compileResources.MaxDualSourceDrawBuffers
+ << ":NV_draw_buffers:" << compileResources.NV_draw_buffers
+ << ":WEBGL_debug_shader_precision:" << compileResources.WEBGL_debug_shader_precision
+ << ":MaxImageUnits:" << compileResources.MaxImageUnits
+ << ":MaxVertexImageUniforms:" << compileResources.MaxVertexImageUniforms
+ << ":MaxFragmentImageUniforms:" << compileResources.MaxFragmentImageUniforms
+ << ":MaxComputeImageUniforms:" << compileResources.MaxComputeImageUniforms
+ << ":MaxCombinedImageUniforms:" << compileResources.MaxCombinedImageUniforms
+ << ":MaxCombinedShaderOutputResources:" << compileResources.MaxCombinedShaderOutputResources
+ << ":MaxComputeWorkGroupCountX:" << compileResources.MaxComputeWorkGroupCount[0]
+ << ":MaxComputeWorkGroupCountY:" << compileResources.MaxComputeWorkGroupCount[1]
+ << ":MaxComputeWorkGroupCountZ:" << compileResources.MaxComputeWorkGroupCount[2]
+ << ":MaxComputeWorkGroupSizeX:" << compileResources.MaxComputeWorkGroupSize[0]
+ << ":MaxComputeWorkGroupSizeY:" << compileResources.MaxComputeWorkGroupSize[1]
+ << ":MaxComputeWorkGroupSizeZ:" << compileResources.MaxComputeWorkGroupSize[2]
+ << ":MaxComputeUniformComponents:" << compileResources.MaxComputeUniformComponents
+ << ":MaxComputeTextureImageUnits:" << compileResources.MaxComputeTextureImageUnits
+ << ":MaxComputeAtomicCounters:" << compileResources.MaxComputeAtomicCounters
+ << ":MaxComputeAtomicCounterBuffers:" << compileResources.MaxComputeAtomicCounterBuffers
+ << ":MaxVertexAtomicCounters:" << compileResources.MaxVertexAtomicCounters
+ << ":MaxFragmentAtomicCounters:" << compileResources.MaxFragmentAtomicCounters
+ << ":MaxCombinedAtomicCounters:" << compileResources.MaxCombinedAtomicCounters
+ << ":MaxAtomicCounterBindings:" << compileResources.MaxAtomicCounterBindings
+ << ":MaxVertexAtomicCounterBuffers:" << compileResources.MaxVertexAtomicCounterBuffers
+ << ":MaxFragmentAtomicCounterBuffers:" << compileResources.MaxFragmentAtomicCounterBuffers
+ << ":MaxCombinedAtomicCounterBuffers:" << compileResources.MaxCombinedAtomicCounterBuffers
+ << ":MaxAtomicCounterBufferSize:" << compileResources.MaxAtomicCounterBufferSize;
// clang-format on
builtInResourcesString = strstream.str();
@@ -669,16 +665,16 @@
switch (mCallDag.init(root, &infoSink.info))
{
- case CallDAG::INITDAG_SUCCESS:
- return true;
- case CallDAG::INITDAG_RECURSION:
- infoSink.info.prefix(EPrefixError);
- infoSink.info << "Function recursion detected";
- return false;
- case CallDAG::INITDAG_UNDEFINED:
- infoSink.info.prefix(EPrefixError);
- infoSink.info << "Unimplemented function detected";
- return false;
+ case CallDAG::INITDAG_SUCCESS:
+ return true;
+ case CallDAG::INITDAG_RECURSION:
+ infoSink.info.prefix(EPrefixError);
+ infoSink.info << "Function recursion detected";
+ return false;
+ case CallDAG::INITDAG_UNDEFINED:
+ infoSink.info.prefix(EPrefixError);
+ infoSink.info << "Unimplemented function detected";
+ return false;
}
UNREACHABLE();
@@ -772,8 +768,7 @@
{
public:
UnusedPredicate(const CallDAG *callDag, const std::vector<FunctionMetadata> *metadatas)
- : mCallDag(callDag),
- mMetadatas(metadatas)
+ : mCallDag(callDag), mMetadatas(metadatas)
{
}
@@ -846,7 +841,7 @@
bool TCompiler::limitExpressionComplexity(TIntermNode* root)
{
- TMaxDepthTraverser traverser(maxExpressionComplexity+1);
+ TMaxDepthTraverser traverser(maxExpressionComplexity + 1);
root->traverse(&traverser);
if (traverser.getMaxDepth() > maxExpressionComplexity)
@@ -869,7 +864,8 @@
if (!variablesCollected)
{
sh::CollectVariables collect(&attributes, &outputVariables, &uniforms, &varyings,
- &interfaceBlocks, hashFunction, symbolTable, extensionBehavior);
+ &interfaceBlocks, hashFunction, symbolTable,
+ extensionBehavior);
root->traverse(&collect);
// This is for enforcePackingRestriction().
@@ -993,3 +989,5 @@
return false;
}
+
+} // namespace sh
diff --git a/src/compiler/translator/Compiler.h b/src/compiler/translator/Compiler.h
index da57012..603d7eb 100644
--- a/src/compiler/translator/Compiler.h
+++ b/src/compiler/translator/Compiler.h
@@ -24,6 +24,9 @@
#include "compiler/translator/VariableInfo.h"
#include "third_party/compiler/ArrayBoundsClamper.h"
+namespace sh
+{
+
class TCompiler;
#ifdef ANGLE_ENABLE_HLSL
class TranslatorHLSL;
@@ -257,4 +260,6 @@
sh::GLenum type, ShShaderSpec spec, ShShaderOutput output);
void DeleteCompiler(TCompiler*);
+} // namespace sh
+
#endif // COMPILER_TRANSLATOR_COMPILER_H_
diff --git a/src/compiler/translator/EmulatePrecision.cpp b/src/compiler/translator/EmulatePrecision.cpp
index f38d925..94cdf50 100644
--- a/src/compiler/translator/EmulatePrecision.cpp
+++ b/src/compiler/translator/EmulatePrecision.cpp
@@ -716,6 +716,6 @@
default:
// Other languages not yet supported
return (outputLanguage == SH_GLSL_COMPATIBILITY_OUTPUT ||
- IsGLSL130OrNewer(outputLanguage));
+ sh::IsGLSL130OrNewer(outputLanguage));
}
}
diff --git a/src/compiler/translator/OutputGLSL.cpp b/src/compiler/translator/OutputGLSL.cpp
index 928c073..76a0012 100644
--- a/src/compiler/translator/OutputGLSL.cpp
+++ b/src/compiler/translator/OutputGLSL.cpp
@@ -39,11 +39,11 @@
{
out << "gl_FragDepth";
}
- else if (symbol == "gl_FragColor" && IsGLSL130OrNewer(getShaderOutput()))
+ else if (symbol == "gl_FragColor" && sh::IsGLSL130OrNewer(getShaderOutput()))
{
out << "webgl_FragColor";
}
- else if (symbol == "gl_FragData" && IsGLSL130OrNewer(getShaderOutput()))
+ else if (symbol == "gl_FragData" && sh::IsGLSL130OrNewer(getShaderOutput()))
{
out << "webgl_FragData";
}
@@ -89,8 +89,8 @@
"textureCubeGradEXT", "textureGrad",
NULL, NULL
};
- const char **mapping = (IsGLSL130OrNewer(getShaderOutput())) ?
- legacyToCoreRename : simpleRename;
+ const char **mapping =
+ (sh::IsGLSL130OrNewer(getShaderOutput())) ? legacyToCoreRename : simpleRename;
for (int i = 0; mapping[i] != NULL; i += 2)
{
diff --git a/src/compiler/translator/OutputGLSLBase.cpp b/src/compiler/translator/OutputGLSLBase.cpp
index a81f154..172de43 100644
--- a/src/compiler/translator/OutputGLSLBase.cpp
+++ b/src/compiler/translator/OutputGLSLBase.cpp
@@ -150,7 +150,7 @@
{
TQualifier qualifier = type.getQualifier();
TInfoSinkBase &out = objSink();
- bool removeInvariant = (qualifier == EvqVaryingIn && IsGLSL420OrNewer(mOutput) &&
+ bool removeInvariant = (qualifier == EvqVaryingIn && sh::IsGLSL420OrNewer(mOutput) &&
!(mCompileOptions & SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT));
if (type.isInvariant() && !removeInvariant)
{
@@ -163,7 +163,7 @@
}
if (qualifier != EvqTemporary && qualifier != EvqGlobal)
{
- if (IsGLSL130OrNewer(mOutput))
+ if (sh::IsGLSL130OrNewer(mOutput))
{
switch (qualifier)
{
diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp
index 344c92f..eb96d2a 100644
--- a/src/compiler/translator/ParseContext.cpp
+++ b/src/compiler/translator/ParseContext.cpp
@@ -65,6 +65,50 @@
} // namespace
+TParseContext::TParseContext(TSymbolTable &symt,
+ TExtensionBehavior &ext,
+ sh::GLenum type,
+ ShShaderSpec spec,
+ ShCompileOptions options,
+ bool checksPrecErrors,
+ TInfoSink &is,
+ const ShBuiltInResources &resources)
+ : intermediate(),
+ symbolTable(symt),
+ mDeferredSingleDeclarationErrorCheck(false),
+ mShaderType(type),
+ mShaderSpec(spec),
+ mCompileOptions(options),
+ mShaderVersion(100),
+ mTreeRoot(nullptr),
+ mLoopNestingLevel(0),
+ mStructNestingLevel(0),
+ mSwitchNestingLevel(0),
+ mCurrentFunctionType(nullptr),
+ mFunctionReturnsValue(false),
+ mChecksPrecisionErrors(checksPrecErrors),
+ mFragmentPrecisionHighOnESSL1(false),
+ mDefaultMatrixPacking(EmpColumnMajor),
+ mDefaultBlockStorage(sh::IsWebGLBasedSpec(spec) ? EbsStd140 : EbsShared),
+ mDiagnostics(is),
+ mDirectiveHandler(ext,
+ mDiagnostics,
+ mShaderVersion,
+ mShaderType,
+ resources.WEBGL_debug_shader_precision == 1),
+ mPreprocessor(&mDiagnostics, &mDirectiveHandler),
+ mScanner(nullptr),
+ mUsesFragData(false),
+ mUsesFragColor(false),
+ mUsesSecondaryOutputs(false),
+ mMinProgramTexelOffset(resources.MinProgramTexelOffset),
+ mMaxProgramTexelOffset(resources.MaxProgramTexelOffset),
+ mComputeShaderLocalSizeDeclared(false),
+ mDeclaringFunction(false)
+{
+ mComputeShaderLocalSize.fill(-1);
+}
+
//
// Look at a '.' field selector string and change it into offsets
// for a vector.
@@ -481,7 +525,7 @@
error(line, reservedErrMsg, "gl_");
return false;
}
- if (IsWebGLBasedSpec(mShaderSpec))
+ if (sh::IsWebGLBasedSpec(mShaderSpec))
{
if (identifier.compare(0, 6, "webgl_") == 0)
{
@@ -2844,7 +2888,7 @@
void TParseContext::checkIsBelowStructNestingLimit(const TSourceLoc &line, const TField &field)
{
- if (!IsWebGLBasedSpec(mShaderSpec))
+ if (!sh::IsWebGLBasedSpec(mShaderSpec))
{
return;
}
@@ -3134,7 +3178,7 @@
if (qualifierType == "shared")
{
- if (IsWebGLBasedSpec(mShaderSpec))
+ if (sh::IsWebGLBasedSpec(mShaderSpec))
{
error(qualifierTypeLine, "Only std140 layout is allowed in WebGL", "shared");
}
@@ -3142,7 +3186,7 @@
}
else if (qualifierType == "packed")
{
- if (IsWebGLBasedSpec(mShaderSpec))
+ if (sh::IsWebGLBasedSpec(mShaderSpec))
{
error(qualifierTypeLine, "Only std140 layout is allowed in WebGL", "packed");
}
diff --git a/src/compiler/translator/ParseContext.h b/src/compiler/translator/ParseContext.h
index 68fda25..27b53bb 100644
--- a/src/compiler/translator/ParseContext.h
+++ b/src/compiler/translator/ParseContext.h
@@ -36,42 +36,7 @@
ShCompileOptions options,
bool checksPrecErrors,
TInfoSink &is,
- const ShBuiltInResources &resources)
- : intermediate(),
- symbolTable(symt),
- mDeferredSingleDeclarationErrorCheck(false),
- mShaderType(type),
- mShaderSpec(spec),
- mCompileOptions(options),
- mShaderVersion(100),
- mTreeRoot(nullptr),
- mLoopNestingLevel(0),
- mStructNestingLevel(0),
- mSwitchNestingLevel(0),
- mCurrentFunctionType(nullptr),
- mFunctionReturnsValue(false),
- mChecksPrecisionErrors(checksPrecErrors),
- mFragmentPrecisionHighOnESSL1(false),
- mDefaultMatrixPacking(EmpColumnMajor),
- mDefaultBlockStorage(IsWebGLBasedSpec(spec) ? EbsStd140 : EbsShared),
- mDiagnostics(is),
- mDirectiveHandler(ext,
- mDiagnostics,
- mShaderVersion,
- mShaderType,
- resources.WEBGL_debug_shader_precision == 1),
- mPreprocessor(&mDiagnostics, &mDirectiveHandler),
- mScanner(nullptr),
- mUsesFragData(false),
- mUsesFragColor(false),
- mUsesSecondaryOutputs(false),
- mMinProgramTexelOffset(resources.MinProgramTexelOffset),
- mMaxProgramTexelOffset(resources.MaxProgramTexelOffset),
- mComputeShaderLocalSizeDeclared(false),
- mDeclaringFunction(false)
- {
- mComputeShaderLocalSize.fill(-1);
- }
+ const ShBuiltInResources &resources);
const pp::Preprocessor &getPreprocessor() const { return mPreprocessor; }
pp::Preprocessor &getPreprocessor() { return mPreprocessor; }
diff --git a/src/compiler/translator/ShaderLang.cpp b/src/compiler/translator/ShaderLang.cpp
index 37b1114..b776ca5 100644
--- a/src/compiler/translator/ShaderLang.cpp
+++ b/src/compiler/translator/ShaderLang.cpp
@@ -20,6 +20,8 @@
#include "compiler/translator/VariablePacker.h"
#include "angle_gl.h"
+using namespace sh;
+
namespace
{
@@ -34,31 +36,31 @@
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();
}
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();
}
@@ -235,8 +237,9 @@
}
// Generate built-in symbol table.
- if (!compiler->Init(*resources)) {
- ShDestruct(base);
+ if (!compiler->Init(*resources))
+ {
+ sh::Destruct(base);
return 0;
}
@@ -332,32 +335,32 @@
return &(compiler->getNameMap());
}
-const std::vector<sh::Uniform> *ShGetUniforms(const ShHandle handle)
+const std::vector<Uniform> *ShGetUniforms(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> *ShGetVaryings(const ShHandle handle)
{
- return GetShaderVariables<sh::Varying>(handle);
+ return GetShaderVariables<Varying>(handle);
}
-const std::vector<sh::Attribute> *ShGetAttributes(const ShHandle handle)
+const std::vector<Attribute> *ShGetAttributes(const ShHandle handle)
{
- return GetShaderVariables<sh::Attribute>(handle);
+ return GetShaderVariables<Attribute>(handle);
}
-const std::vector<sh::OutputVariable> *ShGetOutputVariables(const ShHandle handle)
+const std::vector<OutputVariable> *ShGetOutputVariables(const ShHandle handle)
{
- return GetShaderVariables<sh::OutputVariable>(handle);
+ return GetShaderVariables<OutputVariable>(handle);
}
-const std::vector<sh::InterfaceBlock> *ShGetInterfaceBlocks(const ShHandle handle)
+const std::vector<InterfaceBlock> *ShGetInterfaceBlocks(const ShHandle handle)
{
- return GetShaderVariables<sh::InterfaceBlock>(handle);
+ return GetShaderVariables<InterfaceBlock>(handle);
}
-sh::WorkGroupSize ShGetComputeShaderLocalGroupSize(const ShHandle handle)
+WorkGroupSize ShGetComputeShaderLocalGroupSize(const ShHandle handle)
{
ASSERT(handle);
@@ -369,7 +372,7 @@
}
bool ShCheckVariablesWithinPackingLimits(int maxVectors,
- const std::vector<sh::ShaderVariable> &variables)
+ const std::vector<ShaderVariable> &variables)
{
VariablePacker packer;
return packer.CheckVariablesWithinPackingLimits(maxVectors, variables);
@@ -408,3 +411,123 @@
return nullptr;
#endif // ANGLE_ENABLE_HLSL
}
+
+namespace sh
+{
+bool Initialize()
+{
+ return ShInitialize();
+}
+
+bool Finalize()
+{
+ return ShFinalize();
+}
+
+void InitBuiltInResources(ShBuiltInResources *resources)
+{
+ ShInitBuiltInResources(resources);
+}
+
+const std::string &GetBuiltInResourcesString(const ShHandle handle)
+{
+ return ShGetBuiltInResourcesString(handle);
+}
+
+ShHandle ConstructCompiler(sh::GLenum type,
+ ShShaderSpec spec,
+ ShShaderOutput output,
+ const ShBuiltInResources *resources)
+{
+ return ShConstructCompiler(type, spec, output, resources);
+}
+
+void Destruct(ShHandle handle)
+{
+ return ShDestruct(handle);
+}
+
+bool Compile(const ShHandle handle,
+ const char *const shaderStrings[],
+ size_t numStrings,
+ ShCompileOptions compileOptions)
+{
+ return ShCompile(handle, shaderStrings, numStrings, compileOptions);
+}
+
+void ClearResults(const ShHandle handle)
+{
+ return ShClearResults(handle);
+}
+
+int GetShaderVersion(const ShHandle handle)
+{
+ return ShGetShaderVersion(handle);
+}
+
+ShShaderOutput GetShaderOutputType(const ShHandle handle)
+{
+ return ShGetShaderOutputType(handle);
+}
+
+const std::string &GetInfoLog(const ShHandle handle)
+{
+ return ShGetInfoLog(handle);
+}
+
+const std::string &GetObjectCode(const ShHandle handle)
+{
+ return ShGetObjectCode(handle);
+}
+
+const std::map<std::string, std::string> *GetNameHashingMap(const ShHandle handle)
+{
+ return ShGetNameHashingMap(handle);
+}
+
+const std::vector<sh::Uniform> *GetUniforms(const ShHandle handle)
+{
+ return ShGetUniforms(handle);
+}
+const std::vector<sh::Varying> *GetVaryings(const ShHandle handle)
+{
+ return ShGetVaryings(handle);
+}
+const std::vector<sh::Attribute> *GetAttributes(const ShHandle handle)
+{
+ return ShGetAttributes(handle);
+}
+
+const std::vector<sh::OutputVariable> *GetOutputVariables(const ShHandle handle)
+{
+ return ShGetOutputVariables(handle);
+}
+const std::vector<sh::InterfaceBlock> *GetInterfaceBlocks(const ShHandle handle)
+{
+ return ShGetInterfaceBlocks(handle);
+}
+
+sh::WorkGroupSize GetComputeShaderLocalGroupSize(const ShHandle handle)
+{
+ return ShGetComputeShaderLocalGroupSize(handle);
+}
+
+bool CheckVariablesWithinPackingLimits(int maxVectors,
+ const std::vector<sh::ShaderVariable> &variables)
+{
+ return ShCheckVariablesWithinPackingLimits(maxVectors, variables);
+}
+
+bool GetInterfaceBlockRegister(const ShHandle handle,
+ const std::string &interfaceBlockName,
+ unsigned int *indexOut)
+{
+ return ShGetInterfaceBlockRegister(handle, interfaceBlockName, indexOut);
+}
+
+const std::map<std::string, unsigned int> *GetUniformRegisterMap(const ShHandle handle)
+{
+ return ShGetUniformRegisterMap(handle);
+}
+
+} // namespace sh
diff --git a/src/compiler/translator/TranslatorESSL.cpp b/src/compiler/translator/TranslatorESSL.cpp
index c942880..55c1b67 100644
--- a/src/compiler/translator/TranslatorESSL.cpp
+++ b/src/compiler/translator/TranslatorESSL.cpp
@@ -11,6 +11,9 @@
#include "compiler/translator/OutputESSL.h"
#include "angle_gl.h"
+namespace sh
+{
+
TranslatorESSL::TranslatorESSL(sh::GLenum type, ShShaderSpec spec)
: TCompiler(type, spec, SH_ESSL_OUTPUT)
{
@@ -107,3 +110,5 @@
}
}
}
+
+} // namespace sh
diff --git a/src/compiler/translator/TranslatorESSL.h b/src/compiler/translator/TranslatorESSL.h
index f147ca0..b7b46a6 100644
--- a/src/compiler/translator/TranslatorESSL.h
+++ b/src/compiler/translator/TranslatorESSL.h
@@ -9,6 +9,9 @@
#include "compiler/translator/Compiler.h"
+namespace sh
+{
+
class TranslatorESSL : public TCompiler
{
public:
@@ -22,4 +25,6 @@
void writeExtensionBehavior();
};
+} // namespace sh
+
#endif // COMPILER_TRANSLATOR_TRANSLATORESSL_H_
diff --git a/src/compiler/translator/TranslatorGLSL.cpp b/src/compiler/translator/TranslatorGLSL.cpp
index 5ba3e01..4bbff97 100644
--- a/src/compiler/translator/TranslatorGLSL.cpp
+++ b/src/compiler/translator/TranslatorGLSL.cpp
@@ -14,6 +14,9 @@
#include "compiler/translator/RewriteTexelFetchOffset.h"
#include "compiler/translator/VersionGLSL.h"
+namespace sh
+{
+
TranslatorGLSL::TranslatorGLSL(sh::GLenum type,
ShShaderSpec spec,
ShShaderOutput output)
@@ -296,3 +299,5 @@
sink << "invariant " << builtinVaryingName << ";\n";
}
}
+
+} // namespace sh
diff --git a/src/compiler/translator/TranslatorGLSL.h b/src/compiler/translator/TranslatorGLSL.h
index af3b187..d6f6948 100644
--- a/src/compiler/translator/TranslatorGLSL.h
+++ b/src/compiler/translator/TranslatorGLSL.h
@@ -9,6 +9,9 @@
#include "compiler/translator/Compiler.h"
+namespace sh
+{
+
class TranslatorGLSL : public TCompiler
{
public:
@@ -28,4 +31,6 @@
void conditionallyOutputInvariantDeclaration(const char *builtinVaryingName);
};
+} // namespace sh
+
#endif // COMPILER_TRANSLATOR_TRANSLATORGLSL_H_
diff --git a/src/compiler/translator/TranslatorHLSL.cpp b/src/compiler/translator/TranslatorHLSL.cpp
index fb011da..7ef1d4e 100644
--- a/src/compiler/translator/TranslatorHLSL.cpp
+++ b/src/compiler/translator/TranslatorHLSL.cpp
@@ -24,6 +24,9 @@
#include "compiler/translator/SplitSequenceOperator.h"
#include "compiler/translator/UnfoldShortCircuitToIf.h"
+namespace sh
+{
+
TranslatorHLSL::TranslatorHLSL(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output)
: TCompiler(type, spec, output)
{
@@ -141,3 +144,5 @@
{
return &mUniformRegisterMap;
}
+
+} // namespace sh
diff --git a/src/compiler/translator/TranslatorHLSL.h b/src/compiler/translator/TranslatorHLSL.h
index 213d860..3bf64b2 100644
--- a/src/compiler/translator/TranslatorHLSL.h
+++ b/src/compiler/translator/TranslatorHLSL.h
@@ -9,6 +9,9 @@
#include "compiler/translator/Compiler.h"
+namespace sh
+{
+
class TranslatorHLSL : public TCompiler
{
public:
@@ -31,4 +34,6 @@
std::map<std::string, unsigned int> mUniformRegisterMap;
};
+} // namespace sh
+
#endif // COMPILER_TRANSLATOR_TRANSLATORHLSL_H_
diff --git a/src/compiler/translator/glslang.l b/src/compiler/translator/glslang.l
index ed82498..0924e83 100644
--- a/src/compiler/translator/glslang.l
+++ b/src/compiler/translator/glslang.l
@@ -599,7 +599,7 @@
if (context->getFragmentPrecisionHigh())
preprocessor->predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
- preprocessor->setMaxTokenSize(GetGlobalMaxTokenSize(context->getShaderSpec()));
+ preprocessor->setMaxTokenSize(sh::GetGlobalMaxTokenSize(context->getShaderSpec()));
return 0;
}
diff --git a/src/compiler/translator/glslang_lex.cpp b/src/compiler/translator/glslang_lex.cpp
index 0e23a0f..77f0bea 100644
--- a/src/compiler/translator/glslang_lex.cpp
+++ b/src/compiler/translator/glslang_lex.cpp
@@ -3260,7 +3260,7 @@
if (context->getFragmentPrecisionHigh())
preprocessor->predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
- preprocessor->setMaxTokenSize(GetGlobalMaxTokenSize(context->getShaderSpec()));
+ preprocessor->setMaxTokenSize(sh::GetGlobalMaxTokenSize(context->getShaderSpec()));
return 0;
}
diff --git a/src/compiler/translator/length_limits.h b/src/compiler/translator/length_limits.h
index 8863438..607157f 100644
--- a/src/compiler/translator/length_limits.h
+++ b/src/compiler/translator/length_limits.h
@@ -16,6 +16,11 @@
// These constants are factored out from the rest of the headers to
// make it easier to reference them from the compiler sources.
+namespace sh
+{
+
size_t GetGlobalMaxTokenSize(ShShaderSpec spec);
+} // namespace sh
+
#endif // COMPILER_TRANSLATOR_LENGTHLIMITS_H_