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 <zzyiwei@chromium.org> Reviewed-by: Chia-I Wu <olvaffe@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12171>
This commit is contained in:
@@ -1128,10 +1128,7 @@ vn_android_fix_buffer_create_info(
|
|||||||
}
|
}
|
||||||
|
|
||||||
VkResult
|
VkResult
|
||||||
vn_android_buffer_from_ahb(struct vn_device *dev,
|
vn_android_init_ahb_buffer_memory_type_bits(struct vn_device *dev)
|
||||||
const VkBufferCreateInfo *create_info,
|
|
||||||
const VkAllocationCallbacks *alloc,
|
|
||||||
struct vn_buffer **out_buf)
|
|
||||||
{
|
{
|
||||||
const uint32_t format = AHARDWAREBUFFER_FORMAT_BLOB;
|
const uint32_t format = AHARDWAREBUFFER_FORMAT_BLOB;
|
||||||
/* ensure dma_buf_memory_type_bits covers host visible usage */
|
/* 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;
|
int dma_buf_fd = -1;
|
||||||
uint64_t alloc_size = 0;
|
uint64_t alloc_size = 0;
|
||||||
uint32_t mem_type_bits = 0;
|
uint32_t mem_type_bits = 0;
|
||||||
struct vn_android_buffer_create_info local_info;
|
|
||||||
VkResult result;
|
VkResult result;
|
||||||
|
|
||||||
ahb = vn_android_ahb_allocate(4096, 1, 1, format, usage);
|
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)
|
if (result != VK_SUCCESS)
|
||||||
return result;
|
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);
|
create_info = vn_android_fix_buffer_create_info(create_info, &local_info);
|
||||||
result = vn_buffer_create(dev, create_info, alloc, out_buf);
|
result = vn_buffer_create(dev, create_info, alloc, out_buf);
|
||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS)
|
||||||
@@ -1174,7 +1184,7 @@ vn_android_buffer_from_ahb(struct vn_device *dev,
|
|||||||
* properties.
|
* properties.
|
||||||
*/
|
*/
|
||||||
(*out_buf)->memory_requirements.memoryRequirements.memoryTypeBits &=
|
(*out_buf)->memory_requirements.memoryRequirements.memoryTypeBits &=
|
||||||
mem_type_bits;
|
dev->ahb_buffer_memory_type_bits;
|
||||||
|
|
||||||
assert((*out_buf)->memory_requirements.memoryRequirements.memoryTypeBits);
|
assert((*out_buf)->memory_requirements.memoryRequirements.memoryTypeBits);
|
||||||
|
|
||||||
|
@@ -75,6 +75,9 @@ vn_android_buffer_from_ahb(struct vn_device *dev,
|
|||||||
const VkAllocationCallbacks *alloc,
|
const VkAllocationCallbacks *alloc,
|
||||||
struct vn_buffer **out_buf);
|
struct vn_buffer **out_buf);
|
||||||
|
|
||||||
|
VkResult
|
||||||
|
vn_android_init_ahb_buffer_memory_type_bits(struct vn_device *dev);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static inline const VkNativeBufferANDROID *
|
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;
|
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 /* ANDROID */
|
||||||
|
|
||||||
#endif /* VN_ANDROID_H */
|
#endif /* VN_ANDROID_H */
|
||||||
|
@@ -3386,6 +3386,15 @@ vn_CreateDevice(VkPhysicalDevice physicalDevice,
|
|||||||
mtx_init(&pool->mutex, mtx_plain);
|
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;
|
*pDevice = dev_handle;
|
||||||
|
|
||||||
if (pCreateInfo == &local_create_info)
|
if (pCreateInfo == &local_create_info)
|
||||||
|
@@ -139,6 +139,9 @@ struct vn_device {
|
|||||||
uint32_t queue_count;
|
uint32_t queue_count;
|
||||||
|
|
||||||
struct vn_device_memory_pool memory_pools[VK_MAX_MEMORY_TYPES];
|
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,
|
VK_DEFINE_HANDLE_CASTS(vn_device,
|
||||||
base.base.base,
|
base.base.base,
|
||||||
|
Reference in New Issue
Block a user