Metal: Simplify GrFence to use completedHandler in all cases.

Currently GrFence is used only to determine if the current command
buffer is completed, so we don't need the granularity of MTLSharedEvent.
This makes the implementation of GrFence the same across all versions.

Bug: skia:9589
Change-Id: I2556304362a99a67d12e38144e08e8066a6850a7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/255302
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
Jim Van Verth 2019-11-19 13:36:49 -05:00 committed by Skia Commit-Bot
parent 525705e279
commit 041aab95b2
2 changed files with 7 additions and 43 deletions

View File

@ -224,11 +224,6 @@ private:
GrMtlResourceProvider fResourceProvider;
// For FenceSync
id<MTLSharedEvent> fSharedEvent API_AVAILABLE(macos(10.14), ios(12.0));
MTLSharedEventListener* fSharedEventListener API_AVAILABLE(macos(10.14), ios(12.0));
uint64_t fLatestEvent;
bool fDisconnected;
struct FinishCallback {

View File

@ -120,14 +120,6 @@ GrMtlGpu::GrMtlGpu(GrContext* context, const GrContextOptions& options,
, fDisconnected(false) {
fMtlCaps.reset(new GrMtlCaps(options, fDevice, featureSet));
fCaps = fMtlCaps;
if (@available(macOS 10.14, iOS 12.0, *)) {
if (fMtlCaps->fenceSyncSupport()) {
fSharedEvent = [fDevice newSharedEvent];
dispatch_queue_t dispatchQ = dispatch_queue_create("MTLFenceSync", NULL);
fSharedEventListener = [[MTLSharedEventListener alloc] initWithDispatchQueue:dispatchQ];
fLatestEvent = 0;
}
}
}
GrMtlGpu::~GrMtlGpu() {
@ -1239,14 +1231,8 @@ bool GrMtlGpu::readOrTransferPixels(GrSurface* surface, int left, int top, int w
GrFence SK_WARN_UNUSED_RESULT GrMtlGpu::insertFence() {
GrMtlCommandBuffer* cmdBuffer = this->commandBuffer();
if (@available(macOS 10.14, iOS 12.0, *)) {
++fLatestEvent;
cmdBuffer->encodeSignalEvent(fSharedEvent, fLatestEvent);
return fLatestEvent;
}
// If MTLSharedEvent isn't available, we create a semaphore and signal it
// within the current command buffer's completion handler.
// We create a semaphore and signal it within the current
// command buffer's completion handler.
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
cmdBuffer->addCompletedHandler(^(id <MTLCommandBuffer>commandBuffer) {
dispatch_semaphore_signal(semaphore);
@ -1257,35 +1243,18 @@ GrFence SK_WARN_UNUSED_RESULT GrMtlGpu::insertFence() {
}
bool GrMtlGpu::waitFence(GrFence fence, uint64_t timeout) {
dispatch_semaphore_t semaphore;
if (@available(macOS 10.14, iOS 12.0, *)) {
semaphore = dispatch_semaphore_create(0);
const void* cfFence = (const void*) fence;
dispatch_semaphore_t semaphore = (__bridge dispatch_semaphore_t)cfFence;
// Add listener for this particular value or greater
__block dispatch_semaphore_t block_sema = semaphore;
[fSharedEvent notifyListener: fSharedEventListener
atValue: fence
block: ^(id<MTLSharedEvent> sharedEvent, uint64_t value) {
dispatch_semaphore_signal(block_sema);
}];
} else {
const void* cfFence = (const void*) fence;
semaphore = (__bridge dispatch_semaphore_t)cfFence;
}
long result = dispatch_semaphore_wait(semaphore, timeout);
return !result;
}
void GrMtlGpu::deleteFence(GrFence fence) const {
if (@available(macOS 10.14, iOS 12.0, *)) {
// nothing to delete
} else {
const void* cfFence = (const void*) fence;
// In this case it's easier to release in CoreFoundation than depend on ARC
CFRelease(cfFence);
}
const void* cfFence = (const void*) fence;
// In this case it's easier to release in CoreFoundation than depend on ARC
CFRelease(cfFence);
}
std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT GrMtlGpu::makeSemaphore(bool /*isOwned*/) {