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 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
|
/* Copyright (c) 2018-2025 The Khronos Group Inc.
* Copyright (c) 2018-2025 Valve Corporation
* Copyright (c) 2018-2025 LunarG, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <array>
#include <cmath>
#include <cstring>
#include <string>
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__GNU__)
#include <unistd.h>
#endif
#include "chassis/dispatch_object.h"
#include "gpuav/core/gpuav.h"
#include "gpuav/core/gpuav_constants.h"
#include "gpuav/instrumentation/descriptor_checks.h"
#include "gpuav/resources/gpuav_state_trackers.h"
#include "gpuav/shaders/gpuav_error_header.h"
#include "gpuav/shaders/gpuav_shaders_constants.h"
#include "utils/dispatch_utils.h"
namespace gpuav {
// Location to add per-queue submit debug info if built with -D DEBUG_CAPTURE_KEYBOARD=ON
void Validator::DebugCapture() {}
void Validator::Created(vvl::DescriptorSet &set) {
set.SetSubState(container_type, std::make_unique<DescriptorSetSubState>(set, *this));
}
void Validator::Created(vvl::CommandBuffer &cb_state) {
cb_state.SetSubState(container_type, std::make_unique<CommandBufferSubState>(*this, cb_state));
}
void Validator::Created(vvl::Queue &queue) { queue.SetSubState(container_type, std::make_unique<QueueSubState>(*this, queue)); }
void Validator::Created(vvl::Image &obj) {
DescriptorHeap &desc_heap = shared_resources_manager.Get<DescriptorHeap>();
obj.SetSubState(container_type, std::make_unique<ImageSubState>(obj, desc_heap));
}
void Validator::Created(vvl::ImageView &obj) {
DescriptorHeap &desc_heap = shared_resources_manager.Get<DescriptorHeap>();
obj.SetSubState(container_type, std::make_unique<ImageViewSubState>(obj, desc_heap));
}
void Validator::Created(vvl::Buffer &obj) {
DescriptorHeap &desc_heap = shared_resources_manager.Get<DescriptorHeap>();
obj.SetSubState(container_type, std::make_unique<BufferSubState>(obj, desc_heap));
}
void Validator::Created(vvl::BufferView &obj) {
DescriptorHeap &desc_heap = shared_resources_manager.Get<DescriptorHeap>();
obj.SetSubState(container_type, std::make_unique<BufferViewSubState>(obj, desc_heap));
}
void Validator::Created(vvl::Sampler &obj) {
DescriptorHeap &desc_heap = shared_resources_manager.Get<DescriptorHeap>();
obj.SetSubState(container_type, std::make_unique<SamplerSubState>(obj, desc_heap));
}
void Validator::Created(vvl::AccelerationStructureNV &obj) {
DescriptorHeap &desc_heap = shared_resources_manager.Get<DescriptorHeap>();
obj.SetSubState(container_type, std::make_unique<AccelerationStructureNVSubState>(obj, desc_heap));
}
void Validator::Created(vvl::AccelerationStructureKHR &obj) {
DescriptorHeap &desc_heap = shared_resources_manager.Get<DescriptorHeap>();
obj.SetSubState(container_type, std::make_unique<AccelerationStructureKHRSubState>(obj, desc_heap));
}
void Validator::Created(vvl::ShaderObject &obj) { obj.SetSubState(container_type, std::make_unique<ShaderObjectSubState>(obj)); }
// Trampolines to make VMA call Dispatch for Vulkan calls
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL gpuVkGetInstanceProcAddr(VkInstance inst, const char *name) {
return DispatchGetInstanceProcAddr(inst, name);
}
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL gpuVkGetDeviceProcAddr(VkDevice dev, const char *name) {
return DispatchGetDeviceProcAddr(dev, name);
}
static VKAPI_ATTR void VKAPI_CALL gpuVkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
VkPhysicalDeviceProperties *pProperties) {
DispatchGetPhysicalDeviceProperties(physicalDevice, pProperties);
}
static VKAPI_ATTR void VKAPI_CALL gpuVkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice,
VkPhysicalDeviceMemoryProperties *pMemoryProperties) {
DispatchGetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
}
static VKAPI_ATTR VkResult VKAPI_CALL gpuVkAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory) {
return DispatchAllocateMemory(device, pAllocateInfo, pAllocator, pMemory);
}
static VKAPI_ATTR void VKAPI_CALL gpuVkFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks *pAllocator) {
DispatchFreeMemory(device, memory, pAllocator);
}
static VKAPI_ATTR VkResult VKAPI_CALL gpuVkMapMemory(VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, VkDeviceSize size,
VkMemoryMapFlags flags, void **ppData) {
return DispatchMapMemory(device, memory, offset, size, flags, ppData);
}
static VKAPI_ATTR void VKAPI_CALL gpuVkUnmapMemory(VkDevice device, VkDeviceMemory memory) { DispatchUnmapMemory(device, memory); }
static VKAPI_ATTR VkResult VKAPI_CALL gpuVkFlushMappedMemoryRanges(VkDevice device, uint32_t memoryRangeCount,
const VkMappedMemoryRange *pMemoryRanges) {
return DispatchFlushMappedMemoryRanges(device, memoryRangeCount, pMemoryRanges);
}
static VKAPI_ATTR VkResult VKAPI_CALL gpuVkInvalidateMappedMemoryRanges(VkDevice device, uint32_t memoryRangeCount,
const VkMappedMemoryRange *pMemoryRanges) {
return DispatchInvalidateMappedMemoryRanges(device, memoryRangeCount, pMemoryRanges);
}
static VKAPI_ATTR VkResult VKAPI_CALL gpuVkBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory,
VkDeviceSize memoryOffset) {
return DispatchBindBufferMemory(device, buffer, memory, memoryOffset);
}
static VKAPI_ATTR VkResult VKAPI_CALL gpuVkBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory memory,
VkDeviceSize memoryOffset) {
return DispatchBindImageMemory(device, image, memory, memoryOffset);
}
static VKAPI_ATTR void VKAPI_CALL gpuVkGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
VkMemoryRequirements *pMemoryRequirements) {
DispatchGetBufferMemoryRequirements(device, buffer, pMemoryRequirements);
}
static VKAPI_ATTR void VKAPI_CALL gpuVkGetImageMemoryRequirements(VkDevice device, VkImage image,
VkMemoryRequirements *pMemoryRequirements) {
DispatchGetImageMemoryRequirements(device, image, pMemoryRequirements);
}
static VKAPI_ATTR VkResult VKAPI_CALL gpuVkCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer) {
return DispatchCreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
}
static VKAPI_ATTR void VKAPI_CALL gpuVkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
return DispatchDestroyBuffer(device, buffer, pAllocator);
}
static VKAPI_ATTR VkResult VKAPI_CALL gpuVkCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkImage *pImage) {
return DispatchCreateImage(device, pCreateInfo, pAllocator, pImage);
}
static VKAPI_ATTR void VKAPI_CALL gpuVkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
DispatchDestroyImage(device, image, pAllocator);
}
static VKAPI_ATTR void VKAPI_CALL gpuVkCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
uint32_t regionCount, const VkBufferCopy *pRegions) {
DispatchCmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
}
static VkResult UtilInitializeVma(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device,
VmaAllocator *pAllocator) {
VmaVulkanFunctions functions;
VmaAllocatorCreateInfo allocator_info = {};
allocator_info.instance = instance;
allocator_info.device = device;
allocator_info.physicalDevice = physical_device;
allocator_info.flags |= VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT;
functions.vkGetInstanceProcAddr = static_cast<PFN_vkGetInstanceProcAddr>(gpuVkGetInstanceProcAddr);
functions.vkGetDeviceProcAddr = static_cast<PFN_vkGetDeviceProcAddr>(gpuVkGetDeviceProcAddr);
functions.vkGetPhysicalDeviceProperties = static_cast<PFN_vkGetPhysicalDeviceProperties>(gpuVkGetPhysicalDeviceProperties);
functions.vkGetPhysicalDeviceMemoryProperties =
static_cast<PFN_vkGetPhysicalDeviceMemoryProperties>(gpuVkGetPhysicalDeviceMemoryProperties);
functions.vkAllocateMemory = static_cast<PFN_vkAllocateMemory>(gpuVkAllocateMemory);
functions.vkFreeMemory = static_cast<PFN_vkFreeMemory>(gpuVkFreeMemory);
functions.vkMapMemory = static_cast<PFN_vkMapMemory>(gpuVkMapMemory);
functions.vkUnmapMemory = static_cast<PFN_vkUnmapMemory>(gpuVkUnmapMemory);
functions.vkFlushMappedMemoryRanges = static_cast<PFN_vkFlushMappedMemoryRanges>(gpuVkFlushMappedMemoryRanges);
functions.vkInvalidateMappedMemoryRanges = static_cast<PFN_vkInvalidateMappedMemoryRanges>(gpuVkInvalidateMappedMemoryRanges);
functions.vkBindBufferMemory = static_cast<PFN_vkBindBufferMemory>(gpuVkBindBufferMemory);
functions.vkBindImageMemory = static_cast<PFN_vkBindImageMemory>(gpuVkBindImageMemory);
functions.vkGetBufferMemoryRequirements = static_cast<PFN_vkGetBufferMemoryRequirements>(gpuVkGetBufferMemoryRequirements);
functions.vkGetImageMemoryRequirements = static_cast<PFN_vkGetImageMemoryRequirements>(gpuVkGetImageMemoryRequirements);
functions.vkCreateBuffer = static_cast<PFN_vkCreateBuffer>(gpuVkCreateBuffer);
functions.vkDestroyBuffer = static_cast<PFN_vkDestroyBuffer>(gpuVkDestroyBuffer);
functions.vkCreateImage = static_cast<PFN_vkCreateImage>(gpuVkCreateImage);
functions.vkDestroyImage = static_cast<PFN_vkDestroyImage>(gpuVkDestroyImage);
functions.vkCmdCopyBuffer = static_cast<PFN_vkCmdCopyBuffer>(gpuVkCmdCopyBuffer);
allocator_info.pVulkanFunctions = &functions;
return vmaCreateAllocator(&allocator_info, pAllocator);
}
void Instance::PreCallRecordCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, const RecordObject &record_obj,
vku::safe_VkDeviceCreateInfo *modified_create_info) {
BaseClass::PreCallRecordCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice, record_obj, modified_create_info);
// GPU-AV requirements not met, exit early or future Vulkan calls may be invalid
if (api_version < VK_API_VERSION_1_1) {
return;
}
AddFeatures(physicalDevice, modified_create_info, record_obj.location);
}
// Perform initializations that can be done at Create Device time.
void Validator::FinishDeviceSetup(const VkDeviceCreateInfo *pCreateInfo, const Location &loc) {
// GPU-AV not supported, exit early to prevent errors inside Validator::PostCallRecordCreateDevice
if (api_version < VK_API_VERSION_1_1) {
InternalError(device, loc, "GPU Shader Instrumentation requires Vulkan 1.1 or later.");
return;
}
instrumentation_bindings_ = {
// DebugPrintf Output buffer
{glsl::kBindingInstDebugPrintf, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_ALL, nullptr},
// Error output buffer
{glsl::kBindingInstErrorBuffer, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_ALL, nullptr},
// Buffer holding output from GPU to do processing on the CPU
{glsl::kBindingInstPostProcess, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_ALL, nullptr},
// Buffer holding input from CPU into the shader for descriptor indexing
{glsl::kBindingInstDescriptorIndexingOOB, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_ALL, nullptr},
// Buffer holding buffer device addresses
{glsl::kBindingInstBufferDeviceAddress, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_ALL, nullptr},
// Buffer holding action command index in command buffer
{glsl::kBindingInstActionIndex, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_ALL, nullptr},
// Buffer holding a resource index from the per command buffer command resources list
{glsl::kBindingInstCmdResourceIndex, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_ALL, nullptr},
// Commands errors counts buffer
{glsl::kBindingInstCmdErrorsCount, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_ALL, nullptr},
// Vertex attribute fetch limits
{glsl::kBindingInstVertexAttributeFetchLimits, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT, nullptr},
};
// TODO - Now that GPU-AV and DebugPrintf are merged, we should just have a single FinishDeviceSetup if possible (or at least
// better divide what belongs where as it is easy to mess)
BaseClass::FinishDeviceSetup(pCreateInfo, loc);
// We might fail in parent class device creation if global requirements are not met
if (aborted_) {
return;
}
// Need the device to be created before we can query features for settings
InitSettings(loc);
VkResult result = UtilInitializeVma(instance, physical_device, device, &vma_allocator_);
if (result != VK_SUCCESS) {
InternalVmaError(device, result, "Could not initialize VMA");
return;
}
desc_set_manager_ =
std::make_unique<vko::DescriptorSetManager>(device, static_cast<uint32_t>(instrumentation_bindings_.size()));
// If api version 1.1 or later, SetDeviceLoaderData will be in the loader
{
auto chain_info = GetChainInfo(pCreateInfo, VK_LOADER_DATA_CALLBACK);
assert(chain_info->u.pfnSetDeviceLoaderData);
vk_set_device_loader_data_ = chain_info->u.pfnSetDeviceLoaderData;
}
DescriptorChecksOnFinishDeviceSetup(*this);
// Create error logging buffer allocation pool
{
VkBufferCreateInfo error_buffer_ci = vku::InitStructHelper();
error_buffer_ci.size = glsl::kErrorBufferByteSize;
error_buffer_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
VmaAllocationCreateInfo error_buffer_alloc_ci = {};
error_buffer_alloc_ci.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
error_buffer_alloc_ci.preferredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
uint32_t mem_type_index;
result = vmaFindMemoryTypeIndexForBufferInfo(vma_allocator_, &error_buffer_ci, &error_buffer_alloc_ci, &mem_type_index);
if (result != VK_SUCCESS) {
InternalVmaError(device, result, "Unable to find memory type index.");
return;
}
}
// Create command indices buffer
{
indices_buffer_alignment_ = sizeof(uint32_t) * static_cast<uint32_t>(phys_dev_props.limits.minStorageBufferOffsetAlignment);
VkBufferCreateInfo buffer_info = vku::InitStructHelper();
buffer_info.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
buffer_info.size = cst::indices_count * indices_buffer_alignment_;
VmaAllocationCreateInfo alloc_info = {};
alloc_info.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
alloc_info.preferredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
const bool success = indices_buffer_.Create(&buffer_info, &alloc_info);
if (!success) {
return;
}
auto indices_ptr = (uint32_t *)indices_buffer_.GetMappedPtr();
for (uint32_t i = 0; i < buffer_info.size / sizeof(uint32_t); ++i) {
indices_ptr[i] = i / (indices_buffer_alignment_ / sizeof(uint32_t));
}
}
}
namespace setting {
// Each setting in GPU-AV has a common interface to make adding a new setting easier
struct Setting {
virtual bool IsEnabled(const GpuAVSettings &settings) = 0;
virtual bool HasRequiredFeatures(const DeviceFeatures &features) = 0;
virtual void Disable(GpuAVSettings &settings) = 0;
virtual std::string DisableMessage() = 0;
};
struct BufferDeviceAddress : public Setting {
bool IsEnabled(const GpuAVSettings &settings) { return settings.shader_instrumentation.buffer_device_address; }
bool HasRequiredFeatures(const DeviceFeatures &features) { return features.shaderInt64; }
void Disable(GpuAVSettings &settings) { settings.shader_instrumentation.buffer_device_address = false; }
std::string DisableMessage() {
return "Buffer Device Address validation option was enabled, but the shaderInt64 feature was not supported [Disabling "
"gpuav_buffer_address_oob]";
}
};
struct RayQuery : public Setting {
bool IsEnabled(const GpuAVSettings &settings) { return settings.shader_instrumentation.ray_query; }
bool HasRequiredFeatures(const DeviceFeatures &features) { return features.rayQuery; }
void Disable(GpuAVSettings &settings) { settings.shader_instrumentation.ray_query = false; }
std::string DisableMessage() {
return "Ray Query validation option was enabled, but the rayQuery feature was not supported [Disabling "
"gpuav_validate_ray_query]";
}
};
struct BufferCopies : public Setting {
bool IsEnabled(const GpuAVSettings &settings) { return settings.validate_buffer_copies; }
// copy_buffer_to_image.comp relies on uint8_t buffers to perform validation
bool HasRequiredFeatures(const DeviceFeatures &features) { return features.storageBuffer8BitAccess; }
void Disable(GpuAVSettings &settings) { settings.validate_buffer_copies = false; }
std::string DisableMessage() {
return "Buffer copies option was enabled, but the storageBuffer8BitAccess feature was not supported [Disabling "
"gpuav_buffer_copies]";
}
};
struct BufferContent : public Setting {
bool IsEnabled(const GpuAVSettings &settings) { return settings.IsBufferValidationEnabled(); }
bool HasRequiredFeatures(const DeviceFeatures &features) { return features.shaderInt64; }
void Disable(GpuAVSettings &settings) { settings.SetBufferValidationEnabled(false); }
std::string DisableMessage() {
return "Buffer content validation option was enabled, but the shaderInt64 feature was not supported [Disabling "
"gpuav_buffers_validation]";
}
};
} // namespace setting
// At this point extensions/features may have been turned on by us in PreCallRecord.
// Now that we have all the information, here is where we might disable GPU-AV settings that are missing requirements
void Validator::InitSettings(const Location &loc) {
setting::BufferDeviceAddress buffer_device_address;
setting::RayQuery ray_query;
setting::BufferCopies buffer_copies;
setting::BufferContent buffer_content;
std::array<setting::Setting *, 4> all_settings = {&buffer_device_address, &ray_query, &buffer_copies, &buffer_content};
for (auto &setting_object : all_settings) {
if (setting_object->IsEnabled(gpuav_settings) && !setting_object->HasRequiredFeatures(modified_features)) {
setting_object->Disable(gpuav_settings);
InternalWarning(device, loc, setting_object->DisableMessage().c_str());
}
}
if (IsExtEnabled(extensions.vk_ext_descriptor_buffer)) {
InternalWarning(
device, loc,
"VK_EXT_descriptor_buffer is enabled, but GPU-AV does not currently support validation of descriptor buffers. "
"[Disabling all shader instrumentation checks]");
// Because of VUs like VUID-VkPipelineLayoutCreateInfo-pSetLayouts-08008 we currently would need to rework the entire shader
// instrumentation logic
gpuav_settings.DisableShaderInstrumentationAndOptions();
if (gpuav_settings.debug_printf_enabled) {
InternalWarning(device, loc,
"VK_EXT_descriptor_buffer is enabled, but DebugPrintf uses a normal descriptor and currently can't "
"exist with descriptor buffers. [Disabling debug_printf]");
gpuav_settings.debug_printf_enabled = false;
}
}
// If we have turned off all the possible things to instrument, turn off everything fully
if (!gpuav_settings.IsShaderInstrumentationEnabled()) {
gpuav_settings.DisableShaderInstrumentationAndOptions();
}
gpuav_settings.TracyLogSettings();
}
void Validator::InternalVmaError(LogObjectList objlist, VkResult result, const char *const specific_message) const {
aborted_ = true;
std::string error_message = specific_message;
char *stats_string;
vmaBuildStatsString(vma_allocator_, &stats_string, false);
error_message += " VMA statistics = ";
error_message += stats_string;
vmaFreeStatsString(vma_allocator_, stats_string);
char const *layer_name = gpuav_settings.debug_printf_only ? "DebugPrintf" : "GPU-AV";
char const *vuid = gpuav_settings.debug_printf_only ? "UNASSIGNED-DEBUG-PRINTF" : "UNASSIGNED-GPU-Assisted-Validation";
LogError(vuid, objlist, Location(vvl::Func::Empty), "Internal VMA Error (%s), %s is being disabled. Details:\n%s",
string_VkResult(result), layer_name, error_message.c_str());
// Once we encounter an internal issue disconnect everything.
// This prevents need to check "if (aborted)" (which is awful when we easily forget to check somewhere and the user gets spammed
// with errors making it hard to see the first error with the real source of the problem).
dispatch_device_->ReleaseValidationObject(LayerObjectTypeGpuAssisted);
}
// Things like DescriptorHeap are singleton class that lives in GPU-AV, but are used when state tracking adds/destroy new resources
// we need to track. One issue is on vkDestroyDevice we need to teardown the GPU-AV class, then after we try and destroy leaked
// state objects (ex. user forgot to call vkDestroySampler).
void Validator::DestroySubstate() {
if (!dispatch_device_ || aborted_) {
return;
}
// While this is not ideal, it is more important to keep normal code fast and do extra cleanup on teardown
for (auto object_it = dispatch_device_->object_dispatch.begin(); object_it != dispatch_device_->object_dispatch.end();
object_it++) {
if ((*object_it)->container_type == LayerObjectTypeStateTracker) {
auto &state_tracker = dynamic_cast<vvl::DeviceState &>(**object_it);
state_tracker.RemoveSubState(LayerObjectTypeGpuAssisted);
}
}
}
} // namespace gpuav
|