2022-02-04 18:18:18 +00:00
|
|
|
// Copyright 2017 The Dawn Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2022-04-11 18:30:50 +00:00
|
|
|
#ifndef INCLUDE_DAWN_DAWN_WSI_H_
|
|
|
|
#define INCLUDE_DAWN_DAWN_WSI_H_
|
2022-02-04 18:18:18 +00:00
|
|
|
|
2022-04-19 14:24:04 +00:00
|
|
|
#include "dawn/webgpu.h"
|
2022-02-04 18:18:18 +00:00
|
|
|
|
|
|
|
// Error message (or nullptr if there was no error)
|
|
|
|
typedef const char* DawnSwapChainError;
|
|
|
|
constexpr DawnSwapChainError DAWN_SWAP_CHAIN_NO_ERROR = nullptr;
|
2022-06-12 17:56:42 +00:00
|
|
|
constexpr DawnSwapChainError DAWN_SWAP_CHAIN_ERROR_OUT_OF_DATE = "Out of date";
|
2022-02-04 18:18:18 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/// Backend-specific texture id/name/pointer
|
|
|
|
union {
|
|
|
|
void* ptr;
|
|
|
|
uint64_t u64;
|
|
|
|
uint32_t u32;
|
|
|
|
} texture;
|
|
|
|
} DawnSwapChainNextTexture;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/// Initialize the swap chain implementation.
|
|
|
|
/// (*wsiContext) is one of DawnWSIContext{D3D12,Metal,GL}
|
|
|
|
void (*Init)(void* userData, void* wsiContext);
|
|
|
|
|
|
|
|
/// Destroy the swap chain implementation.
|
|
|
|
void (*Destroy)(void* userData);
|
|
|
|
|
|
|
|
/// Configure/reconfigure the swap chain.
|
|
|
|
DawnSwapChainError (*Configure)(void* userData,
|
|
|
|
WGPUTextureFormat format,
|
|
|
|
WGPUTextureUsage allowedUsage,
|
|
|
|
uint32_t width,
|
|
|
|
uint32_t height);
|
|
|
|
|
|
|
|
/// Acquire the next texture from the swap chain.
|
|
|
|
DawnSwapChainError (*GetNextTexture)(void* userData, DawnSwapChainNextTexture* nextTexture);
|
|
|
|
|
|
|
|
/// Present the last acquired texture to the screen.
|
|
|
|
DawnSwapChainError (*Present)(void* userData);
|
|
|
|
|
|
|
|
/// Each function is called with userData as its first argument.
|
|
|
|
void* userData;
|
|
|
|
|
|
|
|
/// For use by the D3D12 and Vulkan backends: how the swapchain will use the texture.
|
|
|
|
WGPUTextureUsage textureUsage;
|
|
|
|
} DawnSwapChainImplementation;
|
|
|
|
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_D3D12) && defined(__cplusplus)
|
|
|
|
struct DawnWSIContextD3D12 {
|
|
|
|
WGPUDevice device = nullptr;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_METAL) && defined(__OBJC__)
|
2022-05-01 14:40:55 +00:00
|
|
|
#import <Metal/Metal.h>
|
2022-02-04 18:18:18 +00:00
|
|
|
|
|
|
|
struct DawnWSIContextMetal {
|
|
|
|
id<MTLDevice> device = nil;
|
|
|
|
id<MTLCommandQueue> queue = nil;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DAWN_ENABLE_BACKEND_OPENGL
|
|
|
|
typedef struct {
|
|
|
|
} DawnWSIContextGL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DAWN_ENABLE_BACKEND_VULKAN
|
|
|
|
typedef struct {
|
|
|
|
} DawnWSIContextVulkan;
|
|
|
|
#endif
|
|
|
|
|
2022-04-11 18:30:50 +00:00
|
|
|
#endif // INCLUDE_DAWN_DAWN_WSI_H_
|