diff options
-rw-r--r-- | src/amd/vulkan/radv_device.c | 40 | ||||
-rw-r--r-- | src/amd/vulkan/radv_entrypoints_gen.py | 1 | ||||
-rw-r--r-- | src/amd/vulkan/radv_private.h | 7 | ||||
-rw-r--r-- | src/amd/vulkan/radv_wsi.c | 34 |
4 files changed, 62 insertions, 20 deletions
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index 7b8132989c5..eaf610c286e 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -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) diff --git a/src/amd/vulkan/radv_entrypoints_gen.py b/src/amd/vulkan/radv_entrypoints_gen.py index 420de2c7871..b7b2bcf97e4 100644 --- a/src/amd/vulkan/radv_entrypoints_gen.py +++ b/src/amd/vulkan/radv_entrypoints_gen.py @@ -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', diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 140bf8d5ca3..37549c554d0 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -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. * diff --git a/src/amd/vulkan/radv_wsi.c b/src/amd/vulkan/radv_wsi.c index 335a963e0b1..e43c6cfd410 100644 --- a/src/amd/vulkan/radv_wsi.c +++ b/src/amd/vulkan/radv_wsi.c @@ -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; |