From 39eb9fe5d86f82311b922204947879539dd62ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Fri, 18 Jan 2019 10:25:48 +0100 Subject: [PATCH] vkd3d: Allow D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT only for small textures. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a simple heuristic to decide if a resource is "small". The heuristic is based on theoretical constraints for the most detailed mip level of small resources. Those constraints are mentioned in D3D12 validation layer errors and in the DirectX 12 Graphics samples. Signed-off-by: Józef Kucia Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- libs/vkd3d/device.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 7c200623..7a6dcb68 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -2076,6 +2076,7 @@ static D3D12_RESOURCE_ALLOCATION_INFO * STDMETHODCALLTYPE d3d12_device_GetResour { 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; @@ -2118,7 +2119,26 @@ static D3D12_RESOURCE_ALLOCATION_INFO * STDMETHODCALLTYPE d3d12_device_GetResour valid = false; } - info->Alignment = max(info->Alignment, D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT); + if (valid && info->Alignment < D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT) + { + 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); + } + } + else + { + WARN("Invalid format %#x.\n", desc->Format); + valid = false; + } + } } if (valid && desc->Alignment % info->Alignment)