venus: prepare vn_CreateBuffer for AHB

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/11661>
This commit is contained in:
Yiwei Zhang 2021-06-30 06:04:39 +00:00 committed by Marge Bot
parent 0ea726b5fd
commit 3527146a26
2 changed files with 45 additions and 16 deletions

View File

@ -19,29 +19,30 @@
/* buffer commands */
VkResult
vn_CreateBuffer(VkDevice device,
const VkBufferCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkBuffer *pBuffer)
vn_buffer_create(struct vn_device *dev,
const VkBufferCreateInfo *create_info,
const VkAllocationCallbacks *alloc,
struct vn_buffer **out_buf)
{
struct vn_device *dev = vn_device_from_handle(device);
const VkAllocationCallbacks *alloc =
pAllocator ? pAllocator : &dev->base.base.alloc;
VkDevice device = vn_device_to_handle(dev);
struct vn_buffer *buf = NULL;
VkBuffer buffer = VK_NULL_HANDLE;
VkResult result;
struct vn_buffer *buf = vk_zalloc(alloc, sizeof(*buf), VN_DEFAULT_ALIGN,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
buf = vk_zalloc(alloc, sizeof(*buf), VN_DEFAULT_ALIGN,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!buf)
return vn_error(dev->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
return VK_ERROR_OUT_OF_HOST_MEMORY;
vn_object_base_init(&buf->base, VK_OBJECT_TYPE_BUFFER, &dev->base);
VkBuffer buf_handle = vn_buffer_to_handle(buf);
buffer = vn_buffer_to_handle(buf);
/* TODO async */
VkResult result = vn_call_vkCreateBuffer(dev->instance, device,
pCreateInfo, NULL, &buf_handle);
result = vn_call_vkCreateBuffer(dev->instance, device, create_info, NULL,
&buffer);
if (result != VK_SUCCESS) {
vk_free(alloc, buf);
return vn_error(dev->instance, result);
return result;
}
/* TODO add a per-device cache for the requirements */
@ -55,11 +56,33 @@ vn_CreateBuffer(VkDevice device,
dev->instance, device,
&(VkBufferMemoryRequirementsInfo2){
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2,
.buffer = vn_buffer_to_handle(buf),
.buffer = buffer,
},
&buf->memory_requirements);
*pBuffer = buf_handle;
*out_buf = buf;
return VK_SUCCESS;
}
VkResult
vn_CreateBuffer(VkDevice device,
const VkBufferCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkBuffer *pBuffer)
{
struct vn_device *dev = vn_device_from_handle(device);
const VkAllocationCallbacks *alloc =
pAllocator ? pAllocator : &dev->base.base.alloc;
struct vn_buffer *buf = NULL;
VkResult result;
result = vn_buffer_create(dev, pCreateInfo, alloc, &buf);
if (result != VK_SUCCESS)
return vn_error(dev->instance, result);
*pBuffer = vn_buffer_to_handle(buf);
return VK_SUCCESS;
}

View File

@ -32,4 +32,10 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(vn_buffer_view,
VkBufferView,
VK_OBJECT_TYPE_BUFFER_VIEW)
VkResult
vn_buffer_create(struct vn_device *dev,
const VkBufferCreateInfo *create_info,
const VkAllocationCallbacks *alloc,
struct vn_buffer **out_buf);
#endif /* VN_BUFFER_H */