Commit 3f18ad09 by Charlie Lao Committed by Commit Bot

Vulkan: Factor out DriverUniform code to tree_utils/DriverUniform.cpp

The driver uniform code is used by various tree_ops functions. But all driver uniform code are defined and implemented in the TranslatorVulkan.cpp file. There is dependency rule that tree_ops code can not call into vulkan specific function. Right now we are working around this problem by always having TranslatorVulkan creates uniform and pass it down to tree_ops. This creates inefficiency for cases that dFdy/dFdx where we don't know if we will need the driver uniform or not, until we walk the tree and see the dFdx node. This CL refactors driver uniform code into its own file and class under tree_utils so that everybody can use. Mean time we can also make it much easier for metal to expand it to have its own uniform structure. Bug: b/173047182 Change-Id: I06bd9a005ccd6dc0a21321a3010dda1eab9d6fdb Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2533443 Commit-Queue: Charlie Lao <cclao@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com>
parent 6df1ffdc
...@@ -210,6 +210,8 @@ angle_translator_sources = [ ...@@ -210,6 +210,8 @@ angle_translator_sources = [
"src/compiler/translator/tree_util/BuiltIn.h", "src/compiler/translator/tree_util/BuiltIn.h",
"src/compiler/translator/tree_util/BuiltIn_ESSL_autogen.h", "src/compiler/translator/tree_util/BuiltIn_ESSL_autogen.h",
"src/compiler/translator/tree_util/BuiltIn_complete_autogen.h", "src/compiler/translator/tree_util/BuiltIn_complete_autogen.h",
"src/compiler/translator/tree_util/DriverUniform.cpp",
"src/compiler/translator/tree_util/DriverUniform.h",
"src/compiler/translator/tree_util/FindFunction.cpp", "src/compiler/translator/tree_util/FindFunction.cpp",
"src/compiler/translator/tree_util/FindFunction.h", "src/compiler/translator/tree_util/FindFunction.h",
"src/compiler/translator/tree_util/FindMain.cpp", "src/compiler/translator/tree_util/FindMain.cpp",
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "compiler/translator/StaticType.h" #include "compiler/translator/StaticType.h"
#include "compiler/translator/tree_ops/InitializeVariables.h" #include "compiler/translator/tree_ops/InitializeVariables.h"
#include "compiler/translator/tree_util/BuiltIn.h" #include "compiler/translator/tree_util/BuiltIn.h"
#include "compiler/translator/tree_util/DriverUniform.h"
#include "compiler/translator/tree_util/FindMain.h" #include "compiler/translator/tree_util/FindMain.h"
#include "compiler/translator/tree_util/FindSymbolNode.h" #include "compiler/translator/tree_util/FindSymbolNode.h"
#include "compiler/translator/tree_util/IntermNode_util.h" #include "compiler/translator/tree_util/IntermNode_util.h"
...@@ -40,23 +41,11 @@ const char kRasterizerDiscardEnabledConstName[] = "ANGLERasterizerDisabled"; ...@@ -40,23 +41,11 @@ const char kRasterizerDiscardEnabledConstName[] = "ANGLERasterizerDisabled";
namespace namespace
{ {
// Metal specific driver uniforms
constexpr const char kCoverageMask[] = "coverageMask";
constexpr ImmutableString kCoverageMaskField = ImmutableString("coverageMask");
constexpr ImmutableString kSampleMaskWriteFuncName = ImmutableString("ANGLEWriteSampleMask"); constexpr ImmutableString kSampleMaskWriteFuncName = ImmutableString("ANGLEWriteSampleMask");
TIntermBinary *CreateDriverUniformRef(const TVariable *driverUniforms, const char *fieldName)
{
size_t fieldIndex =
FindFieldIndex(driverUniforms->getType().getInterfaceBlock()->fields(), fieldName);
TIntermSymbol *angleUniformsRef = new TIntermSymbol(driverUniforms);
TConstantUnion *uniformIndex = new TConstantUnion;
uniformIndex->setIConst(static_cast<int>(fieldIndex));
TIntermConstantUnion *indexRef =
new TIntermConstantUnion(uniformIndex, *StaticType::GetBasic<EbtInt>());
return new TIntermBinary(EOpIndexDirectInterfaceBlock, angleUniformsRef, indexRef);
}
// Unlike Vulkan having auto viewport flipping extension, in Metal we have to flip gl_Position.y // Unlike Vulkan having auto viewport flipping extension, in Metal we have to flip gl_Position.y
// manually. // manually.
// This operation performs flipping the gl_Position.y using this expression: // This operation performs flipping the gl_Position.y using this expression:
...@@ -120,9 +109,27 @@ ANGLE_NO_DISCARD bool InitializeUnusedOutputs(TIntermBlock *root, ...@@ -120,9 +109,27 @@ ANGLE_NO_DISCARD bool InitializeUnusedOutputs(TIntermBlock *root,
return true; return true;
} }
} // anonymous namespace } // anonymous namespace
TFieldList *DriverUniformMetal::createUniformFields(TSymbolTable *symbolTable) const
{
TFieldList *driverFieldList = DriverUniform::createUniformFields(symbolTable);
// Add coverage mask to driver uniform. Metal doesn't have built-in GL_SAMPLE_COVERAGE_VALUE
// equivalent functionality, needs to emulate it using fragment shader's [[sample_mask]] output
// value.
TField *coverageMaskField = new TField(new TType(EbtUInt), ImmutableString(kCoverageMask),
TSourceLoc(), SymbolType::AngleInternal);
driverFieldList->push_back(coverageMaskField);
return driverFieldList;
}
TIntermBinary *DriverUniformMetal::getCoverageMaskFieldRef() const
{
return createDriverUniformRef(kCoverageMask);
}
TranslatorMetal::TranslatorMetal(sh::GLenum type, ShShaderSpec spec) : TranslatorVulkan(type, spec) TranslatorMetal::TranslatorMetal(sh::GLenum type, ShShaderSpec spec) : TranslatorVulkan(type, spec)
{} {}
...@@ -136,7 +143,7 @@ bool TranslatorMetal::translate(TIntermBlock *root, ...@@ -136,7 +143,7 @@ bool TranslatorMetal::translate(TIntermBlock *root,
getNameMap(), &getSymbolTable(), getShaderType(), getNameMap(), &getSymbolTable(), getShaderType(),
getShaderVersion(), getOutputType(), false, true, compileOptions); getShaderVersion(), getOutputType(), false, true, compileOptions);
const TVariable *driverUniforms = nullptr; DriverUniformMetal driverUniforms;
if (!TranslatorVulkan::translateImpl(root, compileOptions, perfDiagnostics, &driverUniforms, if (!TranslatorVulkan::translateImpl(root, compileOptions, perfDiagnostics, &driverUniforms,
&outputGLSL)) &outputGLSL))
{ {
...@@ -151,7 +158,7 @@ bool TranslatorMetal::translate(TIntermBlock *root, ...@@ -151,7 +158,7 @@ bool TranslatorMetal::translate(TIntermBlock *root,
if (getShaderType() == GL_VERTEX_SHADER) if (getShaderType() == GL_VERTEX_SHADER)
{ {
auto negFlipY = getDriverUniformNegFlipYRef(driverUniforms); auto negFlipY = driverUniforms.getNegFlipYRef();
// Append gl_Position.y correction to main // Append gl_Position.y correction to main
if (!AppendVertexShaderPositionYCorrectionToMain(this, root, &getSymbolTable(), negFlipY)) if (!AppendVertexShaderPositionYCorrectionToMain(this, root, &getSymbolTable(), negFlipY))
...@@ -167,7 +174,7 @@ bool TranslatorMetal::translate(TIntermBlock *root, ...@@ -167,7 +174,7 @@ bool TranslatorMetal::translate(TIntermBlock *root,
} }
else if (getShaderType() == GL_FRAGMENT_SHADER) else if (getShaderType() == GL_FRAGMENT_SHADER)
{ {
if (!insertSampleMaskWritingLogic(root, driverUniforms)) if (!insertSampleMaskWritingLogic(root, &driverUniforms))
{ {
return false; return false;
} }
...@@ -203,7 +210,7 @@ bool TranslatorMetal::translate(TIntermBlock *root, ...@@ -203,7 +210,7 @@ bool TranslatorMetal::translate(TIntermBlock *root,
// This is achieved by multiply the depth value with scale value stored in // This is achieved by multiply the depth value with scale value stored in
// driver uniform's depthRange.reserved // driver uniform's depthRange.reserved
bool TranslatorMetal::transformDepthBeforeCorrection(TIntermBlock *root, bool TranslatorMetal::transformDepthBeforeCorrection(TIntermBlock *root,
const TVariable *driverUniforms) const DriverUniform *driverUniforms)
{ {
// Create a symbol reference to "gl_Position" // Create a symbol reference to "gl_Position"
const TVariable *position = BuiltInVariable::gl_Position(); const TVariable *position = BuiltInVariable::gl_Position();
...@@ -214,7 +221,7 @@ bool TranslatorMetal::transformDepthBeforeCorrection(TIntermBlock *root, ...@@ -214,7 +221,7 @@ bool TranslatorMetal::transformDepthBeforeCorrection(TIntermBlock *root,
TIntermSwizzle *positionZ = new TIntermSwizzle(positionRef, swizzleOffsetZ); TIntermSwizzle *positionZ = new TIntermSwizzle(positionRef, swizzleOffsetZ);
// Create a ref to "depthRange.reserved" // Create a ref to "depthRange.reserved"
TIntermBinary *viewportZScale = getDriverUniformDepthRangeReservedFieldRef(driverUniforms); TIntermBinary *viewportZScale = driverUniforms->getDepthRangeReservedFieldRef();
// Create the expression "gl_Position.z * depthRange.reserved". // Create the expression "gl_Position.z * depthRange.reserved".
TIntermBinary *zScale = new TIntermBinary(EOpMul, positionZ->deepCopy(), viewportZScale); TIntermBinary *zScale = new TIntermBinary(EOpMul, positionZ->deepCopy(), viewportZScale);
...@@ -227,20 +234,11 @@ bool TranslatorMetal::transformDepthBeforeCorrection(TIntermBlock *root, ...@@ -227,20 +234,11 @@ bool TranslatorMetal::transformDepthBeforeCorrection(TIntermBlock *root,
return RunAtTheEndOfShader(this, root, assignment, &getSymbolTable()); return RunAtTheEndOfShader(this, root, assignment, &getSymbolTable());
} }
void TranslatorMetal::createAdditionalGraphicsDriverUniformFields(std::vector<TField *> *fieldsOut)
{
// Add coverage mask to driver uniform. Metal doesn't have built-in GL_SAMPLE_COVERAGE_VALUE
// equivalent functionality, needs to emulate it using fragment shader's [[sample_mask]] output
// value.
TField *coverageMaskField =
new TField(new TType(EbtUInt), kCoverageMaskField, TSourceLoc(), SymbolType::AngleInternal);
fieldsOut->push_back(coverageMaskField);
}
// Add sample_mask writing to main, guarded by the specialization constant // Add sample_mask writing to main, guarded by the specialization constant
// kCoverageMaskEnabledConstName // kCoverageMaskEnabledConstName
ANGLE_NO_DISCARD bool TranslatorMetal::insertSampleMaskWritingLogic(TIntermBlock *root, ANGLE_NO_DISCARD bool TranslatorMetal::insertSampleMaskWritingLogic(
const TVariable *driverUniforms) TIntermBlock *root,
const DriverUniformMetal *driverUniforms)
{ {
TInfoSinkBase &sink = getInfoSink().obj; TInfoSinkBase &sink = getInfoSink().obj;
TSymbolTable *symbolTable = &getSymbolTable(); TSymbolTable *symbolTable = &getSymbolTable();
...@@ -273,7 +271,7 @@ ANGLE_NO_DISCARD bool TranslatorMetal::insertSampleMaskWritingLogic(TIntermBlock ...@@ -273,7 +271,7 @@ ANGLE_NO_DISCARD bool TranslatorMetal::insertSampleMaskWritingLogic(TIntermBlock
sampleMaskWriteFunc->addParameter(maskArg); sampleMaskWriteFunc->addParameter(maskArg);
// coverageMask // coverageMask
TIntermBinary *coverageMask = CreateDriverUniformRef(driverUniforms, kCoverageMaskField.data()); TIntermBinary *coverageMask = driverUniforms->getCoverageMaskFieldRef();
// Insert this code to the end of main() // Insert this code to the end of main()
// if (ANGLECoverageMaskEnabled) // if (ANGLECoverageMaskEnabled)
......
...@@ -16,10 +16,23 @@ ...@@ -16,10 +16,23 @@
#define LIBANGLE_RENDERER_METAL_TRANSLATORMETAL_H_ #define LIBANGLE_RENDERER_METAL_TRANSLATORMETAL_H_
#include "compiler/translator/TranslatorVulkan.h" #include "compiler/translator/TranslatorVulkan.h"
#include "compiler/translator/tree_util/DriverUniform.h"
namespace sh namespace sh
{ {
class DriverUniformMetal : public DriverUniform
{
public:
DriverUniformMetal() : DriverUniform() {}
~DriverUniformMetal() override {}
TIntermBinary *getCoverageMaskFieldRef() const;
protected:
TFieldList *createUniformFields(TSymbolTable *symbolTable) const override;
};
class TranslatorMetal : public TranslatorVulkan class TranslatorMetal : public TranslatorVulkan
{ {
public: public:
...@@ -30,13 +43,12 @@ class TranslatorMetal : public TranslatorVulkan ...@@ -30,13 +43,12 @@ class TranslatorMetal : public TranslatorVulkan
ShCompileOptions compileOptions, ShCompileOptions compileOptions,
PerformanceDiagnostics *perfDiagnostics) override; PerformanceDiagnostics *perfDiagnostics) override;
ANGLE_NO_DISCARD bool transformDepthBeforeCorrection(TIntermBlock *root, ANGLE_NO_DISCARD bool transformDepthBeforeCorrection(
const TVariable *driverUniforms) override; TIntermBlock *root,
const DriverUniform *driverUniforms) override;
void createAdditionalGraphicsDriverUniformFields(std::vector<TField *> *fieldsOut) override;
ANGLE_NO_DISCARD bool insertSampleMaskWritingLogic(TIntermBlock *root, ANGLE_NO_DISCARD bool insertSampleMaskWritingLogic(TIntermBlock *root,
const TVariable *driverUniforms); const DriverUniformMetal *driverUniforms);
ANGLE_NO_DISCARD bool insertRasterizerDiscardLogic(TIntermBlock *root); ANGLE_NO_DISCARD bool insertRasterizerDiscardLogic(TIntermBlock *root);
}; };
......
...@@ -18,6 +18,7 @@ namespace sh ...@@ -18,6 +18,7 @@ namespace sh
{ {
class TOutputVulkanGLSL; class TOutputVulkanGLSL;
class DriverUniform;
class TranslatorVulkan : public TCompiler class TranslatorVulkan : public TCompiler
{ {
...@@ -30,27 +31,22 @@ class TranslatorVulkan : public TCompiler ...@@ -30,27 +31,22 @@ class TranslatorVulkan : public TCompiler
PerformanceDiagnostics *perfDiagnostics) override; PerformanceDiagnostics *perfDiagnostics) override;
bool shouldFlattenPragmaStdglInvariantAll() override; bool shouldFlattenPragmaStdglInvariantAll() override;
TIntermSwizzle *getDriverUniformNegFlipYRef(const TVariable *driverUniforms) const;
TIntermBinary *getDriverUniformDepthRangeReservedFieldRef(
const TVariable *driverUniforms) const;
// Subclass can call this method to transform the AST before writing the final output. // Subclass can call this method to transform the AST before writing the final output.
// See TranslatorMetal.cpp. // See TranslatorMetal.cpp.
ANGLE_NO_DISCARD bool translateImpl(TIntermBlock *root, ANGLE_NO_DISCARD bool translateImpl(TIntermBlock *root,
ShCompileOptions compileOptions, ShCompileOptions compileOptions,
PerformanceDiagnostics *perfDiagnostics, PerformanceDiagnostics *perfDiagnostics,
const TVariable **driverUniformsOut, DriverUniform *driverUniforms,
TOutputVulkanGLSL *outputGLSL); TOutputVulkanGLSL *outputGLSL);
// Give subclass such as TranslatorMetal a chance to do depth transform before // Give subclass such as TranslatorMetal a chance to do depth transform before
// TranslatorVulkan apply its own transform. // TranslatorVulkan apply its own transform.
ANGLE_NO_DISCARD virtual bool transformDepthBeforeCorrection(TIntermBlock *root, ANGLE_NO_DISCARD virtual bool transformDepthBeforeCorrection(
const TVariable *driverUniforms) TIntermBlock *root,
const DriverUniform *driverUniforms)
{ {
return true; return true;
} }
// Back-end specific fields to be added to driver uniform. See TranslatorMetal.cpp.
virtual void createAdditionalGraphicsDriverUniformFields(std::vector<TField *> *fieldsOut) {}
}; };
} // namespace sh } // namespace sh
......
//
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// DriverUniform.cpp: Add code to support driver uniforms
//
#include "compiler/translator/tree_util/DriverUniform.h"
#include "compiler/translator/Compiler.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/StaticType.h"
#include "compiler/translator/SymbolTable.h"
#include "compiler/translator/tree_util/FindMain.h"
#include "compiler/translator/tree_util/IntermNode_util.h"
#include "compiler/translator/tree_util/IntermTraverse.h"
#include "compiler/translator/util.h"
namespace sh
{
namespace
{
constexpr ImmutableString kEmulatedDepthRangeParams = ImmutableString("ANGLEDepthRangeParams");
constexpr const char kViewport[] = "viewport";
constexpr const char kHalfRenderArea[] = "halfRenderArea";
constexpr const char kFlipXY[] = "flipXY";
constexpr const char kNegFlipXY[] = "negFlipXY";
constexpr const char kClipDistancesEnabled[] = "clipDistancesEnabled";
constexpr const char kXfbActiveUnpaused[] = "xfbActiveUnpaused";
constexpr const char kXfbVerticesPerDraw[] = "xfbVerticesPerDraw";
constexpr const char kXfbBufferOffsets[] = "xfbBufferOffsets";
constexpr const char kAcbBufferOffsets[] = "acbBufferOffsets";
constexpr const char kDepthRange[] = "depthRange";
constexpr const char kPreRotation[] = "preRotation";
constexpr const char kFragRotation[] = "fragRotation";
constexpr size_t kNumGraphicsDriverUniforms = 12;
constexpr std::array<const char *, kNumGraphicsDriverUniforms> kGraphicsDriverUniformNames = {
{kViewport, kHalfRenderArea, kFlipXY, kNegFlipXY, kClipDistancesEnabled, kXfbActiveUnpaused,
kXfbVerticesPerDraw, kXfbBufferOffsets, kAcbBufferOffsets, kDepthRange, kPreRotation,
kFragRotation}};
constexpr size_t kNumComputeDriverUniforms = 1;
constexpr std::array<const char *, kNumComputeDriverUniforms> kComputeDriverUniformNames = {
{kAcbBufferOffsets}};
} // anonymous namespace
bool DriverUniform::addComputeDriverUniformsToShader(TIntermBlock *root, TSymbolTable *symbolTable)
{
ASSERT(!mDriverUniforms);
// This field list mirrors the structure of ComputeDriverUniforms in ContextVk.cpp.
TFieldList *driverFieldList = new TFieldList;
const std::array<TType *, kNumComputeDriverUniforms> kDriverUniformTypes = {{
new TType(EbtUInt, 4),
}};
for (size_t uniformIndex = 0; uniformIndex < kNumComputeDriverUniforms; ++uniformIndex)
{
TField *driverUniformField =
new TField(kDriverUniformTypes[uniformIndex],
ImmutableString(kComputeDriverUniformNames[uniformIndex]), TSourceLoc(),
SymbolType::AngleInternal);
driverFieldList->push_back(driverUniformField);
}
// Define a driver uniform block "ANGLEUniformBlock" with instance name "ANGLEUniforms".
mDriverUniforms = DeclareInterfaceBlock(
root, symbolTable, driverFieldList, EvqUniform, TMemoryQualifier::Create(), 0,
ImmutableString(vk::kDriverUniformsBlockName), ImmutableString(vk::kDriverUniformsVarName));
return mDriverUniforms != nullptr;
}
TFieldList *DriverUniform::createUniformFields(TSymbolTable *symbolTable) const
{
// This field list mirrors the structure of GraphicsDriverUniforms in ContextVk.cpp.
TFieldList *driverFieldList = new TFieldList;
const std::array<TType *, kNumGraphicsDriverUniforms> kDriverUniformTypes = {{
new TType(EbtFloat, 4),
new TType(EbtFloat, 2),
new TType(EbtFloat, 2),
new TType(EbtFloat, 2),
new TType(EbtUInt), // uint clipDistancesEnabled; // 32 bits for 32 clip distances max
new TType(EbtUInt),
new TType(EbtUInt),
// NOTE: There's a vec3 gap here that can be used in the future
new TType(EbtInt, 4),
new TType(EbtUInt, 4),
createEmulatedDepthRangeType(symbolTable),
new TType(EbtFloat, 2, 2),
new TType(EbtFloat, 2, 2),
}};
for (size_t uniformIndex = 0; uniformIndex < kNumGraphicsDriverUniforms; ++uniformIndex)
{
TField *driverUniformField =
new TField(kDriverUniformTypes[uniformIndex],
ImmutableString(kGraphicsDriverUniformNames[uniformIndex]), TSourceLoc(),
SymbolType::AngleInternal);
driverFieldList->push_back(driverUniformField);
}
return driverFieldList;
}
TType *DriverUniform::createEmulatedDepthRangeType(TSymbolTable *symbolTable) const
{
// Init the depth range type.
TFieldList *depthRangeParamsFields = new TFieldList();
depthRangeParamsFields->push_back(new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1, 1),
ImmutableString("near"), TSourceLoc(),
SymbolType::AngleInternal));
depthRangeParamsFields->push_back(new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1, 1),
ImmutableString("far"), TSourceLoc(),
SymbolType::AngleInternal));
depthRangeParamsFields->push_back(new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1, 1),
ImmutableString("diff"), TSourceLoc(),
SymbolType::AngleInternal));
// This additional field might be used by subclass such as TranslatorMetal.
depthRangeParamsFields->push_back(new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1, 1),
ImmutableString("reserved"), TSourceLoc(),
SymbolType::AngleInternal));
TStructure *emulatedDepthRangeParams = new TStructure(
symbolTable, kEmulatedDepthRangeParams, depthRangeParamsFields, SymbolType::AngleInternal);
TType *emulatedDepthRangeType = new TType(emulatedDepthRangeParams, false);
return emulatedDepthRangeType;
}
// The Add*DriverUniformsToShader operation adds an internal uniform block to a shader. The driver
// block is used to implement Vulkan-specific features and workarounds. Returns the driver uniforms
// variable.
//
// There are Graphics and Compute variations as they require different uniforms.
bool DriverUniform::addGraphicsDriverUniformsToShader(TIntermBlock *root, TSymbolTable *symbolTable)
{
ASSERT(!mDriverUniforms);
TType *emulatedDepthRangeType = createEmulatedDepthRangeType(symbolTable);
// Declare a global depth range variable.
TVariable *depthRangeVar =
new TVariable(symbolTable->nextUniqueId(), kEmptyImmutableString, SymbolType::Empty,
TExtension::UNDEFINED, emulatedDepthRangeType);
DeclareGlobalVariable(root, depthRangeVar);
TFieldList *driverFieldList = createUniformFields(symbolTable);
// Define a driver uniform block "ANGLEUniformBlock" with instance name "ANGLEUniforms".
mDriverUniforms = DeclareInterfaceBlock(
root, symbolTable, driverFieldList, EvqUniform, TMemoryQualifier::Create(), 0,
ImmutableString(vk::kDriverUniformsBlockName), ImmutableString(vk::kDriverUniformsVarName));
return mDriverUniforms != nullptr;
}
TIntermBinary *DriverUniform::createDriverUniformRef(const char *fieldName) const
{
size_t fieldIndex =
FindFieldIndex(mDriverUniforms->getType().getInterfaceBlock()->fields(), fieldName);
TIntermSymbol *angleUniformsRef = new TIntermSymbol(mDriverUniforms);
TConstantUnion *uniformIndex = new TConstantUnion;
uniformIndex->setIConst(static_cast<int>(fieldIndex));
TIntermConstantUnion *indexRef =
new TIntermConstantUnion(uniformIndex, *StaticType::GetBasic<EbtInt>());
return new TIntermBinary(EOpIndexDirectInterfaceBlock, angleUniformsRef, indexRef);
}
TIntermBinary *DriverUniform::getFlipXYRef() const
{
return createDriverUniformRef(kFlipXY);
}
TIntermBinary *DriverUniform::getNegFlipXYRef() const
{
return createDriverUniformRef(kNegFlipXY);
}
TIntermBinary *DriverUniform::getFragRotationMatrixRef() const
{
return createDriverUniformRef(kFragRotation);
}
TIntermBinary *DriverUniform::getPreRotationMatrixRef() const
{
return createDriverUniformRef(kPreRotation);
}
TIntermBinary *DriverUniform::getViewportRef() const
{
return createDriverUniformRef(kViewport);
}
TIntermBinary *DriverUniform::getHalfRenderAreaRef() const
{
return createDriverUniformRef(kHalfRenderArea);
}
TIntermBinary *DriverUniform::getAbcBufferOffsets() const
{
return createDriverUniformRef(kAcbBufferOffsets);
}
TIntermBinary *DriverUniform::getClipDistancesEnabled() const
{
return createDriverUniformRef(kClipDistancesEnabled);
}
TIntermBinary *DriverUniform::getDepthRangeRef() const
{
return createDriverUniformRef(kDepthRange);
}
TIntermSwizzle *DriverUniform::getNegFlipYRef() const
{
// Create a swizzle to "negFlipXY.y"
TIntermBinary *negFlipXY = createDriverUniformRef(kNegFlipXY);
TVector<int> swizzleOffsetY = {1};
TIntermSwizzle *negFlipY = new TIntermSwizzle(negFlipXY, swizzleOffsetY);
return negFlipY;
}
TIntermBinary *DriverUniform::getDepthRangeReservedFieldRef() const
{
TIntermBinary *depthRange = createDriverUniformRef(kDepthRange);
return new TIntermBinary(EOpIndexDirectStruct, depthRange, CreateIndexNode(3));
}
} // namespace sh
//
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// DriverUniform.h: Add code to support driver uniforms
//
#ifndef COMPILER_TRANSLATOR_TREEUTIL_DRIVERUNIFORM_H_
#define COMPILER_TRANSLATOR_TREEUTIL_DRIVERUNIFORM_H_
#include "common/angleutils.h"
#include "compiler/translator/Types.h"
namespace sh
{
class TCompiler;
class TIntermBlock;
class TIntermNode;
class TSymbolTable;
class TIntermTyped;
class TIntermSwizzle;
class TIntermBinary;
class DriverUniform
{
public:
DriverUniform() : mDriverUniforms(nullptr) {}
virtual ~DriverUniform() = default;
bool addComputeDriverUniformsToShader(TIntermBlock *root, TSymbolTable *symbolTable);
bool addGraphicsDriverUniformsToShader(TIntermBlock *root, TSymbolTable *symbolTable);
TIntermBinary *getFlipXYRef() const;
TIntermBinary *getNegFlipXYRef() const;
TIntermBinary *getFragRotationMatrixRef() const;
TIntermBinary *getPreRotationMatrixRef() const;
TIntermBinary *getViewportRef() const;
TIntermBinary *getHalfRenderAreaRef() const;
TIntermBinary *getAbcBufferOffsets() const;
TIntermBinary *getClipDistancesEnabled() const;
TIntermSwizzle *getNegFlipYRef() const;
TIntermBinary *getDepthRangeRef() const;
TIntermBinary *getDepthRangeReservedFieldRef() const;
protected:
TIntermBinary *createDriverUniformRef(const char *fieldName) const;
virtual TFieldList *createUniformFields(TSymbolTable *symbolTable) const;
TType *createEmulatedDepthRangeType(TSymbolTable *symbolTable) const;
const TVariable *mDriverUniforms;
};
} // namespace sh
#endif // COMPILER_TRANSLATOR_TREEUTIL_DRIVERUNIFORM_H_
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