Mesa (main): venus: implement vn_buffer_get_max_buffer_size
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Oct 28 00:33:48 UTC 2021
Module: Mesa
Branch: main
Commit: a74f2495ca07bb536e8f1caaa8c2a4ed36c10d67
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=a74f2495ca07bb536e8f1caaa8c2a4ed36c10d67
Author: Yiwei Zhang <zzyiwei at chromium.org>
Date: Mon Oct 18 18:03:11 2021 +0000
venus: implement vn_buffer_get_max_buffer_size
This change estimates the max_buffer_size with quick sort. Try to
avoid some traffic upon device creation time, but not worth adding a
buffer simple create api to avoid the extra requirement query traffic
since this is temporary.
Signed-off-by: Yiwei Zhang <zzyiwei at chromium.org>
Reviewed-by: Chia-I Wu <olvaffe at gmail.com>
Reviewed-by: Ryan Neph <ryanneph at google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13428>
---
src/virtio/vulkan/vn_buffer.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/src/virtio/vulkan/vn_buffer.c b/src/virtio/vulkan/vn_buffer.c
index 5a5a8d25e5f..00392a9a988 100644
--- a/src/virtio/vulkan/vn_buffer.c
+++ b/src/virtio/vulkan/vn_buffer.c
@@ -43,7 +43,33 @@ static VkResult
vn_buffer_get_max_buffer_size(struct vn_device *dev,
uint64_t *out_max_buffer_size)
{
- *out_max_buffer_size = 0;
+ /* XXX use VK_KHR_maintenance4 when available */
+ const VkAllocationCallbacks *alloc = &dev->base.base.alloc;
+ VkDevice dev_handle = vn_device_to_handle(dev);
+ VkBuffer buf_handle;
+ VkBufferCreateInfo create_info = {
+ .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
+ .usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
+ .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
+ };
+ uint64_t max_buffer_size = 0;
+ uint8_t begin = 0;
+ uint8_t end = 64;
+
+ while (begin <= end) {
+ uint8_t mid = (begin + end) >> 1;
+ create_info.size = 1 << mid;
+ if (vn_CreateBuffer(dev_handle, &create_info, alloc, &buf_handle) ==
+ VK_SUCCESS) {
+ vn_DestroyBuffer(dev_handle, buf_handle, alloc);
+ max_buffer_size = create_info.size;
+ begin = mid + 1;
+ } else {
+ end = mid - 1;
+ }
+ }
+
+ *out_max_buffer_size = max_buffer_size;
return VK_SUCCESS;
}
More information about the mesa-commit
mailing list