radv: Allow non-dedicated linear images and buffer.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Mon, 27 Jan 2020 15:50:23 +0000 (16:50 +0100)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sun, 2 Feb 2020 16:47:14 +0000 (17:47 +0100)
Requested for virtualized Vulkan as they need to export memory to
map it.

Since radeonsi and the kernel assume an image without metadata is
linear, this should work just fine.

Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3583>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3583>

src/amd/vulkan/radv_device.c
src/amd/vulkan/radv_formats.c

index 0a2e3836eefd0fbf5654f3a04c86662c76705f57..890225f7b9fd318ee95985b69989cf8936b4ee20 100644 (file)
@@ -4876,7 +4876,8 @@ bool radv_get_memory_fd(struct radv_device *device,
        struct radeon_bo_metadata metadata;
 
        if (memory->image) {
-               radv_init_metadata(device, memory->image, &metadata);
+               if (memory->image->tiling != VK_IMAGE_TILING_LINEAR)
+                       radv_init_metadata(device, memory->image, &metadata);
                device->ws->buffer_set_metadata(memory->bo, &metadata);
        }
 
@@ -5164,13 +5165,12 @@ void radv_GetBufferMemoryRequirements2(
 {
        radv_GetBufferMemoryRequirements(device, pInfo->buffer,
                                         &pMemoryRequirements->memoryRequirements);
-       RADV_FROM_HANDLE(radv_buffer, buffer, pInfo->buffer);
        vk_foreach_struct(ext, pMemoryRequirements->pNext) {
                switch (ext->sType) {
                case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS: {
                        VkMemoryDedicatedRequirements *req =
                                       (VkMemoryDedicatedRequirements *) ext;
-                       req->requiresDedicatedAllocation = buffer->shareable;
+                       req->requiresDedicatedAllocation = false;
                        req->prefersDedicatedAllocation = req->requiresDedicatedAllocation;
                        break;
                }
@@ -5209,7 +5209,8 @@ void radv_GetImageMemoryRequirements2(
                case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS: {
                        VkMemoryDedicatedRequirements *req =
                                       (VkMemoryDedicatedRequirements *) ext;
-                       req->requiresDedicatedAllocation = image->shareable;
+                       req->requiresDedicatedAllocation = image->shareable &&
+                                                          image->tiling != VK_IMAGE_TILING_LINEAR;
                        req->prefersDedicatedAllocation = req->requiresDedicatedAllocation;
                        break;
                }
index 67a9cb7bfe0ba26b837d9ab5dde969e7f7b52fcb..a790459c900c6054d19795fb297430587974f569 100644 (file)
@@ -1323,7 +1323,10 @@ get_external_image_format_properties(struct radv_physical_device *physical_devic
        case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
                switch (pImageFormatInfo->type) {
                case VK_IMAGE_TYPE_2D:
-                       flags = VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT|VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT|VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
+                       flags = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT|VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
+                       if (pImageFormatInfo->tiling != VK_IMAGE_TILING_LINEAR)
+                               flags |= VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT;
+
                        compat_flags = export_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT |
                                                      VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
                        break;
@@ -1346,7 +1349,10 @@ get_external_image_format_properties(struct radv_physical_device *physical_devic
                format_properties->maxArrayLayers = MIN2(1, format_properties->maxArrayLayers);
                format_properties->sampleCounts &= VK_SAMPLE_COUNT_1_BIT;
 
-               flags = VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT|VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT|VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
+               flags = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT|VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
+               if (pImageFormatInfo->tiling != VK_IMAGE_TILING_LINEAR)
+                       flags |= VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT;
+
                compat_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
                break;
        case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT: