Updates to SetupWindowAndGetSurfaceDescriptor

This commit is contained in:
Luke Street 2023-05-27 14:57:24 -04:00
parent fca51127a2
commit 9c75c739e4
2 changed files with 45 additions and 38 deletions

View File

@ -1,6 +1,8 @@
#include "BackendBinding.hpp" #include "BackendBinding.hpp"
#include <SDL_syswm.h> #include <SDL_syswm.h>
#include <memory>
#if defined(DAWN_ENABLE_BACKEND_D3D12) #if defined(DAWN_ENABLE_BACKEND_D3D12)
#include <dawn/native/D3D12Backend.h> #include <dawn/native/D3D12Backend.h>
#endif #endif
@ -63,15 +65,15 @@ bool DiscoverAdapter(dawn::native::Instance* instance, [[maybe_unused]] SDL_Wind
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 4); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 4);
SDL_GLContext context = SDL_GL_CreateContext(window); SDL_GLContext context = SDL_GL_CreateContext(window);
dawn::native::opengl::AdapterDiscoveryOptions adapterOptions{WGPUBackendType_OpenGL}; dawn::native::opengl::PhysicalDeviceDiscoveryOptions options{WGPUBackendType_OpenGL};
adapterOptions.getProc = SDL_GL_GetProcAddress; options.getProc = SDL_GL_GetProcAddress;
adapterOptions.makeCurrent = GLMakeCurrent; options.makeCurrent = GLMakeCurrent;
adapterOptions.destroy = GLDestroy; options.destroy = GLDestroy;
adapterOptions.userData = new GLUserData{ options.userData = new GLUserData{
.window = window, .window = window,
.context = context, .context = context,
}; };
return instance->DiscoverAdapters(&adapterOptions); return instance->DiscoverPhysicalDevices(&options);
} }
#endif #endif
#if defined(DAWN_ENABLE_BACKEND_OPENGLES) #if defined(DAWN_ENABLE_BACKEND_OPENGLES)
@ -81,15 +83,15 @@ bool DiscoverAdapter(dawn::native::Instance* instance, [[maybe_unused]] SDL_Wind
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GLContext context = SDL_GL_CreateContext(window); SDL_GLContext context = SDL_GL_CreateContext(window);
dawn::native::opengl::AdapterDiscoveryOptions adapterOptions{WGPUBackendType_OpenGLES}; dawn::native::opengl::PhysicalDeviceDiscoveryOptions options{WGPUBackendType_OpenGLES};
adapterOptions.getProc = SDL_GL_GetProcAddress; options.getProc = SDL_GL_GetProcAddress;
adapterOptions.makeCurrent = GLMakeCurrent; options.makeCurrent = GLMakeCurrent;
adapterOptions.destroy = GLDestroy; options.destroy = GLDestroy;
adapterOptions.userData = new GLUserData{ options.userData = new GLUserData{
.window = window, .window = window,
.context = context, .context = context,
}; };
return instance->DiscoverAdapters(&adapterOptions); return instance->DiscoverPhysicalDevices(&options);
} }
#endif #endif
#if defined(DAWN_ENABLE_BACKEND_NULL) #if defined(DAWN_ENABLE_BACKEND_NULL)
@ -105,40 +107,44 @@ bool DiscoverAdapter(dawn::native::Instance* instance, [[maybe_unused]] SDL_Wind
std::unique_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptorCocoa(SDL_Window* window); std::unique_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptorCocoa(SDL_Window* window);
std::unique_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptor(SDL_Window* window) { std::unique_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptor(SDL_Window* window) {
#if _WIN32 #if defined(SDL_VIDEO_DRIVER_COCOA)
std::unique_ptr<wgpu::SurfaceDescriptorFromWindowsHWND> desc =
std::make_unique<wgpu::SurfaceDescriptorFromWindowsHWND>();
desc->hwnd = glfwGetWin32Window(window);
desc->hinstance = GetModuleHandle(nullptr);
return std::move(desc);
#elif defined(DAWN_ENABLE_BACKEND_METAL)
return SetupWindowAndGetSurfaceDescriptorCocoa(window); return SetupWindowAndGetSurfaceDescriptorCocoa(window);
#elif defined(DAWN_USE_WAYLAND) || defined(DAWN_USE_X11)
#if defined(GLFW_PLATFORM_WAYLAND) && defined(DAWN_USE_WAYLAND)
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) {
std::unique_ptr<wgpu::SurfaceDescriptorFromWaylandSurface> desc =
std::make_unique<wgpu::SurfaceDescriptorFromWaylandSurface>();
desc->display = glfwGetWaylandDisplay();
desc->surface = glfwGetWaylandWindow(window);
return std::move(desc);
} else // NOLINT(readability/braces)
#endif
#if defined(DAWN_USE_X11)
{
std::unique_ptr<wgpu::SurfaceDescriptorFromXlibWindow> desc =
std::make_unique<wgpu::SurfaceDescriptorFromXlibWindow>();
desc->display = glfwGetX11Display();
desc->window = glfwGetX11Window(window);
return std::move(desc);
}
#else #else
{ SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
if (SDL_GetWindowWMInfo(window, &wmInfo) == SDL_FALSE) {
return nullptr; return nullptr;
} }
#if defined(SDL_VIDEO_DRIVER_WINDOWS)
std::unique_ptr<wgpu::SurfaceDescriptorFromWindowsHWND> desc =
std::make_unique<wgpu::SurfaceDescriptorFromWindowsHWND>();
desc->hwnd = wmInfo.info.window;
desc->hinstance = wmInfo.info.hinstance;
return std::move(desc);
#elif defined(SDL_VIDEO_DRIVER_WAYLAND) || defined(SDL_VIDEO_DRIVER_X11)
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
if (wmInfo.subsystem == SDL_SYSWM_WAYLAND) {
std::unique_ptr<wgpu::SurfaceDescriptorFromWaylandSurface> desc =
std::make_unique<wgpu::SurfaceDescriptorFromWaylandSurface>();
desc->display = wmInfo.info.wl.display;
desc->surface = wmInfo.info.wl.surface;
return std::move(desc);
}
#endif #endif
#if defined(SDL_VIDEO_DRIVER_X11)
if (wmInfo.subsystem == SDL_SYSWM_X11) {
std::unique_ptr<wgpu::SurfaceDescriptorFromXlibWindow> desc =
std::make_unique<wgpu::SurfaceDescriptorFromXlibWindow>();
desc->display = wmInfo.info.x11.display;
desc->window = wmInfo.info.x11.window;
return std::move(desc);
}
#endif
return nullptr;
#else #else
return nullptr; return nullptr;
#endif #endif
#endif
} }
} // namespace aurora::webgpu::utils } // namespace aurora::webgpu::utils

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <dawn/native/DawnNative.h> #include <dawn/native/DawnNative.h>
#include <memory>
#include <webgpu/webgpu_cpp.h> #include <webgpu/webgpu_cpp.h>
struct SDL_Window; struct SDL_Window;