diff --git a/src/dawn_native/metal/DeviceMTL.h b/src/dawn_native/metal/DeviceMTL.h index fa96d4e75a..434ffa8970 100644 --- a/src/dawn_native/metal/DeviceMTL.h +++ b/src/dawn_native/metal/DeviceMTL.h @@ -34,7 +34,7 @@ namespace dawn_native { namespace metal { class Device : public DeviceBase { public: - Device(id mtlDevice); + Device(); ~Device(); CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override; diff --git a/src/dawn_native/metal/DeviceMTL.mm b/src/dawn_native/metal/DeviceMTL.mm index 1e54f5fd24..1c139b1f84 100644 --- a/src/dawn_native/metal/DeviceMTL.mm +++ b/src/dawn_native/metal/DeviceMTL.mm @@ -122,8 +122,13 @@ namespace dawn_native { namespace metal { } } // anonymous namespace - dawnDevice CreateDevice(id metalDevice) { - return reinterpret_cast(new Device(metalDevice)); + dawnDevice CreateDevice() { + return reinterpret_cast(new Device()); + } + + id GetMetalDevice(dawnDevice cDevice) { + Device* device = reinterpret_cast(cDevice); + return device->GetMTLDevice(); } BackendConnection* Connect(InstanceBase* instance) { @@ -132,8 +137,8 @@ namespace dawn_native { namespace metal { // Device - Device::Device(id mtlDevice) - : mMtlDevice(mtlDevice), + Device::Device() + : mMtlDevice(MTLCreateSystemDefaultDevice()), mMapTracker(new MapRequestTracker(this)), mResourceUploader(new ResourceUploader(this)) { [mMtlDevice retain]; diff --git a/src/include/dawn_native/MetalBackend.h b/src/include/dawn_native/MetalBackend.h index 08089576c2..aad945a7b6 100644 --- a/src/include/dawn_native/MetalBackend.h +++ b/src/include/dawn_native/MetalBackend.h @@ -23,7 +23,8 @@ #import namespace dawn_native { namespace metal { - DAWN_NATIVE_EXPORT dawnDevice CreateDevice(id metalDevice); + DAWN_NATIVE_EXPORT dawnDevice CreateDevice(); + DAWN_NATIVE_EXPORT id GetMetalDevice(dawnDevice device); }} // namespace dawn_native::metal #endif // DAWNNATIVE_METALBACKEND_H_ diff --git a/src/utils/MetalBinding.mm b/src/utils/MetalBinding.mm index 0b41c149ef..55558eda02 100644 --- a/src/utils/MetalBinding.mm +++ b/src/utils/MetalBinding.mm @@ -111,9 +111,11 @@ namespace utils { void SetupGLFWWindowHints() override { glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); } + dawnDevice CreateDevice() override { - mMetalDevice = MTLCreateSystemDefaultDevice(); - return dawn_native::metal::CreateDevice(mMetalDevice); + dawnDevice device = dawn_native::metal::CreateDevice(); + mMetalDevice = dawn_native::metal::GetMetalDevice(device); + return device; } uint64_t GetSwapChainImplementation() override {