From 7bdeb5e17c8be25c8d53ef9c169067f2db319c6a Mon Sep 17 00:00:00 2001 From: Luke Street Date: Wed, 28 Jun 2023 20:02:15 -0400 Subject: [PATCH] Update dawn, add D3D11 backend, disable OpenGL (broken) --- CMakeLists.txt | 3 +++ include/aurora/aurora.h | 1 + lib/aurora.cpp | 15 +++++++++------ lib/dawn/BackendBinding.cpp | 13 +++++++++++-- lib/gfx/common.hpp | 4 ++-- lib/webgpu/gpu.cpp | 2 ++ 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df5659c..a3e22e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,9 @@ if (DAWN_ENABLE_METAL) target_sources(aurora PRIVATE lib/dawn/MetalBinding.mm) set_source_files_properties(lib/dawn/MetalBinding.mm PROPERTIES COMPILE_FLAGS -fobjc-arc) endif () +if (DAWN_ENABLE_D3D11) + target_compile_definitions(aurora PRIVATE DAWN_ENABLE_BACKEND_D3D11) +endif () if (DAWN_ENABLE_D3D12) target_compile_definitions(aurora PRIVATE DAWN_ENABLE_BACKEND_D3D12) endif () diff --git a/include/aurora/aurora.h b/include/aurora/aurora.h index 1cc9877..5004dcd 100644 --- a/include/aurora/aurora.h +++ b/include/aurora/aurora.h @@ -14,6 +14,7 @@ extern "C" { typedef enum { BACKEND_AUTO, + BACKEND_D3D11, BACKEND_D3D12, BACKEND_METAL, BACKEND_VULKAN, diff --git a/lib/aurora.cpp b/lib/aurora.cpp index d50176d..013264d 100644 --- a/lib/aurora.cpp +++ b/lib/aurora.cpp @@ -26,7 +26,7 @@ constexpr std::array PreferredBackendOrder{ BACKEND_WEBGPU, #endif #ifdef DAWN_ENABLE_BACKEND_D3D12 -// BACKEND_D3D12, + BACKEND_D3D12, #endif #ifdef DAWN_ENABLE_BACKEND_METAL BACKEND_METAL, @@ -34,12 +34,15 @@ constexpr std::array PreferredBackendOrder{ #ifdef DAWN_ENABLE_BACKEND_VULKAN BACKEND_VULKAN, #endif -#ifdef DAWN_ENABLE_BACKEND_DESKTOP_GL - BACKEND_OPENGL, -#endif -#ifdef DAWN_ENABLE_BACKEND_OPENGLES - BACKEND_OPENGLES, +#ifdef DAWN_ENABLE_BACKEND_D3D11 + BACKEND_D3D11, #endif +//#ifdef DAWN_ENABLE_BACKEND_DESKTOP_GL +// BACKEND_OPENGL, +//#endif +//#ifdef DAWN_ENABLE_BACKEND_OPENGLES +// BACKEND_OPENGLES, +//#endif #ifdef DAWN_ENABLE_BACKEND_NULL BACKEND_NULL, #endif diff --git a/lib/dawn/BackendBinding.cpp b/lib/dawn/BackendBinding.cpp index a4c0889..d3f5f3d 100644 --- a/lib/dawn/BackendBinding.cpp +++ b/lib/dawn/BackendBinding.cpp @@ -3,6 +3,9 @@ #include #include +#if defined(DAWN_ENABLE_BACKEND_D3D11) +#include +#endif #if defined(DAWN_ENABLE_BACKEND_D3D12) #include #endif @@ -40,6 +43,12 @@ void GLDestroy(void* userData) { bool DiscoverAdapter(dawn::native::Instance* instance, [[maybe_unused]] SDL_Window* window, wgpu::BackendType type) { switch (type) { +#if defined(DAWN_ENABLE_BACKEND_D3D11) + case wgpu::BackendType::D3D11: { + dawn::native::d3d11::PhysicalDeviceDiscoveryOptions options; + return instance->DiscoverPhysicalDevices(&options); + } +#endif #if defined(DAWN_ENABLE_BACKEND_D3D12) case wgpu::BackendType::D3D12: { dawn::native::d3d12::PhysicalDeviceDiscoveryOptions options; @@ -118,8 +127,8 @@ std::unique_ptr SetupWindowAndGetSurfaceDescriptor(SDL_Wind #if defined(SDL_VIDEO_DRIVER_WINDOWS) std::unique_ptr desc = std::make_unique(); - desc->hwnd = wmInfo.info.window; - desc->hinstance = wmInfo.info.hinstance; + desc->hwnd = wmInfo.info.win.window; + desc->hinstance = wmInfo.info.win.hinstance; return std::move(desc); #elif defined(SDL_VIDEO_DRIVER_WAYLAND) || defined(SDL_VIDEO_DRIVER_X11) #if defined(SDL_VIDEO_DRIVER_WAYLAND) diff --git a/lib/gfx/common.hpp b/lib/gfx/common.hpp index 6121bbd..2b15620 100644 --- a/lib/gfx/common.hpp +++ b/lib/gfx/common.hpp @@ -155,8 +155,8 @@ struct TextureRef; using TextureHandle = std::shared_ptr; enum class ShaderType { - Stream = 'STRM', - Model = 'CMDL', + Stream, + Model, }; void initialize(); diff --git a/lib/webgpu/gpu.cpp b/lib/webgpu/gpu.cpp index ad5ae08..1eead6f 100644 --- a/lib/webgpu/gpu.cpp +++ b/lib/webgpu/gpu.cpp @@ -316,6 +316,8 @@ static wgpu::BackendType to_wgpu_backend(AuroraBackend backend) { switch (backend) { case BACKEND_WEBGPU: return wgpu::BackendType::WebGPU; + case BACKEND_D3D11: + return wgpu::BackendType::D3D11; case BACKEND_D3D12: return wgpu::BackendType::D3D12; case BACKEND_METAL: