Some driver, e.g. MoltenVK, fail in some cases if the image view usage is too broad or unknown.
-- v2: wined3d: Expose the image view usage for non-default views. wined3d: Expose the image view usage for null views. wined3d: Mark an extension as supported if it is core for the Vulkan version in use.
From: Giovanni Mascellani gmascellani@codeweavers.com
--- dlls/wined3d/adapter_vk.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/dlls/wined3d/adapter_vk.c b/dlls/wined3d/adapter_vk.c index d6f4449ce06..e6152ad3026 100644 --- a/dlls/wined3d/adapter_vk.c +++ b/dlls/wined3d/adapter_vk.c @@ -2436,14 +2436,30 @@ static bool wined3d_adapter_vk_init_device_extensions(struct wined3d_adapter_vk
for (i = 0; i < ARRAY_SIZE(map); ++i) { + bool supported = false; + for (j = 0; j < enable_count; ++j) { if (!strcmp(enabled_extensions[j], map[i].name)) { - vk_info->supported[map[i].extension] = TRUE; + supported = true; break; } } + + if (!supported) + { + for (j = 0; j < ARRAY_SIZE(info); ++j) + { + if (!strcmp(info[j].name, map[i].name) && info[j].core_since_version >= vk_info->api_version) + { + supported = true; + break; + } + } + } + + vk_info->supported[map[i].extension] = supported; }
done:
From: Giovanni Mascellani gmascellani@codeweavers.com
--- dlls/wined3d/adapter_vk.c | 2 ++ dlls/wined3d/device.c | 11 +++++++++++ dlls/wined3d/wined3d_vk.h | 1 + 3 files changed, 14 insertions(+)
diff --git a/dlls/wined3d/adapter_vk.c b/dlls/wined3d/adapter_vk.c index e6152ad3026..7aa3155f42b 100644 --- a/dlls/wined3d/adapter_vk.c +++ b/dlls/wined3d/adapter_vk.c @@ -2358,6 +2358,7 @@ static bool wined3d_adapter_vk_init_device_extensions(struct wined3d_adapter_vk {VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME, ~0u}, {VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME, ~0u, true}, {VK_KHR_MAINTENANCE1_EXTENSION_NAME, VK_API_VERSION_1_1, true}, + {VK_KHR_MAINTENANCE2_EXTENSION_NAME, VK_API_VERSION_1_1}, {VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME,VK_API_VERSION_1_2}, {VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME, VK_API_VERSION_1_1}, {VK_KHR_SWAPCHAIN_EXTENSION_NAME, ~0u, true}, @@ -2372,6 +2373,7 @@ static bool wined3d_adapter_vk_init_device_extensions(struct wined3d_adapter_vk map[] = { {VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME, WINED3D_VK_EXT_TRANSFORM_FEEDBACK}, + {VK_KHR_MAINTENANCE2_EXTENSION_NAME, WINED3D_VK_KHR_MAINTENANCE2}, {VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME, WINED3D_VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE}, {VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME, WINED3D_VK_KHR_SHADER_DRAW_PARAMETERS}, {VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME, WINED3D_VK_EXT_HOST_QUERY_RESET}, diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 201b76eab28..d9859aec0e5 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -722,6 +722,7 @@ bool wined3d_device_vk_create_null_views(struct wined3d_device_vk *device_vk, st struct wined3d_null_resources_vk *r = &device_vk->null_resources_vk; struct wined3d_null_views_vk *v = &device_vk->null_views_vk; VkBufferViewCreateInfo buffer_create_info; + VkImageViewUsageCreateInfoKHR usage_desc; const struct wined3d_vk_info *vk_info; VkImageViewCreateInfo view_desc; VkResult vr; @@ -768,6 +769,16 @@ bool wined3d_device_vk_create_null_views(struct wined3d_device_vk *device_vk, st view_desc.subresourceRange.levelCount = 1; view_desc.subresourceRange.baseArrayLayer = 0; view_desc.subresourceRange.layerCount = 1; + + if (wined3d_adapter_vk(device_vk->d.adapter)->vk_info.supported[WINED3D_VK_KHR_MAINTENANCE2]) + { + usage_desc.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO_KHR; + usage_desc.pNext = NULL; + usage_desc.usage = VK_IMAGE_USAGE_SAMPLED_BIT; + + view_desc.pNext = &usage_desc; + } + if ((vr = VK_CALL(vkCreateImageView(device_vk->vk_device, &view_desc, NULL, &v->vk_info_1d.imageView))) < 0) { ERR("Failed to create 1D image view, vr %s.\n", wined3d_debug_vkresult(vr)); diff --git a/dlls/wined3d/wined3d_vk.h b/dlls/wined3d/wined3d_vk.h index 5d2191e9833..6d619ad89b8 100644 --- a/dlls/wined3d/wined3d_vk.h +++ b/dlls/wined3d/wined3d_vk.h @@ -216,6 +216,7 @@ enum wined3d_vk_extension WINED3D_VK_EXT_NONE,
WINED3D_VK_EXT_TRANSFORM_FEEDBACK, + WINED3D_VK_KHR_MAINTENANCE2, WINED3D_VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE, WINED3D_VK_KHR_SHADER_DRAW_PARAMETERS, WINED3D_VK_EXT_HOST_QUERY_RESET,
From: Giovanni Mascellani gmascellani@codeweavers.com
--- dlls/wined3d/view.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c index 967c758b1ed..1d53147e567 100644 --- a/dlls/wined3d/view.c +++ b/dlls/wined3d/view.c @@ -751,11 +751,13 @@ static VkBufferView wined3d_view_vk_create_vk_buffer_view(struct wined3d_context
static VkImageView wined3d_view_vk_create_vk_image_view(struct wined3d_context_vk *context_vk, const struct wined3d_view_desc *desc, struct wined3d_texture_vk *texture_vk, - const struct wined3d_format_vk *view_format_vk, struct color_fixup_desc fixup, bool rtv) + const struct wined3d_format_vk *view_format_vk, struct color_fixup_desc fixup, bool rtv, + VkImageUsageFlags usage) { const struct wined3d_resource *resource = &texture_vk->t.resource; const struct wined3d_vk_info *vk_info = context_vk->vk_info; const struct wined3d_format_vk *format_vk; + VkImageViewUsageCreateInfoKHR usage_info; struct wined3d_device_vk *device_vk; VkImageViewCreateInfo create_info; VkImageView vk_image_view; @@ -847,6 +849,13 @@ static VkImageView wined3d_view_vk_create_vk_image_view(struct wined3d_context_v create_info.subresourceRange.baseArrayLayer = desc->u.texture.layer_idx; create_info.subresourceRange.layerCount = desc->u.texture.layer_count; } + if (wined3d_adapter_vk(device_vk->d.adapter)->vk_info.supported[WINED3D_VK_KHR_MAINTENANCE2]) + { + usage_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO_KHR; + usage_info.pNext = NULL; + usage_info.usage = usage; + create_info.pNext = &usage_info; + } if ((vr = VK_CALL(vkCreateImageView(device_vk->vk_device, &create_info, NULL, &vk_image_view))) < 0) { ERR("Failed to create Vulkan image view, vr %s.\n", wined3d_debug_vkresult(vr)); @@ -899,7 +908,7 @@ static void wined3d_render_target_view_vk_cs_init(void *object)
context = context_acquire(resource->device, NULL, 0); view_vk->vk_image_view = wined3d_view_vk_create_vk_image_view(wined3d_context_vk(context), - desc, texture_vk, format_vk, COLOR_FIXUP_IDENTITY, true); + desc, texture_vk, format_vk, COLOR_FIXUP_IDENTITY, true, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); context_release(context);
if (!view_vk->vk_image_view) @@ -1219,7 +1228,7 @@ static void wined3d_shader_resource_view_vk_cs_init(void *object)
context = context_acquire(resource->device, NULL, 0); vk_image_view = wined3d_view_vk_create_vk_image_view(wined3d_context_vk(context), - desc, texture_vk, wined3d_format_vk(format), format->color_fixup, false); + desc, texture_vk, wined3d_format_vk(format), format->color_fixup, false, VK_IMAGE_USAGE_SAMPLED_BIT); context_release(context);
if (!vk_image_view) @@ -2228,7 +2237,7 @@ void wined3d_unordered_access_view_vk_clear(struct wined3d_unordered_access_view vk_image_info.imageView = wined3d_view_vk_create_vk_image_view(context_vk, view_desc, texture_vk, wined3d_format_vk(wined3d_get_format(context_vk->c.device->adapter, format_id, WINED3D_BIND_UNORDERED_ACCESS)), - COLOR_FIXUP_IDENTITY, false); + COLOR_FIXUP_IDENTITY, false, VK_IMAGE_USAGE_STORAGE_BIT);
if (vk_image_info.imageView == VK_NULL_HANDLE) return; @@ -2446,7 +2455,7 @@ static void wined3d_unordered_access_view_vk_cs_init(void *object)
context_vk = wined3d_context_vk(context_acquire(&device_vk->d, NULL, 0)); vk_image_view = wined3d_view_vk_create_vk_image_view(context_vk, desc, - texture_vk, format_vk, format_vk->f.color_fixup, false); + texture_vk, format_vk, format_vk->f.color_fixup, false, VK_IMAGE_USAGE_STORAGE_BIT); context_release(&context_vk->c);
if (!vk_image_view)