a/vk: Remove global command pool

This commit is contained in:
Jakob Bornecrantz 2023-04-02 01:12:57 +01:00
parent e9475b1313
commit 86262e8b4e
9 changed files with 0 additions and 304 deletions

View file

@ -1166,9 +1166,6 @@ err_destroy:
VkResult
vk_init_mutex(struct vk_bundle *vk)
{
if (os_mutex_init(&vk->cmd_pool_mutex) < 0) {
return VK_ERROR_INITIALIZATION_FAILED;
}
if (os_mutex_init(&vk->queue_mutex) < 0) {
return VK_ERROR_INITIALIZATION_FAILED;
}
@ -1178,29 +1175,10 @@ vk_init_mutex(struct vk_bundle *vk)
VkResult
vk_deinit_mutex(struct vk_bundle *vk)
{
os_mutex_destroy(&vk->cmd_pool_mutex);
os_mutex_destroy(&vk->queue_mutex);
return VK_SUCCESS;
}
XRT_CHECK_RESULT VkResult
vk_init_cmd_pool(struct vk_bundle *vk)
{
VkCommandPoolCreateInfo cmd_pool_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
.queueFamilyIndex = vk->queue_family_index,
};
VkResult ret;
ret = vk->vkCreateCommandPool(vk->device, &cmd_pool_info, NULL, &vk->cmd_pool);
if (ret != VK_SUCCESS) {
VK_ERROR(vk, "vkCreateCommandPool: %s", vk_result_string(ret));
}
return ret;
}
/*
*
@ -1283,12 +1261,6 @@ vk_init_from_given(struct vk_bundle *vk,
vk->vkGetDeviceQueue(vk->device, vk->queue_family_index, vk->queue_index, &vk->queue);
// Create the pool.
ret = vk_init_cmd_pool(vk);
if (ret != VK_SUCCESS) {
goto err_memset;
}
return VK_SUCCESS;

View file

@ -1352,166 +1352,6 @@ vk_update_buffer(struct vk_bundle *vk, float *buffer, size_t buffer_size, VkDevi
*
*/
VkResult
vk_cmd_buffer_create(struct vk_bundle *vk, VkCommandBuffer *out_cmd_buffer)
{
VkCommandBuffer cmd_buffer;
VkResult ret;
// Allocate the command buffer.
VkCommandBufferAllocateInfo cmd_buffer_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.commandPool = vk->cmd_pool,
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
.commandBufferCount = 1,
};
os_mutex_lock(&vk->cmd_pool_mutex);
ret = vk->vkAllocateCommandBuffers(vk->device, &cmd_buffer_info, &cmd_buffer);
os_mutex_unlock(&vk->cmd_pool_mutex);
if (ret != VK_SUCCESS) {
VK_ERROR(vk, "vkAllocateCommandBuffers: %s", vk_result_string(ret));
// Nothing to cleanup
return ret;
}
*out_cmd_buffer = cmd_buffer;
return VK_SUCCESS;
}
VkResult
vk_cmd_buffer_create_and_begin(struct vk_bundle *vk, VkCommandBuffer *out_cmd_buffer)
{
VkCommandBuffer cmd_buffer;
VkResult ret;
ret = vk_cmd_buffer_create(vk, &cmd_buffer);
if (ret != VK_SUCCESS) {
VK_ERROR(vk, "vk_cmd_buffer_create: %s", vk_result_string(ret));
// Nothing to cleanup
return ret;
}
// Start the command buffer as well.
VkCommandBufferBeginInfo begin_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
};
os_mutex_lock(&vk->cmd_pool_mutex);
ret = vk->vkBeginCommandBuffer(cmd_buffer, &begin_info);
os_mutex_unlock(&vk->cmd_pool_mutex);
if (ret != VK_SUCCESS) {
VK_ERROR(vk, "vkBeginCommandBuffer: %s", vk_result_string(ret));
goto err_buffer;
}
*out_cmd_buffer = cmd_buffer;
return VK_SUCCESS;
err_buffer:
vk->vkFreeCommandBuffers(vk->device, vk->cmd_pool, 1, &cmd_buffer);
return ret;
}
XRT_CHECK_RESULT VkResult
vk_cmd_buffer_submit(struct vk_bundle *vk, VkCommandBuffer cmd_buffer)
{
VkResult ret = VK_SUCCESS;
VkFence fence;
VkFenceCreateInfo fence_info = {
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
};
VkSubmitInfo submitInfo = {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
.commandBufferCount = 1,
.pCommandBuffers = &cmd_buffer,
};
// Finish the command buffer first.
os_mutex_lock(&vk->cmd_pool_mutex);
ret = vk->vkEndCommandBuffer(cmd_buffer);
os_mutex_unlock(&vk->cmd_pool_mutex);
if (ret != VK_SUCCESS) {
VK_ERROR(vk, "vkEndCommandBuffer: %s", vk_result_string(ret));
goto out;
}
// Create the fence.
ret = vk->vkCreateFence(vk->device, &fence_info, NULL, &fence);
if (ret != VK_SUCCESS) {
VK_ERROR(vk, "vkCreateFence: %s", vk_result_string(ret));
goto out;
}
// Do the actual submitting.
ret = vk_locked_submit(vk, vk->queue, 1, &submitInfo, fence);
if (ret != VK_SUCCESS) {
VK_ERROR(vk, "Error: Could not submit to queue.\n");
goto out_fence;
}
// Then wait for the fence.
ret = vk->vkWaitForFences(vk->device, 1, &fence, VK_TRUE, 1000000000);
if (ret != VK_SUCCESS) {
VK_ERROR(vk, "vkWaitForFences: %s", vk_result_string(ret));
goto out_fence;
}
// Yes fall through.
out_fence:
vk->vkDestroyFence(vk->device, fence, NULL);
out:
os_mutex_lock(&vk->cmd_pool_mutex);
vk->vkFreeCommandBuffers(vk->device, vk->cmd_pool, 1, &cmd_buffer);
os_mutex_unlock(&vk->cmd_pool_mutex);
return ret;
}
XRT_CHECK_RESULT VkResult
vk_locked_submit(struct vk_bundle *vk, VkQueue queue, uint32_t count, const VkSubmitInfo *infos, VkFence fence)
{
VkResult ret;
os_mutex_lock(&vk->queue_mutex);
os_mutex_lock(&vk->cmd_pool_mutex);
ret = vk->vkQueueSubmit(queue, count, infos, fence);
os_mutex_unlock(&vk->cmd_pool_mutex);
os_mutex_unlock(&vk->queue_mutex);
return ret;
}
void
vk_cmd_image_barrier_gpu(struct vk_bundle *vk,
VkCommandBuffer cmd_buffer,
VkImage image,
VkAccessFlags src_access_mask,
VkAccessFlags dst_access_mask,
VkImageLayout old_layout,
VkImageLayout new_layout,
VkImageSubresourceRange subresource_range)
{
os_mutex_lock(&vk->cmd_pool_mutex);
vk_cmd_image_barrier_gpu_locked( //
vk, // vk_bundle
cmd_buffer, // cmd_buffer
image, // image
src_access_mask, // src_access_mask
dst_access_mask, // dst_access_mask
old_layout, // old_image_layout
new_layout, // new_image_layout
subresource_range); // subresource_range
os_mutex_unlock(&vk->cmd_pool_mutex);
}
void
vk_cmd_image_barrier_locked(struct vk_bundle *vk,
VkCommandBuffer cmd_buffer,

View file

@ -167,10 +167,6 @@ struct vk_bundle
VkPhysicalDeviceMemoryProperties device_memory_props;
VkCommandPool cmd_pool;
struct os_mutex cmd_pool_mutex;
// Loader functions
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
PFN_vkCreateInstance vkCreateInstance;
@ -674,14 +670,6 @@ vk_init_mutex(struct vk_bundle *vk);
VkResult
vk_deinit_mutex(struct vk_bundle *vk);
/*!
* Requires device and queue to have been set up.
*
* @ingroup aux_vk
*/
XRT_CHECK_RESULT VkResult
vk_init_cmd_pool(struct vk_bundle *vk);
/*!
* Initialize a bundle with objects given to us by client code,
* used by @ref client_vk_compositor in @ref comp_client.
@ -935,77 +923,6 @@ bool
vk_update_buffer(struct vk_bundle *vk, float *buffer, size_t buffer_size, VkDeviceMemory memory);
/*
*
* Helpers for writing command buffers using the global command pool.
*
*/
/*!
* Create a new command buffer, takes the pool lock.
*
* @pre Requires successful call to vk_init_mutex.
*
* @ingroup aux_vk
*/
VkResult
vk_cmd_buffer_create(struct vk_bundle *vk, VkCommandBuffer *out_cmd_buffer);
/*!
* Create and begins a new command buffer, takes the pool lock.
*
* @pre Requires successful call to vk_init_mutex.
*
* @ingroup aux_vk
*/
VkResult
vk_cmd_buffer_create_and_begin(struct vk_bundle *vk, VkCommandBuffer *out_cmd_buffer);
/*!
* A do everything command buffer submission function, during the operation
* the pool lock will be taken and released.
*
* * Creates a new fence.
* * Submits @p cmd_buffer to the queue, along with the fence.
* * Waits for the fence to complete.
* * Destroys the fence.
* * Destroy @p cmd_buffer.
*
* @pre Requires successful call to vk_init_mutex.
*
* @ingroup aux_vk
*/
XRT_CHECK_RESULT VkResult
vk_cmd_buffer_submit(struct vk_bundle *vk, VkCommandBuffer cmd_buffer);
/*!
* Submits to the given queue, with the given fence.
*
* @pre Requires successful call to vk_init_mutex.
*
* @ingroup aux_vk
*/
XRT_CHECK_RESULT VkResult
vk_locked_submit(struct vk_bundle *vk, VkQueue queue, uint32_t count, const VkSubmitInfo *infos, VkFence fence);
/*!
* Set the image layout using a barrier command, takes the pool lock.
*
* @pre Requires successful call to vk_init_mutex.
*
* @ingroup aux_vk
*/
void
vk_cmd_image_barrier_gpu(struct vk_bundle *vk,
VkCommandBuffer cmd_buffer,
VkImage image,
VkAccessFlags src_access_mask,
VkAccessFlags dst_access_mask,
VkImageLayout old_layout,
VkImageLayout new_layout,
VkImageSubresourceRange subresource_range);
/*
*
* Helpers for writing command buffers, in the vk_helpers.c file.

View file

@ -365,12 +365,6 @@ client_vk_compositor_destroy(struct xrt_compositor *xc)
// Now safe to free the pool.
vk_cmd_pool_destroy(vk, &c->pool);
// Still needs to free this, even tho it's not used.
if (vk->cmd_pool != VK_NULL_HANDLE) {
vk->vkDestroyCommandPool(vk->device, vk->cmd_pool, NULL);
vk->cmd_pool = VK_NULL_HANDLE;
}
vk_deinit_mutex(vk);
free(c);

View file

@ -474,11 +474,6 @@ compositor_destroy(struct xrt_compositor *xc)
// As long as vk_bundle is valid it's safe to call this function.
render_shaders_close(&c->shaders, vk);
if (vk->cmd_pool != VK_NULL_HANDLE) {
vk->vkDestroyCommandPool(vk->device, vk->cmd_pool, NULL);
vk->cmd_pool = VK_NULL_HANDLE;
}
if (vk->device != VK_NULL_HANDLE) {
vk->vkDestroyDevice(vk->device, NULL);
vk->device = VK_NULL_HANDLE;

View file

@ -509,12 +509,6 @@ null_compositor_destroy(struct xrt_compositor *xc)
// Must be destroyed before Vulkan.
comp_swapchain_shared_destroy(&c->base.cscs, vk);
if (vk->cmd_pool != VK_NULL_HANDLE) {
vk->vkDestroyCommandPool(vk->device, vk->cmd_pool, NULL);
vk->cmd_pool = VK_NULL_HANDLE;
}
if (vk->device != VK_NULL_HANDLE) {
vk->vkDestroyDevice(vk->device, NULL);
vk->device = VK_NULL_HANDLE;

View file

@ -272,12 +272,6 @@ create_device(struct vk_bundle *vk, const struct comp_vulkan_arguments *vk_args)
return ret;
}
ret = vk_init_cmd_pool(vk);
if (ret != VK_SUCCESS) {
VK_ERROR_RET(vk, "vk_init_cmd_pool", "Failed to init command pool.", ret);
return ret;
}
// Print device information.
vk_print_opened_device_info(vk, U_LOGGING_INFO);

View file

@ -525,11 +525,6 @@ sdl_compositor_destroy(struct xrt_compositor *xc)
// Must be destroyed before Vulkan.
comp_swapchain_shared_destroy(&c->base.cscs, vk);
if (vk->cmd_pool != VK_NULL_HANDLE) {
vk->vkDestroyCommandPool(vk->device, vk->cmd_pool, NULL);
vk->cmd_pool = VK_NULL_HANDLE;
}
if (vk->device != VK_NULL_HANDLE) {
vk->vkDestroyDevice(vk->device, NULL);
vk->device = VK_NULL_HANDLE;

View file

@ -177,11 +177,6 @@ TEST_CASE("client_compositor", "[.][needgpu]")
xrt_comp_destroy(&xc);
if (vk->cmd_pool != VK_NULL_HANDLE) {
vk->vkDeviceWaitIdle(vk->device);
vk->vkDestroyCommandPool(vk->device, vk->cmd_pool, NULL);
vk->cmd_pool = VK_NULL_HANDLE;
}
vk_deinit_mutex(vk);
xrt_comp_native_destroy(&xcn);