c/render: Take the pool lock to fix threading errors

This commit is contained in:
Jakob Bornecrantz 2022-04-08 14:34:57 +01:00
parent 0ee1127431
commit 400c3900f0
5 changed files with 66 additions and 14 deletions

View file

@ -282,6 +282,7 @@ renderer_build_rendering(struct comp_renderer *r,
*/
render_gfx_init(rr, &c->nr);
render_gfx_begin(rr);
/*
@ -371,7 +372,7 @@ renderer_build_rendering(struct comp_renderer *r,
render_gfx_end_target(rr);
// Make the command buffer usable.
render_gfx_finalize(rr);
render_gfx_end(rr);
}
/*!

View file

@ -278,8 +278,14 @@ render_compute_begin(struct render_compute *crc)
{
struct vk_bundle *vk = vk_from_crc(crc);
C(vk_begin_command_buffer(vk, crc->cmd));
os_mutex_lock(&vk->cmd_pool_mutex);
VkResult ret = vk_begin_command_buffer(vk, crc->cmd);
if (ret != VK_SUCCESS) {
os_mutex_unlock(&vk->cmd_pool_mutex);
return false;
}
// Yes we leave the mutex locked.
return true;
}
@ -288,7 +294,11 @@ render_compute_end(struct render_compute *crc)
{
struct vk_bundle *vk = vk_from_crc(crc);
C(vk_end_command_buffer(vk, crc->cmd));
VkResult ret = vk_end_command_buffer(vk, crc->cmd);
os_mutex_unlock(&vk->cmd_pool_mutex);
if (ret != VK_SUCCESS) {
return false;
}
return true;
}

View file

@ -504,9 +504,6 @@ render_gfx_init(struct render_gfx *rr, struct render_resources *r)
C(vk_create_command_buffer(vk, &rr->cmd));
C(vk_begin_command_buffer(vk, rr->cmd));
/*
* Mesh per view
*/
@ -526,12 +523,34 @@ render_gfx_init(struct render_gfx *rr, struct render_resources *r)
return true;
}
void
render_gfx_finalize(struct render_gfx *rr)
bool
render_gfx_begin(struct render_gfx *rr)
{
struct vk_bundle *vk = vk_from_rr(rr);
vk_end_command_buffer(vk, rr->cmd);
os_mutex_lock(&vk->cmd_pool_mutex);
VkResult ret = vk_begin_command_buffer(vk, rr->cmd);
if (ret != VK_SUCCESS) {
os_mutex_unlock(&vk->cmd_pool_mutex);
return false;
}
// Yes we leave the mutex locked.
return true;
}
bool
render_gfx_end(struct render_gfx *rr)
{
struct vk_bundle *vk = vk_from_rr(rr);
VkResult ret = vk_end_command_buffer(vk, rr->cmd);
os_mutex_unlock(&vk->cmd_pool_mutex);
if (ret != VK_SUCCESS) {
return false;
}
return true;
}
void

View file

@ -470,10 +470,17 @@ bool
render_gfx_init(struct render_gfx *rr, struct render_resources *r);
/*!
* Frees any unneeded resources and ends the command buffer so it can be used.
* Begins the rendering, takes the vk_bundle's pool lock and leaves it locked.
*/
void
render_gfx_finalize(struct render_gfx *rr);
bool
render_gfx_begin(struct render_gfx *rr);
/*!
* Frees any unneeded resources and ends the command buffer so it can be used,
* also unlocks the vk_bundle's pool lock that was taken by begin.
*/
bool
render_gfx_end(struct render_gfx *rr);
/*!
* Frees all resources held by the rendering, does not free the struct itself.
@ -581,9 +588,20 @@ render_compute_init(struct render_compute *crc, struct render_resources *r);
void
render_compute_close(struct render_compute *crc);
/*!
* Begin the compute command buffer building, takes the vk_bundle's pool lock
* and leaves it locked.
*/
bool
render_compute_begin(struct render_compute *crc);
/*!
* Frees any unneeded resources and ends the command buffer so it can be used,
* also unlocks the vk_bundle's pool lock that was taken by begin.
*/
bool
render_compute_end(struct render_compute *crc);
void
render_compute_projection_timewarp(struct render_compute *crc,
VkSampler src_samplers[2],
@ -611,8 +629,6 @@ render_compute_clear(struct render_compute *crc, //
VkImageView target_image_view, //
const struct render_viewport_data views[2]); //
bool
render_compute_end(struct render_compute *crc);
/*!

View file

@ -293,6 +293,9 @@ queue_upload_for_first_level_and_layer(
.layerCount = VK_REMAINING_ARRAY_LAYERS,
};
// Take the lock here.
os_mutex_lock(&vk->cmd_pool_mutex);
vk_cmd_image_barrier_gpu_locked( //
vk, //
cmd, //
@ -337,6 +340,9 @@ queue_upload_for_first_level_and_layer(
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, //
subresource_range); //
// Once we are done writing commands.
os_mutex_unlock(&vk->cmd_pool_mutex);
return VK_SUCCESS;
}