radv: add support for NV_dedicated_allocation
authorDave Airlie <airlied@redhat.com>
Sun, 26 Feb 2017 23:52:08 +0000 (23:52 +0000)
committerDave Airlie <airlied@redhat.com>
Mon, 27 Feb 2017 00:22:51 +0000 (00:22 +0000)
This adds initial support for NV_dedicated_allocation, then
uses it for the wsi image/memory allocation paths internally
in the driver.

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Signed-off-by: Dave Airlie <airlied@redhat.com>
src/amd/vulkan/radv_device.c
src/amd/vulkan/radv_entrypoints_gen.py
src/amd/vulkan/radv_private.h
src/amd/vulkan/radv_wsi.c

index 7b8132989c51c109ca9909b8717b201767fec515..eaf610c286ede7712e2b0e0f28108eafaeca5a0f 100644 (file)
@@ -33,7 +33,7 @@
 #include "radv_cs.h"
 #include "util/disk_cache.h"
 #include "util/strtod.h"
-
+#include "util/vk_util.h"
 #include <xf86drm.h>
 #include <amdgpu.h>
 #include <amdgpu_drm.h>
@@ -111,6 +111,10 @@ static const VkExtensionProperties common_device_extensions[] = {
                .extensionName = VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME,
                .specVersion = 1,
        },
+       {
+               .extensionName = VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME,
+               .specVersion = 1,
+       },
 };
 
 static VkResult
@@ -1635,6 +1639,21 @@ PFN_vkVoidFunction radv_GetDeviceProcAddr(
        return radv_lookup_entrypoint(pName);
 }
 
