1 // Copyright 2018 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef DAWNNATIVE_METALBACKEND_H_ 16 #define DAWNNATIVE_METALBACKEND_H_ 17 18 #include <dawn/dawn_wsi.h> 19 #include <dawn_native/DawnNative.h> 20 21 // The specifics of the Metal backend expose types in function signatures that might not be 22 // available in dependent's minimum supported SDK version. Suppress all availability errors using 23 // clang's pragmas. Dependents using the types without guarded availability will still get errors 24 // when using the types. 25 #pragma clang diagnostic push 26 #pragma clang diagnostic ignored "-Wunguarded-availability" 27 28 struct __IOSurface; 29 typedef __IOSurface* IOSurfaceRef; 30 31 #ifdef __OBJC__ 32 # import <Metal/Metal.h> 33 #endif //__OBJC__ 34 35 namespace dawn_native { namespace metal { 36 37 struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase { 38 AdapterDiscoveryOptions(); 39 }; 40 41 struct DAWN_NATIVE_EXPORT ExternalImageDescriptorIOSurface : ExternalImageDescriptor { 42 public: 43 ExternalImageDescriptorIOSurface(); 44 45 IOSurfaceRef ioSurface; 46 uint32_t plane; 47 }; 48 49 DAWN_NATIVE_EXPORT WGPUTexture 50 WrapIOSurface(WGPUDevice device, const ExternalImageDescriptorIOSurface* descriptor); 51 52 // When making Metal interop with other APIs, we need to be careful that QueueSubmit doesn't 53 // mean that the operations will be visible to other APIs/Metal devices right away. macOS 54 // does have a global queue of graphics operations, but the command buffers are inserted there 55 // when they are "scheduled". Submitting other operations before the command buffer is 56 // scheduled could lead to races in who gets scheduled first and incorrect rendering. 57 DAWN_NATIVE_EXPORT void WaitForCommandsToBeScheduled(WGPUDevice device); 58 59 }} // namespace dawn_native::metal 60 61 #ifdef __OBJC__ 62 namespace dawn_native { namespace metal { 63 64 DAWN_NATIVE_EXPORT id<MTLDevice> GetMetalDevice(WGPUDevice device); 65 66 }} // namespace dawn_native::metal 67 #endif // __OBJC__ 68 69 #pragma clang diagnostic pop 70 71 #endif // DAWNNATIVE_METALBACKEND_H_ 72