2 * Copyright © 2017 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include "anv_private.h"
27 /* This file contains implementation for VK_EXT_debug_report. */
30 anv_CreateDebugReportCallbackEXT(VkInstance _instance
,
31 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
32 const VkAllocationCallbacks
* pAllocator
,
33 VkDebugReportCallbackEXT
* pCallback
)
35 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
37 struct anv_debug_report_callback
*cb
=
38 vk_alloc2(&instance
->alloc
, pAllocator
,
39 sizeof(struct anv_debug_report_callback
), 8,
40 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
43 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
45 cb
->flags
= pCreateInfo
->flags
;
46 cb
->callback
= pCreateInfo
->pfnCallback
;
47 cb
->data
= pCreateInfo
->pUserData
;
49 pthread_mutex_lock(&instance
->callbacks_mutex
);
50 list_addtail(&cb
->link
, &instance
->callbacks
);
51 pthread_mutex_unlock(&instance
->callbacks_mutex
);
53 *pCallback
= anv_debug_report_callback_to_handle(cb
);
59 anv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
60 VkDebugReportCallbackEXT _callback
,
61 const VkAllocationCallbacks
* pAllocator
)
63 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
64 ANV_FROM_HANDLE(anv_debug_report_callback
, callback
, _callback
);
66 /* Remove from list and destroy given callback. */
67 pthread_mutex_lock(&instance
->callbacks_mutex
);
68 list_del(&callback
->link
);
69 vk_free2(&instance
->alloc
, pAllocator
, callback
);
70 pthread_mutex_unlock(&instance
->callbacks_mutex
);
74 anv_DebugReportMessageEXT(VkInstance _instance
,
75 VkDebugReportFlagsEXT flags
,
76 VkDebugReportObjectTypeEXT objectType
,
80 const char* pLayerPrefix
,
83 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
84 anv_debug_report(instance
, flags
, objectType
, object
,
85 location
, messageCode
, pLayerPrefix
, pMessage
);
89 anv_debug_report(struct anv_instance
*instance
,
90 VkDebugReportFlagsEXT flags
,
91 VkDebugReportObjectTypeEXT object_type
,
95 const char* pLayerPrefix
,
98 /* Allow NULL for convinience, return if no callbacks registered. */
99 if (!instance
|| list_empty(&instance
->callbacks
))
102 pthread_mutex_lock(&instance
->callbacks_mutex
);
104 /* Section 33.2 of the Vulkan 1.0.59 spec says:
106 * "callback is an externally synchronized object and must not be
107 * used on more than one thread at a time. This means that
108 * vkDestroyDebugReportCallbackEXT must not be called when a callback
111 list_for_each_entry(struct anv_debug_report_callback
, cb
,
112 &instance
->callbacks
, link
) {
113 if (cb
->flags
& flags
)
114 cb
->callback(flags
, object_type
, handle
, location
, messageCode
,
115 pLayerPrefix
, pMessage
, cb
->data
);
118 pthread_mutex_unlock(&instance
->callbacks_mutex
);