Guard macOS or iOS specific code in #if guards

This is necessary because @available(macOS 10.N, *) is taken on all iOS
versions but there is no way to say the branch is just not taken on any
iOS version. The proper way to deal with this is to add additional #if
guards to just not compile the code on iOS / macOS.

BUG=dawn:225

Change-Id: I76ec01f933364e9b47b5dda1198359f2ab4d1188
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11900
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Corentin Wallez 2019-10-08 07:44:21 +00:00 committed by Commit Bot service account
parent 97231682d0
commit b629c50a20
3 changed files with 19 additions and 2 deletions

View File

@ -28,7 +28,6 @@ namespace dawn_native { namespace metal {
namespace {
#if defined(DAWN_PLATFORM_MACOS)
struct PCIIDs {
uint32_t vendorId;
uint32_t deviceId;
@ -39,6 +38,7 @@ namespace dawn_native { namespace metal {
uint32_t vendorId;
};
#if defined(DAWN_PLATFORM_MACOS)
const Vendor kVendors[] = {{"AMD", kVendorID_AMD},
{"Radeon", kVendorID_AMD},
{"Intel", kVendorID_Intel},
@ -158,7 +158,8 @@ namespace dawn_native { namespace metal {
#elif defined(DAWN_PLATFORM_IOS)
MaybeError GetDevicePCIInfo(id<MTLDevice> device, PCIIDs* ids) {
DAWN_UNUSED(device);
*ids = PCIIDs(0, 0);
*ids = PCIIDs{0, 0};
return {};
}
bool IsMetalSupported() {
@ -183,11 +184,17 @@ namespace dawn_native { namespace metal {
mPCIInfo.deviceId = ids.deviceId;
};
#if defined(DAWN_PLATFORM_IOS)
mDeviceType = DeviceType::IntegratedGPU;
#elif defined(DAWN_PLATFORM_MACOS)
if ([device isLowPower]) {
mDeviceType = DeviceType::IntegratedGPU;
} else {
mDeviceType = DeviceType::DiscreteGPU;
}
#else
# error "Unsupported Apple platform."
#endif
InitializeSupportedExtensions();
}
@ -201,9 +208,11 @@ namespace dawn_native { namespace metal {
return {new Device(this, mDevice, descriptor)};
}
void InitializeSupportedExtensions() {
#if defined(DAWN_PLATFORM_MACOS)
if ([mDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v1]) {
mSupportedExtensions.EnableExtension(Extension::TextureCompressionBC);
}
#endif
}
id<MTLDevice> mDevice = nil;
@ -221,6 +230,7 @@ namespace dawn_native { namespace metal {
std::vector<std::unique_ptr<AdapterBase>> adapters;
if (@available(macOS 10.11, *)) {
#if defined(DAWN_PLATFORM_MACOS)
NSArray<id<MTLDevice>>* devices = MTLCopyAllDevices();
for (id<MTLDevice> device in devices) {
@ -228,10 +238,13 @@ namespace dawn_native { namespace metal {
}
[devices release];
#endif
} else if (@available(iOS 8.0, *)) {
#if defined(DAWN_PLATFORM_IOS)
// iOS only has a single device so MTLCopyAllDevices doesn't exist there.
adapters.push_back(
std::make_unique<Adapter>(GetInstance(), MTLCreateSystemDefaultDevice()));
#endif
} else {
UNREACHABLE();
}

View File

@ -76,11 +76,13 @@ namespace dawn_native { namespace metal {
}
void Device::InitTogglesFromDriver() {
#if defined(DAWN_PLATFORM_MACOS)
if (@available(macOS 10.12, *)) {
bool emulateStoreAndMSAAResolve =
![mMtlDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v2];
SetToggle(Toggle::EmulateStoreAndMSAAResolve, emulateStoreAndMSAAResolve);
}
#endif
// TODO(jiawei.shao@intel.com): check iOS feature sets

View File

@ -214,6 +214,7 @@ namespace dawn_native { namespace metal {
case dawn::TextureFormat::Depth24PlusStencil8:
return MTLPixelFormatDepth32Float_Stencil8;
#if defined(DAWN_PLATFORM_MACOS)
case dawn::TextureFormat::BC1RGBAUnorm:
return MTLPixelFormatBC1_RGBA;
case dawn::TextureFormat::BC1RGBAUnormSrgb:
@ -242,6 +243,7 @@ namespace dawn_native { namespace metal {
return MTLPixelFormatBC7_RGBAUnorm;
case dawn::TextureFormat::BC7RGBAUnormSrgb:
return MTLPixelFormatBC7_RGBAUnorm_sRGB;
#endif
default:
UNREACHABLE();