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@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; }
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@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))
On 29 Jul 2021, at 18:36, Zebediah Figura (she/her) zfigura@codeweavers.com wrote:
This will still spew an ERR message, though, which seems less than ideal.
Maybe “Failed to find a suitable memory type” could be a WARN instead? I think other failures could stay ERR. I’d upgrade to an ERR at the call site as well.
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))
Yeah, it isn’t exactly equivalent (the loop could go DCV -> DV -> VC -> V), but I guess the last step isn’t helping much. I’ll do the simplified thing in v2.
- Jan