On Fri, 30 Jul 2021 at 17:09, Jan Sikorski <jsikorski(a)codeweavers.com> wrote:
@@ -1410,14 +1411,22 @@ static BOOL wined3d_buffer_vk_create_buffer_object(struct wined3d_buffer_vk *buf FIXME("Ignoring some bind flags %#x.\n", bind_flags);
memory_type = 0; + if (!(resource->usage & WINED3DUSAGE_DYNAMIC)) + 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; else if (resource->access & WINED3D_RESOURCE_ACCESS_MAP_W) memory_type |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; - else if (!(resource->usage & WINED3DUSAGE_DYNAMIC)) - memory_type |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
- if (!(wined3d_context_vk_create_bo(context_vk, resource->size, usage, memory_type, &buffer_vk->bo))) + success = wined3d_context_vk_create_bo(context_vk, resource->size, usage, memory_type, &buffer_vk->bo); + if (!success && memory_type & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) + success = wined3d_context_vk_create_bo(context_vk, resource->size, usage, + memory_type & ~VK_MEMORY_PROPERTY_HOST_CACHED_BIT, &buffer_vk->bo); + if (!success && memory_type & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) + success = wined3d_context_vk_create_bo(context_vk, resource->size, usage, + memory_type & ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &buffer_vk->bo); + + if (!success) { WARN("Failed to create Vulkan buffer.\n"); return FALSE;
I think this works, but it still feels a little unfortunate. The nice thing about the vkd3d approach (using a list of acceptable memory types) is that it would allow the failover to be mostly handled in wined3d_context_vk_create_bo(), while at the same time making it very clear which memory types are tried.