Some driver, e.g. MoltenVK, fail in some cases if the image view usage is too broad or unknown.
-- v6: wined3d: Expose the image view usage for non-default views. wined3d: Expose the image view usage for null views.
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 d6f4449ce06..e677cf0f1be 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..d40e4be9c70 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 (vk_info->supported[WINED3D_VK_KHR_MAINTENANCE2] || vk_info->api_version >= VK_API_VERSION_1_1) + { + 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 | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c index 967c758b1ed..c86501c118a 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 (vk_info->supported[WINED3D_VK_KHR_MAINTENANCE2] || vk_info->api_version >= VK_API_VERSION_1_1) + { + 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)); @@ -864,6 +873,7 @@ static void wined3d_render_target_view_vk_cs_init(void *object) struct wined3d_texture_vk *texture_vk; struct wined3d_resource *resource; struct wined3d_context *context; + VkImageUsageFlags vk_usage = 0; uint32_t default_flags = 0;
TRACE("view_vk %p.\n", view_vk); @@ -897,9 +907,14 @@ static void wined3d_render_target_view_vk_cs_init(void *object) return; }
+ if (resource->bind_flags & WINED3D_BIND_RENDER_TARGET) + vk_usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + if (resource->bind_flags & WINED3D_BIND_DEPTH_STENCIL) + vk_usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + 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_usage); context_release(context);
if (!view_vk->vk_image_view) @@ -1219,7 +1234,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 +2243,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 +2461,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)
On Tue Jan 23 14:18:13 2024 +0000, Giovanni Mascellani wrote:
changed this line in [version 6 of the diff](/wine/wine/-/merge_requests/4022/diffs?diff_id=95248&start_sha=d16b34f8f8688809f9ede39335a99d49d6d02b17#52757952624f881d229fda807b2824f20d2f9055_773_773)
Yeah. I assumed we were enabling the bits by default and then checking those that are optional.
This merge request was approved by Jan Sikorski.
This merge request was approved by Giovanni Mascellani.
This merge request was approved by Zebediah Figura.