From 8f3db5ecef9fa4367e888edfd089f90beb0e5749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Fri, 18 Jan 2019 10:25:49 +0100 Subject: [PATCH] vkd3d: Simplify d3d12_device_GetResourceAllocationInfo(). 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/device.c | 64 ++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 7a6dcb68..52e74105 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -2074,11 +2074,10 @@ static D3D12_RESOURCE_ALLOCATION_INFO * STDMETHODCALLTYPE d3d12_device_GetResour ID3D12Device *iface, D3D12_RESOURCE_ALLOCATION_INFO *info, UINT visible_mask, UINT count, const D3D12_RESOURCE_DESC *resource_descs) { - UINT64 default_alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT; struct d3d12_device *device = impl_from_ID3D12Device(iface); const struct vkd3d_format *format; const D3D12_RESOURCE_DESC *desc; - bool valid = true; + UINT64 estimated_size; TRACE("iface %p, info %p, visible_mask 0x%08x, count %u, resource_descs %p.\n", iface, info, visible_mask, count, resource_descs); @@ -2099,7 +2098,7 @@ static D3D12_RESOURCE_ALLOCATION_INFO * STDMETHODCALLTYPE d3d12_device_GetResour if (FAILED(d3d12_resource_validate_desc(desc))) { WARN("Invalid resource desc.\n"); - valid = false; + goto invalid; } if (desc->Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) @@ -2109,57 +2108,56 @@ static D3D12_RESOURCE_ALLOCATION_INFO * STDMETHODCALLTYPE d3d12_device_GetResour } else { - /* FIXME: Should we support D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT for small MSSA resources? */ - if (desc->SampleDesc.Count != 1) - default_alignment = D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT; - - if (valid && FAILED(vkd3d_get_image_allocation_info(device, desc, info))) + if (FAILED(vkd3d_get_image_allocation_info(device, desc, info))) { WARN("Failed to get allocation info for texture.\n"); - valid = false; + goto invalid; } - if (valid && info->Alignment < D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT) + if (info->Alignment < D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT) { - if ((format = vkd3d_format_from_d3d12_resource_desc(desc, 0))) + if (!(format = vkd3d_format_from_d3d12_resource_desc(desc, 0))) { - if (desc->Width * desc->Height * desc->DepthOrArraySize * format->byte_count - > D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT) - { - info->Alignment = max(info->Alignment, D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT); - } - else - { - info->Alignment = max(info->Alignment, D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT); - } + WARN("Invalid format %#x.\n", desc->Format); + goto invalid; + } + + estimated_size = desc->Width * desc->Height * desc->DepthOrArraySize * format->byte_count; + if (estimated_size > D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT) + { + info->Alignment = max(info->Alignment, D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT); } else { - WARN("Invalid format %#x.\n", desc->Format); - valid = false; + info->Alignment = max(info->Alignment, D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT); } } } - if (valid && desc->Alignment % info->Alignment) + if (desc->Alignment % info->Alignment) { WARN("Invalid resource alignment %#"PRIx64" (required %#"PRIx64").\n", desc->Alignment, info->Alignment); - valid = false; + goto invalid; } - if (valid) - { - info->SizeInBytes = align(info->SizeInBytes, info->Alignment); - } - else - { - info->SizeInBytes = ~(UINT64)0; - info->Alignment = default_alignment; - } + info->SizeInBytes = align(info->SizeInBytes, info->Alignment); TRACE("Size %#"PRIx64", alignment %#"PRIx64".\n", info->SizeInBytes, info->Alignment); + return info; + +invalid: + info->SizeInBytes = ~(UINT64)0; + + /* FIXME: Should we support D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT for small MSSA resources? */ + if (desc->SampleDesc.Count != 1) + info->Alignment = D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT; + else + info->Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT; + + TRACE("Alignment %#"PRIx64".\n", info->Alignment); + return info; }