#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>
.extensionName = VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME,
.specVersion = 1,
},
+ {
+ .extensionName = VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME,
+ .specVersion = 1,
+ },
};
static VkResult
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,
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) {
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)
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',
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;
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.
*
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,
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;