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@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
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/command.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 9ac2bb9f..b4fd6cf3 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -4057,15 +4057,8 @@ static void STDMETHODCALLTYPE d3d12_command_list_ResourceBarrier(ID3D12GraphicsC } else { - const struct vkd3d_format *format; VkImageMemoryBarrier vk_barrier;
- 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); - continue; - } - vk_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; vk_barrier.pNext = NULL; vk_barrier.srcAccessMask = src_access_mask; @@ -4076,7 +4069,7 @@ static void STDMETHODCALLTYPE d3d12_command_list_ResourceBarrier(ID3D12GraphicsC vk_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; vk_barrier.image = resource->u.vk_image;
- vk_barrier.subresourceRange.aspectMask = format->vk_aspect_mask; + vk_barrier.subresourceRange.aspectMask = resource->format->vk_aspect_mask; if (sub_resource_idx == D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES) { vk_barrier.subresourceRange.baseMipLevel = 0;
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com