Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MVKQueue: Make sure waitIdle waits for all commands to be encoded before enqueuing its own waitUntilCompleted. #2297

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "MVKSync.h"
#include "MVKSmallVector.h"
#include <mutex>
#include <condition_variable>

#import <Metal/Metal.h>

Expand Down Expand Up @@ -147,6 +148,9 @@ class MVKQueue : public MVKDispatchableVulkanAPIObject, public MVKDeviceTracking
MVKQueueFamily* _queueFamily;
std::string _name;
dispatch_queue_t _execQueue;
std::mutex _execQueueMutex;
std::condition_variable _execQueueConditionVariable;
uint32_t _execQueueJobCount = 0;
id<MTLCommandQueue> _mtlQueue = nil;
NSString* _mtlCmdBuffLabelBeginCommandBuffer = nil;
NSString* _mtlCmdBuffLabelQueueSubmit = nil;
Expand Down
17 changes: 16 additions & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKQueue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,16 @@
// The submissions will ensure a misconfiguration will be safe to execute.
VkResult rslt = qSubmit->getConfigurationResult();
if (_execQueue) {
dispatch_async(_execQueue, ^{ execute(qSubmit); } );
std::unique_lock lock(_execQueueMutex);
_execQueueJobCount++;

dispatch_async(_execQueue, ^{
execute(qSubmit);

std::unique_lock execLock(_execQueueMutex);
if (!--_execQueueJobCount)
_execQueueConditionVariable.notify_all();
} );
} else {
rslt = execute(qSubmit);
}
Expand Down Expand Up @@ -145,6 +154,12 @@
VkResult rslt = _device->getConfigurationResult();
if (rslt != VK_SUCCESS) { return rslt; }

if (_execQueue) {
std::unique_lock lock(_execQueueMutex);
while (_execQueueJobCount)
_execQueueConditionVariable.wait(lock);
}

@autoreleasepool {
auto* mtlCmdBuff = getMTLCommandBuffer(cmdUse);
[mtlCmdBuff commit];
Expand Down
Loading