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,6 +252,8 @@ void GrMtlCaps::initGrCaps(const id<MTLDevice> device) {
|
||||
|
||||
bool supportsMTLEvent = false;
|
||||
#ifdef GR_METAL_SDK_SUPPORTS_EVENTS
|
||||
// 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 ||
|
||||
@ -259,6 +261,7 @@ void GrMtlCaps::initGrCaps(const id<MTLDevice> device) {
|
||||
#else
|
||||
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
|
||||
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
|
||||
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,12 +107,14 @@ GrMtlGpu::GrMtlGpu(GrContext* context, const GrContextOptions& options,
|
||||
fMtlCaps.reset(new GrMtlCaps(options, fDevice, featureSet));
|
||||
fCaps = fMtlCaps;
|
||||
#ifdef GR_METAL_SDK_SUPPORTS_EVENTS
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
if (fMtlCaps->fenceSyncSupport()) {
|
||||
fSharedEvent = [fDevice newSharedEvent];
|
||||
dispatch_queue_t dispatchQueue = dispatch_queue_create("MTLFenceSync", NULL);
|
||||
fSharedEventListener = [[MTLSharedEventListener alloc] initWithDispatchQueue:dispatchQueue];
|
||||
dispatch_queue_t dispatchQ = dispatch_queue_create("MTLFenceSync", NULL);
|
||||
fSharedEventListener = [[MTLSharedEventListener alloc] initWithDispatchQueue:dispatchQ];
|
||||
fLatestEvent = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1048,6 +1050,7 @@ 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 (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
if (this->caps()->fenceSyncSupport()) {
|
||||
GrMtlCommandBuffer* cmdBuffer = this->commandBuffer();
|
||||
++fLatestEvent;
|
||||
@ -1055,12 +1058,14 @@ GrFence SK_WARN_UNUSED_RESULT GrMtlGpu::insertFence() {
|
||||
|
||||
return fLatestEvent;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool GrMtlGpu::waitFence(GrFence value, uint64_t timeout) {
|
||||
#ifdef GR_METAL_SDK_SUPPORTS_EVENTS
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
if (this->caps()->fenceSyncSupport()) {
|
||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||
|
||||
@ -1076,6 +1081,7 @@ bool GrMtlGpu::waitFence(GrFence value, uint64_t timeout) {
|
||||
|
||||
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
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
GrMtlSemaphore* mtlSem = static_cast<GrMtlSemaphore*>(semaphore.get());
|
||||
|
||||
this->commandBuffer()->encodeSignalEvent(mtlSem->event(), mtlSem->value());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void GrMtlGpu::waitSemaphore(sk_sp<GrSemaphore> semaphore) {
|
||||
#ifdef GR_METAL_SDK_SUPPORTS_EVENTS
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
GrMtlSemaphore* mtlSem = static_cast<GrMtlSemaphore*>(semaphore.get());
|
||||
|
||||
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) {
|
||||
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.
|
||||
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() {
|
||||
if (@available(macOS 10.14, iOS 12.0, *)) {
|
||||
fEvent = nil;
|
||||
}
|
||||
INHERITED::onRelease();
|
||||
}
|
||||
|
||||
void GrMtlSemaphore::onAbandon() {
|
||||
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).
|
||||
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