From: Yiwei Zhang Date: Mon, 2 Aug 2021 15:49:55 +0000 (+0000) Subject: venus: cache ahb backed buffer memory type bits requirement X-Git-Tag: upstream/22.3.5~19635 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e08960482a1330f93d6c6c7b0654b08bc29537f0;p=platform%2Fupstream%2Fmesa.git venus: cache ahb backed buffer memory type bits requirement To properly init buffer memory requirement for AHB, memory type bits from dma_buf fd properties need to be masked. However, creating a test AHB at buffer creation is too costy. This patch caches the ahb backed buffer memory type bits at device creation time if the app is requesting AHB extension. Cc: 21.2 mesa-stable Signed-off-by: Yiwei Zhang Reviewed-by: Chia-I Wu Part-of: --- diff --git a/src/virtio/vulkan/vn_android.c b/src/virtio/vulkan/vn_android.c index 2b0c005..0dbcbc5 100644 --- a/src/virtio/vulkan/vn_android.c +++ b/src/virtio/vulkan/vn_android.c @@ -1128,10 +1128,7 @@ vn_android_fix_buffer_create_info( } VkResult -vn_android_buffer_from_ahb(struct vn_device *dev, - const VkBufferCreateInfo *create_info, - const VkAllocationCallbacks *alloc, - struct vn_buffer **out_buf) +vn_android_init_ahb_buffer_memory_type_bits(struct vn_device *dev) { const uint32_t format = AHARDWAREBUFFER_FORMAT_BLOB; /* ensure dma_buf_memory_type_bits covers host visible usage */ @@ -1142,7 +1139,6 @@ vn_android_buffer_from_ahb(struct vn_device *dev, int dma_buf_fd = -1; uint64_t alloc_size = 0; uint32_t mem_type_bits = 0; - struct vn_android_buffer_create_info local_info; VkResult result; ahb = vn_android_ahb_allocate(4096, 1, 1, format, usage); @@ -1164,6 +1160,20 @@ vn_android_buffer_from_ahb(struct vn_device *dev, if (result != VK_SUCCESS) return result; + dev->ahb_buffer_memory_type_bits = mem_type_bits; + + return VK_SUCCESS; +} + +VkResult +vn_android_buffer_from_ahb(struct vn_device *dev, + const VkBufferCreateInfo *create_info, + const VkAllocationCallbacks *alloc, + struct vn_buffer **out_buf) +{ + struct vn_android_buffer_create_info local_info; + VkResult result; + create_info = vn_android_fix_buffer_create_info(create_info, &local_info); result = vn_buffer_create(dev, create_info, alloc, out_buf); if (result != VK_SUCCESS) @@ -1174,7 +1184,7 @@ vn_android_buffer_from_ahb(struct vn_device *dev, * properties. */ (*out_buf)->memory_requirements.memoryRequirements.memoryTypeBits &= - mem_type_bits; + dev->ahb_buffer_memory_type_bits; assert((*out_buf)->memory_requirements.memoryRequirements.memoryTypeBits); diff --git a/src/virtio/vulkan/vn_android.h b/src/virtio/vulkan/vn_android.h index 8389b6d..038aec3 100644 --- a/src/virtio/vulkan/vn_android.h +++ b/src/virtio/vulkan/vn_android.h @@ -75,6 +75,9 @@ vn_android_buffer_from_ahb(struct vn_device *dev, const VkAllocationCallbacks *alloc, struct vn_buffer **out_buf); +VkResult +vn_android_init_ahb_buffer_memory_type_bits(struct vn_device *dev); + #else static inline const VkNativeBufferANDROID * @@ -157,6 +160,12 @@ vn_android_buffer_from_ahb(UNUSED struct vn_device *dev, return VK_ERROR_OUT_OF_HOST_MEMORY; } +static inline VkResult +vn_android_init_ahb_buffer_memory_type_bits(UNUSED struct vn_device *dev) +{ + return VK_ERROR_FEATURE_NOT_PRESENT; +} + #endif /* ANDROID */ #endif /* VN_ANDROID_H */ diff --git a/src/virtio/vulkan/vn_device.c b/src/virtio/vulkan/vn_device.c index d20a6c6..7e890b4 100644 --- a/src/virtio/vulkan/vn_device.c +++ b/src/virtio/vulkan/vn_device.c @@ -3386,6 +3386,15 @@ vn_CreateDevice(VkPhysicalDevice physicalDevice, mtx_init(&pool->mutex, mtx_plain); } + if (dev->base.base.enabled_extensions + .ANDROID_external_memory_android_hardware_buffer) { + result = vn_android_init_ahb_buffer_memory_type_bits(dev); + if (result != VK_SUCCESS) { + vn_call_vkDestroyDevice(instance, dev_handle, NULL); + goto fail; + } + } + *pDevice = dev_handle; if (pCreateInfo == &local_create_info) diff --git a/src/virtio/vulkan/vn_device.h b/src/virtio/vulkan/vn_device.h index 1e79cec..b0fc465 100644 --- a/src/virtio/vulkan/vn_device.h +++ b/src/virtio/vulkan/vn_device.h @@ -139,6 +139,9 @@ struct vn_device { uint32_t queue_count; struct vn_device_memory_pool memory_pools[VK_MAX_MEMORY_TYPES]; + + /* cache memory type requirement for AHB backed VkBuffer */ + uint32_t ahb_buffer_memory_type_bits; }; VK_DEFINE_HANDLE_CASTS(vn_device, base.base.base,