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 | vk->WaitForFences(s->hwctx->act_dev, 1, &e->fence, VK_TRUE, UINT64_MAX); | 251 | vk->WaitForFences(s->hwctx->act_dev, 1, &e->fence, VK_TRUE, UINT64_MAX); |
| 252 | vk->DestroyFence(s->hwctx->act_dev, e->fence, s->hwctx->alloc); | 252 | vk->DestroyFence(s->hwctx->act_dev, e->fence, s->hwctx->alloc); |
| 253 | } | 253 | } |
| 254 | pthread_mutex_destroy(&e->lock); | ||
| 255 | 254 | ||
| 256 | ff_vk_exec_discard_deps(s, e); | 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 | .flags = VK_FENCE_CREATE_SIGNALED_BIT, | 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 | /* Fence */ | 426 | /* Fence */ |
| 433 | ret = vk->CreateFence(s->hwctx->act_dev, &fence_create, s->hwctx->alloc, | 427 | ret = vk->CreateFence(s->hwctx->act_dev, &fence_create, s->hwctx->alloc, |
| 434 | &e->fence); | 428 | &e->fence); |
| @@ -498,10 +492,8 @@ FFVkExecContext *ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool) · 63 unmodified lines | |||
| 498 | void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e) | 492 | void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e) |
| 499 | { | 493 | { |
| 500 | FFVulkanFunctions *vk = &s->vkfn; | 494 | FFVulkanFunctions *vk = &s->vkfn; |
| 501 | pthread_mutex_lock(&e->lock); | ||
| 502 | vk->WaitForFences(s->hwctx->act_dev, 1, &e->fence, VK_TRUE, UINT64_MAX); | 495 | vk->WaitForFences(s->hwctx->act_dev, 1, &e->fence, VK_TRUE, UINT64_MAX); |
| 503 | ff_vk_exec_discard_deps(s, e); | 496 | ff_vk_exec_discard_deps(s, e); |
| 504 | pthread_mutex_unlock(&e->lock); | ||
| 505 | } | 497 | } |
| 506 | 498 | ||
| 507 | int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e) | 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 | /* Wait for the fence to be signalled */ | 510 | /* Wait for the fence to be signalled */ |
| 519 | vk->WaitForFences(s->hwctx->act_dev, 1, &e->fence, VK_TRUE, UINT64_MAX); | 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 | vk->ResetFences(s->hwctx->act_dev, 1, &e->fence); | 512 | vk->ResetFences(s->hwctx->act_dev, 1, &e->fence); |
| 524 | pthread_mutex_unlock(&e->lock); | ||
| 525 | 513 | ||
| 526 | /* Discard queue dependencies */ | 514 | /* Discard queue dependencies */ |
| 527 | ff_vk_exec_discard_deps(s, e); | 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 | * Allocates/frees an execution pool. | 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 | * ff_vk_exec_pool_init_desc() MUST be called if ff_vk_exec_descriptor_set_add() | 405 | * ff_vk_exec_pool_init_desc() MUST be called if ff_vk_exec_descriptor_set_add() |
| 404 | * has been called. | 406 | * has been called. |
| 405 | */ | 407 | */ |