c/main: Use cmd pool helpers in layer render

This commit is contained in:
Jakob Bornecrantz 2023-04-01 23:48:15 +01:00
parent 1ddfcaa5ab
commit 5ef2b647f1
2 changed files with 31 additions and 7 deletions

View file

@ -1,4 +1,4 @@
// Copyright 2020, Collabora, Ltd.
// Copyright 2020-2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
@ -501,6 +501,12 @@ _init(struct comp_layer_renderer *self,
math_matrix_4x4_identity(&self->mat_eye_view[i]);
}
VkResult ret = vk_cmd_pool_init(vk, &self->pool, 0);
if (ret != VK_SUCCESS) {
VK_ERROR(vk, "vk_cmd_pool_init: %s", vk_result_string(ret));
return false;
}
if (!_init_render_pass(vk, format, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, self->sample_count,
&self->render_pass))
return false;
@ -627,22 +633,35 @@ void
comp_layer_renderer_draw(struct comp_layer_renderer *self)
{
COMP_TRACE_MARKER();
VkResult ret;
struct vk_bundle *vk = self->vk;
struct vk_cmd_pool *pool = &self->pool;
// Writing and submitting commands.
vk_cmd_pool_lock(pool);
VkCommandBuffer cmd_buffer;
if (vk_cmd_buffer_create_and_begin(vk, &cmd_buffer) != VK_SUCCESS)
ret = vk_cmd_pool_create_and_begin_cmd_buffer_locked(vk, pool, 0, &cmd_buffer);
if (ret != VK_SUCCESS) {
vk_cmd_pool_unlock(pool);
return;
os_mutex_lock(&vk->cmd_pool_mutex);
}
if (self->layer_count == 0) {
_render_stereo(self, vk, cmd_buffer, &background_color_idle);
} else {
_render_stereo(self, vk, cmd_buffer, &background_color_active);
}
os_mutex_unlock(&vk->cmd_pool_mutex);
VkResult res = vk_cmd_buffer_submit(vk, cmd_buffer);
vk_check_error("vk_submit_cmd_buffer", res, );
// Done writing commands, submit to queue, waits for command to finish.
ret = vk_cmd_pool_end_submit_wait_and_free_cmd_buffer_locked(vk, pool, cmd_buffer);
// Done submitting commands.
vk_cmd_pool_unlock(pool);
// Check results from submit.
vk_check_error("vk_submit_cmd_buffer", ret, );
}
static void
@ -699,6 +718,9 @@ comp_layer_renderer_destroy(struct comp_layer_renderer **ptr_clr)
vk_buffer_destroy(&self->vertex_buffer, vk);
vk->vkDestroyPipelineCache(vk->device, self->pipeline_cache, NULL);
vk_cmd_pool_destroy(vk, &self->pool);
free(self);
*ptr_clr = NULL;
}

View file

@ -1,4 +1,4 @@
// Copyright 2020-2021, Collabora, Ltd.
// Copyright 2020-2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
@ -29,6 +29,8 @@ struct comp_layer_renderer
VkFramebuffer handle;
} framebuffers[2];
struct vk_cmd_pool pool;
VkRenderPass render_pass;
VkExtent2D extent;