Commit c75473c2 by Charlie Lao Committed by Commit Bot

Vulkan: Generalize FlipRotationSpecConst to SpecializationConstant

Specialization constant are used not just for flip/rotation. It also used for other things. This CL merges all specialization constant usage (lineRasterEmulation, flip, rotation, halfRenderArea) into one class and rename FlipRotationSpecConst to SpecConst. Bug: b/173800146 Change-Id: I8dc3354b6caedbb183cec29855fc1c301ec8872a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2555812 Commit-Queue: Charlie Lao <cclao@google.com> Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org>
parent dcc0bebf
...@@ -346,7 +346,7 @@ const ShCompileOptions SH_ADD_PRE_ROTATION = UINT64_C(1) << 56; ...@@ -346,7 +346,7 @@ const ShCompileOptions SH_ADD_PRE_ROTATION = UINT64_C(1) << 56;
const ShCompileOptions SH_FORCE_SHADER_PRECISION_HIGHP_TO_MEDIUMP = UINT64_C(1) << 57; const ShCompileOptions SH_FORCE_SHADER_PRECISION_HIGHP_TO_MEDIUMP = UINT64_C(1) << 57;
// Allow compiler to use specialization constant to do pre-rotation and y flip. // Allow compiler to use specialization constant to do pre-rotation and y flip.
const ShCompileOptions SH_USE_ROTATION_SPECIALIZATION_CONSTANT = UINT64_C(1) << 58; const ShCompileOptions SH_USE_SPECIALIZATION_CONSTANT = UINT64_C(1) << 58;
// Defines alternate strategies for implementing array index clamping. // Defines alternate strategies for implementing array index clamping.
enum ShArrayIndexClampingStrategy enum ShArrayIndexClampingStrategy
......
...@@ -220,8 +220,6 @@ angle_translator_sources = [ ...@@ -220,8 +220,6 @@ angle_translator_sources = [
"src/compiler/translator/tree_util/FindMain.h", "src/compiler/translator/tree_util/FindMain.h",
"src/compiler/translator/tree_util/FindSymbolNode.cpp", "src/compiler/translator/tree_util/FindSymbolNode.cpp",
"src/compiler/translator/tree_util/FindSymbolNode.h", "src/compiler/translator/tree_util/FindSymbolNode.h",
"src/compiler/translator/tree_util/FlipRotateSpecConst.cpp",
"src/compiler/translator/tree_util/FlipRotateSpecConst.h",
"src/compiler/translator/tree_util/IntermNodePatternMatcher.cpp", "src/compiler/translator/tree_util/IntermNodePatternMatcher.cpp",
"src/compiler/translator/tree_util/IntermNodePatternMatcher.h", "src/compiler/translator/tree_util/IntermNodePatternMatcher.h",
"src/compiler/translator/tree_util/IntermNode_util.cpp", "src/compiler/translator/tree_util/IntermNode_util.cpp",
...@@ -243,6 +241,8 @@ angle_translator_sources = [ ...@@ -243,6 +241,8 @@ angle_translator_sources = [
"src/compiler/translator/tree_util/RunAtTheBeginningOfShader.h", "src/compiler/translator/tree_util/RunAtTheBeginningOfShader.h",
"src/compiler/translator/tree_util/RunAtTheEndOfShader.cpp", "src/compiler/translator/tree_util/RunAtTheEndOfShader.cpp",
"src/compiler/translator/tree_util/RunAtTheEndOfShader.h", "src/compiler/translator/tree_util/RunAtTheEndOfShader.h",
"src/compiler/translator/tree_util/SpecializationConstant.cpp",
"src/compiler/translator/tree_util/SpecializationConstant.h",
"src/compiler/translator/tree_util/Visit.h", "src/compiler/translator/tree_util/Visit.h",
"src/compiler/translator/util.cpp", "src/compiler/translator/util.cpp",
"src/compiler/translator/util.h", "src/compiler/translator/util.h",
......
...@@ -143,9 +143,10 @@ bool TranslatorMetal::translate(TIntermBlock *root, ...@@ -143,9 +143,10 @@ bool TranslatorMetal::translate(TIntermBlock *root,
getNameMap(), &getSymbolTable(), getShaderType(), getNameMap(), &getSymbolTable(), getShaderType(),
getShaderVersion(), getOutputType(), false, true, compileOptions); getShaderVersion(), getOutputType(), false, true, compileOptions);
SpecConstMetal specConst(&getSymbolTable(), compileOptions);
DriverUniformMetal driverUniforms; DriverUniformMetal driverUniforms;
if (!TranslatorVulkan::translateImpl(root, compileOptions, perfDiagnostics, &driverUniforms, if (!TranslatorVulkan::translateImpl(root, compileOptions, perfDiagnostics, &specConst,
&outputGLSL)) &driverUniforms, &outputGLSL))
{ {
return false; return false;
} }
......
...@@ -17,10 +17,24 @@ ...@@ -17,10 +17,24 @@
#include "compiler/translator/TranslatorVulkan.h" #include "compiler/translator/TranslatorVulkan.h"
#include "compiler/translator/tree_util/DriverUniform.h" #include "compiler/translator/tree_util/DriverUniform.h"
#include "compiler/translator/tree_util/SpecializationConstant.h"
namespace sh namespace sh
{ {
// TODO: http://anglebug.com/5339 Implement it using actual specialization constant. For now we are
// redirecting to driver uniforms
class SpecConstMetal : public SpecConst
{
public:
SpecConstMetal(TSymbolTable *symbolTable, ShCompileOptions compileOptions)
: SpecConst(symbolTable, compileOptions)
{}
~SpecConstMetal() override {}
private:
};
class DriverUniformMetal : public DriverUniform class DriverUniformMetal : public DriverUniform
{ {
public: public:
......
...@@ -18,6 +18,7 @@ namespace sh ...@@ -18,6 +18,7 @@ namespace sh
{ {
class TOutputVulkanGLSL; class TOutputVulkanGLSL;
class SpecConst;
class DriverUniform; class DriverUniform;
class TranslatorVulkan : public TCompiler class TranslatorVulkan : public TCompiler
...@@ -36,6 +37,7 @@ class TranslatorVulkan : public TCompiler ...@@ -36,6 +37,7 @@ class TranslatorVulkan : public TCompiler
ANGLE_NO_DISCARD bool translateImpl(TIntermBlock *root, ANGLE_NO_DISCARD bool translateImpl(TIntermBlock *root,
ShCompileOptions compileOptions, ShCompileOptions compileOptions,
PerformanceDiagnostics *perfDiagnostics, PerformanceDiagnostics *perfDiagnostics,
SpecConst *specConst,
DriverUniform *driverUniforms, DriverUniform *driverUniforms,
TOutputVulkanGLSL *outputGLSL); TOutputVulkanGLSL *outputGLSL);
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
#include "compiler/translator/TranslatorVulkan.h" #include "compiler/translator/TranslatorVulkan.h"
#include "compiler/translator/tree_util/DriverUniform.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"
#include "compiler/translator/tree_util/SpecializationConstant.h"
namespace sh namespace sh
{ {
...@@ -30,30 +30,30 @@ class Traverser : public TIntermTraverser ...@@ -30,30 +30,30 @@ class Traverser : public TIntermTraverser
ShCompileOptions compileOptions, ShCompileOptions compileOptions,
TIntermNode *root, TIntermNode *root,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
FlipRotateSpecConst *rotationSpecConst, SpecConst *specConst,
const DriverUniform *driverUniforms); const DriverUniform *driverUniforms);
private: private:
Traverser(TSymbolTable *symbolTable, Traverser(TSymbolTable *symbolTable,
ShCompileOptions compileOptions, ShCompileOptions compileOptions,
FlipRotateSpecConst *rotationSpecConst, SpecConst *specConst,
const DriverUniform *driverUniforms); const DriverUniform *driverUniforms);
bool visitUnary(Visit visit, TIntermUnary *node) override; bool visitUnary(Visit visit, TIntermUnary *node) override;
bool visitUnaryWithRotation(Visit visit, TIntermUnary *node); bool visitUnaryWithRotation(Visit visit, TIntermUnary *node);
bool visitUnaryWithoutRotation(Visit visit, TIntermUnary *node); bool visitUnaryWithoutRotation(Visit visit, TIntermUnary *node);
FlipRotateSpecConst *mRotationSpecConst = nullptr; SpecConst *mRotationSpecConst = nullptr;
const DriverUniform *mDriverUniforms = nullptr; const DriverUniform *mDriverUniforms = nullptr;
bool mUsePreRotation = false; bool mUsePreRotation = false;
}; };
Traverser::Traverser(TSymbolTable *symbolTable, Traverser::Traverser(TSymbolTable *symbolTable,
ShCompileOptions compileOptions, ShCompileOptions compileOptions,
FlipRotateSpecConst *rotationSpecConst, SpecConst *specConst,
const DriverUniform *driverUniforms) const DriverUniform *driverUniforms)
: TIntermTraverser(true, false, false, symbolTable), : TIntermTraverser(true, false, false, symbolTable),
mRotationSpecConst(rotationSpecConst), mRotationSpecConst(specConst),
mDriverUniforms(driverUniforms), mDriverUniforms(driverUniforms),
mUsePreRotation((compileOptions & SH_ADD_PRE_ROTATION) != 0) mUsePreRotation((compileOptions & SH_ADD_PRE_ROTATION) != 0)
{} {}
...@@ -63,11 +63,11 @@ bool Traverser::Apply(TCompiler *compiler, ...@@ -63,11 +63,11 @@ bool Traverser::Apply(TCompiler *compiler,
ShCompileOptions compileOptions, ShCompileOptions compileOptions,
TIntermNode *root, TIntermNode *root,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
FlipRotateSpecConst *rotationSpecConst, SpecConst *specConst,
const DriverUniform *driverUniforms) const DriverUniform *driverUniforms)
{ {
TSymbolTable *pSymbolTable = const_cast<TSymbolTable *>(&symbolTable); TSymbolTable *pSymbolTable = const_cast<TSymbolTable *>(&symbolTable);
Traverser traverser(pSymbolTable, compileOptions, rotationSpecConst, driverUniforms); Traverser traverser(pSymbolTable, compileOptions, specConst, driverUniforms);
root->traverse(&traverser); root->traverse(&traverser);
return traverser.updateTree(compiler, root); return traverser.updateTree(compiler, root);
} }
...@@ -217,15 +217,14 @@ bool RewriteDfdy(TCompiler *compiler, ...@@ -217,15 +217,14 @@ bool RewriteDfdy(TCompiler *compiler,
TIntermNode *root, TIntermNode *root,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
int shaderVersion, int shaderVersion,
FlipRotateSpecConst *rotationSpecConst, SpecConst *specConst,
const DriverUniform *driverUniforms) const DriverUniform *driverUniforms)
{ {
// dFdy is only valid in GLSL 3.0 and later. // dFdy is only valid in GLSL 3.0 and later.
if (shaderVersion < 300) if (shaderVersion < 300)
return true; return true;
return Traverser::Apply(compiler, compileOptions, root, symbolTable, rotationSpecConst, return Traverser::Apply(compiler, compileOptions, root, symbolTable, specConst, driverUniforms);
driverUniforms);
} }
} // namespace sh } // namespace sh
...@@ -26,7 +26,7 @@ class TIntermBinary; ...@@ -26,7 +26,7 @@ class TIntermBinary;
class TIntermTyped; class TIntermTyped;
class TSymbolTable; class TSymbolTable;
class TVariable; class TVariable;
class FlipRotateSpecConst; class SpecConst;
class DriverUniform; class DriverUniform;
// If fragRotation = nullptr, no rotation will be applied. // If fragRotation = nullptr, no rotation will be applied.
...@@ -35,7 +35,7 @@ ANGLE_NO_DISCARD bool RewriteDfdy(TCompiler *compiler, ...@@ -35,7 +35,7 @@ ANGLE_NO_DISCARD bool RewriteDfdy(TCompiler *compiler,
TIntermNode *root, TIntermNode *root,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
int shaderVersion, int shaderVersion,
FlipRotateSpecConst *rotationSpecConst, SpecConst *specConst,
const DriverUniform *driverUniforms); const DriverUniform *driverUniforms);
} // namespace sh } // namespace sh
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
#include "compiler/translator/TranslatorVulkan.h" #include "compiler/translator/TranslatorVulkan.h"
#include "compiler/translator/tree_util/DriverUniform.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"
#include "compiler/translator/tree_util/SpecializationConstant.h"
namespace sh namespace sh
{ {
...@@ -31,33 +31,33 @@ class Traverser : public TIntermTraverser ...@@ -31,33 +31,33 @@ class Traverser : public TIntermTraverser
TIntermNode *root, TIntermNode *root,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
int ShaderVersion, int ShaderVersion,
FlipRotateSpecConst *rotationSpecConst, SpecConst *specConst,
const DriverUniform *driverUniforms); const DriverUniform *driverUniforms);
private: private:
Traverser(TSymbolTable *symbolTable, Traverser(TSymbolTable *symbolTable,
ShCompileOptions compileOptions, ShCompileOptions compileOptions,
int shaderVersion, int shaderVersion,
FlipRotateSpecConst *rotationSpecConst, SpecConst *specConst,
const DriverUniform *driverUniforms); const DriverUniform *driverUniforms);
bool visitAggregate(Visit visit, TIntermAggregate *node) override; bool visitAggregate(Visit visit, TIntermAggregate *node) override;
const TSymbolTable *symbolTable = nullptr; const TSymbolTable *symbolTable = nullptr;
const int shaderVersion; const int shaderVersion;
FlipRotateSpecConst *mRotationSpecConst = nullptr; SpecConst *mRotationSpecConst = nullptr;
const DriverUniform *mDriverUniforms = nullptr; const DriverUniform *mDriverUniforms = nullptr;
bool mUsePreRotation = false; bool mUsePreRotation = false;
}; };
Traverser::Traverser(TSymbolTable *symbolTable, Traverser::Traverser(TSymbolTable *symbolTable,
ShCompileOptions compileOptions, ShCompileOptions compileOptions,
int shaderVersion, int shaderVersion,
FlipRotateSpecConst *rotationSpecConst, SpecConst *specConst,
const DriverUniform *driverUniforms) const DriverUniform *driverUniforms)
: TIntermTraverser(true, false, false, symbolTable), : TIntermTraverser(true, false, false, symbolTable),
symbolTable(symbolTable), symbolTable(symbolTable),
shaderVersion(shaderVersion), shaderVersion(shaderVersion),
mRotationSpecConst(rotationSpecConst), mRotationSpecConst(specConst),
mDriverUniforms(driverUniforms), mDriverUniforms(driverUniforms),
mUsePreRotation((compileOptions & SH_ADD_PRE_ROTATION) != 0) mUsePreRotation((compileOptions & SH_ADD_PRE_ROTATION) != 0)
{} {}
...@@ -68,12 +68,11 @@ bool Traverser::Apply(TCompiler *compiler, ...@@ -68,12 +68,11 @@ bool Traverser::Apply(TCompiler *compiler,
TIntermNode *root, TIntermNode *root,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
int shaderVersion, int shaderVersion,
FlipRotateSpecConst *rotationSpecConst, SpecConst *specConst,
const DriverUniform *driverUniforms) const DriverUniform *driverUniforms)
{ {
TSymbolTable *pSymbolTable = const_cast<TSymbolTable *>(&symbolTable); TSymbolTable *pSymbolTable = const_cast<TSymbolTable *>(&symbolTable);
Traverser traverser(pSymbolTable, compileOptions, shaderVersion, rotationSpecConst, Traverser traverser(pSymbolTable, compileOptions, shaderVersion, specConst, driverUniforms);
driverUniforms);
root->traverse(&traverser); root->traverse(&traverser);
return traverser.updateTree(compiler, root); return traverser.updateTree(compiler, root);
} }
...@@ -144,7 +143,7 @@ bool RewriteInterpolateAtOffset(TCompiler *compiler, ...@@ -144,7 +143,7 @@ bool RewriteInterpolateAtOffset(TCompiler *compiler,
TIntermNode *root, TIntermNode *root,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
int shaderVersion, int shaderVersion,
FlipRotateSpecConst *rotationSpecConst, SpecConst *specConst,
const DriverUniform *driverUniforms) const DriverUniform *driverUniforms)
{ {
// interpolateAtOffset is only valid in GLSL 3.0 and later. // interpolateAtOffset is only valid in GLSL 3.0 and later.
...@@ -153,8 +152,8 @@ bool RewriteInterpolateAtOffset(TCompiler *compiler, ...@@ -153,8 +152,8 @@ bool RewriteInterpolateAtOffset(TCompiler *compiler,
return true; return true;
} }
return Traverser::Apply(compiler, compileOptions, root, symbolTable, shaderVersion, return Traverser::Apply(compiler, compileOptions, root, symbolTable, shaderVersion, specConst,
rotationSpecConst, driverUniforms); driverUniforms);
} }
} // namespace sh } // namespace sh
...@@ -31,7 +31,7 @@ ANGLE_NO_DISCARD bool RewriteInterpolateAtOffset(TCompiler *compiler, ...@@ -31,7 +31,7 @@ ANGLE_NO_DISCARD bool RewriteInterpolateAtOffset(TCompiler *compiler,
TIntermNode *root, TIntermNode *root,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
int shaderVersion, int shaderVersion,
FlipRotateSpecConst *rotationSpecConst, SpecConst *specConst,
const DriverUniform *driverUniforms); const DriverUniform *driverUniforms);
} // namespace sh } // namespace sh
......
...@@ -3,12 +3,11 @@ ...@@ -3,12 +3,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// FlipRotationSpecConst.h: Add code to generate AST node for flip and rotation matrices and // SpecializationConst.h: Add code to generate AST node for specialization constant.
// vectors.
// //
#ifndef COMPILER_TRANSLATOR_TREEUTIL_FLIPROTATESPECCONST_H_ #ifndef COMPILER_TRANSLATOR_TREEUTIL_SPECIALIZATIONCONSTANT_H_
#define COMPILER_TRANSLATOR_TREEUTIL_FLIPROTATESPECCONST_H_ #define COMPILER_TRANSLATOR_TREEUTIL_SPECIALIZATIONCONSTANT_H_
#include "common/angleutils.h" #include "common/angleutils.h"
#include "compiler/translator/Compiler.h" #include "compiler/translator/Compiler.h"
...@@ -21,12 +20,16 @@ class TVariable; ...@@ -21,12 +20,16 @@ class TVariable;
namespace sh namespace sh
{ {
class FlipRotateSpecConst class SpecConst
{ {
public: public:
FlipRotateSpecConst(); SpecConst(TSymbolTable *symbolTable, ShCompileOptions compileOptions);
~FlipRotateSpecConst(); virtual ~SpecConst();
// Line rasterizaton emulation
TIntermSymbol *getLineRasterEmulation();
// Flip/rotation
TIntermTyped *getMultiplierXForDFdx(); TIntermTyped *getMultiplierXForDFdx();
TIntermTyped *getMultiplierYForDFdx(); TIntermTyped *getMultiplierYForDFdx();
TIntermTyped *getMultiplierXForDFdy(); TIntermTyped *getMultiplierXForDFdy();
...@@ -36,24 +39,28 @@ class FlipRotateSpecConst ...@@ -36,24 +39,28 @@ class FlipRotateSpecConst
TIntermTyped *getFlipXY(); TIntermTyped *getFlipXY();
TIntermTyped *getNegFlipXY(); TIntermTyped *getNegFlipXY();
TIntermTyped *getFlipY(); TIntermTyped *getFlipY();
TIntermTyped *getNegFlipY();
TIntermTyped *getFragRotationMultiplyFlipXY(); TIntermTyped *getFragRotationMultiplyFlipXY();
// Half render area
TIntermBinary *getHalfRenderArea(); TIntermBinary *getHalfRenderArea();
TIntermTyped *getHalfRenderAreaRotationMatrix();
void generateSymbol(TSymbolTable *symbolTable);
void outputLayoutString(TInfoSinkBase &sink) const; void outputLayoutString(TInfoSinkBase &sink) const;
SpecConstUsageBits getSpecConstUsageBits() const { return mUsageBits; } SpecConstUsageBits getSpecConstUsageBits() const { return mUsageBits; }
private: private:
TIntermSymbol *getFlipRotation();
TIntermTyped *getNegFlipY();
TIntermSymbol *getDrawableWidth(); TIntermSymbol *getDrawableWidth();
TIntermSymbol *getDrawableHeight(); TIntermSymbol *getDrawableHeight();
TIntermTyped *getHalfRenderAreaRotationMatrix();
// If unsupported, this should be set to null.
TSymbolTable *mSymbolTable; TSymbolTable *mSymbolTable;
TIntermSymbol *mSpecConstSymbol; ShCompileOptions mCompileOptions;
// Bit is set if YFlip or Rotation has been used // Bit is set if YFlip or Rotation has been used
SpecConstUsageBits mUsageBits; SpecConstUsageBits mUsageBits;
}; };
} // namespace sh } // namespace sh
#endif // COMPILER_TRANSLATOR_TREEUTIL_FLIPROTATESPECCONST_H_ #endif // COMPILER_TRANSLATOR_TREEUTIL_SPECIALIZATIONCONSTANT_H_
...@@ -75,7 +75,7 @@ std::shared_ptr<WaitableCompileEvent> ShaderVk::compile(const gl::Context *conte ...@@ -75,7 +75,7 @@ std::shared_ptr<WaitableCompileEvent> ShaderVk::compile(const gl::Context *conte
// Let compiler use specialized constant for pre-rotation. // Let compiler use specialized constant for pre-rotation.
if (!contextVk->getFeatures().forceDriverUniformOverSpecConst.enabled) if (!contextVk->getFeatures().forceDriverUniformOverSpecConst.enabled)
{ {
compileOptions |= SH_USE_ROTATION_SPECIALIZATION_CONSTANT; compileOptions |= SH_USE_SPECIALIZATION_CONSTANT;
} }
if (contextVk->getFeatures().enablePreRotateSurfaces.enabled || if (contextVk->getFeatures().enablePreRotateSurfaces.enabled ||
......
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