Re: [Mesa-dev] [PATCH 1/2] anv: implementation of VK_EXT_debug_report extension

2017-08-24 Thread Tapani Pälli



On 08/25/2017 08:08 AM, Jason Ekstrand wrote:
On Thu, Aug 24, 2017 at 9:52 PM, Tapani Pälli > wrote:



 +
 +   vk_foreach_struct(info, pCreateInfo) {


Usually, we handle the primary structure directly and then call
vk_foreach_struct on pCreateInfo->pNext.  This is because the
things in the pNext chain are going to be modifiers to the
original thing so they probably need to happen between
allocating the callback and list_addtail().


Right, this would be for extending the functionality. I wrote it
like this because it seems for me that the typical pattern would be
to chain few report callbacks and send them all at once rather than
calling the function n times. I'll change so that I handle first
item out of the loop.


Is that allowed??? That would be weird but it honestly wouldn't surprise 
me that much for this extension.  Normally, you don't chain multiple of 
the same struct together.  You chain extension structs on to modify the 
original struct.  If inserting multiple callbacks at one go this way is 
allowed, then we should probably do it the way you did it.


Heh I see now that this was my own invention, I thought these chains 
allow one to create multiple objects with one call but that's not true, 
these are meant for extending. Sorry about that, will fix.




 +  switch (info->sType) {
 +  case
VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT: {
 + struct anv_debug_callback *cb =
 +vk_alloc(alloc, sizeof(struct
anv_debug_callback), 8,
 + VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
 + if (!cb)
 +return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 +
 + cb->flags = pCreateInfo->flags;
 + cb->callback = pCreateInfo->pfnCallback;
 + cb->data = pCreateInfo->pUserData;
 +
 + list_addtail(>link, >callbacks);


What kind of threading guarantees does debug_report provide? 
I'm guessing none in which case we need to lock around this list.



True, this is something I completely forgot. Will add locking.



 + break;
 +  }
 +  default:
 + anv_debug_ignored_stype(info->sType);
 + break;
 +  }
 +   }
 +
 +   return VK_SUCCESS;
 +}
 +
 +void
 +anv_DestroyDebugReportCallbackEXT(VkInstance _instance,
 +  VkDebugReportCallbackEXT
callback,
 +  const VkAllocationCallbacks*
 pAllocator)
 +{
 +   ANV_FROM_HANDLE(anv_instance, instance, _instance);
 +   const VkAllocationCallbacks *alloc =
 +  pAllocator ? pAllocator : >alloc;
 +
 +   list_for_each_entry_safe(struct anv_debug_callback,
debug_cb,
 +>callbacks, link) {
 +  /* Found a match, remove from list and destroy given
callback. */
 +  if ((VkDebugReportCallbackEXT)debug_cb->callback ==
callback) {
 + list_del(_cb->link);


lock

 + vk_free(alloc, debug_cb);
 +  }
 +   }
 +}
 +
 +void
 +anv_DebugReportMessageEXT(VkInstance _instance,
 +  VkDebugReportFlagsEXT flags,
 +  VkDebugReportObjectTypeEXT
objectType,
 +  uint64_t object,
 +  size_t location,
 +  int32_t messageCode,
 +  const char* pLayerPrefix,
 +  const char* pMessage)


Woah... This is a bit unexpected.  I wonder why this entrypoint
even exists.  One would think that the loader could just do the
aggrigation without it.


