From f223c5af9ff49c1d25ec862e11f0191e1339916e Mon Sep 17 00:00:00 2001 From: Luke Street Date: Fri, 27 May 2022 13:30:13 -0400 Subject: [PATCH] Add tvOS support --- src/dawn/common/Platform.h | 5 ++++- src/dawn/native/CMakeLists.txt | 12 ++++++++++-- src/dawn/native/metal/BackendMTL.mm | 13 +++++++++++-- src/dawn/native/metal/DeviceMTL.mm | 13 ++++++++++--- src/dawn/native/metal/QuerySetMTL.mm | 6 +++--- 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/dawn/common/Platform.h b/src/dawn/common/Platform.h index 8e81b489b4..83aa25144d 100644 --- a/src/dawn/common/Platform.h +++ b/src/dawn/common/Platform.h @@ -37,7 +37,10 @@ #define DAWN_PLATFORM_APPLE 1 #define DAWN_PLATFORM_POSIX 1 #include -#if TARGET_OS_IPHONE +#if TARGET_OS_TV +#define DAWN_PLATFORM_TVOS +#define DAWN_PLATFORM_IOS +#elif TARGET_OS_IPHONE #define DAWN_PLATFORM_IOS #elif TARGET_OS_MAC #define DAWN_PLATFORM_MACOS diff --git a/src/dawn/native/CMakeLists.txt b/src/dawn/native/CMakeLists.txt index 29a263fdee..72a520130b 100644 --- a/src/dawn/native/CMakeLists.txt +++ b/src/dawn/native/CMakeLists.txt @@ -355,9 +355,17 @@ if (DAWN_ENABLE_METAL) "metal/UtilsMetal.h" "metal/UtilsMetal.mm" ) + if (NOT IOS AND NOT TVOS) + target_link_libraries(dawn_native PRIVATE + "-framework Cocoa" + ) + endif () + if (NOT TVOS) + target_link_libraries(dawn_native PRIVATE + "-framework IOKit" + ) + endif () target_link_libraries(dawn_native PRIVATE - "-framework Cocoa" - "-framework IOKit" "-framework IOSurface" "-framework QuartzCore" "-framework Metal" diff --git a/src/dawn/native/metal/BackendMTL.mm b/src/dawn/native/metal/BackendMTL.mm index 2545e11977..8b5c35bb2d 100644 --- a/src/dawn/native/metal/BackendMTL.mm +++ b/src/dawn/native/metal/BackendMTL.mm @@ -248,7 +248,7 @@ DAWN_NOINLINE bool IsGPUCounterSupported(id device, } } - if (@available(macOS 11.0, iOS 14.0, *)) { + if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) { // Check whether it can read GPU counters at the specified command boundary. Apple // family GPUs do not support sampling between different Metal commands, because // they defer fragment processing until after the GPU processes all the primitives @@ -315,7 +315,7 @@ class Adapter : public AdapterBase { mSupportedFeatures.EnableFeature(Feature::TextureCompressionBC); } #endif -#if defined(DAWN_PLATFORM_IOS) +#if defined(DAWN_PLATFORM_IOS) && !defined(DAWN_PLATFORM_TVOS) if ([*mDevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v1]) { mSupportedFeatures.EnableFeature(Feature::TextureCompressionETC2); } @@ -404,6 +404,14 @@ class Adapter : public AdapterBase { ResultOrError GetMTLGPUFamily() const { // https://developer.apple.com/documentation/metal/mtldevice/detecting_gpu_features_and_metal_software_versions?language=objc +#if defined(DAWN_PLATFORM_TVOS) + if ([*mDevice supportsFeatureSet:MTLFeatureSet_tvOS_GPUFamily2_v1]) { + return MTLGPUFamily::Apple3; + } + if ([*mDevice supportsFeatureSet:MTLFeatureSet_tvOS_GPUFamily1_v1]) { + return MTLGPUFamily::Apple2; + } +#else if (@available(macOS 10.15, iOS 10.13, *)) { if ([*mDevice supportsFamily:MTLGPUFamilyMac2]) { return MTLGPUFamily::Mac2; @@ -433,6 +441,7 @@ class Adapter : public AdapterBase { return MTLGPUFamily::Apple1; } } +#endif #if TARGET_OS_OSX if (@available(macOS 10.14, *)) { diff --git a/src/dawn/native/metal/DeviceMTL.mm b/src/dawn/native/metal/DeviceMTL.mm index 6f4b4d9510..383662b1c8 100644 --- a/src/dawn/native/metal/DeviceMTL.mm +++ b/src/dawn/native/metal/DeviceMTL.mm @@ -163,6 +163,8 @@ void Device::InitTogglesFromDriver() { haveStoreAndMSAAResolve = [*mMtlDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v2]; } +#elif defined(DAWN_PLATFORM_TVOS) + haveStoreAndMSAAResolve = [*mMtlDevice supportsFeatureSet:MTLFeatureSet_tvOS_GPUFamily2_v1]; #elif defined(DAWN_PLATFORM_IOS) haveStoreAndMSAAResolve = [*mMtlDevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v2]; #endif @@ -170,14 +172,19 @@ void Device::InitTogglesFromDriver() { SetToggle(Toggle::EmulateStoreAndMSAAResolve, !haveStoreAndMSAAResolve); bool haveSamplerCompare = true; -#if defined(DAWN_PLATFORM_IOS) +#if defined(DAWN_PLATFORM_TVOS) + haveSamplerCompare = [*mMtlDevice supportsFeatureSet:MTLFeatureSet_tvOS_GPUFamily2_v1]; +#elif defined(DAWN_PLATFORM_IOS) haveSamplerCompare = [*mMtlDevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1]; #endif // TODO(crbug.com/dawn/342): Investigate emulation -- possibly expensive. SetToggle(Toggle::MetalDisableSamplerCompare, !haveSamplerCompare); bool haveBaseVertexBaseInstance = true; -#if defined(DAWN_PLATFORM_IOS) +#if defined(DAWN_PLATFORM_TVOS) + haveBaseVertexBaseInstance = + [*mMtlDevice supportsFeatureSet:MTLFeatureSet_tvOS_GPUFamily2_v1]; +#elif defined(DAWN_PLATFORM_IOS) haveBaseVertexBaseInstance = [*mMtlDevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1]; #endif @@ -201,7 +208,7 @@ void Device::InitTogglesFromDriver() { // TODO(crbug.com/dawn/847): Use MTLStorageModeShared instead of MTLStorageModePrivate when // creating MTLCounterSampleBuffer in QuerySet on Intel platforms, otherwise it fails to // create the buffer. Change to use MTLStorageModePrivate when the bug is fixed. - if (@available(macOS 10.15, iOS 14.0, *)) { + if (@available(macOS 10.15, iOS 14.0, tvOS 14.0, *)) { bool useSharedMode = gpu_info::IsIntel(vendorId); SetToggle(Toggle::MetalUseSharedModeForCounterSampleBuffer, useSharedMode); } diff --git a/src/dawn/native/metal/QuerySetMTL.mm b/src/dawn/native/metal/QuerySetMTL.mm index 1e19963c16..2e8fec8102 100644 --- a/src/dawn/native/metal/QuerySetMTL.mm +++ b/src/dawn/native/metal/QuerySetMTL.mm @@ -86,7 +86,7 @@ MaybeError QuerySet::Initialize() { break; } case wgpu::QueryType::PipelineStatistics: - if (@available(macOS 10.15, iOS 14.0, *)) { + if (@available(macOS 10.15, iOS 14.0, tvOS 14.0, *)) { DAWN_TRY_ASSIGN(mCounterSampleBuffer, CreateCounterSampleBuffer(device, MTLCommonCounterSetStatistic, GetQueryCount())); @@ -95,7 +95,7 @@ MaybeError QuerySet::Initialize() { } break; case wgpu::QueryType::Timestamp: - if (@available(macOS 10.15, iOS 14.0, *)) { + if (@available(macOS 10.15, iOS 14.0, tvOS 14.0, *)) { DAWN_TRY_ASSIGN(mCounterSampleBuffer, CreateCounterSampleBuffer(device, MTLCommonCounterSetTimestamp, GetQueryCount())); @@ -129,7 +129,7 @@ void QuerySet::DestroyImpl() { // mCounterSampleBuffer isn't an NSRef because API_AVAILABLE doesn't work will with // templates. - if (@available(macOS 10.15, iOS 14.0, *)) { + if (@available(macOS 10.15, iOS 14.0, tvOS 14.0, *)) { [mCounterSampleBuffer release]; mCounterSampleBuffer = nullptr; }