Hash :
8fcd4a50
Author :
Date :
2023-09-19T14:08:14
Cleanup POD struct usage to make them more consistent In recent months, I have made many CLs to wrap various data structures into a trivially copy-able struct. Some of them uses different terminology. This CL replaces all of these to use a consistent name "pod" in the struct, and "mPod" in a class. This CL also turns ActiveVariable methods into macros to remove the code duplication. This CL also moves ProgramInput/ProgramOutput struct implementations from Program.cpp to ProgramExecutable.cpp Bug: b/275102061 Change-Id: Ia2a4210a9ea633f3d323bebe674ee74f8b90b363 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4877335 Commit-Queue: Charlie Lao <cclao@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Roman Lavrov <romanl@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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
//
// 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;
struct LinkedUniform;
#define ACTIVE_VARIABLE_COMMON_INTERFACES \
void setActive(ShaderType shaderType, bool used, uint32_t id) \
{ \
ASSERT(shaderType != ShaderType::InvalidEnum); \
pod.activeUseBits.set(shaderType, used); \
pod.ids[shaderType] = id; \
} \
ShaderType getFirstActiveShaderType() const \
{ \
return pod.activeUseBits.first(); \
} \
bool isActive(ShaderType shaderType) const \
{ \
return pod.activeUseBits[shaderType]; \
} \
const ShaderMap<uint32_t> &getIds() const \
{ \
return pod.ids; \
} \
uint32_t getId(ShaderType shaderType) const \
{ \
return pod.ids[shaderType]; \
} \
ShaderBitSet activeShaders() const \
{ \
return pod.activeUseBits; \
} \
uint32_t activeShaderCount() const \
{ \
return static_cast<uint32_t>(pod.activeUseBits.count()); \
}
struct ActiveVariable
{
ActiveVariable() { memset(&pod, 0, sizeof(pod)); }
ACTIVE_VARIABLE_COMMON_INTERFACES
struct PODStruct
{
ShaderBitSet activeUseBits;
// The id of a linked variable in each shader stage. This id originates from
// sh::ShaderVariable::id or sh::InterfaceBlock::id
ShaderMap<uint32_t> ids;
} pod;
};
// 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.
ANGLE_ENABLE_STRUCT_PADDING_WARNINGS
struct LinkedUniform
{
LinkedUniform() = default;
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 UsedUniform &usedUniform);
bool isSampler() const { return GetUniformTypeInfo(pod.type).isSampler; }
bool isImage() const { return GetUniformTypeInfo(pod.type).isImageType; }
bool isAtomicCounter() const { return IsAtomicCounterType(pod.type); }
bool isInDefaultBlock() const { return pod.bufferIndex == -1; }
size_t getElementSize() const { return GetUniformTypeInfo(pod.type).externalSize; }
GLint getElementComponents() const { return GetUniformTypeInfo(pod.type).componentCount; }
bool isTexelFetchStaticUse() const { return pod.flagBits.texelFetchStaticUse; }
bool isFragmentInOut() const { return pod.flagBits.isFragmentInOut; }
bool isArray() const { return pod.flagBits.isArray; }
uint16_t getBasicTypeElementCount() const
{
ASSERT(pod.flagBits.isArray || pod.arraySize == 1u);
return pod.arraySize;
}
GLenum getType() const { return pod.type; }
uint16_t getOuterArrayOffset() const { return pod.outerArrayOffset; }
uint16_t getOuterArraySizeProduct() const { return pod.outerArraySizeProduct; }
int16_t getBinding() const { return pod.binding; }
int16_t getOffset() const { return pod.offset; }
int getBufferIndex() const { return pod.bufferIndex; }
int getLocation() const { return pod.location; }
GLenum getImageUnitFormat() const { return pod.imageUnitFormat; }
ACTIVE_VARIABLE_COMMON_INTERFACES
struct PODStruct
{
uint16_t type;
uint16_t precision;
int32_t location;
// These are from sh::struct BlockMemberInfo struct. See locklayout.h for detail.
uint16_t blockOffset;
uint16_t blockArrayStride;
uint16_t blockMatrixStride;
uint16_t imageUnitFormat;
// maxUniformVectorsCount is 4K due to we clamp maxUniformBlockSize to 64KB. All of these
// variable should be enough to pack into 16 bits to reduce the size of mUniforms.
int16_t binding;
int16_t bufferIndex;
int16_t offset;
uint16_t arraySize;
uint16_t outerArraySizeProduct;
uint16_t outerArrayOffset;
uint16_t parentArrayIndex;
union
{
struct
{
uint8_t isFragmentInOut : 1;
uint8_t texelFetchStaticUse : 1;
uint8_t isArray : 1;
uint8_t blockIsRowMajorMatrix : 1;
uint8_t isBlock : 1;
uint8_t padding : 3;
} flagBits;
uint8_t flagBitsAsUByte;
};
ShaderBitSet activeUseBits;
uint32_t id;
// The id of a linked variable in each shader stage. This id originates from
// sh::ShaderVariable::id or sh::InterfaceBlock::id
ShaderMap<uint32_t> ids;
} pod;
};
ANGLE_DISABLE_STRUCT_PADDING_WARNINGS
struct BufferVariable
{
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);
~BufferVariable() {}
bool isArray() const { return pod.isArray; }
uint32_t getBasicTypeElementCount() const { return pod.basicTypeElementCount; }
ACTIVE_VARIABLE_COMMON_INTERFACES
std::string name;
std::string mappedName;
ANGLE_ENABLE_STRUCT_PADDING_WARNINGS
struct PODStruct
{
uint16_t type;
uint16_t precision;
// 1 byte each
ShaderBitSet activeUseBits;
bool isArray;
int16_t bufferIndex;
// The id of a linked variable in each shader stage. This id originates from
// sh::ShaderVariable::id or sh::InterfaceBlock::id
ShaderMap<uint32_t> ids;
sh::BlockMemberInfo blockInfo;
int32_t topLevelArraySize;
uint32_t basicTypeElementCount;
} pod;
ANGLE_DISABLE_STRUCT_PADDING_WARNINGS
};
// 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() {}
ACTIVE_VARIABLE_COMMON_INTERFACES
int numActiveVariables() const { return static_cast<int>(memberIndexes.size()); }
void unionReferencesWith(const LinkedUniform &otherUniform);
std::vector<unsigned int> memberIndexes;
ANGLE_ENABLE_STRUCT_PADDING_WARNINGS
struct PODStruct
{
// The id of a linked variable in each shader stage. This id originates from
// sh::ShaderVariable::id or sh::InterfaceBlock::id
ShaderMap<uint32_t> ids;
int binding;
unsigned int dataSize;
ShaderBitSet activeUseBits;
uint8_t pads[3];
} pod;
ANGLE_DISABLE_STRUCT_PADDING_WARNINGS
};
using AtomicCounterBuffer = ShaderVariableBuffer;
// Helper struct representing a single shader interface block
struct InterfaceBlock
{
InterfaceBlock();
InterfaceBlock(const std::string &nameIn,
const std::string &mappedNameIn,
bool isArrayIn,
bool isReadOnlyIn,
unsigned int arrayElementIn,
unsigned int firstFieldArraySizeIn,
int bindingIn);
std::string nameWithArrayIndex() const;
std::string mappedNameWithArrayIndex() const;
ACTIVE_VARIABLE_COMMON_INTERFACES
int numActiveVariables() const { return static_cast<int>(memberIndexes.size()); }
void setBinding(GLuint binding) { SetBitField(pod.binding, binding); }
std::string name;
std::string mappedName;
std::vector<unsigned int> memberIndexes;
ANGLE_ENABLE_STRUCT_PADDING_WARNINGS
struct PODStruct
{
uint32_t arrayElement;
uint32_t firstFieldArraySize;
ShaderBitSet activeUseBits;
uint8_t isArray : 1;
// Only valid for SSBOs, specifies whether it has the readonly qualifier.
uint8_t isReadOnly : 1;
uint8_t padings : 6;
int16_t binding;
unsigned int dataSize;
// The id of a linked variable in each shader stage. This id originates from
// sh::ShaderVariable::id or sh::InterfaceBlock::id
ShaderMap<uint32_t> ids;
} pod;
ANGLE_DISABLE_STRUCT_PADDING_WARNINGS
};
#undef ACTIVE_VARIABLE_COMMON_INTERFACES
} // namespace gl
#endif // LIBANGLE_UNIFORM_H_