The right place for alignment validation is d3d12_resource_validate_desc(). The mod alignment test, which returns a size of ~0 on failure, is incorrect on systems where Vulkan requires alignments of 0x20000 or more, and breaks Hitman 2, which uses the returned value unchecked and allocates heaps of 0xffffffff bytes.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- Supersedes 174431. --- libs/vkd3d/device.c | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-)
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 31d793f..e3bb2aa 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -2899,10 +2899,8 @@ static D3D12_RESOURCE_ALLOCATION_INFO * STDMETHODCALLTYPE d3d12_device_GetResour UINT count, const D3D12_RESOURCE_DESC *resource_descs) { struct d3d12_device *device = impl_from_ID3D12Device(iface); - const struct vkd3d_format *format; const D3D12_RESOURCE_DESC *desc; uint64_t requested_alignment; - uint64_t estimated_size;
TRACE("iface %p, info %p, visible_mask 0x%08x, count %u, resource_descs %p.\n", iface, info, visible_mask, count, resource_descs); @@ -2926,9 +2924,6 @@ static D3D12_RESOURCE_ALLOCATION_INFO * STDMETHODCALLTYPE d3d12_device_GetResour goto invalid; }
- requested_alignment = desc->Alignment - ? desc->Alignment : D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT; - if (desc->Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) { info->SizeInBytes = desc->Width; @@ -2942,27 +2937,9 @@ static D3D12_RESOURCE_ALLOCATION_INFO * STDMETHODCALLTYPE d3d12_device_GetResour goto invalid; }
+ requested_alignment = desc->Alignment + ? desc->Alignment : D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT; info->Alignment = max(info->Alignment, requested_alignment); - - if (info->Alignment < D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT) - { - if (!(format = vkd3d_format_from_d3d12_resource_desc(device, desc, 0))) - { - 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); - } - } - - if (desc->Alignment % info->Alignment) - { - WARN("Invalid resource alignment %#"PRIx64" (required %#"PRIx64").\n", - desc->Alignment, info->Alignment); - goto invalid; }
info->SizeInBytes = align(info->SizeInBytes, info->Alignment);
Test large DepthOrArraySize for small resources, and test compressed textures at the 64KB limit.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- Supersedes 174432. --- tests/d3d12.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/tests/d3d12.c b/tests/d3d12.c index 47c1649..578ae56 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -29437,7 +29437,6 @@ static void test_resource_allocation_info(void) ID3D12Device *device; unsigned int i, j; ULONG refcount; - uint64_t size;
static const unsigned int alignments[] = { @@ -29472,12 +29471,15 @@ static void test_resource_allocation_info(void) { 4, 4, 1, 1, DXGI_FORMAT_R8_UINT}, { 8, 8, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM}, {16, 16, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM}, - {16, 16, 6, 1, DXGI_FORMAT_R8G8B8A8_UNORM}, + {16, 16, 1024, 1, DXGI_FORMAT_R8G8B8A8_UNORM}, + {256, 512, 1, 10, DXGI_FORMAT_BC1_UNORM}, + {256, 512, 64, 1, DXGI_FORMAT_BC1_UNORM},
{1024, 1024, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM}, {1024, 1024, 1, 2, DXGI_FORMAT_R8G8B8A8_UNORM}, {1024, 1024, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM}, {1024, 1024, 1, 0, DXGI_FORMAT_R8G8B8A8_UNORM}, + {260, 512, 1, 1, DXGI_FORMAT_BC1_UNORM}, };
if (!(device = create_device())) @@ -29549,8 +29551,7 @@ static void test_resource_allocation_info(void) info = ID3D12Device_GetResourceAllocationInfo(device, 0, 1, &desc); ok(info.Alignment >= D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT, "Got unexpected alignment %"PRIu64".\n", info.Alignment); - size = desc.Width * desc.Height * desc.DepthOrArraySize * format_size(desc.Format); - if (size <= D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT) + if (i < 6) { check_alignment(info.SizeInBytes, info.Alignment); }
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com