From 3b68c87bd0b468e8c393d21e6509da26bc0dd0f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Tue, 28 Aug 2018 12:19:53 +0200 Subject: [PATCH] vkd3d: Create vkd3d_views in vkd3d_create_texture_view(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Józef Kucia Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- libs/vkd3d/resource.c | 51 +++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index 7acd00d4..d97c3dbe 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -1327,13 +1327,15 @@ static bool init_default_texture_view_desc(struct vkd3d_texture_view_desc *desc, return true; } -static VkResult vkd3d_create_texture_view(struct d3d12_device *device, +static HRESULT vkd3d_create_texture_view(struct d3d12_device *device, struct d3d12_resource *resource, const struct vkd3d_texture_view_desc *desc, - VkImageView *vk_view) + struct vkd3d_view **view) { const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs; const struct vkd3d_format *format = desc->format; struct VkImageViewCreateInfo view_desc; + struct vkd3d_view *object; + VkImageView vk_view; VkResult vr; assert(d3d12_resource_is_texture(resource)); @@ -1350,9 +1352,21 @@ static VkResult vkd3d_create_texture_view(struct d3d12_device *device, view_desc.subresourceRange.levelCount = desc->miplevel_count; view_desc.subresourceRange.baseArrayLayer = desc->layer_idx; view_desc.subresourceRange.layerCount = desc->layer_count; - if ((vr = VK_CALL(vkCreateImageView(device->vk_device, &view_desc, NULL, vk_view))) < 0) + if ((vr = VK_CALL(vkCreateImageView(device->vk_device, &view_desc, NULL, &vk_view))) < 0) + { WARN("Failed to create Vulkan image view, vr %d.\n", vr); - return vr; + return hresult_from_vk_result(vr); + } + + if (!(object = vkd3d_view_create())) + { + VK_CALL(vkDestroyImageView(device->vk_device, vk_view, NULL)); + return E_OUTOFMEMORY; + } + + object->u.vk_image_view = vk_view; + *view = object; + return S_OK; } void d3d12_desc_create_cbv(struct d3d12_desc *descriptor, @@ -1519,15 +1533,9 @@ void d3d12_desc_create_srv(struct d3d12_desc *descriptor, } } - if (!(view = vkd3d_view_create())) + if (FAILED(vkd3d_create_texture_view(device, resource, &vkd3d_desc, &view))) return; - if (vkd3d_create_texture_view(device, resource, &vkd3d_desc, &view->u.vk_image_view) < 0) - { - vkd3d_free(view); - return; - } - descriptor->magic = VKD3D_DESCRIPTOR_MAGIC_SRV; descriptor->vk_descriptor_type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; descriptor->u.view = view; @@ -1648,15 +1656,9 @@ static void vkd3d_create_texture_uav(struct d3d12_desc *descriptor, } } - if (!(view = vkd3d_view_create())) + if (FAILED(vkd3d_create_texture_view(device, resource, &vkd3d_desc, &view))) return; - if (vkd3d_create_texture_view(device, resource, &vkd3d_desc, &view->u.vk_image_view) < 0) - { - vkd3d_free(view); - return; - } - descriptor->magic = VKD3D_DESCRIPTOR_MAGIC_UAV; descriptor->vk_descriptor_type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; descriptor->u.view = view; @@ -1904,15 +1906,9 @@ void d3d12_rtv_desc_create_rtv(struct d3d12_rtv_desc *rtv_desc, struct d3d12_dev vkd3d_desc.layer_count = resource->desc.DepthOrArraySize; } - if (!(view = vkd3d_view_create())) + if (FAILED(vkd3d_create_texture_view(device, resource, &vkd3d_desc, &view))) return; - if (vkd3d_create_texture_view(device, resource, &vkd3d_desc, &view->u.vk_image_view) < 0) - { - vkd3d_free(view); - return; - } - rtv_desc->magic = VKD3D_DESCRIPTOR_MAGIC_RTV; rtv_desc->format = vkd3d_desc.format->vk_format; rtv_desc->width = d3d12_resource_desc_get_width(&resource->desc, vkd3d_desc.miplevel_idx); @@ -1982,10 +1978,7 @@ void d3d12_dsv_desc_create_dsv(struct d3d12_dsv_desc *dsv_desc, struct d3d12_dev } } - if (!(view = vkd3d_view_create())) - return; - - if (vkd3d_create_texture_view(device, resource, &vkd3d_desc, &view->u.vk_image_view) < 0) + if (FAILED(vkd3d_create_texture_view(device, resource, &vkd3d_desc, &view))) return; dsv_desc->magic = VKD3D_DESCRIPTOR_MAGIC_DSV;