Commit a6996685 by Olli Etuaho

Automatically enable highp in fragment shaders on ESSL3

Most code using the translator already enables highp with the resources flag when a shader spec that accepts ESSL3 is used, but for example the shader_translator utility doesn't. This fix makes sure that highp is always enabled when a fragment shader written in ESSL3 or newer is being compiled. This will make shader_translator easier to use for testing ESSL3 shaders. BUG=541550 TEST=angle_unittests Change-Id: Ia1911677c55f3c5d921829a8cbb808847ac8b636 Reviewed-on: https://chromium-review.googlesource.com/305190 Tryjob-Request: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent e73a1e84
...@@ -266,7 +266,9 @@ typedef struct ...@@ -266,7 +266,9 @@ typedef struct
// function. This applies to Tegra K1 devices. // function. This applies to Tegra K1 devices.
int NV_draw_buffers; int NV_draw_buffers;
// Set to 1 if highp precision is supported in the fragment language. // Set to 1 if highp precision is supported in the ESSL 1.00 version of the
// fragment language. Does not affect versions of the language where highp
// support is mandatory.
// Default is 0. // Default is 0.
int FragmentPrecisionHigh; int FragmentPrecisionHigh;
......
...@@ -219,7 +219,7 @@ TIntermNode *TCompiler::compileTreeImpl(const char *const shaderStrings[], ...@@ -219,7 +219,7 @@ TIntermNode *TCompiler::compileTreeImpl(const char *const shaderStrings[],
shaderType, shaderSpec, compileOptions, true, shaderType, shaderSpec, compileOptions, true,
infoSink, debugShaderPrecision); infoSink, debugShaderPrecision);
parseContext.setFragmentPrecisionHigh(fragmentPrecisionHigh); parseContext.setFragmentPrecisionHighOnESSL1(fragmentPrecisionHigh);
SetGlobalParseContext(&parseContext); SetGlobalParseContext(&parseContext);
// We preserve symbols at the built-in level from compile-to-compile. // We preserve symbols at the built-in level from compile-to-compile.
...@@ -252,6 +252,9 @@ TIntermNode *TCompiler::compileTreeImpl(const char *const shaderStrings[], ...@@ -252,6 +252,9 @@ TIntermNode *TCompiler::compileTreeImpl(const char *const shaderStrings[],
root = parseContext.getTreeRoot(); root = parseContext.getTreeRoot();
root = intermediate.postProcess(root); root = intermediate.postProcess(root);
// Highp might have been auto-enabled based on shader version
fragmentPrecisionHigh = parseContext.getFragmentPrecisionHigh();
// Disallow expressions deemed too complex. // Disallow expressions deemed too complex.
if (success && (compileOptions & SH_LIMIT_EXPRESSION_COMPLEXITY)) if (success && (compileOptions & SH_LIMIT_EXPRESSION_COMPLEXITY))
success = limitExpressionComplexity(root); success = limitExpressionComplexity(root);
......
...@@ -50,7 +50,7 @@ class TParseContext : angle::NonCopyable ...@@ -50,7 +50,7 @@ class TParseContext : angle::NonCopyable
mCurrentFunctionType(nullptr), mCurrentFunctionType(nullptr),
mFunctionReturnsValue(false), mFunctionReturnsValue(false),
mChecksPrecisionErrors(checksPrecErrors), mChecksPrecisionErrors(checksPrecErrors),
mFragmentPrecisionHigh(false), mFragmentPrecisionHighOnESSL1(false),
mDefaultMatrixPacking(EmpColumnMajor), mDefaultMatrixPacking(EmpColumnMajor),
mDefaultBlockStorage(EbsShared), mDefaultBlockStorage(EbsShared),
mDiagnostics(is), mDiagnostics(is),
...@@ -81,10 +81,13 @@ class TParseContext : angle::NonCopyable ...@@ -81,10 +81,13 @@ class TParseContext : angle::NonCopyable
TIntermNode *getTreeRoot() const { return mTreeRoot; } TIntermNode *getTreeRoot() const { return mTreeRoot; }
void setTreeRoot(TIntermNode *treeRoot) { mTreeRoot = treeRoot; } void setTreeRoot(TIntermNode *treeRoot) { mTreeRoot = treeRoot; }
bool getFragmentPrecisionHigh() const { return mFragmentPrecisionHigh; } bool getFragmentPrecisionHigh() const
void setFragmentPrecisionHigh(bool fragmentPrecisionHigh)
{ {
mFragmentPrecisionHigh = fragmentPrecisionHigh; return mFragmentPrecisionHighOnESSL1 || mShaderVersion >= 300;
}
void setFragmentPrecisionHighOnESSL1(bool fragmentPrecisionHigh)
{
mFragmentPrecisionHighOnESSL1 = fragmentPrecisionHigh;
} }
bool getFunctionReturnsValue() const { return mFunctionReturnsValue; } bool getFunctionReturnsValue() const { return mFunctionReturnsValue; }
...@@ -342,7 +345,8 @@ class TParseContext : angle::NonCopyable ...@@ -342,7 +345,8 @@ class TParseContext : angle::NonCopyable
const TType *mCurrentFunctionType; // the return type of the function that's currently being parsed const TType *mCurrentFunctionType; // the return type of the function that's currently being parsed
bool mFunctionReturnsValue; // true if a non-void function has a return bool mFunctionReturnsValue; // true if a non-void function has a return
bool mChecksPrecisionErrors; // true if an error will be generated when a variable is declared without precision, explicit or implicit. bool mChecksPrecisionErrors; // true if an error will be generated when a variable is declared without precision, explicit or implicit.
bool mFragmentPrecisionHigh; // true if highp precision is supported in the fragment language. bool mFragmentPrecisionHighOnESSL1; // true if highp precision is supported when compiling
// ESSL1.
TLayoutMatrixPacking mDefaultMatrixPacking; TLayoutMatrixPacking mDefaultMatrixPacking;
TLayoutBlockStorage mDefaultBlockStorage; TLayoutBlockStorage mDefaultBlockStorage;
TString mHashErrMsg; TString mHashErrMsg;
......
...@@ -17,11 +17,6 @@ bool compileTestShader(sh::GLenum type, ...@@ -17,11 +17,6 @@ bool compileTestShader(sh::GLenum type,
std::string *translatedCode, std::string *translatedCode,
std::string *infoLog) std::string *infoLog)
{ {
if (spec == SH_GLES3_SPEC || spec == SH_WEBGL2_SPEC)
{
resources->FragmentPrecisionHigh = 1;
}
TCompiler *translator = ConstructCompiler(type, spec, output); TCompiler *translator = ConstructCompiler(type, spec, output);
if (!translator->Init(*resources)) if (!translator->Init(*resources))
{ {
......
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