[PATCH vkd3d v3 2/2] vkd3d: Pad resource allocation size to allow texture placement at a 64kb alignment.

Conor McCarthy cmccarthy at codeweavers.com
Mon Jul 5 22:25:56 CDT 2021


Signed-off-by: Conor McCarthy <cmccarthy at codeweavers.com>
---
 libs/vkd3d/device.c   | 15 ++++++++++++---
 libs/vkd3d/resource.c |  6 ++++++
 tests/d3d12.c         |  1 -
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c
index a63fc92b..159bc470 100644
--- a/libs/vkd3d/device.c
+++ b/libs/vkd3d/device.c
@@ -3221,7 +3221,7 @@ static D3D12_RESOURCE_ALLOCATION_INFO * STDMETHODCALLTYPE d3d12_device_GetResour
 
     if (desc->Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
     {
-        info->SizeInBytes = desc->Width;
+        info->SizeInBytes = align(desc->Width, D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT);
         info->Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT;
     }
     else
@@ -3235,9 +3235,18 @@ static D3D12_RESOURCE_ALLOCATION_INFO * STDMETHODCALLTYPE d3d12_device_GetResour
         requested_alignment = desc->Alignment
                 ? desc->Alignment : D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT;
         info->Alignment = max(info->Alignment, requested_alignment);
-    }
 
-    info->SizeInBytes = align(info->SizeInBytes, info->Alignment);
+        info->SizeInBytes = align(info->SizeInBytes, info->Alignment);
+
+        /* Pad by the maximum heap offset increase which may be needed to align to a higher
+         * Vulkan requirement an offset supplied by the calling application. This allows
+         * us to return the standard D3D12 alignment and adjust resource placement later. */
+        if (info->Alignment > requested_alignment)
+        {
+            info->SizeInBytes += info->Alignment - requested_alignment;
+            info->Alignment = requested_alignment;
+        }
+    }
 
     TRACE("Size %#"PRIx64", alignment %#"PRIx64".\n", info->SizeInBytes, info->Alignment);
 
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c
index 3a66bb15..3faa6794 100644
--- a/libs/vkd3d/resource.c
+++ b/libs/vkd3d/resource.c
@@ -1901,9 +1901,15 @@ static HRESULT vkd3d_bind_heap_memory(struct d3d12_device *device,
     VkResult vr;
 
     if (d3d12_resource_is_buffer(resource))
+    {
         VK_CALL(vkGetBufferMemoryRequirements(vk_device, resource->u.vk_buffer, &requirements));
+    }
     else
+    {
         VK_CALL(vkGetImageMemoryRequirements(vk_device, resource->u.vk_image, &requirements));
+        /* Padding in d3d12_device_GetResourceAllocationInfo() leaves room to align the offset. */
+        heap_offset = align(heap_offset, requirements.alignment);
+    }
 
     if (heap_offset % requirements.alignment)
     {
diff --git a/tests/d3d12.c b/tests/d3d12.c
index 41446370..b3dee1d9 100644
--- a/tests/d3d12.c
+++ b/tests/d3d12.c
@@ -29863,7 +29863,6 @@ static void test_64kb_texture_alignment(void)
     /* If the heap could not be used, the texture is not aliased. */
     reset_command_list(command_list, context.allocator);
     get_texture_readback_with_command_list(textures[1], 0, &rb, queue, command_list);
-    todo_if(info.Alignment > D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT)
     check_readback_data_uint(&rb, &box, 0xdeadbeef, 0);
     release_resource_readback(&rb);
 
-- 
2.31.1




More information about the wine-devel mailing list