Commit acb4b81a by Jamie Madill Committed by Commit Bot

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/408337Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 01a80eeb
......@@ -49,7 +49,7 @@ static bool ParseIntValue(const std::string &, int emptyDefault, int *outValue);
//
void GenerateResources(ShBuiltInResources *resources)
{
ShInitBuiltInResources(resources);
sh::InitBuiltInResources(resources);
resources->MaxVertexAttribs = 8;
resources->MaxVertexUniformVectors = 128;
......@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
ShShaderSpec spec = SH_GLES2_SPEC;
ShShaderOutput output = SH_ESSL_OUTPUT;
ShInitialize();
sh::Initialize();
ShBuiltInResources resources;
GenerateResources(&resources);
......@@ -230,16 +230,16 @@ int main(int argc, char *argv[])
case GL_VERTEX_SHADER:
if (vertexCompiler == 0)
{
vertexCompiler = ShConstructCompiler(
GL_VERTEX_SHADER, spec, output, &resources);
vertexCompiler =
sh::ConstructCompiler(GL_VERTEX_SHADER, spec, output, &resources);
}
compiler = vertexCompiler;
break;
case GL_FRAGMENT_SHADER:
if (fragmentCompiler == 0)
{
fragmentCompiler = ShConstructCompiler(
GL_FRAGMENT_SHADER, spec, output, &resources);
fragmentCompiler =
sh::ConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
}
compiler = fragmentCompiler;
break;
......@@ -247,7 +247,7 @@ int main(int argc, char *argv[])
if (computeCompiler == 0)
{
computeCompiler =
ShConstructCompiler(GL_COMPUTE_SHADER, spec, output, &resources);
sh::ConstructCompiler(GL_COMPUTE_SHADER, spec, output, &resources);
}
compiler = computeCompiler;
break;
......@@ -259,7 +259,7 @@ int main(int argc, char *argv[])
bool compiled = CompileFile(argv[0], compiler, compileOptions);
LogMsg("BEGIN", "COMPILER", numCompiles, "INFO LOG");
std::string log = ShGetInfoLog(compiler);
std::string log = sh::GetInfoLog(compiler);
puts(log.c_str());
LogMsg("END", "COMPILER", numCompiles, "INFO LOG");
printf("\n\n");
......@@ -267,7 +267,7 @@ int main(int argc, char *argv[])
if (compiled && (compileOptions & SH_OBJECT_CODE))
{
LogMsg("BEGIN", "COMPILER", numCompiles, "OBJ CODE");
std::string code = ShGetObjectCode(compiler);
std::string code = sh::GetObjectCode(compiler);
puts(code.c_str());
LogMsg("END", "COMPILER", numCompiles, "OBJ CODE");
printf("\n\n");
......@@ -296,13 +296,13 @@ int main(int argc, char *argv[])
usage();
if (vertexCompiler)
ShDestruct(vertexCompiler);
sh::Destruct(vertexCompiler);
if (fragmentCompiler)
ShDestruct(fragmentCompiler);
sh::Destruct(fragmentCompiler);
if (computeCompiler)
ShDestruct(computeCompiler);
sh::Destruct(computeCompiler);
ShFinalize();
sh::Finalize();
return failCode;
}
......@@ -376,7 +376,7 @@ sh::GLenum FindShaderType(const char *fileName)
}
//
// Read a file's data into a string, and compile it using ShCompile
// Read a file's data into a string, and compile it using sh::Compile
//
bool CompileFile(char *fileName, ShHandle compiler, ShCompileOptions compileOptions)
{
......@@ -384,7 +384,7 @@ bool CompileFile(char *fileName, ShHandle compiler, ShCompileOptions compileOpti
if (!ReadShaderSource(fileName, source))
return false;
int ret = ShCompile(compiler, &source[0], source.size(), compileOptions);
int ret = sh::Compile(compiler, &source[0], source.size(), compileOptions);
FreeShaderSource(source);
return ret ? true : false;
......@@ -447,10 +447,10 @@ void PrintVariable(const std::string &prefix, size_t index, const sh::ShaderVari
static void PrintActiveVariables(ShHandle compiler)
{
const std::vector<sh::Uniform> *uniforms = ShGetUniforms(compiler);
const std::vector<sh::Varying> *varyings = ShGetVaryings(compiler);
const std::vector<sh::Attribute> *attributes = ShGetAttributes(compiler);
const std::vector<sh::OutputVariable> *outputs = ShGetOutputVariables(compiler);
const std::vector<sh::Uniform> *uniforms = sh::GetUniforms(compiler);
const std::vector<sh::Varying> *varyings = sh::GetVaryings(compiler);
const std::vector<sh::Attribute> *attributes = sh::GetAttributes(compiler);
const std::vector<sh::OutputVariable> *outputs = sh::GetOutputVariables(compiler);
for (size_t varCategory = 0; varCategory < 4; ++varCategory)
{
size_t numVars = 0;
......
......@@ -14,6 +14,8 @@
#include "compiler/translator/Compiler.h"
#include "angle_gl.h"
using namespace sh;
struct TranslatorCacheKey
{
bool operator==(const TranslatorCacheKey &other) const
......
......@@ -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 @@ TCompiler* ConstructCompiler(
#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 @@ TCompiler* ConstructCompiler(
#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 @@ void DeleteCompiler(TCompiler* compiler)
{
delete compiler;
}
} // namespace sh
......@@ -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 @@ TCompiler* ConstructCompiler(
sh::GLenum type, ShShaderSpec spec, ShShaderOutput output);
void DeleteCompiler(TCompiler*);
} // namespace sh
#endif // COMPILER_TRANSLATOR_COMPILER_H_
......@@ -716,6 +716,6 @@ bool EmulatePrecision::SupportedInLanguage(const ShShaderOutput outputLanguage)
default:
// Other languages not yet supported
return (outputLanguage == SH_GLSL_COMPATIBILITY_OUTPUT ||
IsGLSL130OrNewer(outputLanguage));
sh::IsGLSL130OrNewer(outputLanguage));
}
}
......@@ -39,11 +39,11 @@ void TOutputGLSL::visitSymbol(TIntermSymbol *node)
{
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 @@ TString TOutputGLSL::translateTextureFunction(TString &name)
"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)
{
......
......@@ -150,7 +150,7 @@ void TOutputGLSLBase::writeVariableType(const TType &type)
{
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 @@ void TOutputGLSLBase::writeVariableType(const TType &type)
}
if (qualifier != EvqTemporary && qualifier != EvqGlobal)
{
if (IsGLSL130OrNewer(mOutput))
if (sh::IsGLSL130OrNewer(mOutput))
{
switch (qualifier)
{
......
......@@ -65,6 +65,50 @@ bool ContainsImage(const TType &type)
} // 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 @@ bool TParseContext::checkIsNotReserved(const TSourceLoc &line, const TString &id
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::exitStructDeclaration()
void TParseContext::checkIsBelowStructNestingLimit(const TSourceLoc &line, const TField &field)
{
if (!IsWebGLBasedSpec(mShaderSpec))
if (!sh::IsWebGLBasedSpec(mShaderSpec))
{
return;
}
......@@ -3134,7 +3178,7 @@ TLayoutQualifier TParseContext::parseLayoutQualifier(const TString &qualifierTyp
if (qualifierType == "shared")
{
if (IsWebGLBasedSpec(mShaderSpec))
if (sh::IsWebGLBasedSpec(mShaderSpec))
{
error(qualifierTypeLine, "Only std140 layout is allowed in WebGL", "shared");
}
......@@ -3142,7 +3186,7 @@ TLayoutQualifier TParseContext::parseLayoutQualifier(const TString &qualifierTyp
}
else if (qualifierType == "packed")
{
if (IsWebGLBasedSpec(mShaderSpec))
if (sh::IsWebGLBasedSpec(mShaderSpec))
{
error(qualifierTypeLine, "Only std140 layout is allowed in WebGL", "packed");
}
......
......@@ -36,42 +36,7 @@ class TParseContext : angle::NonCopyable
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; }
......
......@@ -20,6 +20,8 @@
#include "compiler/translator/VariablePacker.h"
#include "angle_gl.h"
using namespace sh;
namespace
{
......@@ -34,31 +36,31 @@ 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();
}
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 @@ ShHandle ShConstructCompiler(sh::GLenum type, ShShaderSpec spec,
}
// Generate built-in symbol table.
if (!compiler->Init(*resources)) {
ShDestruct(base);
if (!compiler->Init(*resources))
{
sh::Destruct(base);
return 0;
}
......@@ -332,32 +335,32 @@ const std::map<std::string, std::string> *ShGetNameHashingMap(
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 @@ sh::WorkGroupSize ShGetComputeShaderLocalGroupSize(const ShHandle handle)
}
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 @@ const std::map<std::string, unsigned int> *ShGetUniformRegisterMap(const ShHandl
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
......@@ -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 @@ void TranslatorESSL::writeExtensionBehavior() {
}
}
}
} // namespace sh
......@@ -9,6 +9,9 @@
#include "compiler/translator/Compiler.h"
namespace sh
{
class TranslatorESSL : public TCompiler
{
public:
......@@ -22,4 +25,6 @@ class TranslatorESSL : public TCompiler
void writeExtensionBehavior();
};
} // namespace sh
#endif // COMPILER_TRANSLATOR_TRANSLATORESSL_H_
......@@ -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 @@ void TranslatorGLSL::conditionallyOutputInvariantDeclaration(const char *builtin
sink << "invariant " << builtinVaryingName << ";\n";
}
}
} // namespace sh
......@@ -9,6 +9,9 @@
#include "compiler/translator/Compiler.h"
namespace sh
{
class TranslatorGLSL : public TCompiler
{
public:
......@@ -28,4 +31,6 @@ class TranslatorGLSL : public TCompiler
void conditionallyOutputInvariantDeclaration(const char *builtinVaryingName);
};
} // namespace sh
#endif // COMPILER_TRANSLATOR_TRANSLATORGLSL_H_
......@@ -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 @@ const std::map<std::string, unsigned int> *TranslatorHLSL::getUniformRegisterMap
{
return &mUniformRegisterMap;
}
} // namespace sh
......@@ -9,6 +9,9 @@
#include "compiler/translator/Compiler.h"
namespace sh
{
class TranslatorHLSL : public TCompiler
{
public:
......@@ -31,4 +34,6 @@ class TranslatorHLSL : public TCompiler
std::map<std::string, unsigned int> mUniformRegisterMap;
};
} // namespace sh
#endif // COMPILER_TRANSLATOR_TRANSLATORHLSL_H_
......@@ -599,7 +599,7 @@ int glslang_scan(size_t count, const char* const string[], const int length[],
if (context->getFragmentPrecisionHigh())
preprocessor->predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
preprocessor->setMaxTokenSize(GetGlobalMaxTokenSize(context->getShaderSpec()));
preprocessor->setMaxTokenSize(sh::GetGlobalMaxTokenSize(context->getShaderSpec()));
return 0;
}
......
......@@ -3260,7 +3260,7 @@ int glslang_scan(size_t count, const char* const string[], const int length[],
if (context->getFragmentPrecisionHigh())
preprocessor->predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
preprocessor->setMaxTokenSize(GetGlobalMaxTokenSize(context->getShaderSpec()));
preprocessor->setMaxTokenSize(sh::GetGlobalMaxTokenSize(context->getShaderSpec()));
return 0;
}
......
......@@ -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_
......@@ -19,8 +19,8 @@ namespace gl
namespace
{
// Global count of active shader compiler handles. Needed to know when to call ShInitialize and
// ShFinalize.
// Global count of active shader compiler handles. Needed to know when to call sh::Initialize and
// sh::Finalize.
size_t activeCompilerHandles = 0;
ShShaderSpec SelectShaderSpec(GLint majorVersion, GLint minorVersion, bool isWebGL)
......@@ -57,7 +57,7 @@ Compiler::Compiler(rx::GLImplFactory *implFactory, const ContextState &state)
const gl::Caps &caps = state.getCaps();
const gl::Extensions &extensions = state.getExtensions();
ShInitBuiltInResources(&mResources);
sh::InitBuiltInResources(&mResources);
mResources.MaxVertexAttribs = caps.maxVertexAttributes;
mResources.MaxVertexUniformVectors = caps.maxVertexUniformVectors;
mResources.MaxVaryingVectors = caps.maxVaryingVectors;
......@@ -122,7 +122,7 @@ Error Compiler::release()
{
if (mFragmentCompiler)
{
ShDestruct(mFragmentCompiler);
sh::Destruct(mFragmentCompiler);
mFragmentCompiler = nullptr;
ASSERT(activeCompilerHandles > 0);
......@@ -131,7 +131,7 @@ Error Compiler::release()
if (mVertexCompiler)
{
ShDestruct(mVertexCompiler);
sh::Destruct(mVertexCompiler);
mVertexCompiler = nullptr;
ASSERT(activeCompilerHandles > 0);
......@@ -140,7 +140,7 @@ Error Compiler::release()
if (mComputeCompiler)
{
ShDestruct(mComputeCompiler);
sh::Destruct(mComputeCompiler);
mComputeCompiler = nullptr;
ASSERT(activeCompilerHandles > 0);
......@@ -149,7 +149,7 @@ Error Compiler::release()
if (activeCompilerHandles == 0)
{
ShFinalize();
sh::Finalize();
}
mImplementation->release();
......@@ -181,10 +181,10 @@ ShHandle Compiler::getCompilerHandle(GLenum type)
{
if (activeCompilerHandles == 0)
{
ShInitialize();
sh::Initialize();
}
*compiler = ShConstructCompiler(type, mSpec, mOutputType, &mResources);
*compiler = sh::ConstructCompiler(type, mSpec, mOutputType, &mResources);
activeCompilerHandles++;
}
......
......@@ -266,17 +266,17 @@ void Shader::compile(Compiler *compiler)
sourceCStrings.push_back(sourceString.c_str());
bool result =
ShCompile(compilerHandle, &sourceCStrings[0], sourceCStrings.size(), compileOptions);
sh::Compile(compilerHandle, &sourceCStrings[0], sourceCStrings.size(), compileOptions);
if (!result)
{
mInfoLog = ShGetInfoLog(compilerHandle);
mInfoLog = sh::GetInfoLog(compilerHandle);
TRACE("\n%s", mInfoLog.c_str());
mCompiled = false;
return;
}
mState.mTranslatedSource = ShGetObjectCode(compilerHandle);
mState.mTranslatedSource = sh::GetObjectCode(compilerHandle);
#ifndef NDEBUG
// Prefix translated shader with commented out un-translated shader.
......@@ -301,22 +301,22 @@ void Shader::compile(Compiler *compiler)
#endif
// Gather the shader information
mState.mShaderVersion = ShGetShaderVersion(compilerHandle);
mState.mShaderVersion = sh::GetShaderVersion(compilerHandle);
mState.mVaryings = GetShaderVariables(ShGetVaryings(compilerHandle));
mState.mUniforms = GetShaderVariables(ShGetUniforms(compilerHandle));
mState.mInterfaceBlocks = GetShaderVariables(ShGetInterfaceBlocks(compilerHandle));
mState.mVaryings = GetShaderVariables(sh::GetVaryings(compilerHandle));
mState.mUniforms = GetShaderVariables(sh::GetUniforms(compilerHandle));
mState.mInterfaceBlocks = GetShaderVariables(sh::GetInterfaceBlocks(compilerHandle));
switch (mState.mShaderType)
{
case GL_COMPUTE_SHADER:
{
mState.mLocalSize = ShGetComputeShaderLocalGroupSize(compilerHandle);
mState.mLocalSize = sh::GetComputeShaderLocalGroupSize(compilerHandle);
break;
}
case GL_VERTEX_SHADER:
{
mState.mActiveAttributes = GetActiveShaderVariables(ShGetAttributes(compilerHandle));
mState.mActiveAttributes = GetActiveShaderVariables(sh::GetAttributes(compilerHandle));
break;
}
case GL_FRAGMENT_SHADER:
......@@ -324,7 +324,7 @@ void Shader::compile(Compiler *compiler)
// TODO(jmadill): Figure out why we only sort in the FS, and if we need to.
std::sort(mState.mVaryings.begin(), mState.mVaryings.end(), CompareShaderVar);
mState.mActiveOutputVariables =
GetActiveShaderVariables(ShGetOutputVariables(compilerHandle));
GetActiveShaderVariables(sh::GetOutputVariables(compilerHandle));
break;
}
default:
......
......@@ -21,7 +21,7 @@ class ShaderImpl : angle::NonCopyable
ShaderImpl(const gl::ShaderState &data) : mData(data) {}
virtual ~ShaderImpl() { }
// Returns additional ShCompile options.
// Returns additional sh::Compile options.
virtual ShCompileOptions prepareSourceAndReturnOptions(std::stringstream *sourceStream,
std::string *sourcePath) = 0;
// Returns success for compiling on the driver. Returns success.
......
......@@ -201,7 +201,7 @@ bool ShaderD3D::postTranslateCompile(gl::Compiler *compiler, std::string *infoLo
ShHandle compilerHandle = compiler->getCompilerHandle(mData.getShaderType());
mUniformRegisterMap = GetUniformRegisterMap(ShGetUniformRegisterMap(compilerHandle));
mUniformRegisterMap = GetUniformRegisterMap(sh::GetUniformRegisterMap(compilerHandle));
for (const sh::InterfaceBlock &interfaceBlock : mData.getInterfaceBlocks())
{
......@@ -209,7 +209,7 @@ bool ShaderD3D::postTranslateCompile(gl::Compiler *compiler, std::string *infoLo
{
unsigned int index = static_cast<unsigned int>(-1);
bool blockRegisterResult =
ShGetInterfaceBlockRegister(compilerHandle, interfaceBlock.name, &index);
sh::GetInterfaceBlockRegister(compilerHandle, interfaceBlock.name, &index);
ASSERT(blockRegisterResult);
mInterfaceBlockRegisterMap[interfaceBlock.name] = index;
......
......@@ -21,7 +21,7 @@ class ShaderNULL : public ShaderImpl
ShaderNULL(const gl::ShaderState &data);
~ShaderNULL() override;
// Returns additional ShCompile options.
// Returns additional sh::Compile options.
ShCompileOptions prepareSourceAndReturnOptions(std::stringstream *sourceStream,
std::string *sourcePath) override;
// Returns success for compiling on the driver. Returns success.
......
......@@ -21,7 +21,7 @@ class ShaderVk : public ShaderImpl
ShaderVk(const gl::ShaderState &data);
~ShaderVk() override;
// Returns additional ShCompile options.
// Returns additional sh::Compile options.
ShCompileOptions prepareSourceAndReturnOptions(std::stringstream *sourceStream,
std::string *sourcePath) override;
// Returns success for compiling on the driver. Returns success.
......
......@@ -10,17 +10,17 @@
class CompilerTestEnvironment : public testing::Environment
{
public:
virtual void SetUp()
void SetUp() override
{
if (!ShInitialize())
if (!sh::Initialize())
{
FAIL() << "Failed to initialize the compiler.";
}
}
virtual void TearDown()
void TearDown() override
{
if (!ShFinalize())
if (!sh::Finalize())
{
FAIL() << "Failed to finalize the compiler.";
}
......
......@@ -15,11 +15,11 @@ TEST(APITest, CompareShBuiltInResources)
{
ShBuiltInResources a_resources;
memset(&a_resources, 88, sizeof(a_resources));
ShInitBuiltInResources(&a_resources);
sh::InitBuiltInResources(&a_resources);
ShBuiltInResources b_resources;
memset(&b_resources, 77, sizeof(b_resources));
ShInitBuiltInResources(&b_resources);
sh::InitBuiltInResources(&b_resources);
EXPECT_TRUE(memcmp(&a_resources, &b_resources, sizeof(a_resources)) == 0);
}
......
......@@ -15,6 +15,8 @@
#include "compiler/translator/PoolAlloc.h"
#include "compiler/translator/TranslatorESSL.h"
using namespace sh;
template <typename T>
class ConstantFinder : public TIntermTraverser
{
......@@ -107,7 +109,7 @@ class ConstantFoldingTest : public testing::Test
allocator.push();
SetGlobalPoolAllocator(&allocator);
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
InitBuiltInResources(&resources);
mTranslatorESSL = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_GLES3_SPEC);
ASSERT_TRUE(mTranslatorESSL->Init(resources));
......
......@@ -1037,7 +1037,7 @@ TEST(DebugShaderPrecisionNegativeTest, HLSL3Unsupported)
std::string infoLog;
std::string translatedCode;
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
sh::InitBuiltInResources(&resources);
resources.WEBGL_debug_shader_precision = 1;
ASSERT_FALSE(compileTestShader(GL_FRAGMENT_SHADER, SH_GLES3_SPEC, SH_HLSL_3_0_OUTPUT,
shaderString, &resources, 0, &translatedCode, &infoLog));
......
......@@ -124,7 +124,7 @@ class EXTBlendFuncExtendedTest
protected:
virtual void SetUp()
{
ShInitBuiltInResources(&mResources);
sh::InitBuiltInResources(&mResources);
// EXT_draw_buffers is used in some of the shaders for test purposes.
mResources.EXT_draw_buffers = 1;
mResources.NV_draw_buffers = 2;
......@@ -137,7 +137,7 @@ class EXTBlendFuncExtendedTest
{
if (mCompiler)
{
ShDestruct(mCompiler);
sh::Destruct(mCompiler);
mCompiler = NULL;
}
}
......@@ -145,8 +145,8 @@ class EXTBlendFuncExtendedTest
void InitializeCompiler()
{
DestroyCompiler();
mCompiler = ShConstructCompiler(GL_FRAGMENT_SHADER, testing::get<0>(GetParam()),
SH_GLSL_COMPATIBILITY_OUTPUT, &mResources);
mCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, testing::get<0>(GetParam()),
SH_GLSL_COMPATIBILITY_OUTPUT, &mResources);
ASSERT_TRUE(mCompiler != NULL) << "Compiler could not be constructed.";
}
......@@ -163,12 +163,12 @@ class EXTBlendFuncExtendedTest
const char *shader)
{
const char *shaderStrings[] = {version, pragma, shader};
bool success = ShCompile(mCompiler, shaderStrings, 3, 0);
bool success = sh::Compile(mCompiler, shaderStrings, 3, 0);
if (success)
{
return ::testing::AssertionSuccess() << "Compilation success";
}
return ::testing::AssertionFailure() << ShGetInfoLog(mCompiler);
return ::testing::AssertionFailure() << sh::GetInfoLog(mCompiler);
}
protected:
......
......@@ -32,7 +32,7 @@ protected:
// Set up the per compile resources
static void GenerateResources(ShBuiltInResources *res)
{
ShInitBuiltInResources(res);
sh::InitBuiltInResources(res);
res->MaxVertexAttribs = 8;
res->MaxVertexUniformVectors = 128;
......@@ -179,14 +179,14 @@ protected:
ShCompileOptions compileOptions,
const char *expected_error)
{
bool success = ShCompile(compiler, &source, 1, compileOptions) != 0;
if (success)
{
success = !expected_error;
bool success = sh::Compile(compiler, &source, 1, compileOptions) != 0;
if (success)
{
success = !expected_error;
}
else
{
std::string log = ShGetInfoLog(compiler);
std::string log = sh::GetInfoLog(compiler);
if (expected_error)
success = log.find(expected_error) != std::string::npos;
......@@ -211,8 +211,7 @@ TEST_F(ExpressionLimitTest, ExpressionComplexity)
{
ShShaderSpec spec = SH_WEBGL_SPEC;
ShShaderOutput output = SH_ESSL_OUTPUT;
ShHandle vertexCompiler = ShConstructCompiler(
GL_FRAGMENT_SHADER, spec, output, &resources);
ShHandle vertexCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
ShCompileOptions compileOptions = SH_LIMIT_EXPRESSION_COMPLEXITY;
// Test expression under the limit passes.
......@@ -233,15 +232,14 @@ TEST_F(ExpressionLimitTest, ExpressionComplexity)
GenerateShaderWithLongExpression(
kMaxExpressionComplexity + 10).c_str(),
compileOptions & ~SH_LIMIT_EXPRESSION_COMPLEXITY, NULL));
ShDestruct(vertexCompiler);
sh::Destruct(vertexCompiler);
}
TEST_F(ExpressionLimitTest, UnusedExpressionComplexity)
{
ShShaderSpec spec = SH_WEBGL_SPEC;
ShShaderOutput output = SH_ESSL_OUTPUT;
ShHandle vertexCompiler = ShConstructCompiler(
GL_FRAGMENT_SHADER, spec, output, &resources);
ShHandle vertexCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
ShCompileOptions compileOptions = SH_LIMIT_EXPRESSION_COMPLEXITY;
// Test expression under the limit passes.
......@@ -262,15 +260,14 @@ TEST_F(ExpressionLimitTest, UnusedExpressionComplexity)
GenerateShaderWithUnusedLongExpression(
kMaxExpressionComplexity + 10).c_str(),
compileOptions & ~SH_LIMIT_EXPRESSION_COMPLEXITY, NULL));
ShDestruct(vertexCompiler);
sh::Destruct(vertexCompiler);
}
TEST_F(ExpressionLimitTest, CallStackDepth)
{
ShShaderSpec spec = SH_WEBGL_SPEC;
ShShaderOutput output = SH_ESSL_OUTPUT;
ShHandle vertexCompiler = ShConstructCompiler(
GL_FRAGMENT_SHADER, spec, output, &resources);
ShHandle vertexCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
ShCompileOptions compileOptions = SH_LIMIT_CALL_STACK_DEPTH;
// Test call stack under the limit passes.
......@@ -291,15 +288,14 @@ TEST_F(ExpressionLimitTest, CallStackDepth)
GenerateShaderWithDeepFunctionStack(
kMaxCallStackDepth + 10).c_str(),
compileOptions & ~SH_LIMIT_CALL_STACK_DEPTH, NULL));
ShDestruct(vertexCompiler);
sh::Destruct(vertexCompiler);
}
TEST_F(ExpressionLimitTest, UnusedCallStackDepth)
{
ShShaderSpec spec = SH_WEBGL_SPEC;
ShShaderOutput output = SH_ESSL_OUTPUT;
ShHandle vertexCompiler = ShConstructCompiler(
GL_FRAGMENT_SHADER, spec, output, &resources);
ShHandle vertexCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
ShCompileOptions compileOptions = SH_LIMIT_CALL_STACK_DEPTH;
// Test call stack under the limit passes.
......@@ -320,15 +316,14 @@ TEST_F(ExpressionLimitTest, UnusedCallStackDepth)
GenerateShaderWithUnusedDeepFunctionStack(
kMaxCallStackDepth + 10).c_str(),
compileOptions & ~SH_LIMIT_CALL_STACK_DEPTH, NULL));
ShDestruct(vertexCompiler);
sh::Destruct(vertexCompiler);
}
TEST_F(ExpressionLimitTest, Recursion)
{
ShShaderSpec spec = SH_WEBGL_SPEC;
ShShaderOutput output = SH_ESSL_OUTPUT;
ShHandle vertexCompiler = ShConstructCompiler(
GL_FRAGMENT_SHADER, spec, output, &resources);
ShHandle vertexCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
ShCompileOptions compileOptions = 0;
static const char* shaderWithRecursion0 = SHADER(
......@@ -536,14 +531,14 @@ TEST_F(ExpressionLimitTest, Recursion)
EXPECT_TRUE(CheckShaderCompilation(
vertexCompiler, shaderWithNoRecursion,
compileOptions | SH_LIMIT_CALL_STACK_DEPTH, NULL));
ShDestruct(vertexCompiler);
sh::Destruct(vertexCompiler);
}
TEST_F(ExpressionLimitTest, FunctionParameterCount)
{
ShShaderSpec spec = SH_WEBGL_SPEC;
ShShaderOutput output = SH_ESSL_OUTPUT;
ShHandle compiler = ShConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
ShHandle compiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
ShCompileOptions compileOptions = SH_LIMIT_EXPRESSION_COMPLEXITY;
// Test parameters under the limit succeeds.
......@@ -558,5 +553,5 @@ TEST_F(ExpressionLimitTest, FunctionParameterCount)
EXPECT_TRUE(CheckShaderCompilation(
compiler, GenerateShaderWithFunctionParameters(kMaxFunctionParameters + 1).c_str(),
compileOptions & ~SH_LIMIT_EXPRESSION_COMPLEXITY, nullptr));
ShDestruct(compiler);
sh::Destruct(compiler);
}
......@@ -23,7 +23,7 @@ class FragDepthTest : public testing::TestWithParam<bool>
protected:
void SetUp() override
{
ShInitBuiltInResources(&mResources);
sh::InitBuiltInResources(&mResources);
mCompiler = nullptr;
mResources.EXT_frag_depth = GetParam();
}
......@@ -33,7 +33,7 @@ class FragDepthTest : public testing::TestWithParam<bool>
{
if (mCompiler)
{
ShDestruct(mCompiler);
sh::Destruct(mCompiler);
mCompiler = nullptr;
}
}
......@@ -41,8 +41,8 @@ class FragDepthTest : public testing::TestWithParam<bool>
void InitializeCompiler()
{
DestroyCompiler();
mCompiler = ShConstructCompiler(GL_FRAGMENT_SHADER, SH_GLES3_SPEC,
SH_GLSL_COMPATIBILITY_OUTPUT, &mResources);
mCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, SH_GLES3_SPEC,
SH_GLSL_COMPATIBILITY_OUTPUT, &mResources);
ASSERT_TRUE(mCompiler != nullptr) << "Compiler could not be constructed.";
}
......@@ -51,12 +51,12 @@ class FragDepthTest : public testing::TestWithParam<bool>
const char *shader)
{
const char *shaderStrings[] = {version, pragma, shader};
bool success = ShCompile(mCompiler, shaderStrings, 3, 0);
bool success = sh::Compile(mCompiler, shaderStrings, 3, 0);
if (success)
{
return ::testing::AssertionSuccess() << "Compilation success";
}
return ::testing::AssertionFailure() << ShGetInfoLog(mCompiler);
return ::testing::AssertionFailure() << sh::GetInfoLog(mCompiler);
}
protected:
......
......@@ -12,6 +12,8 @@
#include "GLSLANG/ShaderLang.h"
#include "compiler/translator/TranslatorESSL.h"
using namespace sh;
class MalformedShaderTest : public testing::Test
{
public:
......@@ -21,7 +23,7 @@ class MalformedShaderTest : public testing::Test
virtual void SetUp()
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_GLES3_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
......@@ -63,7 +65,7 @@ class MalformedVertexShaderTest : public MalformedShaderTest
void SetUp() override
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_VERTEX_SHADER, SH_GLES3_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
......@@ -79,7 +81,7 @@ class MalformedWebGL2ShaderTest : public MalformedShaderTest
void SetUp() override
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_WEBGL2_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
......@@ -95,7 +97,7 @@ class MalformedWebGL1ShaderTest : public MalformedShaderTest
void SetUp() override
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_WEBGL_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
......@@ -111,7 +113,7 @@ class MalformedVertexShaderGLES31Test : public MalformedShaderTest
void SetUp() override
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_VERTEX_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
......@@ -126,7 +128,7 @@ class MalformedFragmentShaderGLES31Test : public MalformedShaderTest
void SetUp() override
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
......@@ -141,7 +143,7 @@ class MalformedComputeShaderTest : public MalformedShaderTest
void SetUp() override
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_COMPUTE_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
......
......@@ -14,6 +14,8 @@
#include "GLSLANG/ShaderLang.h"
#include "tests/test_utils/compiler_test.h"
using namespace sh;
class QualificationVertexShaderTestESSL31 : public testing::Test
{
public:
......@@ -22,7 +24,7 @@ class QualificationVertexShaderTestESSL31 : public testing::Test
virtual void SetUp()
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_VERTEX_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
......
......@@ -12,6 +12,8 @@
#include "GLSLANG/ShaderLang.h"
#include "compiler/translator/TranslatorESSL.h"
using namespace sh;
class QualificationOrderShaderTest : public testing::Test
{
public:
......@@ -23,10 +25,10 @@ class QualificationOrderShaderTest : public testing::Test
virtual void TearDown() {}
// Return true when compilation succeeds
bool compile(const std::string &shaderString, GLenum shaderType, ShShaderSpec spec)
bool compile(const std::string &shaderString, ::GLenum shaderType, ShShaderSpec spec)
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
InitBuiltInResources(&resources);
resources.MaxDrawBuffers = (spec == SH_GLES2_SPEC) ? 1 : 8;
TranslatorESSL *translator = new TranslatorESSL(shaderType, spec);
......
......@@ -24,8 +24,9 @@ class RemovePowTest : public testing::Test
allocator.push();
SetGlobalPoolAllocator(&allocator);
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
mTranslatorGLSL = new TranslatorGLSL(GL_FRAGMENT_SHADER, SH_GLES2_SPEC, SH_GLSL_COMPATIBILITY_OUTPUT);
sh::InitBuiltInResources(&resources);
mTranslatorGLSL =
new sh::TranslatorGLSL(GL_FRAGMENT_SHADER, SH_GLES2_SPEC, SH_GLSL_COMPATIBILITY_OUTPUT);
ASSERT_TRUE(mTranslatorGLSL->Init(resources));
}
......@@ -55,7 +56,7 @@ class RemovePowTest : public testing::Test
}
private:
TranslatorGLSL *mTranslatorGLSL;
sh::TranslatorGLSL *mTranslatorGLSL;
TIntermNode *mASTRoot;
TPoolAllocator allocator;
......
......@@ -4,7 +4,7 @@
// found in the LICENSE file.
//
// ShCompile_test.cpp
// Test the ShCompile interface with different parameters.
// Test the sh::Compile interface with different parameters.
//
#include "angle_gl.h"
......@@ -19,9 +19,9 @@ class ShCompileTest : public testing::Test
protected:
void SetUp() override
{
ShInitBuiltInResources(&mResources);
mCompiler = ShConstructCompiler(GL_FRAGMENT_SHADER, SH_WEBGL_SPEC,
SH_GLSL_COMPATIBILITY_OUTPUT, &mResources);
sh::InitBuiltInResources(&mResources);
mCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, SH_WEBGL_SPEC,
SH_GLSL_COMPATIBILITY_OUTPUT, &mResources);
ASSERT_TRUE(mCompiler != nullptr) << "Compiler could not be constructed.";
}
......@@ -29,15 +29,15 @@ class ShCompileTest : public testing::Test
{
if (mCompiler)
{
ShDestruct(mCompiler);
sh::Destruct(mCompiler);
mCompiler = nullptr;
}
}
void testCompile(const char **shaderStrings, int stringCount, bool expectation)
{
bool success = ShCompile(mCompiler, shaderStrings, stringCount, 0);
const std::string &compileLog = ShGetInfoLog(mCompiler);
bool success = sh::Compile(mCompiler, shaderStrings, stringCount, 0);
const std::string &compileLog = sh::GetInfoLog(mCompiler);
EXPECT_EQ(expectation, success) << compileLog;
}
......@@ -46,7 +46,7 @@ class ShCompileTest : public testing::Test
ShHandle mCompiler;
};
// Test calling ShCompile with more than one shader source string.
// Test calling sh::Compile with more than one shader source string.
TEST_F(ShCompileTest, MultipleShaderStrings)
{
const std::string &shaderString1 =
......@@ -61,7 +61,7 @@ TEST_F(ShCompileTest, MultipleShaderStrings)
testCompile(shaderStrings, 2, true);
}
// Test calling ShCompile with a tokens split into different shader source strings.
// Test calling sh::Compile with a tokens split into different shader source strings.
TEST_F(ShCompileTest, TokensSplitInShaderStrings)
{
const std::string &shaderString1 =
......
......@@ -52,7 +52,7 @@ class ShaderExtensionTest : public testing::Test
protected:
virtual void SetUp()
{
ShInitBuiltInResources(&mResources);
sh::InitBuiltInResources(&mResources);
mCompiler = NULL;
}
......@@ -65,7 +65,7 @@ class ShaderExtensionTest : public testing::Test
{
if (mCompiler)
{
ShDestruct(mCompiler);
sh::Destruct(mCompiler);
mCompiler = NULL;
}
}
......@@ -73,15 +73,15 @@ class ShaderExtensionTest : public testing::Test
void InitializeCompiler()
{
DestroyCompiler();
mCompiler = ShConstructCompiler(GL_FRAGMENT_SHADER, SH_WEBGL_SPEC,
SH_GLSL_COMPATIBILITY_OUTPUT, &mResources);
mCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, SH_WEBGL_SPEC,
SH_GLSL_COMPATIBILITY_OUTPUT, &mResources);
ASSERT_TRUE(mCompiler != NULL) << "Compiler could not be constructed.";
}
void TestShaderExtension(const char **shaderStrings, int stringCount, bool expectation)
{
bool success = ShCompile(mCompiler, shaderStrings, stringCount, 0);
const std::string& compileLog = ShGetInfoLog(mCompiler);
bool success = sh::Compile(mCompiler, shaderStrings, stringCount, 0);
const std::string &compileLog = sh::GetInfoLog(mCompiler);
EXPECT_EQ(expectation, success) << compileLog;
}
......
......@@ -112,9 +112,9 @@ class ShaderImageTest : public testing::Test
virtual void SetUp()
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_COMPUTE_SHADER, SH_GLES3_1_SPEC);
mTranslator = new sh::TranslatorESSL(GL_COMPUTE_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
......@@ -134,7 +134,7 @@ class ShaderImageTest : public testing::Test
protected:
std::string mTranslatedCode;
std::string mInfoLog;
TranslatorESSL *mTranslator;
sh::TranslatorESSL *mTranslator;
TIntermNode *mASTRoot;
};
......
......@@ -229,10 +229,10 @@ TEST(ShaderVariableTest, IsSameVaryingWithDifferentInvariance)
TEST(ShaderVariableTest, InvariantDoubleDeleteBug)
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
sh::InitBuiltInResources(&resources);
ShHandle compiler = ShConstructCompiler(GL_VERTEX_SHADER, SH_GLES2_SPEC,
SH_GLSL_COMPATIBILITY_OUTPUT, &resources);
ShHandle compiler = sh::ConstructCompiler(GL_VERTEX_SHADER, SH_GLES2_SPEC,
SH_GLSL_COMPATIBILITY_OUTPUT, &resources);
EXPECT_NE(static_cast<ShHandle>(0), compiler);
const char *program[] =
......@@ -246,18 +246,18 @@ TEST(ShaderVariableTest, InvariantDoubleDeleteBug)
"}"
};
EXPECT_TRUE(ShCompile(compiler, program, 1, SH_OBJECT_CODE));
EXPECT_TRUE(ShCompile(compiler, program, 1, SH_OBJECT_CODE));
ShDestruct(compiler);
EXPECT_TRUE(sh::Compile(compiler, program, 1, SH_OBJECT_CODE));
EXPECT_TRUE(sh::Compile(compiler, program, 1, SH_OBJECT_CODE));
sh::Destruct(compiler);
}
TEST(ShaderVariableTest, IllegalInvariantVarying)
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
sh::InitBuiltInResources(&resources);
ShHandle compiler = ShConstructCompiler(GL_VERTEX_SHADER, SH_GLES2_SPEC,
SH_GLSL_COMPATIBILITY_OUTPUT, &resources);
ShHandle compiler = sh::ConstructCompiler(GL_VERTEX_SHADER, SH_GLES2_SPEC,
SH_GLSL_COMPATIBILITY_OUTPUT, &resources);
EXPECT_NE(static_cast<ShHandle>(0), compiler);
const char *program1[] =
......@@ -284,17 +284,17 @@ TEST(ShaderVariableTest, IllegalInvariantVarying)
"}"
};
EXPECT_TRUE(ShCompile(compiler, program1, 1, SH_VARIABLES));
EXPECT_FALSE(ShCompile(compiler, program2, 1, SH_VARIABLES));
EXPECT_TRUE(sh::Compile(compiler, program1, 1, SH_VARIABLES));
EXPECT_FALSE(sh::Compile(compiler, program2, 1, SH_VARIABLES));
}
TEST(ShaderVariableTest, InvariantLeakAcrossShaders)
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
sh::InitBuiltInResources(&resources);
ShHandle compiler = ShConstructCompiler(GL_VERTEX_SHADER, SH_GLES2_SPEC,
SH_GLSL_COMPATIBILITY_OUTPUT, &resources);
ShHandle compiler = sh::ConstructCompiler(GL_VERTEX_SHADER, SH_GLES2_SPEC,
SH_GLSL_COMPATIBILITY_OUTPUT, &resources);
EXPECT_NE(static_cast<ShHandle>(0), compiler);
const char *program1[] =
......@@ -313,15 +313,15 @@ TEST(ShaderVariableTest, InvariantLeakAcrossShaders)
"}"
};
EXPECT_TRUE(ShCompile(compiler, program1, 1, SH_VARIABLES));
const std::vector<sh::Varying> *varyings = ShGetVaryings(compiler);
EXPECT_TRUE(sh::Compile(compiler, program1, 1, SH_VARIABLES));
const std::vector<sh::Varying> *varyings = sh::GetVaryings(compiler);
for (const sh::Varying &varying : *varyings)
{
if (varying.name == "v_varying")
EXPECT_TRUE(varying.isInvariant);
}
EXPECT_TRUE(ShCompile(compiler, program2, 1, SH_VARIABLES));
varyings = ShGetVaryings(compiler);
EXPECT_TRUE(sh::Compile(compiler, program2, 1, SH_VARIABLES));
varyings = sh::GetVaryings(compiler);
for (const sh::Varying &varying : *varyings)
{
if (varying.name == "v_varying")
......@@ -332,10 +332,10 @@ TEST(ShaderVariableTest, InvariantLeakAcrossShaders)
TEST(ShaderVariableTest, GlobalInvariantLeakAcrossShaders)
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
sh::InitBuiltInResources(&resources);
ShHandle compiler = ShConstructCompiler(GL_VERTEX_SHADER, SH_GLES2_SPEC,
SH_GLSL_COMPATIBILITY_OUTPUT, &resources);
ShHandle compiler = sh::ConstructCompiler(GL_VERTEX_SHADER, SH_GLES2_SPEC,
SH_GLSL_COMPATIBILITY_OUTPUT, &resources);
EXPECT_NE(static_cast<ShHandle>(0), compiler);
const char *program1[] =
......@@ -354,15 +354,15 @@ TEST(ShaderVariableTest, GlobalInvariantLeakAcrossShaders)
"}"
};
EXPECT_TRUE(ShCompile(compiler, program1, 1, SH_VARIABLES));
const std::vector<sh::Varying> *varyings = ShGetVaryings(compiler);
EXPECT_TRUE(sh::Compile(compiler, program1, 1, SH_VARIABLES));
const std::vector<sh::Varying> *varyings = sh::GetVaryings(compiler);
for (const sh::Varying &varying : *varyings)
{
if (varying.name == "v_varying")
EXPECT_TRUE(varying.isInvariant);
}
EXPECT_TRUE(ShCompile(compiler, program2, 1, SH_VARIABLES));
varyings = ShGetVaryings(compiler);
EXPECT_TRUE(sh::Compile(compiler, program2, 1, SH_VARIABLES));
varyings = sh::GetVaryings(compiler);
for (const sh::Varying &varying : *varyings)
{
if (varying.name == "v_varying")
......@@ -374,10 +374,10 @@ TEST(ShaderVariableTest, BuiltinInvariantVarying)
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
sh::InitBuiltInResources(&resources);
ShHandle compiler = ShConstructCompiler(GL_VERTEX_SHADER, SH_GLES2_SPEC,
SH_GLSL_COMPATIBILITY_OUTPUT, &resources);
ShHandle compiler = sh::ConstructCompiler(GL_VERTEX_SHADER, SH_GLES2_SPEC,
SH_GLSL_COMPATIBILITY_OUTPUT, &resources);
EXPECT_NE(static_cast<ShHandle>(0), compiler);
const char *program1[] =
......@@ -401,21 +401,21 @@ TEST(ShaderVariableTest, BuiltinInvariantVarying)
"}"
};
EXPECT_TRUE(ShCompile(compiler, program1, 1, SH_VARIABLES));
const std::vector<sh::Varying> *varyings = ShGetVaryings(compiler);
EXPECT_TRUE(sh::Compile(compiler, program1, 1, SH_VARIABLES));
const std::vector<sh::Varying> *varyings = sh::GetVaryings(compiler);
for (const sh::Varying &varying : *varyings)
{
if (varying.name == "gl_Position")
EXPECT_TRUE(varying.isInvariant);
}
EXPECT_TRUE(ShCompile(compiler, program2, 1, SH_VARIABLES));
varyings = ShGetVaryings(compiler);
EXPECT_TRUE(sh::Compile(compiler, program2, 1, SH_VARIABLES));
varyings = sh::GetVaryings(compiler);
for (const sh::Varying &varying : *varyings)
{
if (varying.name == "gl_Position")
EXPECT_FALSE(varying.isInvariant);
}
EXPECT_FALSE(ShCompile(compiler, program3, 1, SH_VARIABLES));
EXPECT_FALSE(sh::Compile(compiler, program3, 1, SH_VARIABLES));
}
} // namespace sh
......@@ -13,26 +13,25 @@
#include "GLSLANG/ShaderLang.h"
#include "compiler/translator/TranslatorESSL.h"
using namespace sh;
class TypeTrackingTest : public testing::Test
{
public:
TypeTrackingTest() {}
protected:
virtual void SetUp()
void SetUp() override
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
InitBuiltInResources(&resources);
resources.FragmentPrecisionHigh = 1;
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_GLES3_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
virtual void TearDown()
{
delete mTranslator;
}
void TearDown() override { delete mTranslator; }
void compile(const std::string& shaderString)
{
......
......@@ -13,6 +13,8 @@
#include "compiler/translator/TranslatorESSL.h"
#include "tests/test_utils/compiler_test.h"
using namespace sh;
class WorkGroupSizeTest : public testing::Test
{
public:
......@@ -22,7 +24,7 @@ class WorkGroupSizeTest : public testing::Test
void SetUp() override
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_COMPUTE_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
......@@ -56,7 +58,7 @@ TEST_F(WorkGroupSizeTest, OnlyLocalSizeXSpecified)
compile(shaderString);
const sh::WorkGroupSize &localSize = mTranslator->getComputeShaderLocalSize();
const WorkGroupSize &localSize = mTranslator->getComputeShaderLocalSize();
ASSERT_EQ(5, localSize[0]);
ASSERT_EQ(1, localSize[1]);
ASSERT_EQ(1, localSize[2]);
......@@ -73,7 +75,7 @@ TEST_F(WorkGroupSizeTest, LocalSizeXandZ)
compile(shaderString);
const sh::WorkGroupSize &localSize = mTranslator->getComputeShaderLocalSize();
const WorkGroupSize &localSize = mTranslator->getComputeShaderLocalSize();
ASSERT_EQ(5, localSize[0]);
ASSERT_EQ(1, localSize[1]);
ASSERT_EQ(10, localSize[2]);
......@@ -90,7 +92,7 @@ TEST_F(WorkGroupSizeTest, LocalSizeAll)
compile(shaderString);
const sh::WorkGroupSize &localSize = mTranslator->getComputeShaderLocalSize();
const WorkGroupSize &localSize = mTranslator->getComputeShaderLocalSize();
ASSERT_EQ(5, localSize[0]);
ASSERT_EQ(15, localSize[1]);
ASSERT_EQ(10, localSize[2]);
......
......@@ -80,7 +80,7 @@ bool compileTestShader(GLenum type,
std::string *translatedCode,
std::string *infoLog)
{
TCompiler *translator = ConstructCompiler(type, spec, output);
sh::TCompiler *translator = sh::ConstructCompiler(type, spec, output);
if (!translator->Init(*resources))
{
SafeDelete(translator);
......@@ -108,7 +108,7 @@ bool compileTestShader(GLenum type,
std::string *infoLog)
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
sh::InitBuiltInResources(&resources);
return compileTestShader(type, spec, output, shaderString, &resources, compileOptions, translatedCode, infoLog);
}
......@@ -117,7 +117,7 @@ MatchOutputCodeTest::MatchOutputCodeTest(GLenum shaderType,
ShShaderOutput outputType)
: mShaderType(shaderType), mDefaultCompileOptions(defaultCompileOptions)
{
ShInitBuiltInResources(&mResources);
sh::InitBuiltInResources(&mResources);
mOutputCode[outputType] = std::string();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment