Commit 15ead5d5 by Charlie Lao Committed by Commit Bot

Reland "Vulkan: Let shader use rotation specialized constant"

This is a reland of 47b3db22 Original change's description: > Vulkan: Let shader use rotation specialized constant > > If use rotation specialized constant is enabled via compiler options, > this CL will use rotation specialized constant to generate flipXY, > rotation matrix and negFlipXY. This allows the driver to optimize for > the minimum instructions for rotation. > > Bug: b/171750979 > Change-Id: I9851ac999d4d35b9f230f796e5445bca0dcb1e77 > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2514773 > Commit-Queue: Charlie Lao <cclao@google.com> > Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> > Reviewed-by: Ian Elliott <ianelliott@google.com> > Reviewed-by: Jamie Madill <jmadill@chromium.org> > Reviewed-by: Tim Van Patten <timvp@google.com> Bug: b/171750979 Change-Id: I9efde40eb138bacb161cce483a30ec01fee0983b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2533933 Commit-Queue: Charlie Lao <cclao@google.com> Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 3f18ad09
......@@ -26,7 +26,7 @@
// Version number for shader translation API.
// It is incremented every time the API changes.
#define ANGLE_SH_VERSION 239
#define ANGLE_SH_VERSION 240
enum ShShaderSpec
{
......@@ -341,6 +341,9 @@ const ShCompileOptions SH_EARLY_FRAGMENT_TESTS_OPTIMIZATION = UINT64_C(1) << 55;
// Allow compiler to insert Android pre-rotation code.
const ShCompileOptions SH_ADD_PRE_ROTATION = UINT64_C(1) << 56;
// Allow compiler to use specialization constant to do pre-rotation and y flip.
const ShCompileOptions SH_USE_ROTATION_SPECIALIZATION_CONSTANT = UINT64_C(1) << 57;
// Defines alternate strategies for implementing array index clamping.
enum ShArrayIndexClampingStrategy
{
......@@ -780,6 +783,21 @@ enum class SpecializationConstantId : uint32_t
EnumCount = InvalidEnum,
};
enum class SurfaceRotation : uint32_t
{
Identity,
Rotated90Degrees,
Rotated180Degrees,
Rotated270Degrees,
FlippedIdentity,
FlippedRotated90Degrees,
FlippedRotated180Degrees,
FlippedRotated270Degrees,
InvalidEnum,
EnumCount = InvalidEnum,
};
// Interface block name containing the aggregate default uniforms
extern const char kDefaultUniformsNameVS[];
extern const char kDefaultUniformsNameTCS[];
......
......@@ -218,6 +218,8 @@ angle_translator_sources = [
"src/compiler/translator/tree_util/FindMain.h",
"src/compiler/translator/tree_util/FindSymbolNode.cpp",
"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.h",
"src/compiler/translator/tree_util/IntermNode_util.cpp",
......
......@@ -53,7 +53,7 @@ constexpr ImmutableString kSampleMaskWriteFuncName = ImmutableString("ANGLEWrite
ANGLE_NO_DISCARD bool AppendVertexShaderPositionYCorrectionToMain(TCompiler *compiler,
TIntermBlock *root,
TSymbolTable *symbolTable,
TIntermSwizzle *negFlipY)
TIntermTyped *negFlipY)
{
// Create a symbol reference to "gl_Position"
const TVariable *position = BuiltInVariable::gl_Position();
......@@ -158,7 +158,7 @@ bool TranslatorMetal::translate(TIntermBlock *root,
if (getShaderType() == GL_VERTEX_SHADER)
{
auto negFlipY = driverUniforms.getNegFlipYRef();
TIntermTyped *negFlipY = driverUniforms.getNegFlipYRef();
// Append gl_Position.y correction to main
if (!AppendVertexShaderPositionYCorrectionToMain(this, root, &getSymbolTable(), negFlipY))
......
......@@ -11,6 +11,9 @@
#include "common/angleutils.h"
#include "compiler/translator/StaticType.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/IntermTraverse.h"
......@@ -24,44 +27,54 @@ class Traverser : public TIntermTraverser
{
public:
ANGLE_NO_DISCARD static bool Apply(TCompiler *compiler,
ShCompileOptions compileOptions,
TIntermNode *root,
const TSymbolTable &symbolTable,
TIntermBinary *flipXY,
TIntermTyped *fragRotation);
FlipRotateSpecConst *rotationSpecConst,
const DriverUniform *driverUniforms);
private:
Traverser(TIntermBinary *flipXY, TIntermTyped *fragRotation, TSymbolTable *symbolTable);
Traverser(TSymbolTable *symbolTable,
ShCompileOptions compileOptions,
FlipRotateSpecConst *rotationSpecConst,
const DriverUniform *driverUniforms);
bool visitUnary(Visit visit, TIntermUnary *node) override;
bool visitUnaryWithRotation(Visit visit, TIntermUnary *node);
bool visitUnaryWithoutRotation(Visit visit, TIntermUnary *node);
TIntermBinary *mFlipXY = nullptr;
TIntermTyped *mFragRotation = nullptr;
FlipRotateSpecConst *mRotationSpecConst = nullptr;
const DriverUniform *mDriverUniforms = nullptr;
bool mUsePreRotation = false;
};
Traverser::Traverser(TIntermBinary *flipXY, TIntermTyped *fragRotation, TSymbolTable *symbolTable)
Traverser::Traverser(TSymbolTable *symbolTable,
ShCompileOptions compileOptions,
FlipRotateSpecConst *rotationSpecConst,
const DriverUniform *driverUniforms)
: TIntermTraverser(true, false, false, symbolTable),
mFlipXY(flipXY),
mFragRotation(fragRotation)
mRotationSpecConst(rotationSpecConst),
mDriverUniforms(driverUniforms),
mUsePreRotation(compileOptions & SH_ADD_PRE_ROTATION)
{}
// static
bool Traverser::Apply(TCompiler *compiler,
ShCompileOptions compileOptions,
TIntermNode *root,
const TSymbolTable &symbolTable,
TIntermBinary *flipXY,
TIntermTyped *fragRotation)
FlipRotateSpecConst *rotationSpecConst,
const DriverUniform *driverUniforms)
{
TSymbolTable *pSymbolTable = const_cast<TSymbolTable *>(&symbolTable);
Traverser traverser(flipXY, fragRotation, pSymbolTable);
Traverser traverser(pSymbolTable, compileOptions, rotationSpecConst, driverUniforms);
root->traverse(&traverser);
return traverser.updateTree(compiler, root);
}
bool Traverser::visitUnary(Visit visit, TIntermUnary *node)
{
if (mFragRotation)
if (mUsePreRotation)
{
return visitUnaryWithRotation(visit, node);
}
......@@ -102,36 +115,51 @@ bool Traverser::visitUnaryWithRotation(Visit visit, TIntermUnary *node)
//
// correctedDfdx(operand) = dFdy(operand) * mFlipXY.y
// correctedDfdy(operand) = dFdx(operand) * mFlipXY.x
//
// TODO(ianelliott): Look at the performance of this approach and potentially optimize it
// http://anglebug.com/4678
// Get a vec2 with the correct half of ANGLEUniforms.fragRotation
TIntermBinary *halfRotationMat = nullptr;
TIntermTyped *multiplierX;
TIntermTyped *multiplierY;
if (node->getOp() == EOpDFdx)
{
halfRotationMat =
new TIntermBinary(EOpIndexDirect, mFragRotation->deepCopy(), CreateIndexNode(0));
multiplierX = mRotationSpecConst->getMultiplierXForDFdx();
multiplierY = mRotationSpecConst->getMultiplierYForDFdx();
}
else
{
halfRotationMat =
new TIntermBinary(EOpIndexDirect, mFragRotation->deepCopy(), CreateIndexNode(1));
multiplierX = mRotationSpecConst->getMultiplierXForDFdy();
multiplierY = mRotationSpecConst->getMultiplierYForDFdy();
}
// Multiply halfRotationMat by ANGLEUniforms.flipXY and store in a temporary variable
TIntermBinary *rotatedFlipXY = new TIntermBinary(EOpMul, mFlipXY->deepCopy(), halfRotationMat);
const TType *vec2Type = StaticType::GetBasic<EbtFloat, 2>();
TIntermSymbol *tmpRotFlipXY = new TIntermSymbol(CreateTempVariable(mSymbolTable, vec2Type));
TIntermSequence *tmpDecl = new TIntermSequence;
tmpDecl->push_back(CreateTempInitDeclarationNode(&tmpRotFlipXY->variable(), rotatedFlipXY));
insertStatementsInParentBlock(*tmpDecl);
// Get the .x and .y swizzles to use as multipliers
TVector<int> swizzleOffsetX = {0};
TVector<int> swizzleOffsetY = {1};
TIntermSwizzle *multiplierX = new TIntermSwizzle(tmpRotFlipXY, swizzleOffsetX);
TIntermSwizzle *multiplierY = new TIntermSwizzle(tmpRotFlipXY->deepCopy(), swizzleOffsetY);
if (!multiplierX)
{
ASSERT(!multiplierY);
TIntermTyped *flipXY = mDriverUniforms->getFlipXYRef();
TIntermTyped *fragRotation = mDriverUniforms->getFragRotationMatrixRef();
// Get a vec2 with the correct half of ANGLEUniforms.fragRotation
TIntermBinary *halfRotationMat = nullptr;
if (node->getOp() == EOpDFdx)
{
halfRotationMat = new TIntermBinary(EOpIndexDirect, fragRotation, CreateIndexNode(0));
}
else
{
halfRotationMat = new TIntermBinary(EOpIndexDirect, fragRotation, CreateIndexNode(1));
}
// Multiply halfRotationMat by ANGLEUniforms.flipXY and store in a temporary variable
TIntermBinary *rotatedFlipXY = new TIntermBinary(EOpMul, flipXY, halfRotationMat);
const TType *vec2Type = StaticType::GetBasic<EbtFloat, 2>();
TIntermSymbol *tmpRotFlipXY = new TIntermSymbol(CreateTempVariable(mSymbolTable, vec2Type));
TIntermSequence *tmpDecl = new TIntermSequence;
tmpDecl->push_back(CreateTempInitDeclarationNode(&tmpRotFlipXY->variable(), rotatedFlipXY));
insertStatementsInParentBlock(*tmpDecl);
// Get the .x and .y swizzles to use as multipliers
TVector<int> swizzleOffsetX = {0};
TVector<int> swizzleOffsetY = {1};
multiplierX = new TIntermSwizzle(tmpRotFlipXY, swizzleOffsetX);
multiplierY = new TIntermSwizzle(tmpRotFlipXY->deepCopy(), swizzleOffsetY);
}
// Get the results of dFdx(operand) and dFdy(operand), and multiply them by the swizzles
TIntermTyped *operand = node->getOperand();
......@@ -166,8 +194,13 @@ bool Traverser::visitUnaryWithoutRotation(Visit visit, TIntermUnary *node)
size_t objectSize = node->getType().getObjectSize();
TOperator multiplyOp = (objectSize == 1) ? EOpMul : EOpVectorTimesScalar;
TIntermBinary *flipY =
new TIntermBinary(EOpIndexDirect, mFlipXY->deepCopy(), CreateIndexNode(1));
TIntermTyped *flipY = mRotationSpecConst->getFlipY();
if (!flipY)
{
TIntermTyped *flipXY = mDriverUniforms->getFlipXYRef();
flipY = new TIntermBinary(EOpIndexDirect, flipXY, CreateIndexNode(1));
}
// Correct dFdy()'s value:
// (dFdy() * mFlipXY.y)
TIntermBinary *correctedDfdy = new TIntermBinary(multiplyOp, newDfdy, flipY);
......@@ -177,21 +210,22 @@ bool Traverser::visitUnaryWithoutRotation(Visit visit, TIntermUnary *node)
return true;
}
} // anonymous namespace
bool RewriteDfdy(TCompiler *compiler,
ShCompileOptions compileOptions,
TIntermNode *root,
const TSymbolTable &symbolTable,
int shaderVersion,
TIntermBinary *flipXY,
TIntermTyped *fragRotation)
FlipRotateSpecConst *rotationSpecConst,
const DriverUniform *driverUniforms)
{
// dFdy is only valid in GLSL 3.0 and later.
if (shaderVersion < 300)
return true;
return Traverser::Apply(compiler, root, symbolTable, flipXY, fragRotation);
return Traverser::Apply(compiler, compileOptions, root, symbolTable, rotationSpecConst,
driverUniforms);
}
} // namespace sh
......@@ -14,23 +14,29 @@
#define COMPILER_TRANSLATOR_TREEOPS_FLIP_DFDY_H_
#include "common/angleutils.h"
#include "compiler/translator/Compiler.h"
namespace sh
{
class TCompiler;
class TIntermNode;
class TIntermSymbol;
class TIntermBinary;
class TIntermTyped;
class TSymbolTable;
class TVariable;
class FlipRotateSpecConst;
class DriverUniform;
// If fragRotation = nullptr, no rotation will be applied.
ANGLE_NO_DISCARD bool RewriteDfdy(TCompiler *compiler,
ShCompileOptions compileOptions,
TIntermNode *root,
const TSymbolTable &symbolTable,
int shaderVersion,
TIntermBinary *flipXY,
TIntermTyped *fragRotation);
FlipRotateSpecConst *rotationSpecConst,
const DriverUniform *driverUniforms);
} // 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.
//
// FlipRotationSpecConst.h: Add code to generate AST node for flip and rotation matrices and
// vectors.
//
#ifndef COMPILER_TRANSLATOR_TREEUTIL_FLIPROTATESPECCONST_H_
#define COMPILER_TRANSLATOR_TREEUTIL_FLIPROTATESPECCONST_H_
#include "common/angleutils.h"
#include "compiler/translator/SymbolTable.h"
class TIntermTyped;
class TIntermSymbol;
class TVariable;
namespace sh
{
class FlipRotateSpecConst
{
public:
FlipRotateSpecConst();
~FlipRotateSpecConst();
TIntermTyped *getMultiplierXForDFdx();
TIntermTyped *getMultiplierYForDFdx();
TIntermTyped *getMultiplierXForDFdy();
TIntermTyped *getMultiplierYForDFdy();
TIntermTyped *getPreRotationMatrix();
TIntermTyped *getFragRotationMatrix();
TIntermTyped *getFlipXY();
TIntermTyped *getNegFlipXY();
TIntermTyped *getFlipY();
TIntermTyped *getNegFlipY();
void generateSymbol(TSymbolTable *symbolTable);
void outputLayoutString(TInfoSinkBase &sink) const;
private:
TIntermSymbol *mSpecConstSymbol;
// True if mSpecConstSymbol has been used
bool mReferenced;
};
} // namespace sh
#endif // COMPILER_TRANSLATOR_TREEUTIL_FLIPROTATESPECCONST_H_
......@@ -3069,13 +3069,23 @@ void ContextVk::updateSurfaceRotationDrawFramebuffer(const gl::State &glState)
mCurrentRotationDrawFramebuffer =
DetermineSurfaceRotation(drawFramebuffer, mCurrentWindowSurface);
if (mCurrentRotationDrawFramebuffer != mGraphicsPipelineDesc->getSurfaceRotation())
// DetermineSurfaceRotation() does not encode yflip information. Shader code uses
// SurfaceRotation specialization constant to determine yflip as well. We add yflip information
// to the SurfaceRotation here so the shader does yflip properly.
SurfaceRotation rotationAndFlip = mCurrentRotationDrawFramebuffer;
if (isViewportFlipEnabledForDrawFBO())
{
ASSERT(ToUnderlying(rotationAndFlip) < ToUnderlying(SurfaceRotation::FlippedIdentity));
rotationAndFlip = static_cast<SurfaceRotation>(
ToUnderlying(SurfaceRotation::FlippedIdentity) + ToUnderlying(rotationAndFlip));
}
if (rotationAndFlip != mGraphicsPipelineDesc->getSurfaceRotation())
{
// surface rotation are specialization constants, which affects program compilation. When
// rotation changes, we need to update GraphicsPipelineDesc so that the correct pipeline
// program object will be retrieved.
mGraphicsPipelineDesc->updateSurfaceRotation(&mGraphicsPipelineTransition,
mCurrentRotationDrawFramebuffer);
mGraphicsPipelineDesc->updateSurfaceRotation(&mGraphicsPipelineTransition, rotationAndFlip);
}
}
......
......@@ -72,6 +72,9 @@ std::shared_ptr<WaitableCompileEvent> ShaderVk::compile(const gl::Context *conte
// context state does not allow it
compileOptions |= SH_EARLY_FRAGMENT_TESTS_OPTIMIZATION;
// Let compiler use specialized constant for pre-rotation.
compileOptions |= SH_USE_ROTATION_SPECIALIZATION_CONSTANT;
if (contextVk->getFeatures().enablePreRotateSurfaces.enabled ||
contextVk->getFeatures().emulatedPrerotation90.enabled ||
contextVk->getFeatures().emulatedPrerotation180.enabled ||
......
......@@ -359,6 +359,12 @@
4344 VULKAN ANDROID : dEQP-GLES2.functional.fragment_ops.random.62 = FAIL
4344 VULKAN ANDROID : dEQP-GLES2.functional.fragment_ops.random.78 = FAIL
// Failing on the Pixel2.
172932466 VULKAN PIXEL2ORXL : dEQP-GLES2.functional.shaders.indexing.tmp_array.float_const_write_dynamic_read_vertex = FAIL
172932466 VULKAN PIXEL2ORXL : dEQP-GLES2.functional.shaders.indexing.tmp_array.vec2_const_write_dynamic_read_vertex = FAIL
172932466 VULKAN PIXEL2ORXL : dEQP-GLES2.functional.shaders.indexing.tmp_array.vec3_const_write_dynamic_read_vertex = FAIL
172932466 VULKAN PIXEL2ORXL : dEQP-GLES2.functional.shaders.indexing.tmp_array.vec4_const_write_dynamic_read_vertex = FAIL
// These tests also fail on AMD windows driver as it is not allowed to use emulation due to errors.
3243 VULKAN WIN AMD : dEQP-GLES2.functional.shaders.texture_functions.vertex.texturecubelod = FAIL
3243 VULKAN WIN AMD : dEQP-GLES2.functional.texture.mipmap.cube.basic.linear_nearest = FAIL
......
......@@ -292,3 +292,7 @@
// Vulkan Android failures with these formats
5277 VULKAN ANDROID : dEQP-GLES31.functional.copy_image.non_compressed.viewclass_32_bits.rgba8_snorm_rgb10_a2* = FAIL
5277 VULKAN ANDROID : dEQP-GLES31.functional.copy_image.non_compressed.viewclass_32_bits.rgba8_snorm_rgb9_e5* = FAIL
// Skip on Pixel2 to reduce the bots test time so that it won't timeout
172936025 VULKAN PIXEL2ORXL : dEQP-GLES31.functional.copy_image.mixed.viewclass_128_bits_mixed.*.* = SKIP
172936025 VULKAN PIXEL2ORXL : dEQP-GLES31.functional.copy_image.compressed.viewclass_astc*.*.* = SKIP
......@@ -642,6 +642,13 @@
// 161540999 PIXEL2ORXL VULKAN : dEQP-GLES3.functional.fragment_ops.random.35 = FAIL
4344 VULKAN ANDROID : dEQP-GLES3.functional.fragment_ops.random.73 = FAIL
// Failing on the Pixel2.
172932466 VULKAN PIXEL2ORXL : dEQP-GLES3.functional.shaders.large_constant_arrays.indexing.float_128_vertex = FAIL
172932466 VULKAN PIXEL2ORXL : dEQP-GLES3.functional.shaders.large_constant_arrays.indexing.float_64_vertex = FAIL
172932466 VULKAN PIXEL2ORXL : dEQP-GLES3.functional.shaders.large_constant_arrays.indexing.vec4_128_vertex = FAIL
172932466 VULKAN PIXEL2ORXL : dEQP-GLES3.functional.shaders.large_constant_arrays.indexing.vec4_16_vertex = FAIL
172932466 VULKAN PIXEL2ORXL : dEQP-GLES3.functional.shaders.large_constant_arrays.indexing.vec4_32_vertex = FAIL
172932466 VULKAN PIXEL2ORXL : dEQP-GLES3.functional.shaders.large_constant_arrays.indexing.vec4_64_vertex = FAIL
// Fails only with SwiftShader:
......
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