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 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
//
// Copyright 2016 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.
//
// DeviceVk.cpp:
// Implements the class methods for DeviceVk.
//
#ifdef UNSAFE_BUFFERS_BUILD
# pragma allow_unsafe_buffers
#endif
#include "libANGLE/renderer/vulkan/DeviceVk.h"
#include <stdint.h>
#include "common/debug.h"
#include "common/vulkan/vulkan_icd.h"
#include "libANGLE/Display.h"
#include "libANGLE/renderer/vulkan/DisplayVk.h"
#include "libANGLE/renderer/vulkan/vk_renderer.h"
namespace rx
{
namespace
{
DeviceVk *gDevice = nullptr;
class [[nodiscard]] ScopedEnv : public angle::vk::ScopedVkLoaderEnvironment
{
public:
ScopedEnv()
: angle::vk::ScopedVkLoaderEnvironment(
gDevice ? gDevice->getRenderer()->getEnableValidationLayers() : false,
gDevice ? gDevice->getRenderer()->getEnabledICD() : angle::vk::ICD::Default)
{
if (!gDevice)
{
WARN() << "No DeviceVk instance.";
}
}
};
} // namespace
DeviceVk::DeviceVk() = default;
DeviceVk::~DeviceVk()
{
if (gDevice == this)
{
gDevice = nullptr;
}
}
egl::Error DeviceVk::initialize()
{
return egl::NoError();
}
egl::Error DeviceVk::getAttribute(const egl::Display *display, EGLint attribute, void **outValue)
{
vk::Renderer *renderer =
static_cast<rx::DisplayVk *>(display->getImplementation())->getRenderer();
ASSERT(mRenderer == nullptr || mRenderer == renderer);
mRenderer = renderer;
switch (attribute)
{
case EGL_VULKAN_VERSION_ANGLE:
{
auto version = static_cast<intptr_t>(mRenderer->getDeviceVersion());
*outValue = reinterpret_cast<void *>(version);
return egl::NoError();
}
case EGL_VULKAN_INSTANCE_ANGLE:
{
*outValue = mRenderer->getInstance();
return egl::NoError();
}
case EGL_VULKAN_DEVICE_ANGLE:
{
*outValue = mRenderer->getDevice();
return egl::NoError();
}
case EGL_VULKAN_PHYSICAL_DEVICE_ANGLE:
{
*outValue = mRenderer->getPhysicalDevice();
return egl::NoError();
}
case EGL_VULKAN_QUEUE_ANGLE:
{
// egl::ContextPriority::Medium is the default context priority.
*outValue = mRenderer->getQueue(egl::ContextPriority::Medium);
return egl::NoError();
}
case EGL_VULKAN_QUEUE_FAMILIY_INDEX_ANGLE:
{
intptr_t index = static_cast<intptr_t>(mRenderer->getQueueFamilyIndex());
*outValue = reinterpret_cast<void *>(index);
return egl::NoError();
}
case EGL_VULKAN_DEVICE_EXTENSIONS_ANGLE:
{
char **extensions = const_cast<char **>(mRenderer->getEnabledDeviceExtensions().data());
*outValue = reinterpret_cast<void *>(extensions);
return egl::NoError();
}
case EGL_VULKAN_INSTANCE_EXTENSIONS_ANGLE:
{
char **extensions =
const_cast<char **>(mRenderer->getEnabledInstanceExtensions().data());
*outValue = reinterpret_cast<void *>(extensions);
return egl::NoError();
}
case EGL_VULKAN_FEATURES_ANGLE:
{
const auto *features = &mRenderer->getEnabledFeatures();
*outValue = const_cast<void *>(reinterpret_cast<const void *>(features));
return egl::NoError();
}
case EGL_VULKAN_GET_INSTANCE_PROC_ADDR:
{
*outValue = reinterpret_cast<void *>(DeviceVk::WrappedGetInstanceProcAddr);
ASSERT(!gDevice || gDevice == this);
gDevice = this;
return egl::NoError();
}
default:
return egl::Error(EGL_BAD_ACCESS);
}
}
void DeviceVk::generateExtensions(egl::DeviceExtensions *outExtensions) const
{
outExtensions->deviceVulkan = true;
}
// static
VKAPI_ATTR VkResult VKAPI_CALL
DeviceVk::WrappedCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkInstance *pInstance)
{
ScopedEnv scopedEnv;
return vkCreateInstance(pCreateInfo, pAllocator, pInstance);
}
// static
VKAPI_ATTR VkResult VKAPI_CALL
DeviceVk::WrappedEnumerateInstanceExtensionProperties(const char *pLayerName,
uint32_t *pPropertyCount,
VkExtensionProperties *pProperties)
{
ScopedEnv scopedEnv;
return vkEnumerateInstanceExtensionProperties(pLayerName, pPropertyCount, pProperties);
}
// static
VKAPI_ATTR VkResult VKAPI_CALL
DeviceVk::WrappedEnumerateInstanceLayerProperties(uint32_t *pPropertyCount,
VkLayerProperties *pProperties)
{
ScopedEnv scopedEnv;
return vkEnumerateInstanceLayerProperties(pPropertyCount, pProperties);
}
// static
VKAPI_ATTR VkResult VKAPI_CALL DeviceVk::WrappedEnumerateInstanceVersion(uint32_t *pApiVersion)
{
ScopedEnv scopedEnv;
return vkEnumerateInstanceVersion(pApiVersion);
}
// static
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL DeviceVk::WrappedGetInstanceProcAddr(VkInstance instance,
const char *pName)
{
if (!pName || pName[0] != 'v' || pName[1] != 'k')
{
return nullptr;
}
if (instance != VK_NULL_HANDLE)
{
return vkGetInstanceProcAddr(instance, pName);
}
if (!strcmp(pName, "vkCreateInstance"))
{
return reinterpret_cast<PFN_vkVoidFunction>(DeviceVk::WrappedCreateInstance);
}
if (!strcmp(pName, "vkEnumerateInstanceExtensionProperties"))
{
return reinterpret_cast<PFN_vkVoidFunction>(
DeviceVk::WrappedEnumerateInstanceExtensionProperties);
}
if (!strcmp(pName, "vkEnumerateInstanceLayerProperties"))
{
return reinterpret_cast<PFN_vkVoidFunction>(
DeviceVk::WrappedEnumerateInstanceLayerProperties);
}
if (!strcmp(pName, "vkEnumerateInstanceVersion"))
{
if (!vkGetInstanceProcAddr(nullptr, "vkEnumerateInstanceVersion"))
{
// Vulkan 1.0 doesn't have vkEnumerateInstanceVersion.
return nullptr;
}
return reinterpret_cast<PFN_vkVoidFunction>(DeviceVk::WrappedEnumerateInstanceVersion);
}
if (!strcmp(pName, "vkGetInstanceProcAddr"))
{
return reinterpret_cast<PFN_vkVoidFunction>(DeviceVk::WrappedGetInstanceProcAddr);
}
return vkGetInstanceProcAddr(instance, pName);
}
} // namespace rx