2022-07-27 15:25:25 +00:00
|
|
|
#include "BackendBinding.hpp"
|
|
|
|
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_D3D12)
|
|
|
|
#include <dawn/native/D3D12Backend.h>
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_METAL)
|
|
|
|
#include <dawn/native/MetalBackend.h>
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_VULKAN)
|
|
|
|
#include <dawn/native/VulkanBackend.h>
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_OPENGL)
|
|
|
|
#include <SDL_video.h>
|
|
|
|
#include <dawn/native/OpenGLBackend.h>
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_NULL)
|
|
|
|
#include <dawn/native/NullBackend.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace aurora::webgpu::utils {
|
|
|
|
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_D3D12)
|
|
|
|
BackendBinding* CreateD3D12Binding(SDL_Window* window, WGPUDevice device);
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_METAL)
|
|
|
|
BackendBinding* CreateMetalBinding(SDL_Window* window, WGPUDevice device);
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_NULL)
|
|
|
|
BackendBinding* CreateNullBinding(SDL_Window* window, WGPUDevice device);
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_OPENGL)
|
|
|
|
BackendBinding* CreateOpenGLBinding(SDL_Window* window, WGPUDevice device);
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_VULKAN)
|
|
|
|
BackendBinding* CreateVulkanBinding(SDL_Window* window, WGPUDevice device);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BackendBinding::BackendBinding(SDL_Window* window, WGPUDevice device) : m_window(window), m_device(device) {}
|
|
|
|
|
2022-08-02 20:37:56 +00:00
|
|
|
bool DiscoverAdapter(dawn::native::Instance* instance, SDL_Window* window, wgpu::BackendType type) {
|
2022-07-27 15:25:25 +00:00
|
|
|
switch (type) {
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_D3D12)
|
2022-08-02 20:37:56 +00:00
|
|
|
case wgpu::BackendType::D3D12: {
|
2022-07-27 15:25:25 +00:00
|
|
|
dawn::native::d3d12::AdapterDiscoveryOptions options;
|
|
|
|
return instance->DiscoverAdapters(&options);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_METAL)
|
2022-08-02 20:37:56 +00:00
|
|
|
case wgpu::BackendType::Metal: {
|
2022-07-27 15:25:25 +00:00
|
|
|
dawn::native::metal::AdapterDiscoveryOptions options;
|
|
|
|
return instance->DiscoverAdapters(&options);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_VULKAN)
|
2022-08-02 20:37:56 +00:00
|
|
|
case wgpu::BackendType::Vulkan: {
|
2022-07-27 15:25:25 +00:00
|
|
|
dawn::native::vulkan::AdapterDiscoveryOptions options;
|
|
|
|
return instance->DiscoverAdapters(&options);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_DESKTOP_GL)
|
2022-08-02 20:37:56 +00:00
|
|
|
case wgpu::BackendType::OpenGL: {
|
2022-07-27 15:25:25 +00:00
|
|
|
SDL_GL_ResetAttributes();
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 4);
|
|
|
|
SDL_GL_CreateContext(window);
|
|
|
|
auto getProc = reinterpret_cast<void* (*)(const char*)>(SDL_GL_GetProcAddress);
|
|
|
|
dawn::native::opengl::AdapterDiscoveryOptions adapterOptions;
|
|
|
|
adapterOptions.getProc = getProc;
|
|
|
|
return instance->DiscoverAdapters(&adapterOptions);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_OPENGLES)
|
2022-08-02 20:37:56 +00:00
|
|
|
case wgpu::BackendType::OpenGLES: {
|
2022-07-27 15:25:25 +00:00
|
|
|
SDL_GL_ResetAttributes();
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
|
|
|
SDL_GL_CreateContext(window);
|
|
|
|
auto getProc = reinterpret_cast<void* (*)(const char*)>(SDL_GL_GetProcAddress);
|
|
|
|
dawn::native::opengl::AdapterDiscoveryOptionsES adapterOptions;
|
|
|
|
adapterOptions.getProc = getProc;
|
|
|
|
return instance->DiscoverAdapters(&adapterOptions);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_NULL)
|
2022-08-02 20:37:56 +00:00
|
|
|
case wgpu::BackendType::Null:
|
2022-07-27 15:25:25 +00:00
|
|
|
instance->DiscoverDefaultAdapters();
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-02 20:37:56 +00:00
|
|
|
BackendBinding* CreateBinding(wgpu::BackendType type, SDL_Window* window, WGPUDevice device) {
|
2022-07-27 15:25:25 +00:00
|
|
|
switch (type) {
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_D3D12)
|
2022-08-02 20:37:56 +00:00
|
|
|
case wgpu::BackendType::D3D12:
|
2022-07-27 15:25:25 +00:00
|
|
|
return CreateD3D12Binding(window, device);
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_METAL)
|
2022-08-02 20:37:56 +00:00
|
|
|
case wgpu::BackendType::Metal:
|
2022-07-27 15:25:25 +00:00
|
|
|
return CreateMetalBinding(window, device);
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_NULL)
|
2022-08-02 20:37:56 +00:00
|
|
|
case wgpu::BackendType::Null:
|
2022-07-27 15:25:25 +00:00
|
|
|
return CreateNullBinding(window, device);
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_DESKTOP_GL)
|
2022-08-02 20:37:56 +00:00
|
|
|
case wgpu::BackendType::OpenGL:
|
2022-07-27 15:25:25 +00:00
|
|
|
return CreateOpenGLBinding(window, device);
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_OPENGLES)
|
2022-08-02 20:37:56 +00:00
|
|
|
case wgpu::BackendType::OpenGLES:
|
2022-07-27 15:25:25 +00:00
|
|
|
return CreateOpenGLBinding(window, device);
|
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_VULKAN)
|
2022-08-02 20:37:56 +00:00
|
|
|
case wgpu::BackendType::Vulkan:
|
2022-07-27 15:25:25 +00:00
|
|
|
return CreateVulkanBinding(window, device);
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace aurora::webgpu::utils
|