[PATCH vkd3d v2 2/2] vkd3d: Pad resource allocation size info to allow texture placement at 64kb alignment.
Conor McCarthy
cmccarthy at codeweavers.com
Thu Jul 1 07:36:32 CDT 2021
Support for D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT is required, and
some apps, e.g. WoW, use it without checking the allocation info.
Signed-of-by: Conor McCarthy <cmccarthy at codeweavers.com>
---
libs/vkd3d/device.c | 15 ++++++++++++---
libs/vkd3d/resource.c | 6 ++++++
2 files changed, 18 insertions(+), 3 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)
{
--
2.31.1
More information about the wine-devel
mailing list