Support compilation of Dawn on iOS.
BUG=dawn:225 Change-Id: I618552c55c8472adc25625733b59d972d7297f57 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11040 Reviewed-by: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
45f9185de5
commit
b495e48405
|
@ -17,15 +17,27 @@
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
# define DAWN_PLATFORM_WINDOWS 1
|
# define DAWN_PLATFORM_WINDOWS 1
|
||||||
|
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
# define DAWN_PLATFORM_LINUX 1
|
# define DAWN_PLATFORM_LINUX 1
|
||||||
# define DAWN_PLATFORM_POSIX 1
|
# define DAWN_PLATFORM_POSIX 1
|
||||||
|
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
# define DAWN_PLATFORM_APPLE 1
|
# define DAWN_PLATFORM_APPLE 1
|
||||||
# define DAWN_PLATFORM_POSIX 1
|
# define DAWN_PLATFORM_POSIX 1
|
||||||
|
# include <TargetConditionals.h>
|
||||||
|
# if TARGET_OS_IPHONE
|
||||||
|
# define DAWN_PLATFORM_IOS
|
||||||
|
# elif TARGET_OS_MAC
|
||||||
|
# define DAWN_PLATFORM_MACOS
|
||||||
|
# else
|
||||||
|
# error "Unsupported Apple platform."
|
||||||
|
# endif
|
||||||
|
|
||||||
#elif defined(__Fuchsia__)
|
#elif defined(__Fuchsia__)
|
||||||
# define DAWN_PLATFORM_FUCHSIA 1
|
# define DAWN_PLATFORM_FUCHSIA 1
|
||||||
# define DAWN_PLATFORM_POSIX 1
|
# define DAWN_PLATFORM_POSIX 1
|
||||||
|
|
||||||
#else
|
#else
|
||||||
# error "Unsupported platform."
|
# error "Unsupported platform."
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,15 +15,20 @@
|
||||||
#include "dawn_native/metal/BackendMTL.h"
|
#include "dawn_native/metal/BackendMTL.h"
|
||||||
|
|
||||||
#include "common/Constants.h"
|
#include "common/Constants.h"
|
||||||
|
#include "common/Platform.h"
|
||||||
#include "dawn_native/Instance.h"
|
#include "dawn_native/Instance.h"
|
||||||
#include "dawn_native/MetalBackend.h"
|
#include "dawn_native/MetalBackend.h"
|
||||||
#include "dawn_native/metal/DeviceMTL.h"
|
#include "dawn_native/metal/DeviceMTL.h"
|
||||||
|
|
||||||
#import <IOKit/IOKitLib.h>
|
#if defined(DAWN_PLATFORM_MACOS)
|
||||||
|
# import <IOKit/IOKitLib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace dawn_native { namespace metal {
|
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;
|
||||||
|
@ -150,6 +155,18 @@ namespace dawn_native { namespace metal {
|
||||||
NSOperatingSystemVersion macOS10_11 = {10, 11, 0};
|
NSOperatingSystemVersion macOS10_11 = {10, 11, 0};
|
||||||
return [NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:macOS10_11];
|
return [NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:macOS10_11];
|
||||||
}
|
}
|
||||||
|
#elif defined(DAWN_PLATFORM_IOS)
|
||||||
|
MaybeError GetDevicePCIInfo(id<MTLDevice> device, PCIIDs* ids) {
|
||||||
|
DAWN_UNUSED(device);
|
||||||
|
*ids = PCIIDs(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsMetalSupported() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# error "Unsupported Apple platform."
|
||||||
|
#endif
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
// The Metal backend's Adapter.
|
// The Metal backend's Adapter.
|
||||||
|
@ -201,14 +218,23 @@ namespace dawn_native { namespace metal {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::unique_ptr<AdapterBase>> Backend::DiscoverDefaultAdapters() {
|
std::vector<std::unique_ptr<AdapterBase>> Backend::DiscoverDefaultAdapters() {
|
||||||
NSArray<id<MTLDevice>>* devices = MTLCopyAllDevices();
|
|
||||||
|
|
||||||
std::vector<std::unique_ptr<AdapterBase>> adapters;
|
std::vector<std::unique_ptr<AdapterBase>> adapters;
|
||||||
for (id<MTLDevice> device in devices) {
|
|
||||||
adapters.push_back(std::make_unique<Adapter>(GetInstance(), device));
|
|
||||||
}
|
|
||||||
|
|
||||||
[devices release];
|
if (@available(macOS 10.12, *)) {
|
||||||
|
NSArray<id<MTLDevice>>* devices = MTLCopyAllDevices();
|
||||||
|
|
||||||
|
for (id<MTLDevice> device in devices) {
|
||||||
|
adapters.push_back(std::make_unique<Adapter>(GetInstance(), device));
|
||||||
|
}
|
||||||
|
|
||||||
|
[devices release];
|
||||||
|
} else if (@available(iOS 8.0, *)) {
|
||||||
|
// iOS only has a single device so MTLCopyAllDevices doesn't exist there.
|
||||||
|
adapters.push_back(
|
||||||
|
std::make_unique<Adapter>(GetInstance(), MTLCreateSystemDefaultDevice()));
|
||||||
|
} else {
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
return adapters;
|
return adapters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,9 @@
|
||||||
#include "dawn_native/Device.h"
|
#include "dawn_native/Device.h"
|
||||||
#include "dawn_native/metal/Forward.h"
|
#include "dawn_native/metal/Forward.h"
|
||||||
|
|
||||||
|
#import <IOSurface/IOSurfaceRef.h>
|
||||||
#import <Metal/Metal.h>
|
#import <Metal/Metal.h>
|
||||||
#import <QuartzCore/CAMetalLayer.h>
|
#import <QuartzCore/QuartzCore.h>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
|
@ -76,10 +76,13 @@ namespace dawn_native { namespace metal {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::InitTogglesFromDriver() {
|
void Device::InitTogglesFromDriver() {
|
||||||
|
if (@available(macOS 10.12, *)) {
|
||||||
|
bool emulateStoreAndMSAAResolve =
|
||||||
|
![mMtlDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v2];
|
||||||
|
SetToggle(Toggle::EmulateStoreAndMSAAResolve, emulateStoreAndMSAAResolve);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(jiawei.shao@intel.com): check iOS feature sets
|
// TODO(jiawei.shao@intel.com): check iOS feature sets
|
||||||
bool emulateStoreAndMSAAResolve =
|
|
||||||
![mMtlDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v2];
|
|
||||||
SetToggle(Toggle::EmulateStoreAndMSAAResolve, emulateStoreAndMSAAResolve);
|
|
||||||
|
|
||||||
// TODO(jiawei.shao@intel.com): tighten this workaround when the driver bug is fixed.
|
// TODO(jiawei.shao@intel.com): tighten this workaround when the driver bug is fixed.
|
||||||
SetToggle(Toggle::AlwaysResolveIntoZeroLevelAndLayer, true);
|
SetToggle(Toggle::AlwaysResolveIntoZeroLevelAndLayer, true);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include "dawn_native/Texture.h"
|
#include "dawn_native/Texture.h"
|
||||||
|
|
||||||
|
#include <IOSurface/IOSurfaceRef.h>
|
||||||
#import <Metal/Metal.h>
|
#import <Metal/Metal.h>
|
||||||
|
|
||||||
namespace dawn_native { namespace metal {
|
namespace dawn_native { namespace metal {
|
||||||
|
|
|
@ -14,10 +14,9 @@
|
||||||
|
|
||||||
#include "dawn_native/metal/TextureMTL.h"
|
#include "dawn_native/metal/TextureMTL.h"
|
||||||
|
|
||||||
|
#include "common/Platform.h"
|
||||||
#include "dawn_native/metal/DeviceMTL.h"
|
#include "dawn_native/metal/DeviceMTL.h"
|
||||||
|
|
||||||
#include <IOSurface/IOSurface.h>
|
|
||||||
|
|
||||||
namespace dawn_native { namespace metal {
|
namespace dawn_native { namespace metal {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -121,6 +120,14 @@ namespace dawn_native { namespace metal {
|
||||||
return DAWN_VALIDATION_ERROR("Unsupported IOSurface format");
|
return DAWN_VALIDATION_ERROR("Unsupported IOSurface format");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(DAWN_PLATFORM_MACOS)
|
||||||
|
MTLStorageMode kIOSurfaceStorageMode = MTLStorageModeManaged;
|
||||||
|
#elif defined(DAWN_PLATFORM_IOS)
|
||||||
|
MTLStorageMode kIOSurfaceStorageMode = MTLStorageModePrivate;
|
||||||
|
#else
|
||||||
|
# error "Unsupported Apple platform."
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
MTLPixelFormat MetalPixelFormat(dawn::TextureFormat format) {
|
MTLPixelFormat MetalPixelFormat(dawn::TextureFormat format) {
|
||||||
|
@ -322,7 +329,7 @@ namespace dawn_native { namespace metal {
|
||||||
uint32_t plane)
|
uint32_t plane)
|
||||||
: TextureBase(device, descriptor, TextureState::OwnedInternal) {
|
: TextureBase(device, descriptor, TextureState::OwnedInternal) {
|
||||||
MTLTextureDescriptor* mtlDesc = CreateMetalTextureDescriptor(descriptor);
|
MTLTextureDescriptor* mtlDesc = CreateMetalTextureDescriptor(descriptor);
|
||||||
mtlDesc.storageMode = MTLStorageModeManaged;
|
mtlDesc.storageMode = kIOSurfaceStorageMode;
|
||||||
mMtlTexture = [device->GetMTLDevice() newTextureWithDescriptor:mtlDesc
|
mMtlTexture = [device->GetMTLDevice() newTextureWithDescriptor:mtlDesc
|
||||||
iosurface:ioSurface
|
iosurface:ioSurface
|
||||||
plane:plane];
|
plane:plane];
|
||||||
|
|
Loading…
Reference in New Issue