vkr: return dma_buf allocation size in vkGetMemoryResourcePropertiesMESA

Handle type must be VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT.
Check if VkMemoryResourceAllocationSizeProperties100000MESA is
chained. If chained, fill with dma_buf allocation size.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
macos/master
Yiwei Zhang 4 years ago
parent 606f2adfac
commit 32a3f0c3c6
  1. 44
      src/vkr_renderer.c

@ -3858,24 +3858,57 @@ vkr_dispatch_vkGetMemoryResourcePropertiesMESA(
enum virgl_resource_fd_type fd_type = virgl_resource_export_fd(att->resource, &fd); enum virgl_resource_fd_type fd_type = virgl_resource_export_fd(att->resource, &fd);
VkExternalMemoryHandleTypeFlagBits handle_type; VkExternalMemoryHandleTypeFlagBits handle_type;
if (!vkr_get_fd_handle_type_from_virgl_fd_type(dev->physical_device, fd_type, if (!vkr_get_fd_handle_type_from_virgl_fd_type(dev->physical_device, fd_type,
&handle_type)) { &handle_type) ||
handle_type != VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT) {
close(fd); close(fd);
args->ret = VK_ERROR_INVALID_EXTERNAL_HANDLE; args->ret = VK_ERROR_INVALID_EXTERNAL_HANDLE;
return; return;
} }
VkMemoryFdPropertiesKHR memory_fd_properties = { VkMemoryFdPropertiesKHR mem_fd_props = {
.sType = VK_STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR, .sType = VK_STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR,
.pNext = NULL, .pNext = NULL,
.memoryTypeBits = 0, .memoryTypeBits = 0,
}; };
vn_replace_vkGetMemoryResourcePropertiesMESA_args_handle(args); vn_replace_vkGetMemoryResourcePropertiesMESA_args_handle(args);
args->ret = args->ret =
dev->get_memory_fd_properties(args->device, handle_type, fd, &memory_fd_properties); dev->get_memory_fd_properties(args->device, handle_type, fd, &mem_fd_props);
args->pMemoryResourceProperties->memoryTypeBits = memory_fd_properties.memoryTypeBits; if (args->ret != VK_SUCCESS) {
close(fd);
return;
}
args->pMemoryResourceProperties->memoryTypeBits = mem_fd_props.memoryTypeBits;
VkMemoryResourceAllocationSizeProperties100000MESA *alloc_size_props = vkr_find_pnext(
args->pMemoryResourceProperties->pNext,
VK_STRUCTURE_TYPE_MEMORY_RESOURCE_ALLOCATION_SIZE_PROPERTIES_100000_MESA);
if (alloc_size_props)
alloc_size_props->allocationSize = lseek(fd, 0, SEEK_END);
close(fd); close(fd);
} }
static void
vkr_dispatch_vkGetVenusExperimentalFeatureData100000MESA(
UNUSED struct vn_dispatch_context *dispatch,
struct vn_command_vkGetVenusExperimentalFeatureData100000MESA *args)
{
const VkVenusExperimentalFeatures100000MESA features = {
.memoryResourceAllocationSize = VK_TRUE,
};
vn_replace_vkGetVenusExperimentalFeatureData100000MESA_args_handle(args);
if (!args->pData) {
*args->pDataSize = sizeof(features);
return;
}
*args->pDataSize = MIN2(*args->pDataSize, sizeof(features));
memcpy(args->pData, &features, *args->pDataSize);
}
static void static void
vkr_dispatch_debug_log(UNUSED struct vn_dispatch_context *dispatch, const char *msg) vkr_dispatch_debug_log(UNUSED struct vn_dispatch_context *dispatch, const char *msg)
{ {
@ -4174,6 +4207,9 @@ vkr_context_init_dispatch(struct vkr_context *ctx)
dispatch->dispatch_vkGetMemoryResourcePropertiesMESA = dispatch->dispatch_vkGetMemoryResourcePropertiesMESA =
vkr_dispatch_vkGetMemoryResourcePropertiesMESA; vkr_dispatch_vkGetMemoryResourcePropertiesMESA;
dispatch->dispatch_vkGetVenusExperimentalFeatureData100000MESA =
vkr_dispatch_vkGetVenusExperimentalFeatureData100000MESA;
} }
static int static int

Loading…
Cancel
Save