Yep, I was wondering about this one as well.

 +{
 +   ANV_FROM_HANDLE(anv_instance, instance, _instance);
 +   anv_debug_report(instance, flags, objectType, object,
 +location, messageCode, pLayerPrefix,
pMessage);
 +
 +}
 +
 +void
 +anv_debug_report_call(struct anv_debug_callback *cb,
 +  VkDebugReportFlagsEXT flags,
 +  VkDebugReportObjectTypeEXT object_type,
 +  

Re: [Mesa-dev] [PATCH 1/2] anv: implementation of VK_EXT_debug_report extension

2017-08-24 Thread Jason Ekstrand
On Thu, Aug 24, 2017 at 9:52 PM, Tapani Pälli 
wrote:

> Hi;
>
> On 08/24/2017 08:36 PM, Jason Ekstrand wrote:
>
>> On Wed, Aug 23, 2017 at 11:23 PM, Tapani Pälli > > wrote:
>>
>> Patch adds required functionality for extension to manage a list of
>> application provided callbacks and handle debug reporting from driver
>> and application side.
>>
>> Signed-off-by: Tapani Pälli > >
>>
>> ---
>>   src/intel/Makefile.sources  |   1 +
>>   src/intel/vulkan/anv_debug_report.c | 133
>> 
>>   src/intel/vulkan/anv_device.c   |  40 +++
>>   src/intel/vulkan/anv_extensions.py  |   1 +
>>   src/intel/vulkan/anv_private.h  |  32 +
>>   5 files changed, 207 insertions(+)
>>   create mode 100644 src/intel/vulkan/anv_debug_report.c
>>
>> diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources
>> index 4074ba9ee5..200713b06e 100644
>> --- a/src/intel/Makefile.sources
>> +++ b/src/intel/Makefile.sources
>> @@ -205,6 +205,7 @@ VULKAN_FILES := \
>>  vulkan/anv_batch_chain.c \
>>  vulkan/anv_blorp.c \
>>  vulkan/anv_cmd_buffer.c \
>> +   vulkan/anv_debug_report.c \
>>  vulkan/anv_descriptor_set.c \
>>  vulkan/anv_device.c \
>>  vulkan/anv_dump.c \
>> diff --git a/src/intel/vulkan/anv_debug_report.c
>> b/src/intel/vulkan/anv_debug_report.c
>> new file mode 100644
>> index 00..1a4868cd52
>> --- /dev/null
>> +++ b/src/intel/vulkan/anv_debug_report.c
>> @@ -0,0 +1,133 @@
>> +/*
>> + * Copyright © 2017 Intel Corporation
>> + *
>> + * Permission is hereby granted, free of charge, to any person
>> obtaining a
>> + * copy of this software and associated documentation files (the
>> "Software"),
>> + * to deal in the Software without restriction, including without
>> limitation
>> + * the rights to use, copy, modify, merge, publish, distribute,
>> sublicense,
>> + * and/or sell copies of the Software, and to permit persons to
>> whom the
>> + * Software is furnished to do so, subject to the following
>> conditions:
>> + *
>> + * The above copyright notice and this permission notice (including
>> the next
>> + * paragraph) shall be included in all copies or substantial
>> portions of the
>> + * Software.
>> + *
>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
>> EXPRESS OR
>> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
>> MERCHANTABILITY,
>> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO
>> EVENT SHALL
>> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
>> DAMAGES OR OTHER
>> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
>> ARISING
>> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
>> OTHER DEALINGS
>> + * IN THE SOFTWARE.
>> + */
>> +
>> +#include "anv_private.h"
>> +#include "vk_util.h"
>> +
>> +/* This file contains implementation for VK_EXT_debug_report. */
>> +
>> +VkResult
>> +anv_CreateDebugReportCallbackEXT(VkInstance _instance,
>> + const
>> VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
>> + const VkAllocationCallbacks*
>> pAllocator,
>> + VkDebugReportCallbackEXT* pCallback)
>> +{
>> +   ANV_FROM_HANDLE(anv_instance, instance, _instance);
>> +   const VkAllocationCallbacks *alloc =
>> +  pAllocator ? pAllocator : >alloc;
>>
>>
>> This is what vk_alloc2 is for.
>>
>
> Thanks, I had a feeling that there might be a helper for this but did not
> figure it out.
>
> +
>> +   vk_foreach_struct(info, pCreateInfo) {
>>
>>
>> Usually, we handle the primary structure directly and then call
>> vk_foreach_struct on pCreateInfo->pNext.  This is because the things in the
>> pNext chain are going to be modifiers to the original thing so they
>> probably need to happen between allocating the callback and list_addtail().
>>
>
> Right, this would be for extending the functionality. I wrote it like this
> because it seems for me that the typical pattern would be to chain few
> report callbacks and send them all at once rather than calling the function
> n times. I'll change so that I handle first item out of the loop.
>

Is that allowed??? That would be weird but it honestly wouldn't surprise me
that much for this extension.  Normally, you don't chain multiple of the
same struct together.  You chain extension structs on to modify the
original struct.  If inserting multiple callbacks at one go this way is
allowed, then we 

Re: [Mesa-dev] [PATCH 1/2] anv: implementation of VK_EXT_debug_report extension

2017-08-24 Thread Tapani Pälli

Hi;

On 08/24/2017 08:36 PM, Jason Ekstrand wrote:
On Wed, Aug 23, 2017 at 11:23 PM, Tapani Pälli > wrote:


Patch adds required functionality for extension to manage a list of
application provided callbacks and handle debug reporting from driver
and application side.

Signed-off-by: Tapani Pälli >
---
  src/intel/Makefile.sources  |   1 +
  src/intel/vulkan/anv_debug_report.c | 133

  src/intel/vulkan/anv_device.c   |  40 +++
  src/intel/vulkan/anv_extensions.py  |   1 +
  src/intel/vulkan/anv_private.h  |  32 +
  5 files changed, 207 insertions(+)
  create mode 100644 src/intel/vulkan/anv_debug_report.c

diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources
index 4074ba9ee5..200713b06e 100644
--- a/src/intel/Makefile.sources
+++ b/src/intel/Makefile.sources
@@ -205,6 +205,7 @@ VULKAN_FILES := \
 vulkan/anv_batch_chain.c \
 vulkan/anv_blorp.c \
 vulkan/anv_cmd_buffer.c \
+   vulkan/anv_debug_report.c \
 vulkan/anv_descriptor_set.c \
 vulkan/anv_device.c \
 vulkan/anv_dump.c \
diff --git a/src/intel/vulkan/anv_debug_report.c
b/src/intel/vulkan/anv_debug_report.c
new file mode 100644
index 00..1a4868cd52
--- /dev/null
+++ b/src/intel/vulkan/anv_debug_report.c
@@ -0,0 +1,133 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
obtaining a
+ * copy of this software and associated documentation files (the
"Software"),
+ * to deal in the Software without restriction, including without
limitation
+ * the rights to use, copy, modify, merge, publish, distribute,
sublicense,
+ * and/or sell copies of the Software, and to permit persons to
whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including
the next
+ * paragraph) shall be included in all copies or substantial
portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO
EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "anv_private.h"
+#include "vk_util.h"
+
+/* This file contains implementation for VK_EXT_debug_report. */
+
+VkResult
+anv_CreateDebugReportCallbackEXT(VkInstance _instance,
+ const
VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
+ const VkAllocationCallbacks*
pAllocator,
+ VkDebugReportCallbackEXT* pCallback)
+{
+   ANV_FROM_HANDLE(anv_instance, instance, _instance);
+   const VkAllocationCallbacks *alloc =
+  pAllocator ? pAllocator : >alloc;


This is what vk_alloc2 is for.


Thanks, I had a feeling that there might be a helper for this but did 
not figure it out.



+
+   vk_foreach_struct(info, pCreateInfo) {


Usually, we handle the primary structure directly and then call 
vk_foreach_struct on pCreateInfo->pNext.  This is because the things in 
the pNext chain are going to be modifiers to the original thing so they 
probably need to happen between allocating the callback and list_addtail().


Right, this would be for extending the functionality. I wrote it like 
this because it seems for me that the typical pattern would be to chain 
few report callbacks and send them all at once rather than calling the 
function n times. I'll change so that I handle first item out of the loop.




+  switch (info->sType) {
+  case VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT: {
+ struct anv_debug_callback *cb =
+vk_alloc(alloc, sizeof(struct anv_debug_callback), 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
+ if (!cb)
+return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+
+ cb->flags = pCreateInfo->flags;
+ cb->callback = pCreateInfo->pfnCallback;
+ cb->data = pCreateInfo->pUserData;
+
+ list_addtail(>link, >callbacks);


What kind of threading guarantees does debug_report provide?  I'm 
guessing none in which case we need to lock 

Re: [Mesa-dev] [PATCH 1/2] anv: implementation of VK_EXT_debug_report extension

2017-08-24 Thread Jason Ekstrand
On Wed, Aug 23, 2017 at 11:23 PM, Tapani Pälli 
wrote:

> Patch adds required functionality for extension to manage a list of
> application provided callbacks and handle debug reporting from driver
> and application side.
>
> Signed-off-by: Tapani Pälli 
> ---
>  src/intel/Makefile.sources  |   1 +
>  src/intel/vulkan/anv_debug_report.c | 133 ++
> ++
>  src/intel/vulkan/anv_device.c   |  40 +++
>  src/intel/vulkan/anv_extensions.py  |   1 +
>  src/intel/vulkan/anv_private.h  |  32 +
>  5 files changed, 207 insertions(+)
>  create mode 100644 src/intel/vulkan/anv_debug_report.c
>
> diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources
> index 4074ba9ee5..200713b06e 100644
> --- a/src/intel/Makefile.sources
> +++ b/src/intel/Makefile.sources
> @@ -205,6 +205,7 @@ VULKAN_FILES := \
> vulkan/anv_batch_chain.c \
> vulkan/anv_blorp.c \
> vulkan/anv_cmd_buffer.c \
> +   vulkan/anv_debug_report.c \
> vulkan/anv_descriptor_set.c \
> vulkan/anv_device.c \
> vulkan/anv_dump.c \
> diff --git a/src/intel/vulkan/anv_debug_report.c
> b/src/intel/vulkan/anv_debug_report.c
> new file mode 100644
> index 00..1a4868cd52
> --- /dev/null
> +++ b/src/intel/vulkan/anv_debug_report.c
> @@ -0,0 +1,133 @@
> +/*
> + * Copyright © 2017 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the
> "Software"),
> + * to deal in the Software without restriction, including without
> limitation
> + * the rights to use, copy, modify, merge, publish, distribute,
> sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the
> next
> + * paragraph) shall be included in all copies or substantial portions of
> the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT
> SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
> OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> DEALINGS
> + * IN THE SOFTWARE.
> + */
> +
> +#include "anv_private.h"
> +#include "vk_util.h"
> +
> +/* This file contains implementation for VK_EXT_debug_report. */
> +
> +VkResult
> +anv_CreateDebugReportCallbackEXT(VkInstance _instance,
> + const VkDebugReportCallbackCreateInfoEXT*
> pCreateInfo,
> + const VkAllocationCallbacks* pAllocator,
> + VkDebugReportCallbackEXT* pCallback)
> +{
> +   ANV_FROM_HANDLE(anv_instance, instance, _instance);
> +   const VkAllocationCallbacks *alloc =
> +  pAllocator ? pAllocator : >alloc;
>

This is what vk_alloc2 is for.


> +
> +   vk_foreach_struct(info, pCreateInfo) {
>

Usually, we handle the primary structure directly and then call
vk_foreach_struct on pCreateInfo->pNext.  This is because the things in the
pNext chain are going to be modifiers to the original thing so they
probably need to happen between allocating the callback and list_addtail().


> +  switch (info->sType) {
> +  case VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT: {
> + struct anv_debug_callback *cb =
> +vk_alloc(alloc, sizeof(struct anv_debug_callback), 8,
> + VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
> + if (!cb)
> +return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
> +
> + cb->flags = pCreateInfo->flags;
> + cb->callback = pCreateInfo->pfnCallback;
> + cb->data = pCreateInfo->pUserData;
> +
> + list_addtail(>link, >callbacks);
>

What kind of threading guarantees does debug_report provide?  I'm guessing
none in which case we need to lock around this list.


> + break;
> +  }
> +  default:
> + anv_debug_ignored_stype(info->sType);
> + break;
> +  }
> +   }
> +
> +   return VK_SUCCESS;
> +}
> +
> +void
> +anv_DestroyDebugReportCallbackEXT(VkInstance _instance,
> +  VkDebugReportCallbackEXT callback,
> +  const VkAllocationCallbacks* pAllocator)
> +{
> +   ANV_FROM_HANDLE(anv_instance, instance, _instance);
> +   const VkAllocationCallbacks *alloc =
> +  pAllocator ? pAllocator : >alloc;
> +
> +   list_for_each_entry_safe(struct anv_debug_callback, debug_cb,
> +>callbacks, link) {
> +  /* Found a match, remove from list and 

Re: [Mesa-dev] [PATCH 1/2] anv: implementation of VK_EXT_debug_report extension

2017-08-24 Thread Tapani Pälli
I've noticed one missing thing, for VK_ERROR_OUT_OF_HOST_MEMORY 
situations we would need function to call debug report without actual 
object (since we failed to allocate it!) by only passing object enum, 
maybe have a separate vk_memory_error macro for these cases?


On 08/24/2017 09:23 AM, Tapani Pälli wrote:

Patch adds required functionality for extension to manage a list of
application provided callbacks and handle debug reporting from driver
and application side.

Signed-off-by: Tapani Pälli 
---
  src/intel/Makefile.sources  |   1 +
  src/intel/vulkan/anv_debug_report.c | 133 
  src/intel/vulkan/anv_device.c   |  40 +++
  src/intel/vulkan/anv_extensions.py  |   1 +
  src/intel/vulkan/anv_private.h  |  32 +
  5 files changed, 207 insertions(+)
  create mode 100644 src/intel/vulkan/anv_debug_report.c

diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources
index 4074ba9ee5..200713b06e 100644
--- a/src/intel/Makefile.sources
+++ b/src/intel/Makefile.sources
@@ -205,6 +205,7 @@ VULKAN_FILES := \
vulkan/anv_batch_chain.c \
vulkan/anv_blorp.c \
vulkan/anv_cmd_buffer.c \
+   vulkan/anv_debug_report.c \
vulkan/anv_descriptor_set.c \
vulkan/anv_device.c \
vulkan/anv_dump.c \
diff --git a/src/intel/vulkan/anv_debug_report.c 
b/src/intel/vulkan/anv_debug_report.c
new file mode 100644
index 00..1a4868cd52
--- /dev/null
+++ b/src/intel/vulkan/anv_debug_report.c
@@ -0,0 +1,133 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "anv_private.h"
+#include "vk_util.h"
+
+/* This file contains implementation for VK_EXT_debug_report. */
+
+VkResult
+anv_CreateDebugReportCallbackEXT(VkInstance _instance,
+ const VkDebugReportCallbackCreateInfoEXT* 
pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkDebugReportCallbackEXT* pCallback)
+{
+   ANV_FROM_HANDLE(anv_instance, instance, _instance);
+   const VkAllocationCallbacks *alloc =
+  pAllocator ? pAllocator : >alloc;
+
+   vk_foreach_struct(info, pCreateInfo) {
+  switch (info->sType) {
+  case VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT: {
+ struct anv_debug_callback *cb =
+vk_alloc(alloc, sizeof(struct anv_debug_callback), 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
+ if (!cb)
+return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+
+ cb->flags = pCreateInfo->flags;
+ cb->callback = pCreateInfo->pfnCallback;
+ cb->data = pCreateInfo->pUserData;
+
+ list_addtail(>link, >callbacks);
+ break;
+  }
+  default:
+ anv_debug_ignored_stype(info->sType);
+ break;
+  }
+   }
+
+   return VK_SUCCESS;
+}
+
+void
+anv_DestroyDebugReportCallbackEXT(VkInstance _instance,
+  VkDebugReportCallbackEXT callback,
+  const VkAllocationCallbacks* pAllocator)
+{
+   ANV_FROM_HANDLE(anv_instance, instance, _instance);
+   const VkAllocationCallbacks *alloc =
+  pAllocator ? pAllocator : >alloc;
+
+   list_for_each_entry_safe(struct anv_debug_callback, debug_cb,
+>callbacks, link) {
+  /* Found a match, remove from list and destroy given callback. */
+  if ((VkDebugReportCallbackEXT)debug_cb->callback == callback) {
+ list_del(_cb->link);
+ vk_free(alloc, debug_cb);
+  }
+   }
+}
+
+void
+anv_DebugReportMessageEXT(VkInstance _instance,
+  VkDebugReportFlagsEXT flags,
+  VkDebugReportObjectTypeEXT objectType,
+  uint64_t object,
+  size_t location,
+   

[Mesa-dev] [PATCH 1/2] anv: implementation of VK_EXT_debug_report extension

2017-08-24 Thread Tapani Pälli
Patch adds required functionality for extension to manage a list of
application provided callbacks and handle debug reporting from driver
and application side.

Signed-off-by: Tapani Pälli 
---
 src/intel/Makefile.sources  |   1 +
 src/intel/vulkan/anv_debug_report.c | 133 
 src/intel/vulkan/anv_device.c   |  40 +++
 src/intel/vulkan/anv_extensions.py  |   1 +
 src/intel/vulkan/anv_private.h  |  32 +
 5 files changed, 207 insertions(+)
 create mode 100644 src/intel/vulkan/anv_debug_report.c

diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources
index 4074ba9ee5..200713b06e 100644
--- a/src/intel/Makefile.sources
+++ b/src/intel/Makefile.sources
@@ -205,6 +205,7 @@ VULKAN_FILES := \
vulkan/anv_batch_chain.c \
vulkan/anv_blorp.c \
vulkan/anv_cmd_buffer.c \
+   vulkan/anv_debug_report.c \
vulkan/anv_descriptor_set.c \
vulkan/anv_device.c \
vulkan/anv_dump.c \
diff --git a/src/intel/vulkan/anv_debug_report.c 
b/src/intel/vulkan/anv_debug_report.c
new file mode 100644
index 00..1a4868cd52
--- /dev/null
+++ b/src/intel/vulkan/anv_debug_report.c
@@ -0,0 +1,133 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "anv_private.h"
+#include "vk_util.h"
+
+/* This file contains implementation for VK_EXT_debug_report. */
+
+VkResult
+anv_CreateDebugReportCallbackEXT(VkInstance _instance,
+ const VkDebugReportCallbackCreateInfoEXT* 
pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkDebugReportCallbackEXT* pCallback)
+{
+   ANV_FROM_HANDLE(anv_instance, instance, _instance);
+   const VkAllocationCallbacks *alloc =
+  pAllocator ? pAllocator : >alloc;
+
+   vk_foreach_struct(info, pCreateInfo) {
+  switch (info->sType) {
+  case VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT: {
+ struct anv_debug_callback *cb =
+vk_alloc(alloc, sizeof(struct anv_debug_callback), 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
+ if (!cb)
+return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+
+ cb->flags = pCreateInfo->flags;
+ cb->callback = pCreateInfo->pfnCallback;
+ cb->data = pCreateInfo->pUserData;
+
+ list_addtail(>link, >callbacks);
+ break;
+  }
+  default:
+ anv_debug_ignored_stype(info->sType);
+ break;
+  }
+   }
+
+   return VK_SUCCESS;
+}
+
+void
+anv_DestroyDebugReportCallbackEXT(VkInstance _instance,
+  VkDebugReportCallbackEXT callback,
+  const VkAllocationCallbacks* pAllocator)
+{
+   ANV_FROM_HANDLE(anv_instance, instance, _instance);
+   const VkAllocationCallbacks *alloc =
+  pAllocator ? pAllocator : >alloc;
+
+   list_for_each_entry_safe(struct anv_debug_callback, debug_cb,
+>callbacks, link) {
+  /* Found a match, remove from list and destroy given callback. */
+  if ((VkDebugReportCallbackEXT)debug_cb->callback == callback) {
+ list_del(_cb->link);
+ vk_free(alloc, debug_cb);
+  }
+   }
+}
+
+void
+anv_DebugReportMessageEXT(VkInstance _instance,
+  VkDebugReportFlagsEXT flags,
+  VkDebugReportObjectTypeEXT objectType,
+  uint64_t object,
+  size_t location,
+  int32_t messageCode,
+  const char* pLayerPrefix,
+  const char* pMessage)
+{
+   ANV_FROM_HANDLE(anv_instance, instance, _instance);
+   anv_debug_report(instance, flags, objectType, object,
+location, messageCode, pLayerPrefix,