Commit 3a1838a1 by Charlie Lao Committed by Commit Bot

Vulkan: Let RewriteInterpolateAtOffset use FlipRotateSpecConst

Instead of using uniform, use flip/rotation specialization constant when available. This allows matrix multiplication calculated at compile time instead of shader execution time. Bug: angleproject:4901 Bug: angleproject:3589 Change-Id: I5a8a82b1cffbbbeba2617cb7e9a0ec38f9984d50 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2530457 Commit-Queue: Charlie Lao <cclao@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarIan Elliott <ianelliott@google.com>
parent 65ee5168
...@@ -914,15 +914,11 @@ bool TranslatorVulkan::translateImpl(TIntermBlock *root, ...@@ -914,15 +914,11 @@ bool TranslatorVulkan::translateImpl(TIntermBlock *root,
return false; return false;
} }
if (!RewriteInterpolateAtOffset(this, compileOptions, root, getSymbolTable(),
getShaderVersion(), &surfaceRotationSpecConst,
driverUniforms))
{ {
TIntermBinary *flipXY = driverUniforms->getFlipXYRef(); return false;
TIntermBinary *fragRotation =
usePreRotation ? driverUniforms->getFragRotationMatrixRef() : nullptr;
if (!RewriteInterpolateAtOffset(this, root, getSymbolTable(), getShaderVersion(),
flipXY, fragRotation))
{
return false;
}
} }
EmitEarlyFragmentTestsGLSL(*this, sink); EmitEarlyFragmentTestsGLSL(*this, sink);
......
...@@ -55,7 +55,7 @@ Traverser::Traverser(TSymbolTable *symbolTable, ...@@ -55,7 +55,7 @@ Traverser::Traverser(TSymbolTable *symbolTable,
: TIntermTraverser(true, false, false, symbolTable), : TIntermTraverser(true, false, false, symbolTable),
mRotationSpecConst(rotationSpecConst), mRotationSpecConst(rotationSpecConst),
mDriverUniforms(driverUniforms), mDriverUniforms(driverUniforms),
mUsePreRotation(compileOptions & SH_ADD_PRE_ROTATION) mUsePreRotation((compileOptions & SH_ADD_PRE_ROTATION) != 0)
{} {}
// static // static
......
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
#include "common/angleutils.h" #include "common/angleutils.h"
#include "compiler/translator/StaticType.h" #include "compiler/translator/StaticType.h"
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
#include "compiler/translator/TranslatorVulkan.h"
#include "compiler/translator/tree_util/DriverUniform.h"
#include "compiler/translator/tree_util/FlipRotateSpecConst.h"
#include "compiler/translator/tree_util/IntermNode_util.h" #include "compiler/translator/tree_util/IntermNode_util.h"
#include "compiler/translator/tree_util/IntermTraverse.h" #include "compiler/translator/tree_util/IntermTraverse.h"
...@@ -24,46 +27,53 @@ class Traverser : public TIntermTraverser ...@@ -24,46 +27,53 @@ class Traverser : public TIntermTraverser
{ {
public: public:
ANGLE_NO_DISCARD static bool Apply(TCompiler *compiler, ANGLE_NO_DISCARD static bool Apply(TCompiler *compiler,
ShCompileOptions compileOptions,
TIntermNode *root, TIntermNode *root,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
TIntermBinary *flipXY, int ShaderVersion,
TIntermTyped *fragRotation, FlipRotateSpecConst *rotationSpecConst,
int ShaderVersion); const DriverUniform *driverUniforms);
private: private:
Traverser(TIntermBinary *flipXY, Traverser(TSymbolTable *symbolTable,
TIntermTyped *fragRotation, ShCompileOptions compileOptions,
TSymbolTable *symbolTable, int shaderVersion,
int shaderVersion); FlipRotateSpecConst *rotationSpecConst,
const DriverUniform *driverUniforms);
bool visitAggregate(Visit visit, TIntermAggregate *node) override; bool visitAggregate(Visit visit, TIntermAggregate *node) override;
TIntermBinary *mFlipXY = nullptr;
TIntermTyped *mFragRotation = nullptr;
const TSymbolTable *symbolTable = nullptr; const TSymbolTable *symbolTable = nullptr;
const int shaderVersion; const int shaderVersion;
FlipRotateSpecConst *mRotationSpecConst = nullptr;
const DriverUniform *mDriverUniforms = nullptr;
bool mUsePreRotation = false;
}; };
Traverser::Traverser(TIntermBinary *flipXY, Traverser::Traverser(TSymbolTable *symbolTable,
TIntermTyped *fragRotation, ShCompileOptions compileOptions,
TSymbolTable *symbolTable, int shaderVersion,
int shaderVersion) FlipRotateSpecConst *rotationSpecConst,
const DriverUniform *driverUniforms)
: TIntermTraverser(true, false, false, symbolTable), : TIntermTraverser(true, false, false, symbolTable),
mFlipXY(flipXY),
mFragRotation(fragRotation),
symbolTable(symbolTable), symbolTable(symbolTable),
shaderVersion(shaderVersion) shaderVersion(shaderVersion),
mRotationSpecConst(rotationSpecConst),
mDriverUniforms(driverUniforms),
mUsePreRotation((compileOptions & SH_ADD_PRE_ROTATION) != 0)
{} {}
// static // static
bool Traverser::Apply(TCompiler *compiler, bool Traverser::Apply(TCompiler *compiler,
ShCompileOptions compileOptions,
TIntermNode *root, TIntermNode *root,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
TIntermBinary *flipXY, int shaderVersion,
TIntermTyped *fragRotation, FlipRotateSpecConst *rotationSpecConst,
int shaderVersion) const DriverUniform *driverUniforms)
{ {
TSymbolTable *pSymbolTable = const_cast<TSymbolTable *>(&symbolTable); TSymbolTable *pSymbolTable = const_cast<TSymbolTable *>(&symbolTable);
Traverser traverser(flipXY, fragRotation, pSymbolTable, shaderVersion); Traverser traverser(pSymbolTable, compileOptions, shaderVersion, rotationSpecConst,
driverUniforms);
root->traverse(&traverser); root->traverse(&traverser);
return traverser.updateTree(compiler, root); return traverser.updateTree(compiler, root);
} }
...@@ -94,14 +104,23 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -94,14 +104,23 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
// If pre-rotation is enabled apply the transformation else just flip the Y-coordinate // If pre-rotation is enabled apply the transformation else just flip the Y-coordinate
TIntermTyped *rotatedXY; TIntermTyped *rotatedXY;
if (mFragRotation) if (mUsePreRotation)
{ {
rotatedXY = rotatedXY = mRotationSpecConst->getFragRotationMultiplyFlipXY();
new TIntermBinary(EOpMatrixTimesVector, mFragRotation->deepCopy(), mFlipXY->deepCopy()); if (!rotatedXY)
{
TIntermTyped *flipXY = mDriverUniforms->getFlipXYRef();
TIntermTyped *fragRotation = mDriverUniforms->getFragRotationMatrixRef();
rotatedXY = new TIntermBinary(EOpMatrixTimesVector, fragRotation, flipXY);
}
} }
else else
{ {
rotatedXY = mFlipXY->deepCopy(); rotatedXY = mRotationSpecConst->getFlipXY();
if (!rotatedXY)
{
rotatedXY = mDriverUniforms->getFlipXYRef();
}
} }
TIntermBinary *correctedOffset = new TIntermBinary(EOpMul, offsetNode, rotatedXY); TIntermBinary *correctedOffset = new TIntermBinary(EOpMul, offsetNode, rotatedXY);
...@@ -121,11 +140,12 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -121,11 +140,12 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
} // anonymous namespace } // anonymous namespace
bool RewriteInterpolateAtOffset(TCompiler *compiler, bool RewriteInterpolateAtOffset(TCompiler *compiler,
ShCompileOptions compileOptions,
TIntermNode *root, TIntermNode *root,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
int shaderVersion, int shaderVersion,
TIntermBinary *flipXY, FlipRotateSpecConst *rotationSpecConst,
TIntermTyped *fragRotation) const DriverUniform *driverUniforms)
{ {
// interpolateAtOffset is only valid in GLSL 3.0 and later. // interpolateAtOffset is only valid in GLSL 3.0 and later.
if (shaderVersion < 300) if (shaderVersion < 300)
...@@ -133,7 +153,8 @@ bool RewriteInterpolateAtOffset(TCompiler *compiler, ...@@ -133,7 +153,8 @@ bool RewriteInterpolateAtOffset(TCompiler *compiler,
return true; return true;
} }
return Traverser::Apply(compiler, root, symbolTable, flipXY, fragRotation, shaderVersion); return Traverser::Apply(compiler, compileOptions, root, symbolTable, shaderVersion,
rotationSpecConst, driverUniforms);
} }
} // namespace sh } // namespace sh
...@@ -27,11 +27,12 @@ class TSymbolTable; ...@@ -27,11 +27,12 @@ class TSymbolTable;
// If fragRotation = nullptr, no rotation will be applied. // If fragRotation = nullptr, no rotation will be applied.
ANGLE_NO_DISCARD bool RewriteInterpolateAtOffset(TCompiler *compiler, ANGLE_NO_DISCARD bool RewriteInterpolateAtOffset(TCompiler *compiler,
ShCompileOptions compileOptions,
TIntermNode *root, TIntermNode *root,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
int shaderVersion, int shaderVersion,
TIntermBinary *flipXY, FlipRotateSpecConst *rotationSpecConst,
TIntermTyped *fragRotation); const DriverUniform *driverUniforms);
} // namespace sh } // namespace sh
......
...@@ -36,6 +36,7 @@ class FlipRotateSpecConst ...@@ -36,6 +36,7 @@ class FlipRotateSpecConst
TIntermTyped *getNegFlipXY(); TIntermTyped *getNegFlipXY();
TIntermTyped *getFlipY(); TIntermTyped *getFlipY();
TIntermTyped *getNegFlipY(); TIntermTyped *getNegFlipY();
TIntermTyped *getFragRotationMultiplyFlipXY();
void generateSymbol(TSymbolTable *symbolTable); void generateSymbol(TSymbolTable *symbolTable);
void outputLayoutString(TInfoSinkBase &sink) const; void outputLayoutString(TInfoSinkBase &sink) const;
......
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