[PATCH v2 1/2] wined3d: Negiotiate less specific memory types on allocation failure.
Try to combine DEVICE_LOCAL with HOST_CACHED and HOST_VISIBLE properties. Drop HOST_CACHED or DEVICE_LOCAL 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(a)codeweavers.com> --- v2: simplified sequence --- dlls/wined3d/buffer.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 4420885b15f..afe186042e5 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -1390,6 +1390,7 @@ static BOOL wined3d_buffer_vk_create_buffer_object(struct wined3d_buffer_vk *buf uint32_t bind_flags = resource->bind_flags; VkMemoryPropertyFlags memory_type; VkBufferUsageFlags usage; + BOOL success; usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; if (bind_flags & WINED3D_BIND_VERTEX_BUFFER) @@ -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; -- 2.30.2
Signed-off-by: Jan Sikorski <jsikorski(a)codeweavers.com> --- dlls/wined3d/buffer.c | 2 +- dlls/wined3d/context_vk.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index afe186042e5..9b026171665 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -1428,7 +1428,7 @@ static BOOL wined3d_buffer_vk_create_buffer_object(struct wined3d_buffer_vk *buf if (!success) { - WARN("Failed to create Vulkan buffer.\n"); + ERR("Failed to create Vulkan buffer.\n"); return FALSE; } diff --git a/dlls/wined3d/context_vk.c b/dlls/wined3d/context_vk.c index c718f3facd5..0c5bc2dc6b2 100644 --- a/dlls/wined3d/context_vk.c +++ b/dlls/wined3d/context_vk.c @@ -376,7 +376,7 @@ static bool wined3d_context_vk_create_slab_bo(struct wined3d_context_vk *context slab->requested_memory_type = memory_type; if (!wined3d_context_vk_create_bo(context_vk, key.size, usage, memory_type, &slab->bo)) { - ERR("Failed to create slab bo.\n"); + WARN("Failed to create slab bo.\n"); heap_free(slab); return false; } @@ -460,7 +460,7 @@ BOOL wined3d_context_vk_create_bo(struct wined3d_context_vk *context_vk, VkDevic memory_requirements.memoryTypeBits, memory_type); if (memory_type_idx == ~0u) { - ERR("Failed to find suitable memory type.\n"); + WARN("Failed to find suitable memory type.\n"); VK_CALL(vkDestroyBuffer(device_vk->vk_device, bo->vk_buffer, NULL)); return FALSE; } -- 2.30.2
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.
participants (2)
-
Henri Verbeet -
Jan Sikorski