Mesa (main): venus: support AHB prop query with host dma_buf size
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Jun 3 19:45:56 UTC 2021
Module: Mesa
Branch: main
Commit: d08930f2fa28cdf1317130984ffd5938ed21e940
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=d08930f2fa28cdf1317130984ffd5938ed21e940
Author: Yiwei Zhang <zzyiwei at chromium.org>
Date: Tue Jun 1 22:23:53 2021 +0000
venus: support AHB prop query with host dma_buf size
Upon instance creation, venus experimental features are cached in the
vn_instance. If memoryResourceAllocationSize feature is supported, chain
VkMemoryResourceAllocationSizeProperties100000MESA to the pNext of
VkMemoryResourcePropertiesMESA to get the host allocation size of the
dma_buf fd.
Signed-off-by: Yiwei Zhang <zzyiwei at chromium.org>
Reviewed-by: Chia-I Wu <olvaffe at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11048>
---
src/virtio/vulkan/vn_android.c | 20 +++++++++++---------
src/virtio/vulkan/vn_device.c | 13 ++++++++++++-
src/virtio/vulkan/vn_device.h | 5 +++++
src/virtio/vulkan/vn_device_memory.c | 14 +++++++++++---
4 files changed, 39 insertions(+), 13 deletions(-)
diff --git a/src/virtio/vulkan/vn_android.c b/src/virtio/vulkan/vn_android.c
index c7afcb299c2..4aaf7a1c529 100644
--- a/src/virtio/vulkan/vn_android.c
+++ b/src/virtio/vulkan/vn_android.c
@@ -450,9 +450,11 @@ vn_android_image_from_anb(struct vn_device *dev,
mem_req.size, alloc_size, mem_req.memoryTypeBits, mem_type_bits);
}
- /* TODO When alloc_size is fixed to return host storage size, we will
- * also check alloc_size is not smaller than mem_req.size here.
- */
+ if (alloc_size < mem_req.size) {
+ result = VK_ERROR_INVALID_EXTERNAL_HANDLE;
+ goto fail;
+ }
+
mem_type_bits &= mem_req.memoryTypeBits;
if (!mem_type_bits) {
result = VK_ERROR_INVALID_EXTERNAL_HANDLE;
@@ -886,21 +888,21 @@ vn_android_device_import_ahb(struct vn_device *dev,
if (result != VK_SUCCESS)
return result;
- /* TODO When alloc_size is fixed to return host storage size, we will
- * also check alloc_size is not smaller than mem_req.size here.
- */
VkMemoryRequirements mem_req;
vn_GetImageMemoryRequirements(device, dedicated_info->image, &mem_req);
+ if (alloc_size < mem_req.size)
+ return VK_ERROR_INVALID_EXTERNAL_HANDLE;
+
alloc_size = mem_req.size;
}
if (dedicated_info && dedicated_info->buffer != VK_NULL_HANDLE) {
- /* TODO When alloc_size is fixed to return host storage size, we will
- * also check alloc_size is not smaller than mem_req.size here.
- */
VkMemoryRequirements mem_req;
vn_GetBufferMemoryRequirements(device, dedicated_info->buffer,
&mem_req);
+ if (alloc_size < mem_req.size)
+ return VK_ERROR_INVALID_EXTERNAL_HANDLE;
+
alloc_size = mem_req.size;
}
diff --git a/src/virtio/vulkan/vn_device.c b/src/virtio/vulkan/vn_device.c
index a9380aebc22..6ef024c87a6 100644
--- a/src/virtio/vulkan/vn_device.c
+++ b/src/virtio/vulkan/vn_device.c
@@ -1453,7 +1453,8 @@ vn_physical_device_get_native_extensions(
renderer_info->has_dma_buf_import) {
#ifdef ANDROID
if (renderer_exts->EXT_image_drm_format_modifier &&
- renderer_exts->EXT_queue_family_foreign) {
+ renderer_exts->EXT_queue_family_foreign &&
+ instance->experimental.memoryResourceAllocationSize == VK_TRUE) {
exts->ANDROID_external_memory_android_hardware_buffer = true;
exts->ANDROID_native_buffer = true;
}
@@ -1895,6 +1896,16 @@ vn_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
if (result != VK_SUCCESS)
goto fail;
+ if (instance->renderer_info.vk_mesa_venus_protocol_spec_version ==
+ 100000) {
+ size_t size = 0;
+ vn_call_vkGetVenusExperimentalFeatureData100000MESA(instance, &size,
+ NULL);
+ size = MIN2(size, sizeof(instance->experimental));
+ vn_call_vkGetVenusExperimentalFeatureData100000MESA(
+ instance, &size, &instance->experimental);
+ }
+
result = vn_instance_init_renderer_versions(instance);
if (result != VK_SUCCESS)
goto fail;
diff --git a/src/virtio/vulkan/vn_device.h b/src/virtio/vulkan/vn_device.h
index 9f01de7c734..1e79cec73ef 100644
--- a/src/virtio/vulkan/vn_device.h
+++ b/src/virtio/vulkan/vn_device.h
@@ -13,6 +13,8 @@
#include "vn_common.h"
+#include "venus-protocol/vn_protocol_driver_defines.h"
+
#include "vn_cs.h"
#include "vn_device_memory.h"
#include "vn_renderer.h"
@@ -63,6 +65,9 @@ struct vn_instance {
mtx_t physical_device_mutex;
struct vn_physical_device *physical_devices;
uint32_t physical_device_count;
+
+ /* XXX staged features to be merged to core venus protocol */
+ VkVenusExperimentalFeatures100000MESA experimental;
};
VK_DEFINE_HANDLE_CASTS(vn_instance,
base.base.base,
diff --git a/src/virtio/vulkan/vn_device_memory.c b/src/virtio/vulkan/vn_device_memory.c
index bf19970bebf..5e427ee4d78 100644
--- a/src/virtio/vulkan/vn_device_memory.c
+++ b/src/virtio/vulkan/vn_device_memory.c
@@ -502,9 +502,18 @@ vn_get_memory_dma_buf_properties(struct vn_device *dev,
vn_instance_roundtrip(dev->instance);
+ VkMemoryResourceAllocationSizeProperties100000MESA alloc_size_props = {
+ .sType =
+ VK_STRUCTURE_TYPE_MEMORY_RESOURCE_ALLOCATION_SIZE_PROPERTIES_100000_MESA,
+ .pNext = NULL,
+ .allocationSize = 0,
+ };
VkMemoryResourcePropertiesMESA props = {
.sType = VK_STRUCTURE_TYPE_MEMORY_RESOURCE_PROPERTIES_MESA,
- .pNext = NULL,
+ .pNext =
+ dev->instance->experimental.memoryResourceAllocationSize == VK_TRUE
+ ? &alloc_size_props
+ : NULL,
.memoryTypeBits = 0,
};
result = vn_call_vkGetMemoryResourcePropertiesMESA(dev->instance, device,
@@ -513,8 +522,7 @@ vn_get_memory_dma_buf_properties(struct vn_device *dev,
if (result != VK_SUCCESS)
return result;
- /* XXX extend VkMemoryResourcePropertiesMESA for host storage size */
- *out_alloc_size = lseek(fd, 0, SEEK_END);
+ *out_alloc_size = alloc_size_props.allocationSize;
*out_mem_type_bits = props.memoryTypeBits;
return VK_SUCCESS;
More information about the mesa-commit
mailing list