[PATCH v5 1/3] winevulkan: Generate helpers for wrapped handles.

Liam Middlebrook lmiddlebrook at nvidia.com
Tue Sep 29 18:17:53 CDT 2020



On 9/25/20 8:16 AM, Georg Lehmann wrote:
> Signed-off-by: Georg Lehmann <dadschoorse at gmail.com>
> ---
>   dlls/winevulkan/make_vulkan      | 51 ++++++++++++++++++++++++++++++--
>   dlls/winevulkan/vulkan.c         | 21 ++-----------
>   dlls/winevulkan/vulkan_private.h |  3 ++
>   3 files changed, 53 insertions(+), 22 deletions(-)
> 
> diff --git a/dlls/winevulkan/make_vulkan b/dlls/winevulkan/make_vulkan
> index 2cddb161d6..afea087a92 100755
> --- a/dlls/winevulkan/make_vulkan
> +++ b/dlls/winevulkan/make_vulkan
> @@ -939,9 +939,6 @@ class VkHandle(object):
>       def native_handle(self, name):
>           """ Provide access to the native handle of a wrapped object. """
>   
> -        # Remember to add any new native handle whose parent is VkDevice
> -        # to unwrap_object_handle() in vulkan.c
> -
>           if self.name == "VkCommandPool":
>               return "wine_cmd_pool_from_handle({0})->command_pool".format(name)
>   
> @@ -965,6 +962,24 @@ class VkHandle(object):
>               LOGGER.error("Unhandled native handle for: {0}".format(self.name))
>           return None
>   
> +    def is_wrapped(self):
> +        return self.native_handle("test") is not None
> +
> +    def object_type(self):
> +        """ Generates the matching VkObjectType """
> +
> +        # FIXME: use the xml comments for VkObjectType instead
> +        if not self.name.startswith("Vk") or any(c.isdigit() for c in self.name):
> +            LOGGER.warn("object type generation might fail for: {0}".format(self.name))

I think it would be good to define out a VkObjectType class that is 
parsed into the VkRegistry. Then at generation time, you should be able 
to look up the VkObjectType's value/name from the comment.

I'd prefer to see this patch without the FIXME.

