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,9 +49,10 @@ typedef unsigned int GLenum;
// Version number for shader translation API.
// It is incremented every time the API changes.
#define ANGLE_SH_VERSION 164
#define ANGLE_SH_VERSION 165
typedef enum {
enum ShShaderSpec
{
SH_GLES2_SPEC,
SH_WEBGL_SPEC,
......@@ -60,10 +61,9 @@ typedef enum {
SH_GLES3_1_SPEC,
SH_WEBGL3_SPEC,
};
} ShShaderSpec;
typedef enum
enum ShShaderOutput
{
// ESSL output only supported in some configurations.
SH_ESSL_OUTPUT = 0x8B45,
......@@ -92,11 +92,11 @@ typedef enum
SH_HLSL_3_0_OUTPUT = 0x8B48, // D3D 9
SH_HLSL_4_1_OUTPUT = 0x8B49, // D3D 11
SH_HLSL_4_0_FL9_3_OUTPUT = 0x8B4A // D3D 11 feature level 9_3
} ShShaderOutput;
};
// Compile options.
typedef uint64_t ShCompileOptions;
using ShCompileOptions = uint64_t;
const ShCompileOptions SH_VALIDATE = 0;
const ShCompileOptions SH_VALIDATE_LOOP_INDEXING = UINT64_C(1) << 0;
......@@ -226,35 +226,24 @@ const ShCompileOptions SH_USE_UNUSED_STANDARD_SHARED_BLOCKS = UINT64_C(1) << 28;
const ShCompileOptions SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT = UINT64_C(1) << 29;
// Defines alternate strategies for implementing array index clamping.
typedef enum {
// Use the clamp intrinsic for array index clamping.
SH_CLAMP_WITH_CLAMP_INTRINSIC = 1,
// Use a user-defined function for array index clamping.
SH_CLAMP_WITH_USER_DEFINED_INT_CLAMP_FUNCTION
} ShArrayIndexClampingStrategy;
enum ShArrayIndexClampingStrategy
{
// Use the clamp intrinsic for array index clamping.
SH_CLAMP_WITH_CLAMP_INTRINSIC = 1,
//
// Driver must call this first, once, before doing any other
// compiler operations.
// If the function succeeds, the return value is true, else false.
//
COMPILER_EXPORT bool ShInitialize();
//
// Driver should call this at shutdown.
// If the function succeeds, the return value is true, else false.
//
COMPILER_EXPORT bool ShFinalize();
// Use a user-defined function for array index clamping.
SH_CLAMP_WITH_USER_DEFINED_INT_CLAMP_FUNCTION
};
// The 64 bits hash function. The first parameter is the input string; the
// second parameter is the string length.
typedef khronos_uint64_t (*ShHashFunction64)(const char*, size_t);
using ShHashFunction64 = khronos_uint64_t (*)(const char *, size_t);
//
// Implementation dependent built-in resources (constants and extensions).
// The names for these resources has been obtained by stripping gl_/GL_.
//
typedef struct
struct ShBuiltInResources
{
// Constants.
int MaxVertexAttribs;
......@@ -386,15 +375,7 @@ typedef struct
// maximum number of buffer object storage in machine units
int MaxAtomicCounterBufferSize;
} ShBuiltInResources;
//
// Initialize built-in resources with minimum expected values.
// Parameters:
// resources: The object to initialize. Will be comparable with memcmp.
//
COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources *resources);
};
//
// ShHandle held by but opaque to the driver. It is allocated,
......@@ -403,7 +384,26 @@ COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources *resources);
//
// If handle creation fails, 0 will be returned.
//
typedef void *ShHandle;
using ShHandle = void *;
//
// Driver must call this first, once, before doing any other
// compiler operations.
// If the function succeeds, the return value is true, else false.
//
COMPILER_EXPORT bool ShInitialize();
//
// Driver should call this at shutdown.
// If the function succeeds, the return value is true, else false.
//
COMPILER_EXPORT bool ShFinalize();
//
// Initialize built-in resources with minimum expected values.
// Parameters:
// resources: The object to initialize. Will be comparable with memcmp.
//
COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources *resources);
//
// Returns the a concatenated list of the items in ShBuiltInResources as a
......@@ -451,9 +451,9 @@ COMPILER_EXPORT void ShDestruct(ShHandle handle);
// There is no need to specify this parameter when
// compiling for WebGL - it is implied.
// SH_INTERMEDIATE_TREE: Writes intermediate tree to info log.
// Can be queried by calling ShGetInfoLog().
// Can be queried by calling sh::GetInfoLog().
// SH_OBJECT_CODE: Translates intermediate tree to glsl or hlsl shader.
// Can be queried by calling ShGetObjectCode().
// Can be queried by calling sh::GetObjectCode().
// SH_VARIABLES: Extracts attributes, uniforms, and varyings.
// Can be queried by calling ShGetVariableInfo().
//
......@@ -503,12 +503,6 @@ COMPILER_EXPORT const std::vector<sh::OutputVariable> *ShGetOutputVariables(cons
COMPILER_EXPORT const std::vector<sh::InterfaceBlock> *ShGetInterfaceBlocks(const ShHandle handle);
COMPILER_EXPORT sh::WorkGroupSize ShGetComputeShaderLocalGroupSize(const ShHandle handle);
typedef struct
{
sh::GLenum type;
int size;
} ShVariableInfo;
// Returns true if the passed in variables pack in maxVectors following
// the packing rules from the GLSL 1.017 spec, Appendix A, section 7.
// Returns false otherwise. Also look at the SH_ENFORCE_PACKING_RESTRICTIONS
......@@ -537,4 +531,146 @@ COMPILER_EXPORT bool ShGetInterfaceBlockRegister(const ShHandle handle,
COMPILER_EXPORT const std::map<std::string, unsigned int> *ShGetUniformRegisterMap(
const ShHandle handle);
// Temporary duplicate of the scoped APIs, to be removed when we roll ANGLE and fix Chromium.
// TODO(jmadill): Consolidate with these APIs once we roll ANGLE.
namespace sh
{
//
// Driver must call this first, once, before doing any other compiler operations.
// If the function succeeds, the return value is true, else false.
//
bool Initialize();
//
// Driver should call this at shutdown.
// If the function succeeds, the return value is true, else false.
//
bool Finalize();
//
// Initialize built-in resources with minimum expected values.
// Parameters:
// resources: The object to initialize. Will be comparable with memcmp.
//
void InitBuiltInResources(ShBuiltInResources *resources);
//
// Returns the a concatenated list of the items in ShBuiltInResources as a null-terminated string.
// This function must be updated whenever ShBuiltInResources is changed.
// Parameters:
// handle: Specifies the handle of the compiler to be used.
const std::string &GetBuiltInResourcesString(const ShHandle handle);
//
// Driver calls these to create and destroy compiler objects.
//
// Returns the handle of constructed compiler, null if the requested compiler is not supported.
// Parameters:
// type: Specifies the type of shader - GL_FRAGMENT_SHADER or GL_VERTEX_SHADER.
// spec: Specifies the language spec the compiler must conform to - SH_GLES2_SPEC or SH_WEBGL_SPEC.
// output: Specifies the output code type - for example SH_ESSL_OUTPUT, SH_GLSL_OUTPUT,
// SH_HLSL_3_0_OUTPUT or SH_HLSL_4_1_OUTPUT. Note: Each output type may only
// be supported in some configurations.
// resources: Specifies the built-in resources.
ShHandle ConstructCompiler(sh::GLenum type,
ShShaderSpec spec,
ShShaderOutput output,
const ShBuiltInResources *resources);
void Destruct(ShHandle handle);
//
// Compiles the given shader source.
// If the function succeeds, the return value is true, else false.
// Parameters:
// handle: Specifies the handle of compiler to be used.
// shaderStrings: Specifies an array of pointers to null-terminated strings containing the shader
// source code.
// numStrings: Specifies the number of elements in shaderStrings array.
// compileOptions: A mask containing the following parameters:
// SH_VALIDATE: Validates shader to ensure that it conforms to the spec
// specified during compiler construction.
// SH_VALIDATE_LOOP_INDEXING: Validates loop and indexing in the shader to
// ensure that they do not exceed the minimum
// functionality mandated in GLSL 1.0 spec,
// Appendix A, Section 4 and 5.
// There is no need to specify this parameter when
// compiling for WebGL - it is implied.
// SH_INTERMEDIATE_TREE: Writes intermediate tree to info log.
// Can be queried by calling sh::GetInfoLog().
// SH_OBJECT_CODE: Translates intermediate tree to glsl or hlsl shader.
// Can be queried by calling sh::GetObjectCode().
// SH_VARIABLES: Extracts attributes, uniforms, and varyings.
// Can be queried by calling ShGetVariableInfo().
//
bool Compile(const ShHandle handle,
const char *const shaderStrings[],
size_t numStrings,
ShCompileOptions compileOptions);
// Clears the results from the previous compilation.
void ClearResults(const ShHandle handle);
// Return the version of the shader language.
int GetShaderVersion(const ShHandle handle);
// Return the currently set language output type.
ShShaderOutput GetShaderOutputType(const ShHandle handle);
// Returns null-terminated information log for a compiled shader.
// Parameters:
// handle: Specifies the compiler
const std::string &GetInfoLog(const ShHandle handle);
// Returns null-terminated object code for a compiled shader.
// Parameters:
// handle: Specifies the compiler
const std::string &GetObjectCode(const ShHandle handle);
// Returns a (original_name, hash) map containing all the user defined names in the shader,
// including variable names, function names, struct names, and struct field names.
// Parameters:
// handle: Specifies the compiler
const std::map<std::string, std::string> *GetNameHashingMap(const ShHandle handle);
// Shader variable inspection.
// Returns a pointer to a list of variables of the designated type.
// (See ShaderVars.h for type definitions, included above)
// Returns NULL on failure.
// Parameters:
// handle: Specifies the compiler
const std::vector<sh::Uniform> *GetUniforms(const ShHandle handle);
const std::vector<sh::Varying> *GetVaryings(const ShHandle handle);
const std::vector<sh::Attribute> *GetAttributes(const ShHandle handle);
const std::vector<sh::OutputVariable> *GetOutputVariables(const ShHandle handle);
const std::vector<sh::InterfaceBlock> *GetInterfaceBlocks(const ShHandle handle);
sh::WorkGroupSize GetComputeShaderLocalGroupSize(const ShHandle handle);
// Returns true if the passed in variables pack in maxVectors followingthe packing rules from the
// GLSL 1.017 spec, Appendix A, section 7.
// Returns false otherwise. Also look at the SH_ENFORCE_PACKING_RESTRICTIONS
// flag above.
// Parameters:
// maxVectors: the available rows of registers.
// variables: an array of variables.
bool CheckVariablesWithinPackingLimits(int maxVectors,
const std::vector<sh::ShaderVariable> &variables);
// Gives the compiler-assigned register for an interface block.
// The method writes the value to the output variable "indexOut".
// Returns true if it found a valid interface block, false otherwise.
// Parameters:
// handle: Specifies the compiler
// interfaceBlockName: Specifies the interface block
// indexOut: output variable that stores the assigned register
bool GetInterfaceBlockRegister(const ShHandle handle,
const std::string &interfaceBlockName,
unsigned int *indexOut);
// Gives a map from uniform names to compiler-assigned registers in the default interface block.
// Note that the map contains also registers of samplers that have been extracted from structs.
const std::map<std::string, unsigned int> *GetUniformRegisterMap(const ShHandle handle);
} // namespace sh
#endif // GLSLANG_SHADERLANG_H_
......@@ -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
......@@ -35,6 +35,9 @@
#include "compiler/translator/VariablePacker.h"
#include "third_party/compiler/ArrayBoundsClamper.h"
namespace sh
{
namespace
{
......@@ -80,24 +83,17 @@ bool IsWebGLBasedSpec(ShShaderSpec spec)
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_t GetGlobalMaxTokenSize(ShShaderSpec spec)
// 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 @@ int MapSpecToShaderVersion(ShShaderSpec spec)
{
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 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
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 @@ void TCompiler::setResourceString()
// 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 @@ bool TCompiler::initCallDag(TIntermNode *root)
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 @@ class TCompiler::UnusedPredicate
{
public:
UnusedPredicate(const CallDAG *callDag, const std::vector<FunctionMetadata> *metadatas)
: mCallDag(callDag),
mMetadatas(metadatas)
: mCallDag(callDag), mMetadatas(metadatas)
{
}
......@@ -846,7 +841,7 @@ bool TCompiler::validateLimitations(TIntermNode* root)
bool TCompiler::limitExpressionComplexity(TIntermNode* root)
{
TMaxDepthTraverser traverser(maxExpressionComplexity+1);
TMaxDepthTraverser traverser(maxExpressionComplexity + 1);
root->traverse(&traverser);
if (traverser.getMaxDepth() > maxExpressionComplexity)
......@@ -869,7 +864,8 @@ void TCompiler::collectVariables(TIntermNode* root)
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 @@ bool TCompiler::isVaryingDefined(const char *varyingName)
return false;
}
} // 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);
}
......
......@@ -14,19 +14,21 @@
#include "GLSLANG/ShaderLang.h"
#include "compiler/translator/TranslatorGLSL.h"
using namespace sh;
#define EXPECT_GLENUM_EQ(expected, actual) \
EXPECT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
EXPECT_EQ(static_cast<::GLenum>(expected), static_cast<::GLenum>(actual))
class CollectVariablesTest : public testing::Test
{
public:
CollectVariablesTest(GLenum shaderType) : mShaderType(shaderType) {}
CollectVariablesTest(::GLenum shaderType) : mShaderType(shaderType) {}
protected:
void SetUp() override
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
InitBuiltInResources(&resources);
resources.MaxDrawBuffers = 8;
initTranslator(resources);
......@@ -45,10 +47,10 @@ class CollectVariablesTest : public testing::Test
const char *shaderStrings[] = { shaderString.c_str() };
ASSERT_TRUE(mTranslator->compile(shaderStrings, 1, SH_VARIABLES));
const std::vector<sh::Uniform> &uniforms = mTranslator->getUniforms();
const std::vector<Uniform> &uniforms = mTranslator->getUniforms();
ASSERT_EQ(1u, uniforms.size());
const sh::Uniform &uniform = uniforms[0];
const Uniform &uniform = uniforms[0];
EXPECT_EQ("gl_DepthRange", uniform.name);
ASSERT_TRUE(uniform.isStruct());
ASSERT_EQ(3u, uniform.fields.size());
......@@ -90,7 +92,7 @@ class CollectVariablesTest : public testing::Test
void validateOutputVariableForShader(const std::string &shaderString,
unsigned int varIndex,
const char *varName,
const sh::OutputVariable **outResult)
const OutputVariable **outResult)
{
const char *shaderStrings[] = {shaderString.c_str()};
ASSERT_TRUE(mTranslator->compile(shaderStrings, 1, SH_VARIABLES))
......@@ -98,7 +100,7 @@ class CollectVariablesTest : public testing::Test
const auto &outputVariables = mTranslator->getOutputVariables();
ASSERT_LT(varIndex, outputVariables.size());
const sh::OutputVariable &outputVariable = outputVariables[varIndex];
const OutputVariable &outputVariable = outputVariables[varIndex];
EXPECT_EQ(-1, outputVariable.location);
EXPECT_TRUE(outputVariable.staticUse);
EXPECT_EQ(varName, outputVariable.name);
......@@ -111,7 +113,7 @@ class CollectVariablesTest : public testing::Test
ASSERT_TRUE(mTranslator->compile(shaderStrings, 1, SH_VARIABLES));
}
GLenum mShaderType;
::GLenum mShaderType;
std::unique_ptr<TranslatorGLSL> mTranslator;
};
......@@ -142,7 +144,7 @@ TEST_F(CollectFragmentVariablesTest, SimpleOutputVar)
const auto &outputVariables = mTranslator->getOutputVariables();
ASSERT_EQ(1u, outputVariables.size());
const sh::OutputVariable &outputVariable = outputVariables[0];
const OutputVariable &outputVariable = outputVariables[0];
EXPECT_EQ(0u, outputVariable.arraySize);
EXPECT_EQ(-1, outputVariable.location);
......@@ -167,7 +169,7 @@ TEST_F(CollectFragmentVariablesTest, LocationOutputVar)
const auto &outputVariables = mTranslator->getOutputVariables();
ASSERT_EQ(1u, outputVariables.size());
const sh::OutputVariable &outputVariable = outputVariables[0];
const OutputVariable &outputVariable = outputVariables[0];
EXPECT_EQ(0u, outputVariable.arraySize);
EXPECT_EQ(5, outputVariable.location);
......@@ -188,10 +190,10 @@ TEST_F(CollectVertexVariablesTest, LocationAttribute)
compile(shaderString);
const std::vector<sh::Attribute> &attributes = mTranslator->getAttributes();
const std::vector<Attribute> &attributes = mTranslator->getAttributes();
ASSERT_EQ(1u, attributes.size());
const sh::Attribute &attribute = attributes[0];
const Attribute &attribute = attributes[0];
EXPECT_EQ(0u, attribute.arraySize);
EXPECT_EQ(5, attribute.location);
......@@ -214,20 +216,20 @@ TEST_F(CollectVertexVariablesTest, SimpleInterfaceBlock)
compile(shaderString);
const std::vector<sh::InterfaceBlock> &interfaceBlocks = mTranslator->getInterfaceBlocks();
const std::vector<InterfaceBlock> &interfaceBlocks = mTranslator->getInterfaceBlocks();
ASSERT_EQ(1u, interfaceBlocks.size());
const sh::InterfaceBlock &interfaceBlock = interfaceBlocks[0];
const InterfaceBlock &interfaceBlock = interfaceBlocks[0];
EXPECT_EQ(0u, interfaceBlock.arraySize);
EXPECT_FALSE(interfaceBlock.isRowMajorLayout);
EXPECT_EQ(sh::BLOCKLAYOUT_SHARED, interfaceBlock.layout);
EXPECT_EQ(BLOCKLAYOUT_SHARED, interfaceBlock.layout);
EXPECT_EQ("b", interfaceBlock.name);
EXPECT_TRUE(interfaceBlock.staticUse);
ASSERT_EQ(1u, interfaceBlock.fields.size());
const sh::InterfaceBlockField &field = interfaceBlock.fields[0];
const InterfaceBlockField &field = interfaceBlock.fields[0];
EXPECT_GLENUM_EQ(GL_HIGH_FLOAT, field.precision);
EXPECT_TRUE(field.staticUse);
......@@ -250,21 +252,21 @@ TEST_F(CollectVertexVariablesTest, SimpleInstancedInterfaceBlock)
compile(shaderString);
const std::vector<sh::InterfaceBlock> &interfaceBlocks = mTranslator->getInterfaceBlocks();
const std::vector<InterfaceBlock> &interfaceBlocks = mTranslator->getInterfaceBlocks();
ASSERT_EQ(1u, interfaceBlocks.size());
const sh::InterfaceBlock &interfaceBlock = interfaceBlocks[0];
const InterfaceBlock &interfaceBlock = interfaceBlocks[0];
EXPECT_EQ(0u, interfaceBlock.arraySize);
EXPECT_FALSE(interfaceBlock.isRowMajorLayout);
EXPECT_EQ(sh::BLOCKLAYOUT_SHARED, interfaceBlock.layout);
EXPECT_EQ(BLOCKLAYOUT_SHARED, interfaceBlock.layout);
EXPECT_EQ("b", interfaceBlock.name);
EXPECT_EQ("blockInstance", interfaceBlock.instanceName);
EXPECT_TRUE(interfaceBlock.staticUse);
ASSERT_EQ(1u, interfaceBlock.fields.size());
const sh::InterfaceBlockField &field = interfaceBlock.fields[0];
const InterfaceBlockField &field = interfaceBlock.fields[0];
EXPECT_GLENUM_EQ(GL_HIGH_FLOAT, field.precision);
EXPECT_TRUE(field.staticUse);
......@@ -288,27 +290,27 @@ TEST_F(CollectVertexVariablesTest, StructInterfaceBlock)
compile(shaderString);
const std::vector<sh::InterfaceBlock> &interfaceBlocks = mTranslator->getInterfaceBlocks();
const std::vector<InterfaceBlock> &interfaceBlocks = mTranslator->getInterfaceBlocks();
ASSERT_EQ(1u, interfaceBlocks.size());
const sh::InterfaceBlock &interfaceBlock = interfaceBlocks[0];
const InterfaceBlock &interfaceBlock = interfaceBlocks[0];
EXPECT_EQ(0u, interfaceBlock.arraySize);
EXPECT_FALSE(interfaceBlock.isRowMajorLayout);
EXPECT_EQ(sh::BLOCKLAYOUT_SHARED, interfaceBlock.layout);
EXPECT_EQ(BLOCKLAYOUT_SHARED, interfaceBlock.layout);
EXPECT_EQ("b", interfaceBlock.name);
EXPECT_TRUE(interfaceBlock.staticUse);
ASSERT_EQ(1u, interfaceBlock.fields.size());
const sh::InterfaceBlockField &field = interfaceBlock.fields[0];
const InterfaceBlockField &field = interfaceBlock.fields[0];
EXPECT_TRUE(field.isStruct());
EXPECT_TRUE(field.staticUse);
EXPECT_EQ("s", field.name);
EXPECT_FALSE(field.isRowMajorLayout);
const sh::ShaderVariable &member = field.fields[0];
const ShaderVariable &member = field.fields[0];
// NOTE: we don't currently mark struct members as statically used or not
EXPECT_FALSE(member.isStruct());
......@@ -331,28 +333,28 @@ TEST_F(CollectVertexVariablesTest, StructInstancedInterfaceBlock)
compile(shaderString);
const std::vector<sh::InterfaceBlock> &interfaceBlocks = mTranslator->getInterfaceBlocks();
const std::vector<InterfaceBlock> &interfaceBlocks = mTranslator->getInterfaceBlocks();
ASSERT_EQ(1u, interfaceBlocks.size());
const sh::InterfaceBlock &interfaceBlock = interfaceBlocks[0];
const InterfaceBlock &interfaceBlock = interfaceBlocks[0];
EXPECT_EQ(0u, interfaceBlock.arraySize);
EXPECT_FALSE(interfaceBlock.isRowMajorLayout);
EXPECT_EQ(sh::BLOCKLAYOUT_SHARED, interfaceBlock.layout);
EXPECT_EQ(BLOCKLAYOUT_SHARED, interfaceBlock.layout);
EXPECT_EQ("b", interfaceBlock.name);
EXPECT_EQ("instanceName", interfaceBlock.instanceName);
EXPECT_TRUE(interfaceBlock.staticUse);
ASSERT_EQ(1u, interfaceBlock.fields.size());
const sh::InterfaceBlockField &field = interfaceBlock.fields[0];
const InterfaceBlockField &field = interfaceBlock.fields[0];
EXPECT_TRUE(field.isStruct());
EXPECT_TRUE(field.staticUse);
EXPECT_EQ("s", field.name);
EXPECT_FALSE(field.isRowMajorLayout);
const sh::ShaderVariable &member = field.fields[0];
const ShaderVariable &member = field.fields[0];
// NOTE: we don't currently mark struct members as statically used or not
EXPECT_FALSE(member.isStruct());
......@@ -375,27 +377,27 @@ TEST_F(CollectVertexVariablesTest, NestedStructRowMajorInterfaceBlock)
compile(shaderString);
const std::vector<sh::InterfaceBlock> &interfaceBlocks = mTranslator->getInterfaceBlocks();
const std::vector<InterfaceBlock> &interfaceBlocks = mTranslator->getInterfaceBlocks();
ASSERT_EQ(1u, interfaceBlocks.size());
const sh::InterfaceBlock &interfaceBlock = interfaceBlocks[0];
const InterfaceBlock &interfaceBlock = interfaceBlocks[0];
EXPECT_EQ(0u, interfaceBlock.arraySize);
EXPECT_TRUE(interfaceBlock.isRowMajorLayout);
EXPECT_EQ(sh::BLOCKLAYOUT_SHARED, interfaceBlock.layout);
EXPECT_EQ(BLOCKLAYOUT_SHARED, interfaceBlock.layout);
EXPECT_EQ("b", interfaceBlock.name);
EXPECT_TRUE(interfaceBlock.staticUse);
ASSERT_EQ(1u, interfaceBlock.fields.size());
const sh::InterfaceBlockField &field = interfaceBlock.fields[0];
const InterfaceBlockField &field = interfaceBlock.fields[0];
EXPECT_TRUE(field.isStruct());
EXPECT_TRUE(field.staticUse);
EXPECT_EQ("s", field.name);
EXPECT_TRUE(field.isRowMajorLayout);
const sh::ShaderVariable &member = field.fields[0];
const ShaderVariable &member = field.fields[0];
// NOTE: we don't currently mark struct members as statically used or not
EXPECT_FALSE(member.isStruct());
......@@ -417,10 +419,10 @@ TEST_F(CollectVertexVariablesTest, VaryingInterpolation)
compile(shaderString);
const std::vector<sh::Varying> &varyings = mTranslator->getVaryings();
const std::vector<Varying> &varyings = mTranslator->getVaryings();
ASSERT_EQ(2u, varyings.size());
const sh::Varying *varying = &varyings[0];
const Varying *varying = &varyings[0];
if (varying->name == "gl_Position")
{
......@@ -432,7 +434,7 @@ TEST_F(CollectVertexVariablesTest, VaryingInterpolation)
EXPECT_TRUE(varying->staticUse);
EXPECT_GLENUM_EQ(GL_FLOAT, varying->type);
EXPECT_EQ("vary", varying->name);
EXPECT_EQ(sh::INTERPOLATION_CENTROID, varying->interpolation);
EXPECT_EQ(INTERPOLATION_CENTROID, varying->interpolation);
}
// Test for builtin uniform "gl_DepthRange" (Vertex shader)
......@@ -469,7 +471,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL1FragColor)
" gl_FragColor = vec4(1.0);\n"
"}\n";
const sh::OutputVariable *outputVariable = nullptr;
const OutputVariable *outputVariable = nullptr;
validateOutputVariableForShader(fragColorShader, 0u, "gl_FragColor", &outputVariable);
ASSERT_NE(outputVariable, nullptr);
EXPECT_EQ(0u, outputVariable->arraySize);
......@@ -495,7 +497,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL1FragData)
resources.MaxDrawBuffers = kMaxDrawBuffers;
initTranslator(resources);
const sh::OutputVariable *outputVariable = nullptr;
const OutputVariable *outputVariable = nullptr;
validateOutputVariableForShader(fragDataShader, 0u, "gl_FragData", &outputVariable);
ASSERT_NE(outputVariable, nullptr);
EXPECT_EQ(kMaxDrawBuffers, outputVariable->arraySize);
......@@ -518,7 +520,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL1FragDepthMediump)
resources.EXT_frag_depth = 1;
initTranslator(resources);
const sh::OutputVariable *outputVariable = nullptr;
const OutputVariable *outputVariable = nullptr;
validateOutputVariableForShader(fragDepthShader, 0u, "gl_FragDepthEXT", &outputVariable);
ASSERT_NE(outputVariable, nullptr);
EXPECT_EQ(0u, outputVariable->arraySize);
......@@ -541,7 +543,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL1FragDepthHighp)
resources.FragmentPrecisionHigh = 1;
initTranslator(resources);
const sh::OutputVariable *outputVariable = nullptr;
const OutputVariable *outputVariable = nullptr;
validateOutputVariableForShader(fragDepthHighShader, 0u, "gl_FragDepthEXT", &outputVariable);
ASSERT_NE(outputVariable, nullptr);
EXPECT_EQ(0u, outputVariable->arraySize);
......@@ -564,7 +566,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL3FragDepthHighp)
resources.EXT_frag_depth = 1;
initTranslator(resources);
const sh::OutputVariable *outputVariable = nullptr;
const OutputVariable *outputVariable = nullptr;
validateOutputVariableForShader(fragDepthHighShader, 0u, "gl_FragDepth", &outputVariable);
ASSERT_NE(outputVariable, nullptr);
EXPECT_EQ(0u, outputVariable->arraySize);
......@@ -592,7 +594,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL1EXTBlendFuncExtendedSecondary
resources.MaxDualSourceDrawBuffers = resources.MaxDrawBuffers;
initTranslator(resources);
const sh::OutputVariable *outputVariable = nullptr;
const OutputVariable *outputVariable = nullptr;
validateOutputVariableForShader(secondaryFragColorShader, 0u, "gl_FragColor", &outputVariable);
ASSERT_NE(outputVariable, nullptr);
EXPECT_EQ(0u, outputVariable->arraySize);
......@@ -630,7 +632,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL1EXTBlendFuncExtendedSecondary
resources.MaxDualSourceDrawBuffers = resources.MaxDrawBuffers;
initTranslator(resources);
const sh::OutputVariable *outputVariable = nullptr;
const OutputVariable *outputVariable = nullptr;
validateOutputVariableForShader(secondaryFragDataShader, 0u, "gl_FragData", &outputVariable);
ASSERT_NE(outputVariable, nullptr);
EXPECT_EQ(kMaxDrawBuffers, outputVariable->arraySize);
......@@ -658,7 +660,7 @@ class CollectHashedVertexVariablesTest : public CollectVertexVariablesTest
{
// Initialize the translate with a hash function
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
sh::InitBuiltInResources(&resources);
resources.HashFunction = SimpleTestHash;
initTranslator(resources);
}
......@@ -677,14 +679,14 @@ TEST_F(CollectHashedVertexVariablesTest, InstancedInterfaceBlock)
compile(shaderString);
const std::vector<sh::InterfaceBlock> &interfaceBlocks = mTranslator->getInterfaceBlocks();
const std::vector<InterfaceBlock> &interfaceBlocks = mTranslator->getInterfaceBlocks();
ASSERT_EQ(1u, interfaceBlocks.size());
const sh::InterfaceBlock &interfaceBlock = interfaceBlocks[0];
const InterfaceBlock &interfaceBlock = interfaceBlocks[0];
EXPECT_EQ(0u, interfaceBlock.arraySize);
EXPECT_FALSE(interfaceBlock.isRowMajorLayout);
EXPECT_EQ(sh::BLOCKLAYOUT_SHARED, interfaceBlock.layout);
EXPECT_EQ(BLOCKLAYOUT_SHARED, interfaceBlock.layout);
EXPECT_EQ("blockName", interfaceBlock.name);
EXPECT_EQ("blockInstance", interfaceBlock.instanceName);
EXPECT_EQ("webgl_9", interfaceBlock.mappedName);
......@@ -692,7 +694,7 @@ TEST_F(CollectHashedVertexVariablesTest, InstancedInterfaceBlock)
ASSERT_EQ(1u, interfaceBlock.fields.size());
const sh::InterfaceBlockField &field = interfaceBlock.fields[0];
const InterfaceBlockField &field = interfaceBlock.fields[0];
EXPECT_GLENUM_EQ(GL_HIGH_FLOAT, field.precision);
EXPECT_TRUE(field.staticUse);
......@@ -720,7 +722,7 @@ TEST_F(CollectHashedVertexVariablesTest, StructUniform)
const auto &uniforms = mTranslator->getUniforms();
ASSERT_EQ(1u, uniforms.size());
const sh::Uniform &uniform = uniforms[0];
const Uniform &uniform = uniforms[0];
EXPECT_EQ(0u, uniform.arraySize);
EXPECT_EQ("u", uniform.name);
......@@ -729,7 +731,7 @@ TEST_F(CollectHashedVertexVariablesTest, StructUniform)
ASSERT_EQ(1u, uniform.fields.size());
const sh::ShaderVariable &field = uniform.fields[0];
const ShaderVariable &field = uniform.fields[0];
EXPECT_GLENUM_EQ(GL_HIGH_FLOAT, field.precision);
// EXPECT_TRUE(field.staticUse); // we don't yet support struct static use
......
......@@ -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