This code was simply incorrect through and through. It did not protect what actually has to be protected in a multi-threaded setup. Perhaps it was used to silence threading errors? Either way, remove it, and document the correct way to use execution pools in a threaded environment.
Unified · Split
| @@ -251,7 +251,6 @@ void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool) · 250 unmodified lines | ||
| 251 | 251 | vk->WaitForFences(s->hwctx->act_dev, 1, &e->fence, VK_TRUE, UINT64_MAX); |
| 252 | 252 | vk->DestroyFence(s->hwctx->act_dev, e->fence, s->hwctx->alloc); |
| 253 | 253 | } |
| 254 | − pthread_mutex_destroy(&e->lock); | |
| 255 | 254 | |
| 256 | 255 | ff_vk_exec_discard_deps(s, e); |
| 257 | 256 | |
| @@ -424,11 +423,6 @@ int ff_vk_exec_pool_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, · 166 unmodified lines | ||
| 424 | 423 | .flags = VK_FENCE_CREATE_SIGNALED_BIT, |
| 425 | 424 | }; |
| 426 | 425 | |
| 427 | − /* Mutex */ | |
| 428 | − err = pthread_mutex_init(&e->lock, NULL); | |
| 429 | − if (err != 0) | |
| 430 | − return AVERROR(err); | |
| 431 | − | |
| 432 | 426 | /* Fence */ |
| 433 | 427 | ret = vk->CreateFence(s->hwctx->act_dev, &fence_create, s->hwctx->alloc, |
| 434 | 428 | &e->fence); |
| @@ -498,10 +492,8 @@ FFVkExecContext *ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool) · 63 unmodified lines | ||
| 498 | 492 | void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e) |
| 499 | 493 | { |
| 500 | 494 | FFVulkanFunctions *vk = &s->vkfn; |
| 501 | − pthread_mutex_lock(&e->lock); | |
| 502 | 495 | vk->WaitForFences(s->hwctx->act_dev, 1, &e->fence, VK_TRUE, UINT64_MAX); |
| 503 | 496 | ff_vk_exec_discard_deps(s, e); |
| 504 | − pthread_mutex_unlock(&e->lock); | |
| 505 | 497 | } |
| 506 | 498 | |
| 507 | 499 | int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e) |
| @@ -517,11 +509,7 @@ int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e) · 9 unmodified lines | ||
| 517 | 509 | |
| 518 | 510 | /* Wait for the fence to be signalled */ |
| 519 | 511 | vk->WaitForFences(s->hwctx->act_dev, 1, &e->fence, VK_TRUE, UINT64_MAX); |
| 520 | − | |
| 521 | − /* vkResetFences is defined as being host-synchronized */ | |
| 522 | − pthread_mutex_lock(&e->lock); | |
| 523 | 512 | vk->ResetFences(s->hwctx->act_dev, 1, &e->fence); |
| 524 | − pthread_mutex_unlock(&e->lock); | |
| 525 | 513 | |
| 526 | 514 | /* Discard queue dependencies */ |
| 527 | 515 | ff_vk_exec_discard_deps(s, e); |
| @@ -400,6 +400,8 @@ int ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, · 399 unmodified lines | ||
| 400 | 400 | |
| 401 | 401 | /** |
| 402 | 402 | * Allocates/frees an execution pool. |
| 403 | + * If used in a multi-threaded context, there must be at least as many contexts | |
| 404 | + * as there are threads. | |
| 403 | 405 | * ff_vk_exec_pool_init_desc() MUST be called if ff_vk_exec_descriptor_set_add() |
| 404 | 406 | * has been called. |
| 405 | 407 | */ |