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:
parent
97231682d0
commit
b629c50a20
|
@ -28,7 +28,6 @@ namespace dawn_native { namespace metal {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
#if defined(DAWN_PLATFORM_MACOS)
|
|
||||||
struct PCIIDs {
|
struct PCIIDs {
|
||||||
uint32_t vendorId;
|
uint32_t vendorId;
|
||||||
uint32_t deviceId;
|
uint32_t deviceId;
|
||||||
|
@ -39,6 +38,7 @@ namespace dawn_native { namespace metal {
|
||||||
uint32_t vendorId;
|
uint32_t vendorId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(DAWN_PLATFORM_MACOS)
|
||||||
const Vendor kVendors[] = {{"AMD", kVendorID_AMD},
|
const Vendor kVendors[] = {{"AMD", kVendorID_AMD},
|
||||||
{"Radeon", kVendorID_AMD},
|
{"Radeon", kVendorID_AMD},
|
||||||
{"Intel", kVendorID_Intel},
|
{"Intel", kVendorID_Intel},
|
||||||
|
@ -158,7 +158,8 @@ namespace dawn_native { namespace metal {
|
||||||
#elif defined(DAWN_PLATFORM_IOS)
|
#elif defined(DAWN_PLATFORM_IOS)
|
||||||
MaybeError GetDevicePCIInfo(id<MTLDevice> device, PCIIDs* ids) {
|
MaybeError GetDevicePCIInfo(id<MTLDevice> device, PCIIDs* ids) {
|
||||||
DAWN_UNUSED(device);
|
DAWN_UNUSED(device);
|
||||||
*ids = PCIIDs(0, 0);
|
*ids = PCIIDs{0, 0};
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsMetalSupported() {
|
bool IsMetalSupported() {
|
||||||
|
@ -183,11 +184,17 @@ namespace dawn_native { namespace metal {
|
||||||
mPCIInfo.deviceId = ids.deviceId;
|
mPCIInfo.deviceId = ids.deviceId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(DAWN_PLATFORM_IOS)
|
||||||
|
mDeviceType = DeviceType::IntegratedGPU;
|
||||||
|
#elif defined(DAWN_PLATFORM_MACOS)
|
||||||
if ([device isLowPower]) {
|
if ([device isLowPower]) {
|
||||||
mDeviceType = DeviceType::IntegratedGPU;
|
mDeviceType = DeviceType::IntegratedGPU;
|
||||||
} else {
|
} else {
|
||||||
mDeviceType = DeviceType::DiscreteGPU;
|
mDeviceType = DeviceType::DiscreteGPU;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
# error "Unsupported Apple platform."
|
||||||
|
#endif
|
||||||
|
|
||||||
InitializeSupportedExtensions();
|
InitializeSupportedExtensions();
|
||||||
}
|
}
|
||||||
|
@ -201,9 +208,11 @@ namespace dawn_native { namespace metal {
|
||||||
return {new Device(this, mDevice, descriptor)};
|
return {new Device(this, mDevice, descriptor)};
|
||||||
}
|
}
|
||||||
void InitializeSupportedExtensions() {
|
void InitializeSupportedExtensions() {
|
||||||
|
#if defined(DAWN_PLATFORM_MACOS)
|
||||||
if ([mDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v1]) {
|
if ([mDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v1]) {
|
||||||
mSupportedExtensions.EnableExtension(Extension::TextureCompressionBC);
|
mSupportedExtensions.EnableExtension(Extension::TextureCompressionBC);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
id<MTLDevice> mDevice = nil;
|
id<MTLDevice> mDevice = nil;
|
||||||
|
@ -221,6 +230,7 @@ namespace dawn_native { namespace metal {
|
||||||
std::vector<std::unique_ptr<AdapterBase>> adapters;
|
std::vector<std::unique_ptr<AdapterBase>> adapters;
|
||||||
|
|
||||||
if (@available(macOS 10.11, *)) {
|
if (@available(macOS 10.11, *)) {
|
||||||
|
#if defined(DAWN_PLATFORM_MACOS)
|
||||||
NSArray<id<MTLDevice>>* devices = MTLCopyAllDevices();
|
NSArray<id<MTLDevice>>* devices = MTLCopyAllDevices();
|
||||||
|
|
||||||
for (id<MTLDevice> device in devices) {
|
for (id<MTLDevice> device in devices) {
|
||||||
|
@ -228,10 +238,13 @@ namespace dawn_native { namespace metal {
|
||||||
}
|
}
|
||||||
|
|
||||||
[devices release];
|
[devices release];
|
||||||
|
#endif
|
||||||
} else if (@available(iOS 8.0, *)) {
|
} else if (@available(iOS 8.0, *)) {
|
||||||
|
#if defined(DAWN_PLATFORM_IOS)
|
||||||
// iOS only has a single device so MTLCopyAllDevices doesn't exist there.
|
// iOS only has a single device so MTLCopyAllDevices doesn't exist there.
|
||||||
adapters.push_back(
|
adapters.push_back(
|
||||||
std::make_unique<Adapter>(GetInstance(), MTLCreateSystemDefaultDevice()));
|
std::make_unique<Adapter>(GetInstance(), MTLCreateSystemDefaultDevice()));
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,11 +76,13 @@ namespace dawn_native { namespace metal {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::InitTogglesFromDriver() {
|
void Device::InitTogglesFromDriver() {
|
||||||
|
#if defined(DAWN_PLATFORM_MACOS)
|
||||||
if (@available(macOS 10.12, *)) {
|
if (@available(macOS 10.12, *)) {
|
||||||
bool emulateStoreAndMSAAResolve =
|
bool emulateStoreAndMSAAResolve =
|
||||||
![mMtlDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v2];
|
![mMtlDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v2];
|
||||||
SetToggle(Toggle::EmulateStoreAndMSAAResolve, emulateStoreAndMSAAResolve);
|
SetToggle(Toggle::EmulateStoreAndMSAAResolve, emulateStoreAndMSAAResolve);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO(jiawei.shao@intel.com): check iOS feature sets
|
// TODO(jiawei.shao@intel.com): check iOS feature sets
|
||||||
|
|
||||||
|
|
|
@ -214,6 +214,7 @@ namespace dawn_native { namespace metal {
|
||||||
case dawn::TextureFormat::Depth24PlusStencil8:
|
case dawn::TextureFormat::Depth24PlusStencil8:
|
||||||
return MTLPixelFormatDepth32Float_Stencil8;
|
return MTLPixelFormatDepth32Float_Stencil8;
|
||||||
|
|
||||||
|
#if defined(DAWN_PLATFORM_MACOS)
|
||||||
case dawn::TextureFormat::BC1RGBAUnorm:
|
case dawn::TextureFormat::BC1RGBAUnorm:
|
||||||
return MTLPixelFormatBC1_RGBA;
|
return MTLPixelFormatBC1_RGBA;
|
||||||
case dawn::TextureFormat::BC1RGBAUnormSrgb:
|
case dawn::TextureFormat::BC1RGBAUnormSrgb:
|
||||||
|
@ -242,6 +243,7 @@ namespace dawn_native { namespace metal {
|
||||||
return MTLPixelFormatBC7_RGBAUnorm;
|
return MTLPixelFormatBC7_RGBAUnorm;
|
||||||
case dawn::TextureFormat::BC7RGBAUnormSrgb:
|
case dawn::TextureFormat::BC7RGBAUnormSrgb:
|
||||||
return MTLPixelFormatBC7_RGBAUnorm_sRGB;
|
return MTLPixelFormatBC7_RGBAUnorm_sRGB;
|
||||||
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
|
|
Loading…
Reference in New Issue