<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Sep 7, 2017 at 9:46 AM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">On Mon, Aug 28, 2017 at 10:44 PM, Tapani Pälli <span dir="ltr"><<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Patch adds required functionality for extension to manage a list of<br>
application provided callbacks and handle debug reporting from driver<br>
and application side.<br>
<br>
v2: remove useless helper anv_debug_report_call<br>
add locking around callbacks list<br>
use vk_alloc2, vk_free2 helpers<br>
refactor CreateDebugReportCallbackEXT<br>
fix bugs found with crucible testing<br>
<br>
Signed-off-by: Tapani Pälli <<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>><br>
---<br>
src/intel/Makefile.sources | 1 +<br>
src/intel/vulkan/anv_debug_re<wbr>port.c | 124 ++++++++++++++++++++++++++++++<wbr>++++++<br>
src/intel/vulkan/anv_device.<wbr>c | 46 +++++++++++++<br>
src/intel/vulkan/anv_extensio<wbr>ns.py | 1 +<br>
src/intel/vulkan/anv_private.<wbr>h | 24 +++++++<br>
5 files changed, 196 insertions(+)<br>
create mode 100644 src/intel/vulkan/anv_debug_rep<wbr>ort.c<br>
<br>
diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources<br>
index 4074ba9ee5..200713b06e 100644<br>
--- a/src/intel/Makefile.sources<br>
+++ b/src/intel/Makefile.sources<br>
@@ -205,6 +205,7 @@ VULKAN_FILES := \<br>
vulkan/anv_batch_chain.c \<br>
vulkan/anv_blorp.c \<br>
vulkan/anv_cmd_buffer.c \<br>
+ vulkan/anv_debug_report.c \<br>
vulkan/anv_descriptor_set.c \<br>
vulkan/anv_device.c \<br>
vulkan/anv_dump.c \<br>
diff --git a/src/intel/vulkan/anv_debug_r<wbr>eport.c b/src/intel/vulkan/anv_debug_r<wbr>eport.c<br>
new file mode 100644<br>
index 0000000000..d3239f0cc0<br>
--- /dev/null<br>
+++ b/src/intel/vulkan/anv_debug_r<wbr>eport.c<br>
@@ -0,0 +1,124 @@<br>
+/*<br>
+ * Copyright © 2017 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ */<br>
+<br>
+#include "anv_private.h"<br>
+#include "vk_util.h"<br>
+<br>
+/* This file contains implementation for VK_EXT_debug_report. */<br>
+<br>
+VkResult<br>
+anv_CreateDebugReportCallback<wbr>EXT(VkInstance _instance,<br>
+ const VkDebugReportCallbackCreateInf<wbr>oEXT* pCreateInfo,<br>
+ const VkAllocationCallbacks* pAllocator,<br>
+ VkDebugReportCallbackEXT* pCallback)<br>
+{<br>
+ ANV_FROM_HANDLE(anv_instance, instance, _instance);<br>
+<br>
+ struct anv_debug_callback *cb =<br>
+ vk_alloc2(&instance->alloc, pAllocator, sizeof(struct anv_debug_callback),<br>
+ 8, VK_SYSTEM_ALLOCATION_SCOPE_INS<wbr>TANCE);<br></blockquote><div><br></div></div></div><div>You should use SCOPE_OBJECT here.<br></div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ if (!cb)<br>
+ return vk_error(VK_ERROR_OUT_OF_HOST_<wbr>MEMORY);<br>
+<br>
+ cb->flags = pCreateInfo->flags;<br>
+ cb->callback = pCreateInfo->pfnCallback;<br>
+ cb->data = pCreateInfo->pUserData;<br>
+<br>
+ pthread_mutex_lock(&instance-<wbr>>callbacks_mutex);<br>
+ list_addtail(&cb->link, &instance->callbacks);<br>
+ pthread_mutex_unlock(&instanc<wbr>e->callbacks_mutex);<br>
+<br>
+ *pCallback = (VkDebugReportCallbackEXT) cb;<br></blockquote><div><br></div></span><div>Please add an ANV_DEFINE_HANDLE_CASTS for anv_debug_report_callback and use anv_debug_report_callback_to_<wbr>handle here.</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ return VK_SUCCESS;<br>
+}<br>
+<br>
+void<br>
+anv_DestroyDebugReportCallbac<wbr>kEXT(VkInstance _instance,<br>
+ VkDebugReportCallbackEXT callback,<br>
+ const VkAllocationCallbacks* pAllocator)<br>
+{<br>
+ ANV_FROM_HANDLE(anv_instance, instance, _instance);<br>
+<br>
+ pthread_mutex_lock(&instance-<wbr>>callbacks_mutex);<br>
+<br>
+ list_for_each_entry_safe(stru<wbr>ct anv_debug_callback, debug_cb,<br>
+ &instance->callbacks, link) {<br>
+ /* Found a match, remove from list and destroy given callback. */<br>
+ if ((VkDebugReportCallbackEXT)deb<wbr>ug_cb == callback) {<br>
+ list_del(&debug_cb->link);<br>
+ vk_free2(&instance->alloc, pAllocator, debug_cb);<br>
+ }<br>
+ }<br></blockquote><div><br></div></span><div>You don't need to walk the list here. You have the callback just do</div><div><br></div><div>ANV_FROM_HANDLE(anv_debug_<wbr>report_callback, callback, _callback);</div><div><br></div><div>at the top and then do</div><div><br></div><div>list_del(&callback->link);</div><div><br></div><div>No search needed.<br></div><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ pthread_mutex_unlock(&instanc<wbr>e->callbacks_mutex);<br>
+}<br>
+<br>
+void<br>
+anv_DebugReportMessageEXT(VkI<wbr>nstance _instance,<br>
+ VkDebugReportFlagsEXT flags,<br>
+ VkDebugReportObjectTypeEXT objectType,<br>
+ uint64_t object,<br>
+ size_t location,<br>
+ int32_t messageCode,<br>
+ const char* pLayerPrefix,<br>
+ const char* pMessage)<br>
+{<br>
+ ANV_FROM_HANDLE(anv_instance, instance, _instance);<br>
+ anv_debug_report(instance, flags, objectType, object,<br>
+ location, messageCode, pLayerPrefix, pMessage);<br>
+}<br>
+<br>
+void<br>
+anv_debug_report(struct anv_instance *instance,<br>
+ VkDebugReportFlagsEXT flags,<br>
+ VkDebugReportObjectTypeEXT object_type,<br>
+ uint64_t handle,<br>
+ size_t location,<br>
+ int32_t messageCode,<br>
+ const char* pLayerPrefix,<br>
+ const char *pMessage)<br>
+{<br>
+ /* Allow NULL for convinience, return if no callbacks registered. */<br>
+ if (!instance || list_empty(&instance->callback<wbr>s))<br>
+ return;<br>
+<br>
+ pthread_mutex_lock(&instance-<wbr>>callbacks_mutex);<br>
+<br>
+ /* Section 33.2 of the Vulkan 1.0.59 spec says:<br>
+ *<br>
+ * "callback is an externally synchronized object and must not be<br>
+ * used on more than one thread at a time. This means that<br>
+ * vkDestroyDebugReportCallbackEX<wbr>T must not be called when a callback<br>
+ * is active."<br>
+ */<br>
+ list_for_each_entry_safe(stru<wbr>ct anv_debug_callback, cb,<br>
+ &instance->callbacks, link) {<br>
+ if (cb->flags & flags)<br>
+ cb->callback(flags, object_type, handle, location, messageCode,<br>
+ pLayerPrefix, pMessage, cb->data);<br>
+ }<br>
+<br>
+ pthread_mutex_unlock(&instanc<wbr>e->callbacks_mutex);<br>
+}<br>
diff --git a/src/intel/vulkan/anv_device.<wbr>c b/src/intel/vulkan/anv_device.<wbr>c<br>
index 2e0fa19b1a..7e091246a8 100644<br>
--- a/src/intel/vulkan/anv_device.<wbr>c<br>
+++ b/src/intel/vulkan/anv_device.<wbr>c<br>
@@ -443,9 +443,28 @@ VkResult anv_CreateInstance(<br>
VkInstance* pInstance)<br>
{<br>
struct anv_instance *instance;<br>
+ <wbr>VkDebugReportCallbackCreateInf<wbr>oEXT *ctor_cb = NULL;<br>
<br>
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CRE<wbr>ATE_INFO);<br>
<br>
+ /* Check if user passed a debug report callback to be used during<br>
+ * Create/Destroy of instance.<br>
+ */<br>
+ vk_foreach_struct(ext, pCreateInfo->pNext) {<br>
+ switch (ext->sType) {<br>
+ case VK_STRUCTURE_TYPE_DEBUG_REPORT<wbr>_CALLBACK_CREATE_INFO_EXT: {<br>
+ ctor_cb = (VkDebugReportCallbackCreateIn<wbr>foEXT *) ext;<br>
+ break;<br>
+ }<br>
+ default:<br>
+ /* We ignore any other type by purpose here, we are only<br>
+ * interested if debug report callback was found for instance<br>
+ * ctor/dtor.<br>
+ */<br>
+ break;<br>
+ }<br>
+ };<br>
+<br>
uint32_t client_version;<br>
if (pCreateInfo->pApplicationInfo &&<br>
pCreateInfo->pApplicationInfo-<wbr>>apiVersion != 0) {<br>
@@ -456,6 +475,17 @@ VkResult anv_CreateInstance(<br>
<br>
if (VK_MAKE_VERSION(1, 0, 0) > client_version ||<br>
client_version > VK_MAKE_VERSION(1, 0, 0xfff)) {<br>
+<br>
+ if (ctor_cb && ctor_cb->flags & VK_DEBUG_REPORT_ERROR_BIT_EXT)<br>
+ ctor_cb->pfnCallback(VK_<wbr>DEBUG_REPORT_ERROR_BIT_EXT,<br>
+ VK_DEBUG_REPORT_OBJECT_TYPE_IN<wbr>STANCE_EXT,<br>
+ 0, /* No handle available yet. */<br></blockquote></div></div></div></div></div></blockquote><div><br></div><div>VK_NULL_HANDLE<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ __LINE__,<br>
+ 0,<br>
+ "anv",<br>
+ "incompatible driver version",<br>
+ ctor_cb->pUserData);<br>
+<br>
return vk_errorf(VK_ERROR_INCOMPATIBL<wbr>E_DRIVER,<br>
"Client requested version %d.%d.%d",<br>
VK_VERSION_MAJOR(client_versio<wbr>n),<br>
@@ -484,6 +514,20 @@ VkResult anv_CreateInstance(<br>
instance->apiVersion = client_version;<br>
instance->physicalDeviceCount = -1;<br>
<br>
+ if (pthread_mutex_init(&instance-<wbr>>callbacks_mutex, NULL) != 0) {<br>
+ vk_free2(&default_alloc, pAllocator, instance);<br>
+ return vk_error(VK_ERROR_INITIALIZATI<wbr>ON_FAILED);<br>
+ }<br>
+<br>
+ list_inithead(&instance->call<wbr>backs);<br>
+<br>
+ /* Store report debug callback to be used during DestroyInstance. */<br>
+ if (ctor_cb) {<br>
+ instance->dtor_cb.flags = ctor_cb->flags;<br>
+ instance->dtor_cb.callback = ctor_cb->pfnCallback;<br>
+ instance->dtor_cb.data = ctor_cb->pUserData;<br>
+ }<br>
+<br>
_mesa_locale_init();<br>
<br>
VG(VALGRIND_CREATE_MEMPOOL(ins<wbr>tance, 0, false));<br>
@@ -510,6 +554,8 @@ void anv_DestroyInstance(<br>
<br>
VG(VALGRIND_DESTROY_MEMPOOL(in<wbr>stance));<br>
<br>
+ pthread_mutex_destroy(&instan<wbr>ce->callbacks_mutex);<br>
+<br>
_mesa_locale_fini();<br>
<br>
vk_free(&instance->alloc, instance);<br>
diff --git a/src/intel/vulkan/anv_extensi<wbr>ons.py b/src/intel/vulkan/anv_extensi<wbr>ons.py<br>
index 6b3d72e4b4..acec785959 100644<br>
--- a/src/intel/vulkan/anv_extensi<wbr>ons.py<br>
+++ b/src/intel/vulkan/anv_extensi<wbr>ons.py<br>
@@ -75,6 +75,7 @@ EXTENSIONS = [<br>
Extension('VK_KHR_xcb_<wbr>surface', 6, 'VK_USE_PLATFORM_XCB_KHR'),<br>
Extension('VK_KHR_xlib_surfac<wbr>e', 6, 'VK_USE_PLATFORM_XLIB_KHR'),<br>
Extension('VK_KHX_multiview',<wbr> 1, True),<br>
+ Extension('VK_EXT_debug_report<wbr>', 8, True),<br>
]<br>
<br>
class VkVersion:<br>
diff --git a/src/intel/vulkan/anv_private<wbr>.h b/src/intel/vulkan/anv_private<wbr>.h<br>
index b30b71f336..ae66c5439b 100644<br>
--- a/src/intel/vulkan/anv_private<wbr>.h<br>
+++ b/src/intel/vulkan/anv_private<wbr>.h<br>
@@ -61,6 +61,8 @@ typedef uint32_t xcb_window_t;<br>
struct anv_buffer;<br>
struct anv_buffer_view;<br>
struct anv_image_view;<br>
+struct anv_instance;<br>
+struct anv_debug_callback;<br>
<br>
struct gen_l3_config;<br>
<br>
@@ -237,6 +239,15 @@ void __anv_perf_warn(const char *file, int line, const char *format, ...)<br>
void anv_loge(const char *format, ...) anv_printflike(1, 2);<br>
void anv_loge_v(const char *format, va_list va);<br>
<br>
+void anv_debug_report(struct anv_instance *instance,<br>
+ VkDebugReportFlagsEXT flags,<br>
+ VkDebugReportObjectTypeEXT object_type,<br>
+ uint64_t handle,<br>
+ size_t location,<br>
+ int32_t messageCode,<br>
+ const char* pLayerPrefix,<br>
+ const char *pMessage);<br>
+<br>
/**<br>
* Print a FINISHME message, including its source location.<br>
*/<br>
@@ -666,6 +677,14 @@ struct anv_physical_device {<br>
int local_fd;<br>
};<br>
<br>
+struct anv_debug_callback {<br>
+ /* Link in the 'callbacks' list in anv_instance struct. */<br>
+ struct list_head link;<br>
+ VkDebugReportFlagsEXT flags;<br>
+ PFN_vkDebugReportCallbackEXT callback;<br>
+ void * data;<br>
+};<br>
+<br>
struct anv_instance {<br>
VK_LOADER_DATA _loader_data;<br>
<br>
@@ -674,6 +693,11 @@ struct anv_instance {<br>
uint32_t apiVersion;<br>
int physicalDeviceCount;<br>
struct anv_physical_device physicalDevice;<br>
+<br>
+ /* VK_EXT_debug_report debug callbacks */<br>
+ pthread_mutex_t callbacks_mutex;<br>
+ struct list_head callbacks;<br>
+ struct anv_debug_callback dtor_cb;<br></blockquote><div><br></div></div></div><div>Maybe call this destroy_debug_cb to be a bit more descriptive?<br></div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
};<br>
<br>
VkResult anv_init_wsi(struct anv_physical_device *physical_device);<br>
<span class="m_8500326419995789654gmail-HOEnZb"><font color="#888888">--<br>
2.13.5<br>
<br>
</font></span></blockquote></span></div><br></div></div>
</blockquote></div><br></div></div>