> +
> +        type_ = "VK_OBJECT_TYPE"
> +        previous = "f"
> +        for char in self.name[2:]:
> +            if char.isupper() and previous.islower():
> +                type_ += "_"
> +            type_ += char.upper()
> +            previous = char
> +        return type_
>   
>   class VkMember(object):
>       def __init__(self, const=False, struct_fwd_decl=False,_type=None, pointer=None, name=None, array_len=None,
> @@ -2276,6 +2291,36 @@ class VkGenerator(object):
>           f.write("            return TRUE;\n")
>           f.write("    }\n")
>           f.write("    return FALSE;\n")
> +        f.write("}\n\n")
> +
> +        f.write("BOOL wine_vk_is_type_wrapped(VkObjectType type)\n")
> +        f.write("{\n")
> +        f.write("    return ")
> +        for handle in self.registry.handles:
> +            if not handle.is_required() or not handle.is_wrapped():
> +                continue
> +            f.write("type == {} || ".format(handle.object_type()))
> +        f.write("FALSE;\n")
> +        f.write("}\n\n")

While it's generated code so it probably doesn't matter much. I think it 
would be nice if there were some newlines here.

How about generating it to look like:

> +BOOL wine_vk_is_type_wrapped(VkObjectType type)
> +{
> +    return FALSE ||
> +           type == VK_OBJECT_TYPE_COMMAND_BUFFER ||
> +           type == VK_OBJECT_TYPE_COMMAND_POOL ||
> +           type == VK_OBJECT_TYPE_DEVICE ||
> +           type == VK_OBJECT_TYPE_INSTANCE ||
> +           type == VK_OBJECT_TYPE_PHYSICAL_DEVICE ||
> +           type == VK_OBJECT_TYPE_QUEUE;
> +}

Thanks,

Liam Middlebrook

> +
> +        f.write("uint64_t wine_vk_unwrap_handle(VkObjectType type, uint64_t handle)\n")
> +        f.write("{\n")
> +        f.write("    switch(type)\n")
> +        f.write("    {\n")
> +        for handle in self.registry.handles:
> +            if not handle.is_required() or not handle.is_wrapped():
> +                continue
> +            f.write("    case {}:\n".format(handle.object_type()))
> +            if handle.is_dispatchable():
> +                f.write("        return (uint64_t) (uintptr_t) ")
> +                f.write(handle.native_handle("(({}) (uintptr_t) handle)".format(handle.name)))
> +            else:
> +                f.write("        return (uint64_t) ")
> +                f.write(handle.native_handle("handle"))
> +            f.write(";\n");
> +        f.write("    default:\n")
> +        f.write("       return handle;\n")
> +        f.write("    }\n")
>           f.write("}\n")
>   
>       def generate_thunks_h(self, f, prefix):
> diff --git a/dlls/winevulkan/vulkan.c b/dlls/winevulkan/vulkan.c
> index f730c04923..3d1e8bd0ab 100644
> --- a/dlls/winevulkan/vulkan.c
> +++ b/dlls/winevulkan/vulkan.c
> @@ -1534,30 +1534,13 @@ void WINAPI wine_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR(VkPhysicalDev
>       properties->externalSemaphoreFeatures = 0;
>   }
>   
> -static uint64_t unwrap_object_handle(VkObjectType type, uint64_t handle)
> -{
> -    switch (type)
> -    {
> -        case VK_OBJECT_TYPE_DEVICE:
> -            return (uint64_t) (uintptr_t) ((VkDevice) (uintptr_t) handle)->device;
> -        case VK_OBJECT_TYPE_QUEUE:
> -            return (uint64_t) (uintptr_t) ((VkQueue) (uintptr_t) handle)->queue;
> -        case VK_OBJECT_TYPE_COMMAND_BUFFER:
> -            return (uint64_t) (uintptr_t) ((VkCommandBuffer) (uintptr_t) handle)->command_buffer;
> -        case VK_OBJECT_TYPE_COMMAND_POOL:
> -            return (uint64_t) wine_cmd_pool_from_handle(handle)->command_pool;
> -        default:
> -            return handle;
> -    }
> -}
> -
>   VkResult WINAPI wine_vkSetPrivateDataEXT(VkDevice device, VkObjectType object_type, uint64_t object_handle,
>           VkPrivateDataSlotEXT private_data_slot, uint64_t data)
>   {
>       TRACE("%p, %#x, 0x%s, 0x%s, 0x%s\n", device, object_type, wine_dbgstr_longlong(object_handle),
>               wine_dbgstr_longlong(private_data_slot), wine_dbgstr_longlong(data));
>   
> -    object_handle = unwrap_object_handle(object_type, object_handle);
> +    object_handle = wine_vk_unwrap_handle(object_type, object_handle);
>       return device->funcs.p_vkSetPrivateDataEXT(device->device, object_type, object_handle, private_data_slot, data);
>   }
>   
> @@ -1567,7 +1550,7 @@ void WINAPI wine_vkGetPrivateDataEXT(VkDevice device, VkObjectType object_type,
>       TRACE("%p, %#x, 0x%s, 0x%s, %p\n", device, object_type, wine_dbgstr_longlong(object_handle),
>               wine_dbgstr_longlong(private_data_slot), data);
>   
> -    object_handle = unwrap_object_handle(object_type, object_handle);
> +    object_handle = wine_vk_unwrap_handle(object_type, object_handle);
>       device->funcs.p_vkGetPrivateDataEXT(device->device, object_type, object_handle, private_data_slot, data);
>   }
>   
> diff --git a/dlls/winevulkan/vulkan_private.h b/dlls/winevulkan/vulkan_private.h
> index 4bcc4de440..bf09401c52 100644
> --- a/dlls/winevulkan/vulkan_private.h
> +++ b/dlls/winevulkan/vulkan_private.h
> @@ -138,4 +138,7 @@ void *wine_vk_get_instance_proc_addr(const char *name) DECLSPEC_HIDDEN;
>   BOOL wine_vk_device_extension_supported(const char *name) DECLSPEC_HIDDEN;
>   BOOL wine_vk_instance_extension_supported(const char *name) DECLSPEC_HIDDEN;
>   
> +BOOL wine_vk_is_type_wrapped(VkObjectType type) DECLSPEC_HIDDEN;
> +uint64_t wine_vk_unwrap_handle(VkObjectType type, uint64_t handle) DECLSPEC_HIDDEN;
> +
>   #endif /* __WINE_VULKAN_PRIVATE_H */
> 



More information about the wine-devel mailing list