Commit ad0d0799 by Qingqing Deng Committed by Jamie Madill

Expand ShShaderOutput for different GLSL versions

BUG=angleproject:968 Change-Id: I2d4c0a8e9a91a940922da4501c22124da0c0399c Reviewed-on: https://chromium-review.googlesource.com/264840Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent e3ef715d
...@@ -48,7 +48,7 @@ typedef unsigned int GLenum; ...@@ -48,7 +48,7 @@ typedef unsigned int GLenum;
// Version number for shader translation API. // Version number for shader translation API.
// It is incremented every time the API changes. // It is incremented every time the API changes.
#define ANGLE_SH_VERSION 134 #define ANGLE_SH_VERSION 135
typedef enum { typedef enum {
SH_GLES2_SPEC = 0x8B40, SH_GLES2_SPEC = 0x8B40,
...@@ -85,7 +85,13 @@ typedef enum { ...@@ -85,7 +85,13 @@ typedef enum {
// SH_GLSL_OUTPUT is deprecated. This is to not break the build. // SH_GLSL_OUTPUT is deprecated. This is to not break the build.
SH_GLSL_OUTPUT = 0x8B46, SH_GLSL_OUTPUT = 0x8B46,
SH_GLSL_COMPATIBILITY_OUTPUT = 0x8B46, SH_GLSL_COMPATIBILITY_OUTPUT = 0x8B46,
// SH_GLSL_CORE_OUTPUT is deprecated.
SH_GLSL_CORE_OUTPUT = 0x8B47, SH_GLSL_CORE_OUTPUT = 0x8B47,
//Note: GL introduced core profiles in 1.5. However, for compatiblity with Chromium, we treat SH_GLSL_CORE_OUTPUT as GLSL_130_OUTPUT.
//TODO: Remove SH_GLSL_CORE_OUTPUT
SH_GLSL_130_OUTPUT = 0x8B47,
SH_GLSL_410_CORE_OUTPUT = 0x8B84,
SH_GLSL_420_CORE_OUTPUT = 0x8B85,
// HLSL output only supported in some configurations. // HLSL output only supported in some configurations.
SH_HLSL_OUTPUT = 0x8B48, SH_HLSL_OUTPUT = 0x8B48,
...@@ -112,7 +118,7 @@ typedef enum { ...@@ -112,7 +118,7 @@ typedef enum {
// This is needed only as a workaround for certain OpenGL driver bugs. // This is needed only as a workaround for certain OpenGL driver bugs.
SH_EMULATE_BUILT_IN_FUNCTIONS = 0x0100, SH_EMULATE_BUILT_IN_FUNCTIONS = 0x0100,
// This is an experimental flag to enforce restrictions that aim to prevent // This is an experimental flag to enforce restrictions that aim to prevent
// timing attacks. // timing attacks.
// It generates compilation errors for shaders that could expose sensitive // It generates compilation errors for shaders that could expose sensitive
// texture information via the timing channel. // texture information via the timing channel.
......
...@@ -21,7 +21,9 @@ TCompiler* ConstructCompiler( ...@@ -21,7 +21,9 @@ TCompiler* ConstructCompiler(
switch (output) { switch (output) {
case SH_ESSL_OUTPUT: case SH_ESSL_OUTPUT:
return new TranslatorESSL(type, spec); return new TranslatorESSL(type, spec);
case SH_GLSL_CORE_OUTPUT: case SH_GLSL_130_OUTPUT:
case SH_GLSL_410_CORE_OUTPUT:
case SH_GLSL_420_CORE_OUTPUT:
case SH_GLSL_COMPATIBILITY_OUTPUT: case SH_GLSL_COMPATIBILITY_OUTPUT:
return new TranslatorGLSL(type, spec, output); return new TranslatorGLSL(type, spec, output);
case SH_HLSL9_OUTPUT: case SH_HLSL9_OUTPUT:
......
...@@ -34,6 +34,13 @@ bool IsWebGLBasedSpec(ShShaderSpec spec) ...@@ -34,6 +34,13 @@ bool IsWebGLBasedSpec(ShShaderSpec spec)
spec == SH_WEBGL2_SPEC); spec == SH_WEBGL2_SPEC);
} }
bool IsGLSL130OrNewer(ShShaderOutput output)
{
return (output == SH_GLSL_130_OUTPUT ||
output == SH_GLSL_410_CORE_OUTPUT ||
output == SH_GLSL_420_CORE_OUTPUT);
}
size_t GetGlobalMaxTokenSize(ShShaderSpec spec) size_t GetGlobalMaxTokenSize(ShShaderSpec spec)
{ {
// WebGL defines a max token legnth of 256, while ES2 leaves max token // WebGL defines a max token legnth of 256, while ES2 leaves max token
......
...@@ -37,6 +37,11 @@ class TranslatorHLSL; ...@@ -37,6 +37,11 @@ class TranslatorHLSL;
bool IsWebGLBasedSpec(ShShaderSpec spec); bool IsWebGLBasedSpec(ShShaderSpec spec);
// //
// Helper function to check if the shader type is GLSL.
//
bool IsGLSL130OrNewer(ShShaderOutput output);
//
// The base class used to back handles returned to the driver. // The base class used to back handles returned to the driver.
// //
class TShHandleBase { class TShHandleBase {
......
...@@ -511,7 +511,7 @@ void EmulatePrecision::writeEmulationHelpers(TInfoSinkBase& sink, ShShaderOutput ...@@ -511,7 +511,7 @@ void EmulatePrecision::writeEmulationHelpers(TInfoSinkBase& sink, ShShaderOutput
{ {
// Other languages not yet supported // Other languages not yet supported
ASSERT(outputLanguage == SH_GLSL_COMPATIBILITY_OUTPUT || ASSERT(outputLanguage == SH_GLSL_COMPATIBILITY_OUTPUT ||
outputLanguage == SH_GLSL_CORE_OUTPUT || IsGLSL130OrNewer(outputLanguage) ||
outputLanguage == SH_ESSL_OUTPUT); outputLanguage == SH_ESSL_OUTPUT);
writeCommonPrecisionEmulationHelpers(sink, outputLanguage); writeCommonPrecisionEmulationHelpers(sink, outputLanguage);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#define COMPILER_TRANSLATOR_EMULATE_PRECISION_H_ #define COMPILER_TRANSLATOR_EMULATE_PRECISION_H_
#include "common/angleutils.h" #include "common/angleutils.h"
#include "compiler/translator/Compiler.h"
#include "compiler/translator/InfoSink.h" #include "compiler/translator/InfoSink.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermNode.h"
#include "GLSLANG/ShaderLang.h" #include "GLSLANG/ShaderLang.h"
......
...@@ -37,11 +37,11 @@ void TOutputGLSL::visitSymbol(TIntermSymbol *node) ...@@ -37,11 +37,11 @@ void TOutputGLSL::visitSymbol(TIntermSymbol *node)
{ {
out << "gl_FragDepth"; out << "gl_FragDepth";
} }
else if (symbol == "gl_FragColor" && getShaderOutput() == SH_GLSL_CORE_OUTPUT) else if (symbol == "gl_FragColor" && IsGLSL130OrNewer(getShaderOutput()))
{ {
out << "webgl_FragColor"; out << "webgl_FragColor";
} }
else if (symbol == "gl_FragData" && getShaderOutput() == SH_GLSL_CORE_OUTPUT) else if (symbol == "gl_FragData" && IsGLSL130OrNewer(getShaderOutput()))
{ {
out << "webgl_FragData"; out << "webgl_FragData";
} }
...@@ -78,7 +78,7 @@ TString TOutputGLSL::translateTextureFunction(TString &name) ...@@ -78,7 +78,7 @@ TString TOutputGLSL::translateTextureFunction(TString &name)
"textureCubeGradEXT", "textureGrad", "textureCubeGradEXT", "textureGrad",
NULL, NULL NULL, NULL
}; };
const char **mapping = (getShaderOutput() == SH_GLSL_CORE_OUTPUT) ? const char **mapping = (IsGLSL130OrNewer(getShaderOutput())) ?
legacyToCoreRename : simpleRename; legacyToCoreRename : simpleRename;
for (int i = 0; mapping[i] != NULL; i += 2) for (int i = 0; mapping[i] != NULL; i += 2)
......
...@@ -95,7 +95,7 @@ void TOutputGLSLBase::writeVariableType(const TType &type) ...@@ -95,7 +95,7 @@ void TOutputGLSLBase::writeVariableType(const TType &type)
TQualifier qualifier = type.getQualifier(); TQualifier qualifier = type.getQualifier();
if (qualifier != EvqTemporary && qualifier != EvqGlobal) if (qualifier != EvqTemporary && qualifier != EvqGlobal)
{ {
if (mOutput == SH_GLSL_CORE_OUTPUT) if (IsGLSL130OrNewer(mOutput))
{ {
switch (qualifier) switch (qualifier)
{ {
......
...@@ -103,8 +103,7 @@ void TranslatorGLSL::translate(TIntermNode *root, int) { ...@@ -103,8 +103,7 @@ void TranslatorGLSL::translate(TIntermNode *root, int) {
// Declare gl_FragColor and glFragData as webgl_FragColor and webgl_FragData // Declare gl_FragColor and glFragData as webgl_FragColor and webgl_FragData
// if it's core profile shaders and they are used. // if it's core profile shaders and they are used.
if (getShaderType() == GL_FRAGMENT_SHADER && if (getShaderType() == GL_FRAGMENT_SHADER && IsGLSL130OrNewer(getOutputType()))
getOutputType() == SH_GLSL_CORE_OUTPUT)
{ {
TFragmentOutSearcher searcher; TFragmentOutSearcher searcher;
root->traverse(&searcher); root->traverse(&searcher);
......
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
static const int GLSL_VERSION_110 = 110; static const int GLSL_VERSION_110 = 110;
static const int GLSL_VERSION_120 = 120; static const int GLSL_VERSION_120 = 120;
static const int GLSL_VERSION_150 = 150; static const int GLSL_VERSION_130 = 130;
static const int GLSL_VERSION_410 = 410;
static const int GLSL_VERSION_420 = 420;
// We need to scan for the following: // We need to scan for the following:
// 1. "invariant" keyword: This can occur in both - vertex and fragment shaders // 1. "invariant" keyword: This can occur in both - vertex and fragment shaders
...@@ -31,9 +33,17 @@ TVersionGLSL::TVersionGLSL(sh::GLenum type, ...@@ -31,9 +33,17 @@ TVersionGLSL::TVersionGLSL(sh::GLenum type,
const TPragma &pragma, const TPragma &pragma,
ShShaderOutput output) ShShaderOutput output)
{ {
if (output == SH_GLSL_CORE_OUTPUT) if (output == SH_GLSL_130_OUTPUT)
{ {
mVersion = GLSL_VERSION_150; mVersion = GLSL_VERSION_130;
}
else if (output == SH_GLSL_410_CORE_OUTPUT)
{
mVersion = GLSL_VERSION_410;
}
else if (output == SH_GLSL_420_CORE_OUTPUT)
{
mVersion = GLSL_VERSION_420;
} }
else else
{ {
......
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