Wrap MTLEvent code in availability attributes.
Allows us to build with a newer SDK and an older deployment target. Bug: skia:8243 Change-Id: I06dc2737e2661dc81d98c2411b93123642d4a1e8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/240514 Reviewed-by: Ben Wagner aka dogben <benjaminwagner@google.com> Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
parent
8e63cab2e8
commit
a431186414
@ -252,13 +252,16 @@ void GrMtlCaps::initGrCaps(const id<MTLDevice> device) {
|
||||
|
||||
bool supportsMTLEvent = false;
|
||||
#ifdef GR_METAL_SDK_SUPPORTS_EVENTS
|
||||
NSOperatingSystemVersion osVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
|
||||
// TODO: this may be redundant
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
NSOperatingSystemVersion osVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
|
||||
#ifdef SK_BUILD_FOR_MAC
|
||||
supportsMTLEvent = (osVersion.majorVersion > 10 ||
|
||||
(osVersion.majorVersion == 10 && osVersion.minorVersion >= 14));
|
||||
supportsMTLEvent = (osVersion.majorVersion > 10 ||
|
||||
(osVersion.majorVersion == 10 && osVersion.minorVersion >= 14));
|
||||
#else
|
||||
supportsMTLEvent = (osVersion.majorVersion >= 12);
|
||||
supportsMTLEvent = (osVersion.majorVersion >= 12);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
fFenceSyncSupport = supportsMTLEvent;
|
||||
fSemaphoreSupport = supportsMTLEvent;
|
||||
|
@ -34,8 +34,8 @@ public:
|
||||
}
|
||||
|
||||
#ifdef GR_METAL_SDK_SUPPORTS_EVENTS
|
||||
void encodeSignalEvent(id<MTLEvent> event, uint64_t value);
|
||||
void encodeWaitForEvent(id<MTLEvent> event, uint64_t value);
|
||||
void encodeSignalEvent(id<MTLEvent>, uint64_t value) API_AVAILABLE(macos(10.14), ios(12.0));
|
||||
void encodeWaitForEvent(id<MTLEvent>, uint64_t value) API_AVAILABLE(macos(10.14), ios(12.0));
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
@ -123,13 +123,17 @@ void GrMtlCommandBuffer::endAllEncoding() {
|
||||
void GrMtlCommandBuffer::encodeSignalEvent(id<MTLEvent> event, uint64_t eventValue) {
|
||||
SkASSERT(fCmdBuffer);
|
||||
this->endAllEncoding(); // ensure we don't have any active command encoders
|
||||
[fCmdBuffer encodeSignalEvent:event value:eventValue];
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
[fCmdBuffer encodeSignalEvent:event value:eventValue];
|
||||
}
|
||||
}
|
||||
|
||||
void GrMtlCommandBuffer::encodeWaitForEvent(id<MTLEvent> event, uint64_t eventValue) {
|
||||
SkASSERT(fCmdBuffer);
|
||||
this->endAllEncoding(); // ensure we don't have any active command encoders
|
||||
// TODO: not sure if needed but probably
|
||||
[fCmdBuffer encodeWaitForEvent:event value:eventValue];
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
[fCmdBuffer encodeWaitForEvent:event value:eventValue];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -243,8 +243,8 @@ private:
|
||||
|
||||
#ifdef GR_METAL_SDK_SUPPORTS_EVENTS
|
||||
// For FenceSync
|
||||
id<MTLSharedEvent> fSharedEvent;
|
||||
MTLSharedEventListener* fSharedEventListener;
|
||||
id<MTLSharedEvent> fSharedEvent API_AVAILABLE(macos(10.14), ios(12.0));
|
||||
MTLSharedEventListener* fSharedEventListener API_AVAILABLE(macos(10.14), ios(12.0));
|
||||
uint64_t fLatestEvent;
|
||||
#endif
|
||||
|
||||
|
@ -107,11 +107,13 @@ GrMtlGpu::GrMtlGpu(GrContext* context, const GrContextOptions& options,
|
||||
fMtlCaps.reset(new GrMtlCaps(options, fDevice, featureSet));
|
||||
fCaps = fMtlCaps;
|
||||
#ifdef GR_METAL_SDK_SUPPORTS_EVENTS
|
||||
if (fMtlCaps->fenceSyncSupport()) {
|
||||
fSharedEvent = [fDevice newSharedEvent];
|
||||
dispatch_queue_t dispatchQueue = dispatch_queue_create("MTLFenceSync", NULL);
|
||||
fSharedEventListener = [[MTLSharedEventListener alloc] initWithDispatchQueue:dispatchQueue];
|
||||
fLatestEvent = 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -1048,12 +1050,14 @@ bool GrMtlGpu::onReadPixels(GrSurface* surface, int left, int top, int width, in
|
||||
|
||||
GrFence SK_WARN_UNUSED_RESULT GrMtlGpu::insertFence() {
|
||||
#ifdef GR_METAL_SDK_SUPPORTS_EVENTS
|
||||
if (this->caps()->fenceSyncSupport()) {
|
||||
GrMtlCommandBuffer* cmdBuffer = this->commandBuffer();
|
||||
++fLatestEvent;
|
||||
cmdBuffer->encodeSignalEvent(fSharedEvent, fLatestEvent);
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
if (this->caps()->fenceSyncSupport()) {
|
||||
GrMtlCommandBuffer* cmdBuffer = this->commandBuffer();
|
||||
++fLatestEvent;
|
||||
cmdBuffer->encodeSignalEvent(fSharedEvent, fLatestEvent);
|
||||
|
||||
return fLatestEvent;
|
||||
return fLatestEvent;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
@ -1061,20 +1065,22 @@ GrFence SK_WARN_UNUSED_RESULT GrMtlGpu::insertFence() {
|
||||
|
||||
bool GrMtlGpu::waitFence(GrFence value, uint64_t timeout) {
|
||||
#ifdef GR_METAL_SDK_SUPPORTS_EVENTS
|
||||
if (this->caps()->fenceSyncSupport()) {
|
||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
if (this->caps()->fenceSyncSupport()) {
|
||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||
|
||||
// Add listener for this particular value or greater
|
||||
__block dispatch_semaphore_t block_sema = semaphore;
|
||||
[fSharedEvent notifyListener: fSharedEventListener
|
||||
atValue: value
|
||||
block: ^(id<MTLSharedEvent> sharedEvent, uint64_t value) {
|
||||
dispatch_semaphore_signal(block_sema);
|
||||
}];
|
||||
// Add listener for this particular value or greater
|
||||
__block dispatch_semaphore_t block_sema = semaphore;
|
||||
[fSharedEvent notifyListener: fSharedEventListener
|
||||
atValue: value
|
||||
block: ^(id<MTLSharedEvent> sharedEvent, uint64_t value) {
|
||||
dispatch_semaphore_signal(block_sema);
|
||||
}];
|
||||
|
||||
long result = dispatch_semaphore_wait(semaphore, timeout);
|
||||
long result = dispatch_semaphore_wait(semaphore, timeout);
|
||||
|
||||
return !result;
|
||||
return !result;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
@ -1107,17 +1113,21 @@ sk_sp<GrSemaphore> GrMtlGpu::wrapBackendSemaphore(const GrBackendSemaphore& sema
|
||||
|
||||
void GrMtlGpu::insertSemaphore(sk_sp<GrSemaphore> semaphore) {
|
||||
#ifdef GR_METAL_SDK_SUPPORTS_EVENTS
|
||||
GrMtlSemaphore* mtlSem = static_cast<GrMtlSemaphore*>(semaphore.get());
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
GrMtlSemaphore* mtlSem = static_cast<GrMtlSemaphore*>(semaphore.get());
|
||||
|
||||
this->commandBuffer()->encodeSignalEvent(mtlSem->event(), mtlSem->value());
|
||||
this->commandBuffer()->encodeSignalEvent(mtlSem->event(), mtlSem->value());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void GrMtlGpu::waitSemaphore(sk_sp<GrSemaphore> semaphore) {
|
||||
#ifdef GR_METAL_SDK_SUPPORTS_EVENTS
|
||||
GrMtlSemaphore* mtlSem = static_cast<GrMtlSemaphore*>(semaphore.get());
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
GrMtlSemaphore* mtlSem = static_cast<GrMtlSemaphore*>(semaphore.get());
|
||||
|
||||
this->commandBuffer()->encodeWaitForEvent(mtlSem->event(), mtlSem->value());
|
||||
this->commandBuffer()->encodeWaitForEvent(mtlSem->event(), mtlSem->value());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -27,18 +27,19 @@ public:
|
||||
uint64_t value,
|
||||
GrWrapOwnership ownership);
|
||||
|
||||
id<MTLEvent> event() const { return fEvent; }
|
||||
id<MTLEvent> event() const API_AVAILABLE(macos(10.14), ios(12.0)) { return fEvent; }
|
||||
uint64_t value() const { return fValue; }
|
||||
|
||||
GrBackendSemaphore backendSemaphore() const override;
|
||||
|
||||
private:
|
||||
GrMtlSemaphore(GrMtlGpu* gpu, id<MTLEvent> event, uint64_t value, bool isOwned);
|
||||
GrMtlSemaphore(GrMtlGpu* gpu, id<MTLEvent> event,
|
||||
uint64_t value, bool isOwned) API_AVAILABLE(macos(10.14), ios(12.0));
|
||||
|
||||
void onRelease() override;
|
||||
void onAbandon() override;
|
||||
|
||||
id<MTLEvent> fEvent;
|
||||
id<MTLEvent> fEvent API_AVAILABLE(macos(10.14), ios(12.0));
|
||||
uint64_t fValue;
|
||||
|
||||
typedef GrSemaphore INHERITED;
|
||||
|
@ -14,9 +14,13 @@
|
||||
|
||||
#ifdef GR_METAL_SDK_SUPPORTS_EVENTS
|
||||
sk_sp<GrMtlSemaphore> GrMtlSemaphore::Make(GrMtlGpu* gpu, bool isOwned) {
|
||||
id<MTLEvent> event = [gpu->device() newEvent];
|
||||
uint64_t value = 1; // seems like a reasonable starting point
|
||||
return sk_sp<GrMtlSemaphore>(new GrMtlSemaphore(gpu, event, value, isOwned));
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
id<MTLEvent> event = [gpu->device() newEvent];
|
||||
uint64_t value = 1; // seems like a reasonable starting point
|
||||
return sk_sp<GrMtlSemaphore>(new GrMtlSemaphore(gpu, event, value, isOwned));
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
sk_sp<GrMtlSemaphore> GrMtlSemaphore::MakeWrapped(GrMtlGpu* gpu,
|
||||
@ -25,10 +29,14 @@ sk_sp<GrMtlSemaphore> GrMtlSemaphore::MakeWrapped(GrMtlGpu* gpu,
|
||||
GrWrapOwnership ownership) {
|
||||
// The GrMtlSemaphore will have strong ownership at this point.
|
||||
// The GrMTLHandle will subsequently only have weak ownership.
|
||||
id<MTLEvent> mtlEvent = (__bridge_transfer id<MTLEvent>)event;
|
||||
auto sema = sk_sp<GrMtlSemaphore>(new GrMtlSemaphore(gpu, mtlEvent, value,
|
||||
kBorrow_GrWrapOwnership != ownership));
|
||||
return sema;
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
id<MTLEvent> mtlEvent = (__bridge_transfer id<MTLEvent>)event;
|
||||
auto sema = sk_sp<GrMtlSemaphore>(new GrMtlSemaphore(gpu, mtlEvent, value,
|
||||
kBorrow_GrWrapOwnership != ownership));
|
||||
return sema;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
GrMtlSemaphore::GrMtlSemaphore(GrMtlGpu* gpu, id<MTLEvent> event, uint64_t value, bool isOwned)
|
||||
@ -38,12 +46,16 @@ GrMtlSemaphore::GrMtlSemaphore(GrMtlGpu* gpu, id<MTLEvent> event, uint64_t value
|
||||
}
|
||||
|
||||
void GrMtlSemaphore::onRelease() {
|
||||
fEvent = nil;
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
fEvent = nil;
|
||||
}
|
||||
INHERITED::onRelease();
|
||||
}
|
||||
|
||||
void GrMtlSemaphore::onAbandon() {
|
||||
fEvent = nil;
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
fEvent = nil;
|
||||
}
|
||||
INHERITED::onAbandon();
|
||||
}
|
||||
|
||||
@ -51,8 +63,10 @@ GrBackendSemaphore GrMtlSemaphore::backendSemaphore() const {
|
||||
GrBackendSemaphore backendSemaphore;
|
||||
// The GrMtlSemaphore and the GrBackendSemaphore will have strong ownership at this point.
|
||||
// Whoever uses the GrBackendSemaphore will subsquently steal this ref (see MakeWrapped, above).
|
||||
GrMTLHandle handle = (__bridge_retained GrMTLHandle)(fEvent);
|
||||
backendSemaphore.initMetal(handle, fValue);
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
GrMTLHandle handle = (__bridge_retained GrMTLHandle)(fEvent);
|
||||
backendSemaphore.initMetal(handle, fValue);
|
||||
}
|
||||
return backendSemaphore;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user