Hash :
23f213d1
Author :
Date :
2022-05-26T23:43:44
Vulkan: Make drawable size uniform As a specialization constant, it's impossible to predict the value the drawable size may take, which in turn makes it impossible to warm up the Vulkan pipeline cache at link time. Bug: angleproject:7366 Change-Id: Ia3d1860a4fcb8e3078fdcb8d02a2e0cd173ea028 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3671976 Reviewed-by: Charlie Lao <cclao@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
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
//
// 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.
//
// SpecializationConst.cpp: Add code to generate AST node for various specialization constants.
//
#include "compiler/translator/tree_util/SpecializationConstant.h"
#include "common/PackedEnums.h"
#include "common/angleutils.h"
#include "compiler/translator/StaticType.h"
#include "compiler/translator/SymbolTable.h"
#include "compiler/translator/tree_util/IntermNode_util.h"
namespace sh
{
namespace
{
// Specialization constant names
constexpr ImmutableString kLineRasterEmulationSpecConstVarName =
ImmutableString("ANGLELineRasterEmulation");
constexpr ImmutableString kSurfaceRotationSpecConstVarName =
ImmutableString("ANGLESurfaceRotation");
constexpr ImmutableString kDitherSpecConstVarName = ImmutableString("ANGLEDither");
const TType *MakeSpecConst(const TType &type, vk::SpecializationConstantId id)
{
// Create a new type with the EvqSpecConst qualifier
TType *specConstType = new TType(type);
specConstType->setQualifier(EvqSpecConst);
// Set the constant_id of the spec const
TLayoutQualifier layoutQualifier = TLayoutQualifier::Create();
layoutQualifier.location = static_cast<int>(id);
specConstType->setLayoutQualifier(layoutQualifier);
return specConstType;
}
} // anonymous namespace
SpecConst::SpecConst(TSymbolTable *symbolTable, ShCompileOptions compileOptions, GLenum shaderType)
: mSymbolTable(symbolTable),
mCompileOptions(compileOptions),
mLineRasterEmulationVar(nullptr),
mSurfaceRotationVar(nullptr),
mDitherVar(nullptr)
{
if (shaderType == GL_FRAGMENT_SHADER || shaderType == GL_COMPUTE_SHADER)
{
return;
}
// Mark SpecConstUsage::Rotation unconditionally. gl_Position is always rotated.
if ((mCompileOptions & SH_USE_SPECIALIZATION_CONSTANT) != 0)
{
mUsageBits.set(vk::SpecConstUsage::Rotation);
}
}
SpecConst::~SpecConst() {}
void SpecConst::declareSpecConsts(TIntermBlock *root)
{
// Add specialization constant declarations. The default value of the specialization
// constant is irrelevant, as it will be set when creating the pipeline.
// Only emit specialized const declaration if it has been referenced.
if (mLineRasterEmulationVar != nullptr)
{
TIntermDeclaration *decl = new TIntermDeclaration();
decl->appendDeclarator(
new TIntermBinary(EOpInitialize, getLineRasterEmulation(), CreateBoolNode(false)));
root->insertStatement(0, decl);
}
if (mSurfaceRotationVar != nullptr)
{
TIntermDeclaration *decl = new TIntermDeclaration();
decl->appendDeclarator(
new TIntermBinary(EOpInitialize, getRotation(), CreateBoolNode(false)));
root->insertStatement(0, decl);
}
if (mDitherVar != nullptr)
{
TIntermDeclaration *decl = new TIntermDeclaration();
decl->appendDeclarator(new TIntermBinary(EOpInitialize, getDither(), CreateUIntNode(0)));
root->insertStatement(0, decl);
}
}
TIntermSymbol *SpecConst::getLineRasterEmulation()
{
if ((mCompileOptions & SH_ADD_BRESENHAM_LINE_RASTER_EMULATION) == 0)
{
return nullptr;
}
if (mLineRasterEmulationVar == nullptr)
{
const TType *type = MakeSpecConst(*StaticType::GetBasic<EbtBool, EbpUndefined>(),
vk::SpecializationConstantId::LineRasterEmulation);
mLineRasterEmulationVar = new TVariable(mSymbolTable, kLineRasterEmulationSpecConstVarName,
type, SymbolType::AngleInternal);
mUsageBits.set(vk::SpecConstUsage::LineRasterEmulation);
}
return new TIntermSymbol(mLineRasterEmulationVar);
}
TIntermSymbol *SpecConst::getRotation()
{
if (mSurfaceRotationVar == nullptr)
{
const TType *type = MakeSpecConst(*StaticType::GetBasic<EbtBool, EbpUndefined>(),
vk::SpecializationConstantId::SurfaceRotation);
mSurfaceRotationVar = new TVariable(mSymbolTable, kSurfaceRotationSpecConstVarName, type,
SymbolType::AngleInternal);
}
return new TIntermSymbol(mSurfaceRotationVar);
}
TIntermTyped *SpecConst::getSwapXY()
{
if ((mCompileOptions & SH_USE_SPECIALIZATION_CONSTANT) == 0)
{
return nullptr;
}
mUsageBits.set(vk::SpecConstUsage::Rotation);
return getRotation();
}
TIntermTyped *SpecConst::getDither()
{
if (mDitherVar == nullptr)
{
const TType *type = MakeSpecConst(*StaticType::GetBasic<EbtUInt, EbpHigh>(),
vk::SpecializationConstantId::Dither);
mDitherVar =
new TVariable(mSymbolTable, kDitherSpecConstVarName, type, SymbolType::AngleInternal);
mUsageBits.set(vk::SpecConstUsage::Dither);
}
return new TIntermSymbol(mDitherVar);
}
} // namespace sh