Commit a1ceb87b by Tobin Ehlis Committed by Commit Bot

Vulkan:Refactor precision emulation code

GLSL, ESSL, and HLSL translators all had the same code to emulate precision so migrate that code to base class. This is a structural change to prepare for honoring precision qualifiers in the Vulkan translator as well, which is done in a follow-on commit. Bug: angleproject:3078 Change-Id: Id85bba83543189e3bbc4002be92b056e63afc8de Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2072644Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Commit-Queue: Tobin Ehlis <tobine@google.com>
parent 27cb806c
......@@ -1115,6 +1115,26 @@ void TCompiler::collectInterfaceBlocks()
mInterfaceBlocks.insert(mInterfaceBlocks.end(), mInBlocks.begin(), mInBlocks.end());
}
bool TCompiler::emulatePrecisionIfNeeded(TIntermBlock *root,
TInfoSinkBase &sink,
bool *isNeeded,
const ShShaderOutput outputLanguage)
{
*isNeeded = getResources().WEBGL_debug_shader_precision && getPragma().debugShaderPrecision;
if (*isNeeded)
{
EmulatePrecision emulatePrecision(&getSymbolTable());
root->traverse(&emulatePrecision);
if (!emulatePrecision.updateTree(this, root))
{
return false;
}
emulatePrecision.writeEmulationHelpers(sink, getShaderVersion(), outputLanguage);
}
return true;
}
void TCompiler::clearResults()
{
mArrayBoundsClamper.Cleanup();
......
......@@ -173,6 +173,12 @@ class TCompiler : public TShHandleBase
virtual bool shouldFlattenPragmaStdglInvariantAll() = 0;
virtual bool shouldCollectVariables(ShCompileOptions compileOptions);
// If precision emulation needed, set isNeeded to true and emulate precision for given
// outputLanguage, returning false if that fails, else returning true.
bool emulatePrecisionIfNeeded(TIntermBlock *root,
TInfoSinkBase &sink,
bool *isNeeded,
const ShShaderOutput outputLanguage);
bool wereVariablesCollected() const;
std::vector<sh::ShaderVariable> mAttributes;
......
......@@ -9,7 +9,6 @@
#include "angle_gl.h"
#include "compiler/translator/BuiltInFunctionEmulatorGLSL.h"
#include "compiler/translator/OutputESSL.h"
#include "compiler/translator/tree_ops/EmulatePrecision.h"
#include "compiler/translator/tree_ops/RecordConstantPrecision.h"
namespace sh
......@@ -47,19 +46,9 @@ bool TranslatorESSL::translate(TIntermBlock *root,
// like non-preprocessor tokens.
writePragma(compileOptions);
bool precisionEmulation =
getResources().WEBGL_debug_shader_precision && getPragma().debugShaderPrecision;
if (precisionEmulation)
{
EmulatePrecision emulatePrecision(&getSymbolTable());
root->traverse(&emulatePrecision);
if (!emulatePrecision.updateTree(this, root))
{
return false;
}
emulatePrecision.writeEmulationHelpers(sink, shaderVer, SH_ESSL_OUTPUT);
}
bool precisionEmulation = false;
if (!emulatePrecisionIfNeeded(root, sink, &precisionEmulation, SH_ESSL_OUTPUT))
return false;
if (!RecordConstantPrecision(this, root, &getSymbolTable()))
{
......
......@@ -11,7 +11,6 @@
#include "compiler/translator/ExtensionGLSL.h"
#include "compiler/translator/OutputGLSL.h"
#include "compiler/translator/VersionGLSL.h"
#include "compiler/translator/tree_ops/EmulatePrecision.h"
#include "compiler/translator/tree_ops/RewriteRowMajorMatrices.h"
#include "compiler/translator/tree_ops/RewriteTexelFetchOffset.h"
#include "compiler/translator/tree_ops/RewriteUnaryMinusOperatorFloat.h"
......@@ -118,19 +117,9 @@ bool TranslatorGLSL::translate(TIntermBlock *root,
}
}
bool precisionEmulation =
getResources().WEBGL_debug_shader_precision && getPragma().debugShaderPrecision;
if (precisionEmulation)
{
EmulatePrecision emulatePrecision(&getSymbolTable());
root->traverse(&emulatePrecision);
if (!emulatePrecision.updateTree(this, root))
{
return false;
}
emulatePrecision.writeEmulationHelpers(sink, getShaderVersion(), getOutputType());
}
bool precisionEmulation = false;
if (!emulatePrecisionIfNeeded(root, sink, &precisionEmulation, getOutputType()))
return false;
// Write emulated built-in functions if needed.
if (!getBuiltInFunctionEmulator().isOutputEmpty())
......
......@@ -10,7 +10,6 @@
#include "compiler/translator/tree_ops/AddDefaultReturnStatements.h"
#include "compiler/translator/tree_ops/ArrayReturnValueToOutParameter.h"
#include "compiler/translator/tree_ops/BreakVariableAliasingInInnerLoops.h"
#include "compiler/translator/tree_ops/EmulatePrecision.h"
#include "compiler/translator/tree_ops/ExpandIntegerPowExpressions.h"
#include "compiler/translator/tree_ops/PruneEmptyCases.h"
#include "compiler/translator/tree_ops/RemoveDynamicIndexing.h"
......@@ -140,20 +139,9 @@ bool TranslatorHLSL::translate(TIntermBlock *root,
return false;
}
bool precisionEmulation =
getResources().WEBGL_debug_shader_precision && getPragma().debugShaderPrecision;
if (precisionEmulation)
{
EmulatePrecision emulatePrecision(&getSymbolTable());
root->traverse(&emulatePrecision);
if (!emulatePrecision.updateTree(this, root))
{
return false;
}
emulatePrecision.writeEmulationHelpers(getInfoSink().obj, getShaderVersion(),
getOutputType());
}
bool precisionEmulation = false;
if (!emulatePrecisionIfNeeded(root, getInfoSink().obj, &precisionEmulation, getOutputType()))
return false;
if ((compileOptions & SH_EXPAND_SELECT_HLSL_INTEGER_POW_EXPRESSIONS) != 0)
{
......
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