Path: blob/21.2-virgl/src/vulkan/util/vk_debug_report.c
7129 views
/*1* Copyright © 2017 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include "vk_debug_report.h"2425#include "vk_alloc.h"26#include "vk_common_entrypoints.h"27#include "vk_instance.h"28#include "vk_util.h"2930struct vk_debug_report_callback {31struct vk_object_base base;3233/* Link in the 'callbacks' list in anv_instance struct. */34struct list_head link;35VkDebugReportFlagsEXT flags;36PFN_vkDebugReportCallbackEXT callback;37void * data;38};3940VK_DEFINE_NONDISP_HANDLE_CASTS(vk_debug_report_callback, base,41VkDebugReportCallbackEXT,42VK_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT)4344VKAPI_ATTR VkResult VKAPI_CALL45vk_common_CreateDebugReportCallbackEXT(VkInstance _instance,46const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,47const VkAllocationCallbacks *pAllocator,48VkDebugReportCallbackEXT *pCallback)49{50VK_FROM_HANDLE(vk_instance, instance, _instance);5152struct vk_debug_report_callback *cb =53vk_alloc2(&instance->alloc, pAllocator,54sizeof(struct vk_debug_report_callback), 8,55VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);5657if (!cb)58return VK_ERROR_OUT_OF_HOST_MEMORY;5960vk_object_base_init(NULL, &cb->base,61VK_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT);6263cb->flags = pCreateInfo->flags;64cb->callback = pCreateInfo->pfnCallback;65cb->data = pCreateInfo->pUserData;6667mtx_lock(&instance->debug_report.callbacks_mutex);68list_addtail(&cb->link, &instance->debug_report.callbacks);69mtx_unlock(&instance->debug_report.callbacks_mutex);7071*pCallback = vk_debug_report_callback_to_handle(cb);7273return VK_SUCCESS;74}7576VKAPI_ATTR void VKAPI_CALL77vk_common_DestroyDebugReportCallbackEXT(VkInstance _instance,78VkDebugReportCallbackEXT _callback,79const VkAllocationCallbacks *pAllocator)80{81VK_FROM_HANDLE(vk_instance, instance, _instance);82VK_FROM_HANDLE(vk_debug_report_callback, callback, _callback);8384if (callback == NULL)85return;8687/* Remove from list and destroy given callback. */88mtx_lock(&instance->debug_report.callbacks_mutex);89list_del(&callback->link);90vk_object_base_finish(&callback->base);91vk_free2(&instance->alloc, pAllocator, callback);92mtx_unlock(&instance->debug_report.callbacks_mutex);93}9495static void96debug_report(struct vk_instance *instance,97VkDebugReportFlagsEXT flags,98VkDebugReportObjectTypeEXT object_type,99uint64_t handle,100size_t location,101int32_t messageCode,102const char* pLayerPrefix,103const char *pMessage)104{105/* Allow NULL for convinience, return if no callbacks registered. */106if (!instance || list_is_empty(&instance->debug_report.callbacks))107return;108109mtx_lock(&instance->debug_report.callbacks_mutex);110111/* Section 33.2 of the Vulkan 1.0.59 spec says:112*113* "callback is an externally synchronized object and must not be114* used on more than one thread at a time. This means that115* vkDestroyDebugReportCallbackEXT must not be called when a callback116* is active."117*/118list_for_each_entry(struct vk_debug_report_callback, cb,119&instance->debug_report.callbacks, link) {120if (cb->flags & flags)121cb->callback(flags, object_type, handle, location, messageCode,122pLayerPrefix, pMessage, cb->data);123}124125mtx_unlock(&instance->debug_report.callbacks_mutex);126}127128VKAPI_ATTR void VKAPI_CALL129vk_common_DebugReportMessageEXT(VkInstance _instance,130VkDebugReportFlagsEXT flags,131VkDebugReportObjectTypeEXT objectType,132uint64_t object,133size_t location,134int32_t messageCode,135const char* pLayerPrefix,136const char* pMessage)137{138VK_FROM_HANDLE(vk_instance, instance, _instance);139debug_report(instance, flags, objectType,140object, location, messageCode, pLayerPrefix, pMessage);141}142143void144vk_debug_report(struct vk_instance *instance,145VkDebugReportFlagsEXT flags,146const struct vk_object_base *object,147size_t location,148int32_t messageCode,149const char* pLayerPrefix,150const char *pMessage)151{152VkDebugReportObjectTypeEXT object_type =153object ? object->type : VK_OBJECT_TYPE_UNKNOWN;154debug_report(instance, flags, object_type, (uint64_t)(uintptr_t)object,155location, messageCode, pLayerPrefix, pMessage);156}157158159