anv: Implement VK_KHR_buffer_device_address

The primary difference between the KHR and EXT versions of the extension
is that the KHR provides the address at AllocateMemory time for replay
so we can replay it safely without moving to a sparse address model.

Reviewed-by: Ivan Briano <ivan.briano@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
This commit is contained in:
Jason Ekstrand 2019-12-02 16:28:58 -06:00
parent 4428cd9127
commit 1b6991ba1d
2 changed files with 53 additions and 7 deletions

View file

@ -998,6 +998,15 @@ void anv_GetPhysicalDeviceFeatures2(
break; break;
} }
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_KHR: {
VkPhysicalDeviceBufferDeviceAddressFeaturesKHR *features = (void *)ext;
features->bufferDeviceAddress = pdevice->has_a64_buffer_access;
features->bufferDeviceAddressCaptureReplay =
pdevice->has_a64_buffer_access;
features->bufferDeviceAddressMultiDevice = false;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV: { case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV: {
VkPhysicalDeviceComputeShaderDerivativesFeaturesNV *features = VkPhysicalDeviceComputeShaderDerivativesFeaturesNV *features =
(VkPhysicalDeviceComputeShaderDerivativesFeaturesNV *)ext; (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV *)ext;
@ -3092,6 +3101,8 @@ VkResult anv_AllocateMemory(
const VkImportMemoryFdInfoKHR *fd_info = NULL; const VkImportMemoryFdInfoKHR *fd_info = NULL;
const VkImportMemoryHostPointerInfoEXT *host_ptr_info = NULL; const VkImportMemoryHostPointerInfoEXT *host_ptr_info = NULL;
const VkMemoryDedicatedAllocateInfo *dedicated_info = NULL; const VkMemoryDedicatedAllocateInfo *dedicated_info = NULL;
VkMemoryAllocateFlags vk_flags = 0;
uint64_t client_address = 0;
vk_foreach_struct_const(ext, pAllocateInfo->pNext) { vk_foreach_struct_const(ext, pAllocateInfo->pNext) {
switch (ext->sType) { switch (ext->sType) {
@ -3111,10 +3122,23 @@ VkResult anv_AllocateMemory(
host_ptr_info = (void *)ext; host_ptr_info = (void *)ext;
break; break;
case VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO: {
const VkMemoryAllocateFlagsInfo *flags_info = (void *)ext;
vk_flags = flags_info->flags;
break;
}
case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO: case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO:
dedicated_info = (void *)ext; dedicated_info = (void *)ext;
break; break;
case VK_STRUCTURE_TYPE_MEMORY_OPAQUE_CAPTURE_ADDRESS_ALLOCATE_INFO_KHR: {
const VkMemoryOpaqueCaptureAddressAllocateInfoKHR *addr_info =
(const VkMemoryOpaqueCaptureAddressAllocateInfoKHR *)ext;
client_address = addr_info->opaqueCaptureAddress;
break;
}
case VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA: { case VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA: {
const struct wsi_memory_allocate_info *wsi_info = (void *)ext; const struct wsi_memory_allocate_info *wsi_info = (void *)ext;
if (wsi_info->implicit_sync) { if (wsi_info->implicit_sync) {
@ -3134,6 +3158,9 @@ VkResult anv_AllocateMemory(
} }
} }
if (vk_flags & VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR)
alloc_flags |= ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS;
/* Check if we need to support Android HW buffer export. If so, /* Check if we need to support Android HW buffer export. If so,
* create AHardwareBuffer and import memory from it. * create AHardwareBuffer and import memory from it.
*/ */
@ -3174,7 +3201,7 @@ VkResult anv_AllocateMemory(
VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT); VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
result = anv_device_import_bo(device, fd_info->fd, alloc_flags, result = anv_device_import_bo(device, fd_info->fd, alloc_flags,
0 /* client_address */, &mem->bo); client_address, &mem->bo);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
goto fail; goto fail;
@ -3227,9 +3254,8 @@ VkResult anv_AllocateMemory(
host_ptr_info->pHostPointer, host_ptr_info->pHostPointer,
pAllocateInfo->allocationSize, pAllocateInfo->allocationSize,
alloc_flags, alloc_flags,
0 /* client_address */, client_address,
&mem->bo); &mem->bo);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
goto fail; goto fail;
@ -3243,8 +3269,7 @@ VkResult anv_AllocateMemory(
alloc_flags |= ANV_BO_ALLOC_EXTERNAL; alloc_flags |= ANV_BO_ALLOC_EXTERNAL;
result = anv_device_alloc_bo(device, pAllocateInfo->allocationSize, result = anv_device_alloc_bo(device, pAllocateInfo->allocationSize,
alloc_flags, 0 /* explicit_address */, alloc_flags, client_address, &mem->bo);
&mem->bo);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
goto fail; goto fail;
@ -3932,17 +3957,37 @@ void anv_DestroyBuffer(
vk_free2(&device->alloc, pAllocator, buffer); vk_free2(&device->alloc, pAllocator, buffer);
} }
VkDeviceAddress anv_GetBufferDeviceAddressEXT( VkDeviceAddress anv_GetBufferDeviceAddressKHR(
VkDevice device, VkDevice device,
const VkBufferDeviceAddressInfoEXT* pInfo) const VkBufferDeviceAddressInfoKHR* pInfo)
{ {
ANV_FROM_HANDLE(anv_buffer, buffer, pInfo->buffer); ANV_FROM_HANDLE(anv_buffer, buffer, pInfo->buffer);
assert(!anv_address_is_null(buffer->address));
assert(buffer->address.bo->flags & EXEC_OBJECT_PINNED); assert(buffer->address.bo->flags & EXEC_OBJECT_PINNED);
return anv_address_physical(buffer->address); return anv_address_physical(buffer->address);
} }
uint64_t anv_GetBufferOpaqueCaptureAddressKHR(
VkDevice device,
const VkBufferDeviceAddressInfoKHR* pInfo)
{
return 0;
}
uint64_t anv_GetDeviceMemoryOpaqueCaptureAddressKHR(
VkDevice device,
const VkDeviceMemoryOpaqueCaptureAddressInfoKHR* pInfo)
{
ANV_FROM_HANDLE(anv_device_memory, memory, pInfo->memory);
assert(memory->bo->flags & EXEC_OBJECT_PINNED);
assert(memory->bo->has_client_visible_address);
return gen_48b_address(memory->bo->offset);
}
void void
anv_fill_buffer_surface_state(struct anv_device *device, struct anv_state state, anv_fill_buffer_surface_state(struct anv_device *device, struct anv_state state,
enum isl_format format, enum isl_format format,

View file

@ -70,6 +70,7 @@ EXTENSIONS = [
Extension('VK_KHR_8bit_storage', 1, 'device->info.gen >= 8'), Extension('VK_KHR_8bit_storage', 1, 'device->info.gen >= 8'),
Extension('VK_KHR_16bit_storage', 1, 'device->info.gen >= 8'), Extension('VK_KHR_16bit_storage', 1, 'device->info.gen >= 8'),
Extension('VK_KHR_bind_memory2', 1, True), Extension('VK_KHR_bind_memory2', 1, True),
Extension('VK_KHR_buffer_device_address', 1, True),
Extension('VK_KHR_create_renderpass2', 1, True), Extension('VK_KHR_create_renderpass2', 1, True),
Extension('VK_KHR_dedicated_allocation', 1, True), Extension('VK_KHR_dedicated_allocation', 1, True),
Extension('VK_KHR_depth_stencil_resolve', 1, True), Extension('VK_KHR_depth_stencil_resolve', 1, True),