turnip: fill VkMemoryDedicatedRequirements
authorDanylo Piliaiev <dpiliaiev@igalia.com>
Tue, 16 Feb 2021 15:04:35 +0000 (17:04 +0200)
committerDanylo Piliaiev <dpiliaiev@igalia.com>
Fri, 12 Mar 2021 09:56:47 +0000 (11:56 +0200)
We support VK_KHR_dedicated_allocation so we must fill
VkMemoryDedicatedRequirements.

Vulkan spec states:

 "[...] requiresDedicatedAllocation may be VK_TRUE under one of the
 following conditions:

 The pNext chain of VkImageCreateInfo for the call to vkCreateImage used
 to create the image being queried included a VkExternalMemoryImageCreateInfo
 structure, and any of the handle types specified in
 VkExternalMemoryImageCreateInfo::handleTypes requires dedicated allocation,
 as reported by vkGetPhysicalDeviceImageFormatProperties2 in
 VkExternalImageFormatProperties::externalMemoryProperties.externalMemoryFeatures,
 the requiresDedicatedAllocation field will be set to VK_TRUE."

All handle types require dedicated allocation at the moment.

Fixes:
 dEQP-VK.api.external.memory.opaque_fd.dedicated.image.info
 dEQP-VK.memory.requirements.dedicated_allocation.buffer.regular
 dEQP-VK.memory.requirements.dedicated_allocation.image.transient_tiling_optimal

Signed-off-by: Danylo Piliaiev <dpiliaiev@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9086>

src/freedreno/ci/deqp-freedreno-a630-fails.txt
src/freedreno/vulkan/tu_device.c
src/freedreno/vulkan/tu_image.c
src/freedreno/vulkan/tu_private.h

index e6bbf23..1557741 100644 (file)
@@ -82,8 +82,6 @@ dEQP-VK.image.subresource_layout.3d.all_levels.r16g16_snorm,Fail
 dEQP-VK.image.subresource_layout.3d.all_levels.r16g16b16a16_snorm,Fail
 dEQP-VK.image.subresource_layout.3d.all_levels.r8_snorm,Fail
 dEQP-VK.image.subresource_layout.3d.all_levels.r8g8b8a8_snorm,Fail
-dEQP-VK.memory.requirements.dedicated_allocation.buffer.regular,Fail
-dEQP-VK.memory.requirements.dedicated_allocation.image.transient_tiling_optimal,Fail
 dEQP-VK.memory_model.message_passing.core11.u32.coherent.fence_fence.atomicwrite.device.payload_local.image.guard_nonlocal.workgroup.comp,Fail
 dEQP-VK.memory_model.message_passing.core11.u32.coherent.fence_fence.atomicwrite.device.payload_nonlocal.workgroup.guard_local.image.comp,Fail
 dEQP-VK.pipeline.extended_dynamic_state.after_pipelines.depth_compare_always_greater,Fail
index 9f5e1f0..f4fe8e5 100644 (file)
@@ -1605,6 +1605,20 @@ tu_GetBufferMemoryRequirements2(
       .alignment = 64,
       .size = MAX2(align64(buffer->size, 64), buffer->size),
    };
+
+   vk_foreach_struct(ext, pMemoryRequirements->pNext) {
+      switch (ext->sType) {
+      case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS: {
+         VkMemoryDedicatedRequirements *req =
+            (VkMemoryDedicatedRequirements *) ext;
+         req->requiresDedicatedAllocation = false;
+         req->prefersDedicatedAllocation = req->requiresDedicatedAllocation;
+         break;
+      }
+      default:
+         break;
+      }
+   }
 }
 
 void
@@ -1619,6 +1633,20 @@ tu_GetImageMemoryRequirements2(VkDevice device,
       .alignment = image->layout[0].base_align,
       .size = image->total_size
    };
+
+   vk_foreach_struct(ext, pMemoryRequirements->pNext) {
+      switch (ext->sType) {
+      case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS: {
+         VkMemoryDedicatedRequirements *req =
+            (VkMemoryDedicatedRequirements *) ext;
+         req->requiresDedicatedAllocation = image->shareable;
+         req->prefersDedicatedAllocation = req->requiresDedicatedAllocation;
+         break;
+      }
+      default:
+         break;
+      }
+   }
 }
 
 void
index c602f4b..7769cb8 100644 (file)
@@ -553,6 +553,10 @@ tu_CreateImage(VkDevice _device,
    if (!image)
       return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
+   const VkExternalMemoryImageCreateInfo *external_info =
+      vk_find_struct_const(pCreateInfo->pNext, EXTERNAL_MEMORY_IMAGE_CREATE_INFO);
+   image->shareable = external_info != NULL;
+
    image->vk_format = pCreateInfo->format;
    image->level_count = pCreateInfo->mipLevels;
    image->layer_count = pCreateInfo->arrayLayers;
index ff6b2f0..0c12cc3 100644 (file)
@@ -1281,6 +1281,8 @@ struct tu_image
    uint32_t lrz_height;
    uint32_t lrz_pitch;
    uint32_t lrz_offset;
+
+   bool shareable;
 };
 
 static inline uint32_t