Hash :
4109a90e
Author :
Date :
2024-04-16T17:31:11
LinkedUniform: avoid frequent GLenum -> index conversion Certain functions such as getElementComponents() are frequently called in driver_overhead benchmark, causing repeated GLenum -> index conversion of the uniform type which shows up in profiling (driver_overhead_2 trace) Change LinkedUniform.pod.type to LinkedUniform.pod.typeIndex storing the UniformTypeInfo index with conversion helpers. Bug: b/335295728 Change-Id: Iae5cd58f4e2703589d23b8e52991fc4b97c5fb08 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5458741 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Roman Lavrov <romanl@google.com> Reviewed-by: Charlie Lao <cclao@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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
//
// Copyright 2010 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.
//
#include "libANGLE/Uniform.h"
#include "common/BinaryStream.h"
#include "libANGLE/ProgramLinkedResources.h"
#include <cstring>
namespace gl
{
LinkedUniform::LinkedUniform(GLenum typeIn,
GLenum precisionIn,
const std::vector<unsigned int> &arraySizesIn,
const int bindingIn,
const int offsetIn,
const int locationIn,
const int bufferIndexIn,
const sh::BlockMemberInfo &blockInfoIn)
{
// arrays are always flattened, which means at most 1D array
ASSERT(arraySizesIn.size() <= 1);
memset(this, 0, sizeof(*this));
pod.typeIndex = GetUniformTypeIndex(typeIn);
SetBitField(pod.precision, precisionIn);
pod.location = locationIn;
SetBitField(pod.binding, bindingIn);
SetBitField(pod.offset, offsetIn);
SetBitField(pod.bufferIndex, bufferIndexIn);
pod.outerArraySizeProduct = 1;
SetBitField(pod.arraySize, arraySizesIn.empty() ? 1u : arraySizesIn[0]);
SetBitField(pod.flagBits.isArray, !arraySizesIn.empty());
if (!(blockInfoIn == sh::kDefaultBlockMemberInfo))
{
pod.flagBits.isBlock = 1;
pod.flagBits.blockIsRowMajorMatrix = blockInfoIn.isRowMajorMatrix;
SetBitField(pod.blockOffset, blockInfoIn.offset);
SetBitField(pod.blockArrayStride, blockInfoIn.arrayStride);
SetBitField(pod.blockMatrixStride, blockInfoIn.matrixStride);
}
}
LinkedUniform::LinkedUniform(const UsedUniform &usedUniform)
{
ASSERT(!usedUniform.isArrayOfArrays());
ASSERT(!usedUniform.isStruct());
ASSERT(usedUniform.active);
ASSERT(usedUniform.blockInfo == sh::kDefaultBlockMemberInfo);
// Note: Ensure every data member is initialized.
pod.flagBitsAsUByte = 0;
pod.typeIndex = GetUniformTypeIndex(usedUniform.type);
SetBitField(pod.precision, usedUniform.precision);
SetBitField(pod.imageUnitFormat, usedUniform.imageUnitFormat);
pod.location = usedUniform.location;
pod.blockOffset = 0;
pod.blockArrayStride = 0;
pod.blockMatrixStride = 0;
SetBitField(pod.binding, usedUniform.binding);
SetBitField(pod.offset, usedUniform.offset);
SetBitField(pod.bufferIndex, usedUniform.bufferIndex);
SetBitField(pod.parentArrayIndex, usedUniform.parentArrayIndex());
SetBitField(pod.outerArraySizeProduct, ArraySizeProduct(usedUniform.outerArraySizes));
SetBitField(pod.outerArrayOffset, usedUniform.outerArrayOffset);
SetBitField(pod.arraySize, usedUniform.isArray() ? usedUniform.getArraySizeProduct() : 1u);
SetBitField(pod.flagBits.isArray, usedUniform.isArray());
pod.id = usedUniform.id;
pod.activeUseBits = usedUniform.activeVariable.activeShaders();
pod.ids = usedUniform.activeVariable.getIds();
SetBitField(pod.flagBits.isFragmentInOut, usedUniform.isFragmentInOut);
SetBitField(pod.flagBits.texelFetchStaticUse, usedUniform.texelFetchStaticUse);
ASSERT(!usedUniform.isArray() || pod.arraySize == usedUniform.getArraySizeProduct());
}
BufferVariable::BufferVariable()
{
memset(&pod, 0, sizeof(pod));
pod.bufferIndex = -1;
pod.blockInfo = sh::kDefaultBlockMemberInfo;
pod.topLevelArraySize = -1;
}
BufferVariable::BufferVariable(GLenum type,
GLenum precision,
const std::string &name,
const std::vector<unsigned int> &arraySizes,
const int bufferIndex,
int topLevelArraySize,
const sh::BlockMemberInfo &blockInfo)
: name(name)
{
memset(&pod, 0, sizeof(pod));
SetBitField(pod.type, type);
SetBitField(pod.precision, precision);
SetBitField(pod.bufferIndex, bufferIndex);
pod.blockInfo = blockInfo;
SetBitField(pod.topLevelArraySize, topLevelArraySize);
pod.isArray = !arraySizes.empty();
SetBitField(pod.basicTypeElementCount, arraySizes.empty() ? 1u : arraySizes.back());
}
AtomicCounterBuffer::AtomicCounterBuffer()
{
memset(&pod, 0, sizeof(pod));
}
void AtomicCounterBuffer::unionReferencesWith(const LinkedUniform &other)
{
pod.activeUseBits |= other.pod.activeUseBits;
for (const ShaderType shaderType : AllShaderTypes())
{
ASSERT(pod.ids[shaderType] == 0 || other.getId(shaderType) == 0 ||
pod.ids[shaderType] == other.getId(shaderType));
if (pod.ids[shaderType] == 0)
{
pod.ids[shaderType] = other.getId(shaderType);
}
}
}
InterfaceBlock::InterfaceBlock()
{
memset(&pod, 0, sizeof(pod));
}
InterfaceBlock::InterfaceBlock(const std::string &name,
const std::string &mappedName,
bool isArray,
bool isReadOnly,
unsigned int arrayElementIn,
unsigned int firstFieldArraySizeIn,
int binding)
: name(name), mappedName(mappedName)
{
memset(&pod, 0, sizeof(pod));
SetBitField(pod.isArray, isArray);
SetBitField(pod.isReadOnly, isReadOnly);
SetBitField(pod.inShaderBinding, binding);
pod.arrayElement = arrayElementIn;
pod.firstFieldArraySize = firstFieldArraySizeIn;
}
std::string InterfaceBlock::nameWithArrayIndex() const
{
std::stringstream fullNameStr;
fullNameStr << name;
if (pod.isArray)
{
fullNameStr << "[" << pod.arrayElement << "]";
}
return fullNameStr.str();
}
std::string InterfaceBlock::mappedNameWithArrayIndex() const
{
std::stringstream fullNameStr;
fullNameStr << mappedName;
if (pod.isArray)
{
fullNameStr << "[" << pod.arrayElement << "]";
}
return fullNameStr.str();
}
} // namespace gl