Hash :
3c554454
Author :
Date :
2025-04-03T16:55:11
Incorrect BUFFER_DATA_SIZE and UNIFORM_OFFSET for ACB array of array The buffer size and offset calculation for the atomic counter buffer defined as an array of arrays is incorrect. The issue occurs with the following declaration: layout (binding=0, offset=0) uniform atomic_uint ac[2][2]; Observed Results: GL_BUFFER_DATA_SIZE -> 8; GL_UNIFORM_OFFSET of "ac[1][0]" -> 0; Expected Results: GL_BUFFER_DATA_SIZE -> 16; GL_UNIFORM_OFFSET of "ac[1][0]" -> 8; Bug: angleproject:407564097 Change-Id: Ibf99ccd5412629f0feb74a9a34337b82894e74c6 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6429625 Auto-Submit: Mavis Deng <mavis.deng@arm.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Amirali Abdolrashidi <abdolrashidi@google.com> Commit-Queue: Amirali Abdolrashidi <abdolrashidi@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 292 293 294 295 296 297 298 299 300 301 302
//
// 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/uniform_type_info_autogen.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;
};
inline const UniformTypeInfo &GetUniformTypeInfoFromIndex(UniformTypeIndex index)
{
ASSERT(index.value >= 0 && index.value < kUniformInfoTable.size());
return kUniformInfoTable[index.value];
}
// 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);
const UniformTypeInfo &getUniformTypeInfo() const
{
return GetUniformTypeInfoFromIndex(pod.typeIndex);
}
bool isSampler() const { return getUniformTypeInfo().isSampler; }
bool isImage() const { return getUniformTypeInfo().isImageType; }
bool isAtomicCounter() const { return IsAtomicCounterType(getType()); }
bool isInDefaultBlock() const { return pod.bufferIndex == -1; }
size_t getElementSize() const { return getUniformTypeInfo().externalSize; }
GLint getElementComponents() const { return GetUniformElementComponents(pod.typeIndex); }
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 getUniformTypeInfo().type; }
uint16_t getOuterArrayOffset() const { return pod.outerArrayOffset; }
uint16_t getOuterArraySizeProduct() const { return pod.outerArraySizeProduct; }
uint16_t getBlockOffset() const { return pod.blockOffset; }
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
{
UniformTypeIndex typeIndex;
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
};
// Represents a single atomic counter buffer
struct AtomicCounterBuffer
{
AtomicCounterBuffer();
~AtomicCounterBuffer() {}
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;
// The binding as specified by the shader.
int inShaderBinding;
unsigned int dataSize;
ShaderBitSet activeUseBits;
uint8_t pads[3];
} pod;
ANGLE_DISABLE_STRUCT_PADDING_WARNINGS
};
// 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()); }
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;
// The binding as specified by the shader (0 if unspecified, per spec)
int16_t inShaderBinding;
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_