[PATCH vkd3d 1/3] vkd3d: Implement d3d12_query_heap_SetName().

Zhiyi Zhang zzhang at codeweavers.com
Tue Jan 29 21:02:01 CST 2019


On 30/01/2019 05:14, Henri Verbeet wrote:
> From: Zhiyi Zhang <zzhang at codeweavers.com>
>
> Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
> Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
> ---
> Note that I made a few (minor) modifications; it would be good if Zhiyi
> could confirm that this still does something reasonable for his
> application.

Thanks for the clean up. It should work as long as *SetName() don't

return E_NOTIMPL anymore.

>
>  Makefile.am                  |   4 +-
>  include/private/vkd3d_utf8.h |  26 +++++++
>  libs/vkd3d-common/utf8.c     | 162 +++++++++++++++++++++++++++++++++++++++++++
>  libs/vkd3d/device.c          |   1 +
>  libs/vkd3d/resource.c        |   5 +-
>  libs/vkd3d/utils.c           |  29 ++++++++
>  libs/vkd3d/vkd3d_private.h   |   5 ++
>  libs/vkd3d/vulkan_procs.h    |   2 +
>  8 files changed, 231 insertions(+), 3 deletions(-)
>  create mode 100644 include/private/vkd3d_utf8.h
>  create mode 100644 libs/vkd3d-common/utf8.c
>
> diff --git a/Makefile.am b/Makefile.am
> index 7869b2e..487d2ea 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -59,7 +59,8 @@ noinst_LTLIBRARIES = libvkd3d-common.la
>  libvkd3d_common_la_SOURCES = \
>  	include/private/vkd3d_debug.h \
>  	libs/vkd3d-common/debug.c \
> -	libs/vkd3d-common/memory.c
> +	libs/vkd3d-common/memory.c \
> +	libs/vkd3d-common/utf8.c
>  
>  lib_LTLIBRARIES = libvkd3d-shader.la libvkd3d.la libvkd3d-utils.la
>  
> @@ -88,6 +89,7 @@ libvkd3d_la_SOURCES = \
>  	include/private/vkd3d_common.h \
>  	include/private/vkd3d_debug.h \
>  	include/private/vkd3d_memory.h \
> +	include/private/vkd3d_utf8.h \
>  	include/private/vkd3d_test.h \
>  	include/vkd3d_d3d12.idl \
>  	include/vkd3d_d3dcommon.idl \
> diff --git a/include/private/vkd3d_utf8.h b/include/private/vkd3d_utf8.h
> new file mode 100644
> index 0000000..ab32884
> --- /dev/null
> +++ b/include/private/vkd3d_utf8.h
> @@ -0,0 +1,26 @@
> +/*
> + * Copyright 2019 Zhiyi Zhang for CodeWeavers
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
> + */
> +
> +#ifndef __VKD3D_UTF8_H
> +#define __VKD3D_UTF8_H
> +
> +#include "vkd3d_common.h"
> +
> +char *vkd3d_strdup_w_utf8(const WCHAR *wstr, size_t wchar_size) DECLSPEC_HIDDEN;
> +
> +#endif /* __VKD3D_UTF8_H */
> diff --git a/libs/vkd3d-common/utf8.c b/libs/vkd3d-common/utf8.c
> new file mode 100644
> index 0000000..e48316d
> --- /dev/null
> +++ b/libs/vkd3d-common/utf8.c
> @@ -0,0 +1,162 @@
> +/*
> + * Copyright 2000 Alexandre Julliard
> + * Copyright 2019 Zhiyi Zhang for CodeWeavers
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
> + */
> +
> +#include "vkd3d_memory.h"
> +#include "vkd3d_utf8.h"
> +
> +#include <inttypes.h>
> +
> +static size_t vkd3d_utf8_len(uint32_t c)
> +{
> +    /* 0x00-0x7f: 1 byte */
> +    if (c < 0x80)
> +        return 1;
> +    /* 0x80-0x7ff: 2 bytes */
> +    if (c < 0x800)
> +        return 2;
> +    /* 0x800-0xffff: 3 bytes */
> +    if (c < 0x10000)
> +        return 3;
> +    /* 0x10000-0x10ffff: 4 bytes */
> +    return 4;
> +}
> +
> +static void vkd3d_utf8_append(char **dst, uint32_t c)
> +{
> +    char *d = *dst;
> +
> +    /* 0x00-0x7f: 1 byte */
> +    if (c < 0x80)
> +    {
> +        d[0] = c;
> +        *dst += 1;
> +        return;
> +    }
> +
> +    /* 0x80-0x7ff: 2 bytes */
> +    if (c < 0x800)
> +    {
> +        d[1] = 0x80 | (c & 0x3f);
> +        c >>= 6;
> +        d[0] = 0xc0 | c;
> +        *dst += 2;
> +        return;
> +    }
> +
> +    /* 0x800-0xffff: 3 bytes */
> +    if (c < 0x10000)  /* 0x800-0xffff: 3 bytes */
> +    {
> +        d[2] = 0x80 | (c & 0x3f);
> +        c >>= 6;
> +        d[1] = 0x80 | (c & 0x3f);
> +        c >>= 6;
> +        d[0] = 0xe0 | c;
> +        *dst += 3;
> +        return;
> +    }
> +
> +    /* 0x10000-0x10ffff: 4 bytes */
> +    d[3] = 0x80 | (c & 0x3f);
> +    c >>= 6;
> +    d[2] = 0x80 | (c & 0x3f);
> +    c >>= 6;
> +    d[1] = 0x80 | (c & 0x3f);
> +    c >>= 6;
> +    d[0] = 0xf0 | c;
> +    *dst += 4;
> +}
> +
> +static uint32_t vkd3d_utf16_read(const uint16_t **src)
> +{
> +    const uint16_t *s = *src;
> +
> +    if (s[0] < 0xd800 || s[0] > 0xdfff) /* Not a surrogate pair. */
> +    {
> +        *src += 1;
> +        return s[0];
> +    }
> +
> +    if (s[0] > 0xdbff /* Invalid high surrogate. */
> +            || s[1] < 0xdc00 || s[1] > 0xdfff) /* Invalid low surrogate. */
> +    {
> +        *src += 1;
> +        return 0;
> +    }
> +
> +    *src += 2;
> +    return 0x10000 + ((s[0] & 0x3ff) << 10) + (s[1] & 0x3ff);
> +}
> +
> +static char *vkd3d_strdup_w16_utf8(const uint16_t *wstr)
> +{
> +    const uint16_t *src = wstr;
> +    size_t dst_size = 0;
> +    uint32_t c;
> +    char *dst;
> +
> +    while (*src)
> +    {
> +        if (!(c = vkd3d_utf16_read(&src)))
> +            continue;
> +        dst_size += vkd3d_utf8_len(c);
> +    }
> +    ++dst_size;
> +
> +    if (!(dst = vkd3d_malloc(dst_size)))
> +        return NULL;
> +
> +    src = wstr;
> +    while (*src)
> +    {
> +        if (!(c = vkd3d_utf16_read(&src)))
> +            continue;
> +        vkd3d_utf8_append(&dst, c);
> +    }
> +    *dst = 0;
> +
> +    return dst;
> +}
> +
> +static char *vkd3d_strdup_w32_utf8(const uint32_t *wstr)
> +{
> +    const uint32_t *src = wstr;
> +    size_t dst_size = 0;
> +    char *dst;
> +
> +    while (*src)
> +        dst_size += vkd3d_utf8_len(*src++);
> +    ++dst_size;
> +
> +    if (!(dst = vkd3d_malloc(dst_size)))
> +        return NULL;
> +
> +    src = wstr;
> +    while (*src)
> +        vkd3d_utf8_append(&dst, *src++);
> +    *dst = 0;
> +
> +    return dst;
> +}
> +
> +char *vkd3d_strdup_w_utf8(const WCHAR *wstr, size_t wchar_size)
> +{
> +    if (wchar_size == 2)
> +        return vkd3d_strdup_w16_utf8((const uint16_t *)wstr);
> +    return vkd3d_strdup_w32_utf8((const uint32_t *)wstr);
> +}
> diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c
> index 64c8391..4b5f522 100644
> --- a/libs/vkd3d/device.c
> +++ b/libs/vkd3d/device.c
> @@ -84,6 +84,7 @@ static const char * const required_device_extensions[] =
>  static const struct vkd3d_optional_extension_info optional_device_extensions[] =
>  {
>      {VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, KHR_push_descriptor)},
> +    {VK_EXT_DEBUG_MARKER_EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, EXT_debug_marker)},
>      {VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME,
>              offsetof(struct vkd3d_vulkan_info, EXT_transform_feedback)},
>      {VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME,
> diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c
> index 6eba450..158240d 100644
> --- a/libs/vkd3d/resource.c
> +++ b/libs/vkd3d/resource.c
> @@ -2730,9 +2730,10 @@ static HRESULT STDMETHODCALLTYPE d3d12_query_heap_SetName(ID3D12QueryHeap *iface
>  {
>      struct d3d12_query_heap *heap = impl_from_ID3D12QueryHeap(iface);
>  
> -    FIXME("iface %p, name %s stub!\n", iface, debugstr_w(name, heap->device->wchar_size));
> +    TRACE("iface %p, name %s.\n", iface, debugstr_w(name, heap->device->wchar_size));
>  
> -    return E_NOTIMPL;
> +    return vkd3d_set_vk_object_name(heap->device, (uint64_t)heap->vk_query_pool,
> +            VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, name);
>  }
>  
>  static HRESULT STDMETHODCALLTYPE d3d12_query_heap_GetDevice(ID3D12QueryHeap *iface,
> diff --git a/libs/vkd3d/utils.c b/libs/vkd3d/utils.c
> index 0144fdc..27333f2 100644
> --- a/libs/vkd3d/utils.c
> +++ b/libs/vkd3d/utils.c
> @@ -642,3 +642,32 @@ HRESULT vkd3d_set_private_data_interface(struct vkd3d_private_store *store,
>      pthread_mutex_unlock(&store->mutex);
>      return hr;
>  }
> +
> +HRESULT vkd3d_set_vk_object_name(struct d3d12_device *device, uint64_t vk_object,
> +        VkDebugReportObjectTypeEXT vk_object_type, const WCHAR *name)
> +{
> +    const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
> +    VkDebugMarkerObjectNameInfoEXT info;
> +    char *name_utf8;
> +    VkResult vr;
> +
> +    if (!name)
> +        return E_INVALIDARG;
> +
> +    if (!device->vk_info.EXT_debug_marker)
> +        return S_OK;
> +
> +    if (!(name_utf8 = vkd3d_strdup_w_utf8(name, device->wchar_size)))
> +        return E_OUTOFMEMORY;
> +
> +    info.sType = VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT;
> +    info.pNext = NULL;
> +    info.objectType = vk_object_type;
> +    info.object = vk_object;
> +    info.pObjectName = name_utf8;
> +    vr = VK_CALL(vkDebugMarkerSetObjectNameEXT(device->vk_device, &info));
> +
> +    vkd3d_free(name_utf8);
> +
> +    return hresult_from_vk_result(vr);
> +}
> diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h
> index 73825bb..69e2cf7 100644
> --- a/libs/vkd3d/vkd3d_private.h
> +++ b/libs/vkd3d/vkd3d_private.h
> @@ -25,6 +25,7 @@
>  
>  #include "vkd3d_common.h"
>  #include "vkd3d_memory.h"
> +#include "vkd3d_utf8.h"
>  #include "list.h"
>  #include "rbtree.h"
>  
> @@ -87,6 +88,7 @@ struct vkd3d_vulkan_info
>      bool EXT_debug_report;
>      /* device extensions */
>      bool KHR_push_descriptor;
> +    bool EXT_debug_marker;
>      bool EXT_transform_feedback;
>      bool EXT_vertex_attribute_divisor;
>  
> @@ -1026,4 +1028,7 @@ static inline void vkd3d_set_thread_name(const char *name)
>  #endif
>  }
>  
> +HRESULT vkd3d_set_vk_object_name(struct d3d12_device *device, uint64_t vk_object,
> +        VkDebugReportObjectTypeEXT vk_object_type, const WCHAR *name) DECLSPEC_HIDDEN;
> +
>  #endif  /* __VKD3D_PRIVATE_H */
> diff --git a/libs/vkd3d/vulkan_procs.h b/libs/vkd3d/vulkan_procs.h
> index be983ec..b62af4e 100644
> --- a/libs/vkd3d/vulkan_procs.h
> +++ b/libs/vkd3d/vulkan_procs.h
> @@ -174,6 +174,8 @@ VK_DEVICE_PFN(vkSetEvent)
>  VK_DEVICE_PFN(vkUnmapMemory)
>  VK_DEVICE_PFN(vkUpdateDescriptorSets)
>  VK_DEVICE_PFN(vkWaitForFences)
> +/* VK_EXT_debug_marker */
> +VK_DEVICE_EXT_PFN(vkDebugMarkerSetObjectNameEXT)
>  /* VK_KHR_push_descriptor */
>  VK_DEVICE_EXT_PFN(vkCmdPushDescriptorSetKHR)
>  /* VK_EXT_transform_feedback */



More information about the wine-devel mailing list