Conor McCarthy : vkd3d: Store the vkd3d format in resource objects.

Alexandre Julliard julliard at winehq.org
Wed Jan 19 15:52:10 CST 2022


Module: vkd3d
Branch: master
Commit: 1f3ec35138edf770ac7e2465da6295e313f79137
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=1f3ec35138edf770ac7e2465da6295e313f79137

Author: Conor McCarthy <cmccarthy at codeweavers.com>
Date:   Tue Jan 18 14:52:09 2022 +1000

vkd3d: Store the vkd3d format in resource objects.

Resource formats are immutable and the format object is static data.
Storing it saves a function call and error check in many locations.
The current implementation for finding a format iterates over the
entire list of formats.

Signed-off-by: Conor McCarthy <cmccarthy at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 libs/vkd3d/command.c       | 9 +--------
 libs/vkd3d/resource.c      | 3 +++
 libs/vkd3d/vkd3d_private.h | 1 +
 3 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c
index 353a61c..421a3c8 100644
--- a/libs/vkd3d/command.c
+++ b/libs/vkd3d/command.c
@@ -2116,17 +2116,10 @@ static void d3d12_command_list_transition_resource_to_initial_state(struct d3d12
     const struct vkd3d_vk_device_procs *vk_procs = &list->device->vk_procs;
     const struct vkd3d_vulkan_info *vk_info = &list->device->vk_info;
     VkPipelineStageFlags src_stage_mask, dst_stage_mask;
-    const struct vkd3d_format *format;
     VkImageMemoryBarrier barrier;
 
     assert(d3d12_resource_is_texture(resource));
 
-    if (!(format = vkd3d_format_from_d3d12_resource_desc(list->device, &resource->desc, 0)))
-    {
-        ERR("Resource %p has invalid format %#x.\n", resource, resource->desc.Format);
-        return;
-    }
-
     barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
     barrier.pNext = NULL;
 
@@ -2146,7 +2139,7 @@ static void d3d12_command_list_transition_resource_to_initial_state(struct d3d12
     barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
     barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
     barrier.image = resource->u.vk_image;
-    barrier.subresourceRange.aspectMask = format->vk_aspect_mask;
+    barrier.subresourceRange.aspectMask = resource->format->vk_aspect_mask;
     barrier.subresourceRange.baseMipLevel = 0;
     barrier.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
     barrier.subresourceRange.baseArrayLayer = 0;
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c
index 78b32bd..b376ecd 100644
--- a/libs/vkd3d/resource.c
+++ b/libs/vkd3d/resource.c
@@ -1778,6 +1778,8 @@ static HRESULT d3d12_resource_init(struct d3d12_resource *resource, struct d3d12
     if (FAILED(hr = d3d12_resource_validate_desc(&resource->desc, device)))
         return hr;
 
+    resource->format = vkd3d_format_from_d3d12_resource_desc(device, desc, 0);
+
     switch (desc->Dimension)
     {
         case D3D12_RESOURCE_DIMENSION_BUFFER:
@@ -2030,6 +2032,7 @@ HRESULT vkd3d_create_image_resource(ID3D12Device *device,
     object->refcount = 1;
     object->internal_refcount = 1;
     object->desc = create_info->desc;
+    object->format = vkd3d_format_from_d3d12_resource_desc(d3d12_device, &create_info->desc, 0);
     object->u.vk_image = create_info->vk_image;
     object->flags = VKD3D_RESOURCE_EXTERNAL;
     object->flags |= create_info->flags & VKD3D_RESOURCE_PUBLIC_FLAGS;
diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h
index 3f5ea21..aa18fcb 100644
--- a/libs/vkd3d/vkd3d_private.h
+++ b/libs/vkd3d/vkd3d_private.h
@@ -430,6 +430,7 @@ struct d3d12_resource
     LONG internal_refcount;
 
     D3D12_RESOURCE_DESC desc;
+    const struct vkd3d_format *format;
 
     D3D12_GPU_VIRTUAL_ADDRESS gpu_address;
     union




More information about the wine-cvs mailing list