[PATCH vkd3d v2 1/6] vkd3d: Store the vkd3d format in resource objects.

Conor McCarthy cmccarthy at codeweavers.com
Mon Jan 17 22:52:09 CST 2022


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>
---
 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 3e252aee..9ac2bb9f 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 78b32bde..b376ecd2 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 047f4a29..6c31467f 100644
--- a/libs/vkd3d/vkd3d_private.h
+++ b/libs/vkd3d/vkd3d_private.h
@@ -427,6 +427,7 @@ struct d3d12_resource
     LONG internal_refcount;
 
     D3D12_RESOURCE_DESC desc;
+    const struct vkd3d_format *format;
 
     D3D12_GPU_VIRTUAL_ADDRESS gpu_address;
     union
-- 
2.34.1




More information about the wine-devel mailing list