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; 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; bool fDisconnected;
struct FinishCallback { struct FinishCallback {

View File

@ -120,14 +120,6 @@ GrMtlGpu::GrMtlGpu(GrContext* context, const GrContextOptions& options,
, fDisconnected(false) { , fDisconnected(false) {
fMtlCaps.reset(new GrMtlCaps(options, fDevice, featureSet)); fMtlCaps.reset(new GrMtlCaps(options, fDevice, featureSet));
fCaps = fMtlCaps; 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() { GrMtlGpu::~GrMtlGpu() {
@ -1239,14 +1231,8 @@ bool GrMtlGpu::readOrTransferPixels(GrSurface* surface, int left, int top, int w
GrFence SK_WARN_UNUSED_RESULT GrMtlGpu::insertFence() { GrFence SK_WARN_UNUSED_RESULT GrMtlGpu::insertFence() {
GrMtlCommandBuffer* cmdBuffer = this->commandBuffer(); GrMtlCommandBuffer* cmdBuffer = this->commandBuffer();
if (@available(macOS 10.14, iOS 12.0, *)) { // We create a semaphore and signal it within the current
++fLatestEvent; // command buffer's completion handler.
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.
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
cmdBuffer->addCompletedHandler(^(id <MTLCommandBuffer>commandBuffer) { cmdBuffer->addCompletedHandler(^(id <MTLCommandBuffer>commandBuffer) {
dispatch_semaphore_signal(semaphore); dispatch_semaphore_signal(semaphore);
@ -1257,36 +1243,19 @@ GrFence SK_WARN_UNUSED_RESULT GrMtlGpu::insertFence() {
} }
bool GrMtlGpu::waitFence(GrFence fence, uint64_t timeout) { 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);
// 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; const void* cfFence = (const void*) fence;
semaphore = (__bridge dispatch_semaphore_t)cfFence; dispatch_semaphore_t semaphore = (__bridge dispatch_semaphore_t)cfFence;
}
long result = dispatch_semaphore_wait(semaphore, timeout); long result = dispatch_semaphore_wait(semaphore, timeout);
return !result; return !result;
} }
void GrMtlGpu::deleteFence(GrFence fence) const { void GrMtlGpu::deleteFence(GrFence fence) const {
if (@available(macOS 10.14, iOS 12.0, *)) {
// nothing to delete
} else {
const void* cfFence = (const void*) fence; const void* cfFence = (const void*) fence;
// In this case it's easier to release in CoreFoundation than depend on ARC // In this case it's easier to release in CoreFoundation than depend on ARC
CFRelease(cfFence); CFRelease(cfFence);
} }
}
std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT GrMtlGpu::makeSemaphore(bool /*isOwned*/) { std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT GrMtlGpu::makeSemaphore(bool /*isOwned*/) {
SkASSERT(this->caps()->semaphoreSupport()); SkASSERT(this->caps()->semaphoreSupport());