Hash :
25390156
        
        Author :
  
        
        Date :
2025-08-21T00:13:19
        
      
Suppress unsafe buffers on a file-by-file basis in src/ [1 of N] In this CL, we suppress many files but stop short of actually enabling the warning by not removing the line from the unsafe_buffers_paths.txt file. That will happen in a follow-on CL, along with resolving any stragglers missed here. This is mostly a manual change so as to familiarize myself with the kinds of issues faced by the Angle codebase when applying buffer safety warnings. -- Re-generate affected hashes. -- Clang-format applied to all changed files. -- Add a few missing .reserve() calls to vectors as noticed. -- Fix some mismatches between file names and header comments. -- Be more consistent with header comment format (blank lines and trailing //-only lines when a filename comment adjoins license boilerplate). Bug: b/436880895 Change-Id: I3bde5cc2059acbe8345057289214f1a26f1c34aa Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6869022 Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@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 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
//
// 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.
//
#ifdef UNSAFE_BUFFERS_BUILD
#    pragma allow_unsafe_libc_calls
#endif
#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);
    SetBitField(pod.flagBits.isFloat16, usedUniform.isFloat16);
    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