Hash :
f355e2b3
Author :
Date :
2025-04-15T18:58:25
Vulkan: Remove preferDriverUniformOverSpecConst This was practically true for every vendor on Android (where rotation matters). For Qualcomm, it was also true due to a bug in version checking and didn't seem to be causing any concerns. Where pre-rotation is supported, it is better to enable this feature to avoid excessive pipeline creation. This change removes the feature and makes sure ANGLE always uses uniforms for rotation instead of spec consts. While technically this may have an adverse effect on platforms that never need pre-rotation, the ability is retained for all vendors since pre-rotation is finding its way into more platforms and would likely eventually be needed everywhere anyway. Bug: angleproject:42265878 Bug: angleproject:42262166 Change-Id: I4b64c04da46db08cfdd44b60789b66d93d8e8b17 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6459025 Reviewed-by: Amirali Abdolrashidi <abdolrashidi@google.com> Reviewed-by: mohan maiya <m.maiya@samsung.com> Auto-Submit: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Cody Northrop <cnorthrop@google.com> Reviewed-by: Cody Northrop <cnorthrop@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
//
// Copyright 2019 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.
//
// Implementation of dFdy viewport transformation.
// See header for more info.
#include "compiler/translator/tree_ops/RewriteDfdy.h"
#include "common/angleutils.h"
#include "compiler/translator/SymbolTable.h"
#include "compiler/translator/tree_util/DriverUniform.h"
#include "compiler/translator/tree_util/IntermNode_util.h"
#include "compiler/translator/tree_util/IntermTraverse.h"
#include "compiler/translator/tree_util/SpecializationConstant.h"
namespace sh
{
namespace
{
class Traverser : public TIntermTraverser
{
public:
Traverser(TSymbolTable *symbolTable, const DriverUniform *driverUniforms);
private:
bool visitAggregate(Visit visit, TIntermAggregate *node) override;
const DriverUniform *mDriverUniforms = nullptr;
};
Traverser::Traverser(TSymbolTable *symbolTable,
const DriverUniform *driverUniforms)
: TIntermTraverser(true, false, false, symbolTable),
mDriverUniforms(driverUniforms)
{}
bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
{
// Decide if the node represents a call to dFdx() or dFdy()
if (node->getOp() != EOpDFdx && node->getOp() != EOpDFdy)
{
return true;
}
const bool isDFdx = node->getOp() == EOpDFdx;
// Two transformations are done on dFdx and dFdy:
//
// - If pre-rotation is applied, dFdx and dFdy may need to swap their axis based on the degree
// of rotation. dFdx becomes dFdy if rotation is 90 or 270 degrees. Similarly, dFdy becomes
// dFdx.
// - The result is potentially negated. This could be due to viewport y-flip or pre-rotation.
//
// Accordingly, there are two variables controlling the above transformations:
//
// - Rotation: A vec2 that is either (0, 1) or (1, 0). dFdx and dFdy are replaced with:
//
// dFdx * Rotation.x + dFdy * Rotation.y
//
// - Scale: A vec2 with -1 or 1 for either x or y components. The previous result is multiplied
// by this.
//
// Together, the above operations account for the combinations of 4 possible rotations and
// y-flip.
// Get the results of dFdx(operand) and dFdy(operand), and multiply them by the swizzles
TIntermTyped *operand = node->getChildNode(0)->getAsTyped();
TIntermTyped *dFdx = CreateBuiltInUnaryFunctionCallNode("dFdx", operand, *mSymbolTable, 300);
TIntermTyped *dFdy =
CreateBuiltInUnaryFunctionCallNode("dFdy", operand->deepCopy(), *mSymbolTable, 300);
// Get rotation multiplier
TIntermTyped *swapXY = mDriverUniforms->getSwapXY();
TIntermTyped *swapXMultiplier = MakeSwapXMultiplier(swapXY);
TIntermTyped *swapYMultiplier = MakeSwapYMultiplier(swapXY->deepCopy());
// Get flip multiplier
TIntermTyped *flipXY = mDriverUniforms->getFlipXY(mSymbolTable, DriverUniformFlip::Fragment);
// Multiply the flip and rotation multipliers
TIntermTyped *xMultiplier =
new TIntermBinary(EOpMul, isDFdx ? swapXMultiplier : swapYMultiplier,
(new TIntermSwizzle(flipXY->deepCopy(), {0}))->fold(nullptr));
TIntermTyped *yMultiplier =
new TIntermBinary(EOpMul, isDFdx ? swapYMultiplier : swapXMultiplier,
(new TIntermSwizzle(flipXY->deepCopy(), {1}))->fold(nullptr));
const TOperator mulOp = dFdx->getType().isVector() ? EOpVectorTimesScalar : EOpMul;
TIntermTyped *rotatedFlippedDfdx = new TIntermBinary(mulOp, dFdx, xMultiplier);
TIntermTyped *rotatedFlippedDfdy = new TIntermBinary(mulOp, dFdy, yMultiplier);
// Sum them together into the result
TIntermBinary *rotatedFlippedResult =
new TIntermBinary(EOpAdd, rotatedFlippedDfdx, rotatedFlippedDfdy);
// Replace the old dFdx() or dFdy() node with the new node that contains the corrected value
//
// Note the following bugs (anglebug.com/42265816):
//
// - Side effects of operand are duplicated with the above
// - If the direct child of this node is itself dFdx/y, its queueReplacement will not be
// effective as the parent is also replaced.
queueReplacement(rotatedFlippedResult, OriginalNode::IS_DROPPED);
return true;
}
} // anonymous namespace
bool RewriteDfdy(TCompiler *compiler,
TIntermBlock *root,
TSymbolTable *symbolTable,
int shaderVersion,
const DriverUniform *driverUniforms)
{
Traverser traverser(symbolTable, driverUniforms);
root->traverse(&traverser);
return traverser.updateTree(compiler, root);
}
} // namespace sh