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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
//
// 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.
//
// Implementation of InterpolateAtOffset viewport transformation.
// See header for more info.
#include "compiler/translator/tree_ops/spirv/RewriteInterpolateAtOffset.h"
#include "common/angleutils.h"
#include "compiler/translator/StaticType.h"
#include "compiler/translator/SymbolTable.h"
#include "compiler/translator/spirv/TranslatorSPIRV.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);
bool update(TCompiler *compiler, TIntermBlock *root);
private:
bool visitAggregate(Visit visit, TIntermAggregate *node) override;
const TFunction *getRotateFunc();
const DriverUniform *mDriverUniforms = nullptr;
TIntermFunctionDefinition *mRotateFunc = nullptr;
};
Traverser::Traverser(TSymbolTable *symbolTable,
const DriverUniform *driverUniforms)
: TIntermTraverser(true, false, false, symbolTable),
mDriverUniforms(driverUniforms)
{}
bool Traverser::update(TCompiler *compiler, TIntermBlock *root)
{
if (mRotateFunc != nullptr)
{
const size_t firstFunctionIndex = FindFirstFunctionDefinitionIndex(root);
root->insertStatement(firstFunctionIndex, mRotateFunc);
}
return updateTree(compiler, root);
}
bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
{
// Decide if the node represents the call of texelFetchOffset.
if (!BuiltInGroup::IsBuiltIn(node->getOp()))
{
return true;
}
ASSERT(node->getFunction()->symbolType() == SymbolType::BuiltIn);
if (node->getFunction()->name() != "interpolateAtOffset")
{
return true;
}
const TIntermSequence *sequence = node->getSequence();
ASSERT(sequence->size() == 2u);
// offset
TIntermTyped *offsetNode = sequence->at(1)->getAsTyped();
ASSERT(offsetNode->getType().getBasicType() == EbtFloat &&
offsetNode->getType().getNominalSize() == 2);
// Rotate the offset as necessary.
const TFunction *rotateFunc = getRotateFunc();
TIntermSequence args = {
offsetNode,
};
TIntermTyped *correctedOffset = TIntermAggregate::CreateFunctionCall(*rotateFunc, &args);
correctedOffset->setLine(offsetNode->getLine());
// Replace the offset by the rotated one.
queueReplacementWithParent(node, offsetNode, correctedOffset, OriginalNode::IS_DROPPED);
return true;
}
const TFunction *Traverser::getRotateFunc()
{
if (mRotateFunc != nullptr)
{
return mRotateFunc->getFunction();
}
// The function prototype is vec2 ANGLERotateInterpolateOffset(vec2 offset)
const TType *vec2Type = StaticType::GetBasic<EbtFloat, EbpMedium, 2>();
TType *offsetType = new TType(*vec2Type);
offsetType->setQualifier(EvqParamIn);
TVariable *offsetParam = new TVariable(mSymbolTable, ImmutableString("offset"), offsetType,
SymbolType::AngleInternal);
TFunction *function =
new TFunction(mSymbolTable, ImmutableString("ANGLERotateInterpolateOffset"),
SymbolType::AngleInternal, vec2Type, true);
function->addParameter(offsetParam);
// The function body is as such:
//
// return (swap ? offset.yx : offset) * flip;
TIntermTyped *swapXY = mDriverUniforms->getSwapXY();
TIntermTyped *flipXY = mDriverUniforms->getFlipXY(mSymbolTable, DriverUniformFlip::Fragment);
TIntermSwizzle *offsetYX = new TIntermSwizzle(new TIntermSymbol(offsetParam), {1, 0});
TIntermTyped *swapped = new TIntermTernary(swapXY, offsetYX, new TIntermSymbol(offsetParam));
TIntermTyped *flipped = new TIntermBinary(EOpMul, swapped, flipXY);
TIntermBranch *returnStatement = new TIntermBranch(EOpReturn, flipped);
TIntermBlock *body = new TIntermBlock;
body->appendStatement(returnStatement);
mRotateFunc = new TIntermFunctionDefinition(new TIntermFunctionPrototype(function), body);
return function;
}
} // anonymous namespace
bool RewriteInterpolateAtOffset(TCompiler *compiler,
TIntermBlock *root,
TSymbolTable *symbolTable,
int shaderVersion,
const DriverUniform *driverUniforms)
{
// interpolateAtOffset is only valid in GLSL 3.0 and later.
if (shaderVersion < 300)
{
return true;
}
Traverser traverser(symbolTable, driverUniforms);
root->traverse(&traverser);
return traverser.update(compiler, root);
}
} // namespace sh