MetalBinding: query the MTLDevice instead of creating it.

With adapters the Metal backend will be in charge of creating the
MTLDevice so we remove this responsibility from the bindings.

BUG=dawn:29

Change-Id: Id7b9e5f6249963e2b87a91242a18119ba8d11c13
Reviewed-on: https://dawn-review.googlesource.com/c/3661
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2019-01-07 10:01:11 +00:00 committed by Commit Bot service account
parent 9506d53938
commit 95fd2821c2
4 changed files with 16 additions and 8 deletions

View File

@ -34,7 +34,7 @@ namespace dawn_native { namespace metal {
class Device : public DeviceBase { class Device : public DeviceBase {
public: public:
Device(id<MTLDevice> mtlDevice); Device();
~Device(); ~Device();
CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override; CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override;

View File

@ -122,8 +122,13 @@ namespace dawn_native { namespace metal {
} }
} // anonymous namespace } // anonymous namespace
dawnDevice CreateDevice(id<MTLDevice> metalDevice) { dawnDevice CreateDevice() {
return reinterpret_cast<dawnDevice>(new Device(metalDevice)); return reinterpret_cast<dawnDevice>(new Device());
}
id<MTLDevice> GetMetalDevice(dawnDevice cDevice) {
Device* device = reinterpret_cast<Device*>(cDevice);
return device->GetMTLDevice();
} }
BackendConnection* Connect(InstanceBase* instance) { BackendConnection* Connect(InstanceBase* instance) {
@ -132,8 +137,8 @@ namespace dawn_native { namespace metal {
// Device // Device
Device::Device(id<MTLDevice> mtlDevice) Device::Device()
: mMtlDevice(mtlDevice), : mMtlDevice(MTLCreateSystemDefaultDevice()),
mMapTracker(new MapRequestTracker(this)), mMapTracker(new MapRequestTracker(this)),
mResourceUploader(new ResourceUploader(this)) { mResourceUploader(new ResourceUploader(this)) {
[mMtlDevice retain]; [mMtlDevice retain];

View File

@ -23,7 +23,8 @@
#import <QuartzCore/CAMetalLayer.h> #import <QuartzCore/CAMetalLayer.h>
namespace dawn_native { namespace metal { namespace dawn_native { namespace metal {
DAWN_NATIVE_EXPORT dawnDevice CreateDevice(id<MTLDevice> metalDevice); DAWN_NATIVE_EXPORT dawnDevice CreateDevice();
DAWN_NATIVE_EXPORT id<MTLDevice> GetMetalDevice(dawnDevice device);
}} // namespace dawn_native::metal }} // namespace dawn_native::metal
#endif // DAWNNATIVE_METALBACKEND_H_ #endif // DAWNNATIVE_METALBACKEND_H_

View File

@ -111,9 +111,11 @@ namespace utils {
void SetupGLFWWindowHints() override { void SetupGLFWWindowHints() override {
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
} }
dawnDevice CreateDevice() override { dawnDevice CreateDevice() override {
mMetalDevice = MTLCreateSystemDefaultDevice(); dawnDevice device = dawn_native::metal::CreateDevice();
return dawn_native::metal::CreateDevice(mMetalDevice); mMetalDevice = dawn_native::metal::GetMetalDevice(device);
return device;
} }
uint64_t GetSwapChainImplementation() override { uint64_t GetSwapChainImplementation() override {