1 // Copyright 2017 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 DAWN_DAWN_WSI_H_ 16 #define DAWN_DAWN_WSI_H_ 17 18 #include <dawn/webgpu.h> 19 20 // Error message (or nullptr if there was no error) 21 typedef const char* DawnSwapChainError; 22 constexpr DawnSwapChainError DAWN_SWAP_CHAIN_NO_ERROR = nullptr; 23 24 typedef struct { 25 /// Backend-specific texture id/name/pointer 26 union { 27 void* ptr; 28 uint64_t u64; 29 uint32_t u32; 30 } texture; 31 } DawnSwapChainNextTexture; 32 33 typedef struct { 34 /// Initialize the swap chain implementation. 35 /// (*wsiContext) is one of DawnWSIContext{D3D12,Metal,GL} 36 void (*Init)(void* userData, void* wsiContext); 37 38 /// Destroy the swap chain implementation. 39 void (*Destroy)(void* userData); 40 41 /// Configure/reconfigure the swap chain. 42 DawnSwapChainError (*Configure)(void* userData, 43 WGPUTextureFormat format, 44 WGPUTextureUsage allowedUsage, 45 uint32_t width, 46 uint32_t height); 47 48 /// Acquire the next texture from the swap chain. 49 DawnSwapChainError (*GetNextTexture)(void* userData, DawnSwapChainNextTexture* nextTexture); 50 51 /// Present the last acquired texture to the screen. 52 DawnSwapChainError (*Present)(void* userData); 53 54 /// Each function is called with userData as its first argument. 55 void* userData; 56 57 /// For use by the D3D12 and Vulkan backends: how the swapchain will use the texture. 58 WGPUTextureUsage textureUsage; 59 } DawnSwapChainImplementation; 60 61 #if defined(DAWN_ENABLE_BACKEND_D3D12) && defined(__cplusplus) 62 struct DawnWSIContextD3D12 { 63 WGPUDevice device = nullptr; 64 }; 65 #endif 66 67 #if defined(DAWN_ENABLE_BACKEND_METAL) && defined(__OBJC__) 68 # import <Metal/Metal.h> 69 70 struct DawnWSIContextMetal { 71 id<MTLDevice> device = nil; 72 id<MTLCommandQueue> queue = nil; 73 }; 74 #endif 75 76 #ifdef DAWN_ENABLE_BACKEND_OPENGL 77 typedef struct { 78 } DawnWSIContextGL; 79 #endif 80 81 #ifdef DAWN_ENABLE_BACKEND_VULKAN 82 typedef struct { 83 } DawnWSIContextVulkan; 84 #endif 85 86 #endif // DAWN_DAWN_WSI_H 87