+bool radv_get_memory_fd(struct radv_device *device,
+                       struct radv_device_memory *memory,
+                       int *pFD)
+{
+       struct radeon_bo_metadata metadata;
+
+       if (memory->image) {
+               radv_init_metadata(device, memory->image, &metadata);
+               device->ws->buffer_set_metadata(memory->bo, &metadata);
+       }
+
+       return device->ws->buffer_get_fd(device->ws, memory->bo,
+                                        pFD);
+}
+
 VkResult radv_AllocateMemory(
        VkDevice                                    _device,
        const VkMemoryAllocateInfo*                 pAllocateInfo,
@@ -1646,6 +1665,7 @@ VkResult radv_AllocateMemory(
        VkResult result;
        enum radeon_bo_domain domain;
        uint32_t flags = 0;
+       const VkDedicatedAllocationMemoryAllocateInfoNV *dedicate_info = NULL;
        assert(pAllocateInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO);
 
        if (pAllocateInfo->allocationSize == 0) {
@@ -1654,11 +1674,29 @@ VkResult radv_AllocateMemory(
                return VK_SUCCESS;
        }
 
+       vk_foreach_struct(ext, pAllocateInfo->pNext) {
+               switch (ext->sType) {
+               case VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV:
+                       dedicate_info = (const VkDedicatedAllocationMemoryAllocateInfoNV *)ext;
+                       break;
+               default:
+                       break;
+               }
+       }
+
        mem = vk_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8,
                          VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
        if (mem == NULL)
                return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
+       if (dedicate_info) {
+               mem->image = radv_image_from_handle(dedicate_info->image);
+               mem->buffer = radv_buffer_from_handle(dedicate_info->buffer);
+       } else {
+               mem->image = NULL;
+               mem->buffer = NULL;
+       }
+
        uint64_t alloc_size = align_u64(pAllocateInfo->allocationSize, 4096);
        if (pAllocateInfo->memoryTypeIndex == RADV_MEM_TYPE_GTT_WRITE_COMBINE ||
            pAllocateInfo->memoryTypeIndex == RADV_MEM_TYPE_GTT_CACHED)
index 420de2c7871eca053e34e8c8d6b435207fcd6e74..b7b2bcf97e4fda4fbd698e038f17019ae006a15b 100644 (file)
@@ -29,6 +29,7 @@ max_api_version = 1.0
 
 supported_extensions = [
    'VK_AMD_draw_indirect_count',
+   'VK_NV_dedicated_allocation',
    'VK_KHR_get_physical_device_properties2',
    'VK_KHR_maintenance1',
    'VK_KHR_sampler_mirror_clamp_to_edge',
index 140bf8d5ca3b715b7ab723338f026a2a5e1306a9..37549c554d0f296ccad3acc9d53102abb350cade 100644 (file)
@@ -523,6 +523,9 @@ struct radv_device {
 
 struct radv_device_memory {
        struct radeon_winsys_bo                      *bo;
+       /* for dedicated allocations */
+       struct radv_image                            *image;
+       struct radv_buffer                           *buffer;
        uint32_t                                     type_index;
        VkDeviceSize                                 map_size;
        void *                                       map;
@@ -814,7 +817,9 @@ void radv_fill_buffer(struct radv_cmd_buffer *cmd_buffer,
                      struct radeon_winsys_bo *bo,
                      uint64_t offset, uint64_t size, uint32_t value);
 void radv_cmd_buffer_trace_emit(struct radv_cmd_buffer *cmd_buffer);
-
+bool radv_get_memory_fd(struct radv_device *device,
+                       struct radv_device_memory *memory,
+                       int *pFD);
 /*
  * Takes x,y,z as exact numbers of invocations, instead of blocks.
  *
index 335a963e0b1c5e491d31d4e6ff110f28dbbffb05..e43c6cfd4104f5ffe095fa5b88c8f647e74e23a1 100644 (file)
@@ -148,12 +148,10 @@ radv_wsi_image_create(VkDevice device_h,
                      uint32_t *offset,
                      uint32_t *row_pitch, int *fd_p)
 {
-       struct radv_device *device = radv_device_from_handle(device_h);
        VkResult result = VK_SUCCESS;
        struct radeon_surf *surface;
        VkImage image_h;
        struct radv_image *image;
-       bool bret;
        int fd;
 
        result = radv_image_create(device_h,
@@ -183,42 +181,42 @@ radv_wsi_image_create(VkDevice device_h,
                return result;
 
        image = radv_image_from_handle(image_h);
+
        VkDeviceMemory memory_h;
-       struct radv_device_memory *memory;
+
+       const VkDedicatedAllocationMemoryAllocateInfoNV ded_alloc = {
+               .sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV,
+               .pNext = NULL,
+               .buffer = NULL,
+               .image = image_h
+       };
 
        result = radv_AllocateMemory(device_h,
                                     &(VkMemoryAllocateInfo) {
                                             .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
-                                                    .allocationSize = image->size,
-                                                    .memoryTypeIndex = linear ? 1 : 0,
-                                                    },
+                                            .pNext = &ded_alloc,
+                                            .allocationSize = image->size,
+                                            .memoryTypeIndex = linear ? 1 : 0,
+                                    },
                                     NULL /* XXX: pAllocator */,
                                     &memory_h);
        if (result != VK_SUCCESS)
                goto fail_create_image;
 
-       memory = radv_device_memory_from_handle(memory_h);
-
-       radv_BindImageMemory(VK_NULL_HANDLE, image_h, memory_h, 0);
+       radv_BindImageMemory(device_h, image_h, memory_h, 0);
 
        /*
         * return the fd for the image in the no copy mode,
         * or the fd for the linear image if a copy is required.
         */
        if (!needs_linear_copy || (needs_linear_copy && linear)) {
-               bret = device->ws->buffer_get_fd(device->ws,
-                                                memory->bo, &fd);
-               if (bret == false)
+               RADV_FROM_HANDLE(radv_device, device, device_h);
+               RADV_FROM_HANDLE(radv_device_memory, memory, memory_h);
+               if (!radv_get_memory_fd(device, memory, &fd))
                        goto fail_alloc_memory;
                *fd_p = fd;
        }
 
-       {
-               struct radeon_bo_metadata metadata;
-               radv_init_metadata(device, image, &metadata);
-               device->ws->buffer_set_metadata(memory->bo, &metadata);
-       }
-
        surface = &image->surface;
 
        *image_p = image_h;