Merge pull request #1393 from billhollings/retain-queue-during-submit

Retain MVKQueue in MVKQueueSubmission to avoid possible race condition.
This commit is contained in:
Bill Hollings 2021-06-28 08:10:49 -04:00 committed by GitHub
commit 30e7b5b0fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -176,6 +176,8 @@ public:
uint32_t waitSemaphoreCount,
const VkSemaphore* pWaitSemaphores);
~MVKQueueSubmission() override;
protected:
friend class MVKQueue;

View File

@ -251,12 +251,18 @@ MVKQueueSubmission::MVKQueueSubmission(MVKQueue* queue,
uint32_t waitSemaphoreCount,
const VkSemaphore* pWaitSemaphores) {
_queue = queue;
_queue->retain(); // Retain here and release in destructor. See note for MVKQueueCommandBufferSubmission::finish().
_waitSemaphores.reserve(waitSemaphoreCount);
for (uint32_t i = 0; i < waitSemaphoreCount; i++) {
_waitSemaphores.push_back(make_pair((MVKSemaphore*)pWaitSemaphores[i], (uint64_t)0));
}
}
MVKQueueSubmission::~MVKQueueSubmission() {
_queue->release();
}
#pragma mark -
#pragma mark MVKQueueCommandBufferSubmission
@ -390,6 +396,11 @@ void MVKQueueCommandBufferSubmission::commitActiveMTLCommandBuffer(bool signalCo
[mtlCmdBuff release]; // retained
}
// Be sure to retain() any API objects referenced in this function, and release() them in the
// destructor (or superclass destructor). It is possible for rare race conditions to result
// in the app destroying API objects before this function completes execution. For example,
// this may occur if a GPU semaphore here triggers another submission that triggers a fence,
// and the app immediately destroys objects. Rare, but it has been encountered.
void MVKQueueCommandBufferSubmission::finish() {
// MVKLogDebug("Finishing submission %p. Submission count %u.", this, _subCount--);