Conor McCarthy : vkd3d: Pad resource allocation size to allow texture placement at a 64kb alignment.

Alexandre Julliard julliard at winehq.org
Tue Jul 6 18:09:06 CDT 2021


Module: vkd3d
Branch: master
Commit: cea28ec77eeb29e92b52d50e7d62fe253836ce89
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=cea28ec77eeb29e92b52d50e7d62fe253836ce89

Author: Conor McCarthy <cmccarthy at codeweavers.com>
Date:   Tue Jul  6 13:25:56 2021 +1000

vkd3d: Pad resource allocation size to allow texture placement at a 64kb alignment.

Signed-off-by: Conor McCarthy <cmccarthy at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 a63fc92..159bc47 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 3a66bb1..3faa679 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 4144637..b3dee1d 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);
 




More information about the wine-cvs mailing list