Hash :
719165c8
Author :
Date :
2023-08-04T12:13:37
Remove "const UniformTypeInfo *typeInfo" from struct LinkedUniform This is a cached pointer to the const kInfoTable. There isn't much of performance benefit to cache here compare to directly retrieve from the table. This cached pointer is removed in this CL, which means we do not need to update the pointer in the ProgramExecutable::load(). This and a few earlier CLs that attempt to do memcpy for entire mUniforms reduced average frame time of blade_and_soul_revolution app trace 3%, from 4.3359 ms to 4.2066ms on pixel 7 pro. Bug: b/275102061 Change-Id: I6fd34d665234e3a5cc85344924049bf5b13aaa80 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4753933 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Charlie Lao <cclao@google.com> Reviewed-by: Yuxin Hu <yuxinhu@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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
//
// 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.
//
#ifndef LIBANGLE_UNIFORM_H_
#define LIBANGLE_UNIFORM_H_
#include <string>
#include <vector>
#include "angle_gl.h"
#include "common/MemoryBuffer.h"
#include "common/debug.h"
#include "common/utilities.h"
#include "compiler/translator/blocklayout.h"
#include "libANGLE/angletypes.h"
namespace gl
{
class BinaryInputStream;
class BinaryOutputStream;
struct UniformTypeInfo;
struct UsedUniform;
// Note: keep this struct memcpy-able: i.e, a simple struct with basic types only and no virtual
// functions. LinkedUniform relies on this so that it can use memcpy to initialize uniform for
// performance.
struct ActiveVariable
{
ActiveVariable();
ActiveVariable(const ActiveVariable &rhs);
~ActiveVariable();
ActiveVariable &operator=(const ActiveVariable &rhs);
ShaderType getFirstActiveShaderType() const
{
return static_cast<ShaderType>(ScanForward(mActiveUseBits.bits()));
}
void setActive(ShaderType shaderType, bool used, uint32_t id);
void unionReferencesWith(const ActiveVariable &other);
bool isActive(ShaderType shaderType) const
{
ASSERT(shaderType != ShaderType::InvalidEnum);
return mActiveUseBits[shaderType];
}
const ShaderMap<uint32_t> &getIds() const { return mIds; }
uint32_t getId(ShaderType shaderType) const { return mIds[shaderType]; }
ShaderBitSet activeShaders() const { return mActiveUseBits; }
GLuint activeShaderCount() const { return static_cast<GLuint>(mActiveUseBits.count()); }
private:
ShaderBitSet mActiveUseBits;
// The id of a linked variable in each shader stage. This id originates from
// sh::ShaderVariable::id or sh::InterfaceBlock::id
ShaderMap<uint32_t> mIds;
};
// Important: This struct must have basic data types only, so that we can initialize with memcpy. Do
// not put any std::vector or objects with virtual functions in it.
// Helper struct representing a single shader uniform. Most of this structure's data member and
// access functions mirrors ShaderVariable; See ShaderVars.h for more info.
struct LinkedUniform
{
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);
LinkedUniform(const LinkedUniform &other);
LinkedUniform(const UsedUniform &usedUniform);
~LinkedUniform();
bool isSampler() const { return GetUniformTypeInfo(type).isSampler; }
bool isImage() const { return GetUniformTypeInfo(type).isImageType; }
bool isAtomicCounter() const { return IsAtomicCounterType(type); }
bool isInDefaultBlock() const { return bufferIndex == -1; }
size_t getElementSize() const { return GetUniformTypeInfo(type).externalSize; }
GLint getElementComponents() const { return GetUniformTypeInfo(type).componentCount; }
bool isTexelFetchStaticUse() const { return flagBits.texelFetchStaticUse; }
bool isFragmentInOut() const { return flagBits.isFragmentInOut; }
bool isArray() const { return flagBits.isArray; }
unsigned int getBasicTypeElementCount() const
{
ASSERT(flagBits.isArray || arraySize == 1u);
return arraySize;
}
GLenum getType() const { return type; }
unsigned int getOuterArrayOffset() const { return outerArrayOffset; }
unsigned int getOuterArraySizeProduct() const { return outerArraySizeProduct; }
int getBinding() const { return binding; }
int getOffset() const { return offset; }
const sh::BlockMemberInfo &getBlockInfo() const { return blockInfo; }
int getBufferIndex() const { return bufferIndex; }
int getLocation() const { return location; }
GLenum getImageUnitFormat() const { return imageUnitFormat; }
int parentArrayIndex() const
{
return flattenedOffsetInParentArrays != -1 ? flattenedOffsetInParentArrays : 0;
}
ShaderType getFirstActiveShaderType() const
{
return activeVariable.getFirstActiveShaderType();
}
void setActive(ShaderType shaderType, bool used, uint32_t _id)
{
activeVariable.setActive(shaderType, used, _id);
}
bool isActive(ShaderType shaderType) const { return activeVariable.isActive(shaderType); }
const ShaderMap<uint32_t> &getIds() const { return activeVariable.getIds(); }
uint32_t getId(ShaderType shaderType) const { return activeVariable.getId(shaderType); }
ShaderBitSet activeShaders() const { return activeVariable.activeShaders(); }
GLuint activeShaderCount() const { return activeVariable.activeShaderCount(); }
sh::BlockMemberInfo blockInfo;
ActiveVariable activeVariable;
GLenum type;
GLenum precision;
GLenum imageUnitFormat;
int location;
int binding;
int offset;
uint32_t id;
int flattenedOffsetInParentArrays;
int bufferIndex;
unsigned int outerArraySizeProduct;
unsigned int outerArrayOffset;
unsigned int arraySize;
union
{
struct
{
uint32_t isFragmentInOut : 1;
uint32_t texelFetchStaticUse : 1;
uint32_t isArray : 1;
uint32_t padding : 29;
} flagBits;
uint32_t flagBitsAsUInt;
};
};
struct BufferVariable : public sh::ShaderVariable
{
BufferVariable();
BufferVariable(GLenum type,
GLenum precision,
const std::string &name,
const std::vector<unsigned int> &arraySizes,
const int bufferIndex,
const sh::BlockMemberInfo &blockInfo);
~BufferVariable();
void setActive(ShaderType shaderType, bool used, uint32_t _id)
{
activeVariable.setActive(shaderType, used, _id);
}
bool isActive(ShaderType shaderType) const { return activeVariable.isActive(shaderType); }
uint32_t getId(ShaderType shaderType) const { return activeVariable.getId(shaderType); }
ShaderBitSet activeShaders() const { return activeVariable.activeShaders(); }
ActiveVariable activeVariable;
int bufferIndex;
sh::BlockMemberInfo blockInfo;
int topLevelArraySize;
};
// Parent struct for atomic counter, uniform block, and shader storage block buffer, which all
// contain a group of shader variables, and have a GL buffer backed.
struct ShaderVariableBuffer
{
ShaderVariableBuffer();
ShaderVariableBuffer(const ShaderVariableBuffer &other);
~ShaderVariableBuffer();
ShaderType getFirstActiveShaderType() const
{
return activeVariable.getFirstActiveShaderType();
}
void setActive(ShaderType shaderType, bool used, uint32_t _id)
{
activeVariable.setActive(shaderType, used, _id);
}
void unionReferencesWith(const ActiveVariable &other)
{
activeVariable.unionReferencesWith(other);
}
bool isActive(ShaderType shaderType) const { return activeVariable.isActive(shaderType); }
const ShaderMap<uint32_t> &getIds() const { return activeVariable.getIds(); }
uint32_t getId(ShaderType shaderType) const { return activeVariable.getId(shaderType); }
ShaderBitSet activeShaders() const { return activeVariable.activeShaders(); }
int numActiveVariables() const;
ActiveVariable activeVariable;
int binding;
unsigned int dataSize;
std::vector<unsigned int> memberIndexes;
};
using AtomicCounterBuffer = ShaderVariableBuffer;
// Helper struct representing a single shader interface block
struct InterfaceBlock : public ShaderVariableBuffer
{
InterfaceBlock();
InterfaceBlock(const std::string &nameIn,
const std::string &mappedNameIn,
bool isArrayIn,
bool isReadOnlyIn,
unsigned int arrayElementIn,
unsigned int firstFieldArraySizeIn,
int bindingIn);
InterfaceBlock(const InterfaceBlock &other);
std::string nameWithArrayIndex() const;
std::string mappedNameWithArrayIndex() const;
std::string name;
std::string mappedName;
bool isArray;
// Only valid for SSBOs, specifies whether it has the readonly qualifier.
bool isReadOnly;
unsigned int arrayElement;
unsigned int firstFieldArraySize;
};
} // namespace gl
#endif // LIBANGLE_UNIFORM_H_