[PATCH] wined3d: Negiotiate less specific memory types on allocation failure.

Zebediah Figura (she/her) zfigura at codeweavers.com
Thu Jul 29 11:36:02 CDT 2021


On 7/29/21 11:31 AM, Jan Sikorski wrote:
> Drop HOST_CACHED and/or DEVICE_LOCAL properties in case the device does
> not support a particular combination or there is no more space in a heap.
> 
> Signed-off-by: Jan Sikorski <jsikorski at codeweavers.com>
> ---
> Superseeds 210471
> ---
>   dlls/wined3d/buffer.c | 24 ++++++++++++++++++------
>   1 file changed, 18 insertions(+), 6 deletions(-)
> 
> diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
> index 4c5e2054fe0..6b0d84ce7a0 100644
> --- a/dlls/wined3d/buffer.c
> +++ b/dlls/wined3d/buffer.c
> @@ -1387,8 +1387,8 @@ static BOOL wined3d_buffer_vk_create_buffer_object(struct wined3d_buffer_vk *buf
>           struct wined3d_context_vk *context_vk)
>   {
>       struct wined3d_resource *resource = &buffer_vk->b.resource;
> +    VkMemoryPropertyFlags memory_type, want_memory_type;
>       uint32_t bind_flags = resource->bind_flags;
> -    VkMemoryPropertyFlags memory_type;
>       VkBufferUsageFlags usage;
>   
>       usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
> @@ -1409,16 +1409,28 @@ static BOOL wined3d_buffer_vk_create_buffer_object(struct wined3d_buffer_vk *buf
>       if (bind_flags & (WINED3D_BIND_RENDER_TARGET | WINED3D_BIND_DEPTH_STENCIL))
>           FIXME("Ignoring some bind flags %#x.\n", bind_flags);
>   
> -    memory_type = 0;
> +    want_memory_type = 0;
>       if (!(resource->usage & WINED3DUSAGE_DYNAMIC))
> -        memory_type |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
> +        want_memory_type |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
>       if (resource->access & WINED3D_RESOURCE_ACCESS_MAP_R)
> -        memory_type |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
> +        want_memory_type |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
>       else if (resource->access & WINED3D_RESOURCE_ACCESS_MAP_W)
> -        memory_type |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
> +        want_memory_type |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
>   
> -    if (!(wined3d_context_vk_create_bo(context_vk, resource->size, usage, memory_type, &buffer_vk->bo)))
> +    memory_type = want_memory_type;
> +
> +    while (!wined3d_context_vk_create_bo(context_vk, resource->size, usage, memory_type, &buffer_vk->bo))
>       {
> +        if (memory_type & VK_MEMORY_PROPERTY_HOST_CACHED_BIT)
> +        {
> +            memory_type = want_memory_type & ~VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
> +            continue;
> +        }
> +        if (memory_type & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
> +        {
> +            memory_type = (want_memory_type &= ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
> +            continue;
> +        }
>           WARN("Failed to create Vulkan buffer.\n");
>           return FALSE;
>       }
> 


This will still spew an ERR message, though, which seems less than ideal.

Also, the while loop seems awkward to me, couldn't we instead do 
something like (abbreviated):

if (!wined3d_context_vk_create_bo(memory_type)
         && !wined3d_context_vk_create_bo(memory_type & ~HOST_CACHED)
         && !wined3d_context_vk_create_bo(memory_type & ~DEVICE_LOCAL))



More information about the wine-devel mailing list