diff --git a/CMakeLists.txt b/CMakeLists.txt index 52b9900..e65989c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,6 @@ endif () target_link_libraries(aurora PRIVATE absl::btree absl::flat_hash_map) if (DAWN_ENABLE_VULKAN) target_compile_definitions(aurora PRIVATE DAWN_ENABLE_BACKEND_VULKAN) - target_sources(aurora PRIVATE lib/dawn/VulkanBinding.cpp) endif () if (DAWN_ENABLE_METAL) target_compile_definitions(aurora PRIVATE DAWN_ENABLE_BACKEND_METAL) @@ -69,7 +68,6 @@ if (DAWN_ENABLE_METAL) endif () if (DAWN_ENABLE_D3D12) target_compile_definitions(aurora PRIVATE DAWN_ENABLE_BACKEND_D3D12) - target_sources(aurora PRIVATE lib/dawn/D3D12Binding.cpp) endif () if (DAWN_ENABLE_DESKTOP_GL OR DAWN_ENABLE_OPENGLES) target_compile_definitions(aurora PRIVATE DAWN_ENABLE_BACKEND_OPENGL) @@ -79,11 +77,9 @@ if (DAWN_ENABLE_DESKTOP_GL OR DAWN_ENABLE_OPENGLES) if (DAWN_ENABLE_OPENGLES) target_compile_definitions(aurora PRIVATE DAWN_ENABLE_BACKEND_OPENGLES) endif () - target_sources(aurora PRIVATE lib/dawn/OpenGLBinding.cpp) endif () if (DAWN_ENABLE_NULL) target_compile_definitions(aurora PRIVATE DAWN_ENABLE_BACKEND_NULL) - target_sources(aurora PRIVATE lib/dawn/NullBinding.cpp) endif () add_library(aurora_main STATIC lib/main.cpp) diff --git a/extern/SDL b/extern/SDL index 34458fe..9b3d146 160000 --- a/extern/SDL +++ b/extern/SDL @@ -1 +1 @@ -Subproject commit 34458fe9f4a11a5b15ced6193e4c5d7ef97cca36 +Subproject commit 9b3d146ea1949831d11eaf04c38d167f4efc6549 diff --git a/extern/dawn b/extern/dawn index db82c79..0bd776d 160000 --- a/extern/dawn +++ b/extern/dawn @@ -1 +1 @@ -Subproject commit db82c79db65e502dd226f5cb4e2c03d85f8ffd2d +Subproject commit 0bd776df12d2f747b17437c6501751fdee70f14d diff --git a/lib/dawn/BackendBinding.cpp b/lib/dawn/BackendBinding.cpp index 8ee5536..cafbd95 100644 --- a/lib/dawn/BackendBinding.cpp +++ b/lib/dawn/BackendBinding.cpp @@ -1,5 +1,6 @@ #include "BackendBinding.hpp" +#include #if defined(DAWN_ENABLE_BACKEND_D3D12) #include #endif @@ -19,24 +20,6 @@ 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) {} - #if defined(DAWN_ENABLE_BACKEND_OPENGL) struct GLUserData { SDL_Window* window; @@ -53,24 +36,24 @@ void GLDestroy(void* userData) { } #endif -bool DiscoverAdapter(dawn::native::Instance* instance, SDL_Window* window, wgpu::BackendType type) { +bool DiscoverAdapter(dawn::native::Instance* instance, [[maybe_unused]] SDL_Window* window, wgpu::BackendType type) { switch (type) { #if defined(DAWN_ENABLE_BACKEND_D3D12) case wgpu::BackendType::D3D12: { - dawn::native::d3d12::AdapterDiscoveryOptions options; - return instance->DiscoverAdapters(&options); + dawn::native::d3d12::PhysicalDeviceDiscoveryOptions options; + return instance->DiscoverPhysicalDevices(&options); } #endif #if defined(DAWN_ENABLE_BACKEND_METAL) case wgpu::BackendType::Metal: { - dawn::native::metal::AdapterDiscoveryOptions options; - return instance->DiscoverAdapters(&options); + dawn::native::metal::PhysicalDeviceDiscoveryOptions options; + return instance->DiscoverPhysicalDevices(&options); } #endif #if defined(DAWN_ENABLE_BACKEND_VULKAN) case wgpu::BackendType::Vulkan: { - dawn::native::vulkan::AdapterDiscoveryOptions options; - return instance->DiscoverAdapters(&options); + dawn::native::vulkan::PhysicalDeviceDiscoveryOptions options; + return instance->DiscoverPhysicalDevices(&options); } #endif #if defined(DAWN_ENABLE_BACKEND_DESKTOP_GL) @@ -111,7 +94,7 @@ bool DiscoverAdapter(dawn::native::Instance* instance, SDL_Window* window, wgpu: #endif #if defined(DAWN_ENABLE_BACKEND_NULL) case wgpu::BackendType::Null: - instance->DiscoverDefaultAdapters(); + instance->DiscoverDefaultPhysicalDevices(); return true; #endif default: @@ -119,35 +102,43 @@ bool DiscoverAdapter(dawn::native::Instance* instance, SDL_Window* window, wgpu: } } -BackendBinding* CreateBinding(wgpu::BackendType type, SDL_Window* window, WGPUDevice device) { - switch (type) { -#if defined(DAWN_ENABLE_BACKEND_D3D12) - case wgpu::BackendType::D3D12: - return CreateD3D12Binding(window, device); +std::unique_ptr SetupWindowAndGetSurfaceDescriptorCocoa(SDL_Window* window); + +std::unique_ptr SetupWindowAndGetSurfaceDescriptor(SDL_Window* window) { +#if _WIN32 + std::unique_ptr desc = + std::make_unique(); + desc->hwnd = glfwGetWin32Window(window); + desc->hinstance = GetModuleHandle(nullptr); + return std::move(desc); +#elif defined(DAWN_ENABLE_BACKEND_METAL) + 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 desc = + std::make_unique(); + desc->display = glfwGetWaylandDisplay(); + desc->surface = glfwGetWaylandWindow(window); + return std::move(desc); + } else // NOLINT(readability/braces) #endif -#if defined(DAWN_ENABLE_BACKEND_METAL) - case wgpu::BackendType::Metal: - return CreateMetalBinding(window, device); -#endif -#if defined(DAWN_ENABLE_BACKEND_NULL) - case wgpu::BackendType::Null: - return CreateNullBinding(window, device); -#endif -#if defined(DAWN_ENABLE_BACKEND_DESKTOP_GL) - case wgpu::BackendType::OpenGL: - return CreateOpenGLBinding(window, device); -#endif -#if defined(DAWN_ENABLE_BACKEND_OPENGLES) - case wgpu::BackendType::OpenGLES: - return CreateOpenGLBinding(window, device); -#endif -#if defined(DAWN_ENABLE_BACKEND_VULKAN) - case wgpu::BackendType::Vulkan: - return CreateVulkanBinding(window, device); -#endif - default: +#if defined(DAWN_USE_X11) + { + std::unique_ptr desc = + std::make_unique(); + desc->display = glfwGetX11Display(); + desc->window = glfwGetX11Window(window); + return std::move(desc); + } +#else + { return nullptr; } +#endif +#else + return nullptr; +#endif } } // namespace aurora::webgpu::utils diff --git a/lib/dawn/BackendBinding.hpp b/lib/dawn/BackendBinding.hpp index e0cc2e8..9eef14d 100644 --- a/lib/dawn/BackendBinding.hpp +++ b/lib/dawn/BackendBinding.hpp @@ -7,21 +7,7 @@ struct SDL_Window; namespace aurora::webgpu::utils { -class BackendBinding { -public: - virtual ~BackendBinding() = default; - - virtual uint64_t GetSwapChainImplementation() = 0; - virtual WGPUTextureFormat GetPreferredSwapChainTextureFormat() = 0; - -protected: - BackendBinding(SDL_Window* window, WGPUDevice device); - - SDL_Window* m_window = nullptr; - WGPUDevice m_device = nullptr; -}; - bool DiscoverAdapter(dawn::native::Instance* instance, SDL_Window* window, wgpu::BackendType type); -BackendBinding* CreateBinding(wgpu::BackendType type, SDL_Window* window, WGPUDevice device); +std::unique_ptr SetupWindowAndGetSurfaceDescriptor(SDL_Window* window); } // namespace aurora::webgpu::utils diff --git a/lib/dawn/MetalBinding.mm b/lib/dawn/MetalBinding.mm index 151ed91..d2b4787 100644 --- a/lib/dawn/MetalBinding.mm +++ b/lib/dawn/MetalBinding.mm @@ -1,108 +1,13 @@ #include "BackendBinding.hpp" #include -#include - -#import - -template DawnSwapChainImplementation CreateSwapChainImplementation(T *swapChain) { - DawnSwapChainImplementation impl = {}; - impl.userData = swapChain; - impl.Init = [](void *userData, void *wsiContext) { - auto *ctx = static_cast(wsiContext); - reinterpret_cast(userData)->Init(ctx); - }; - impl.Destroy = [](void *userData) { delete reinterpret_cast(userData); }; - impl.Configure = [](void *userData, WGPUTextureFormat format, WGPUTextureUsage allowedUsage, uint32_t width, - uint32_t height) { - return static_cast(userData)->Configure(format, allowedUsage, width, height); - }; - impl.GetNextTexture = [](void *userData, DawnSwapChainNextTexture *nextTexture) { - return static_cast(userData)->GetNextTexture(nextTexture); - }; - impl.Present = [](void *userData) { return static_cast(userData)->Present(); }; - return impl; -} namespace aurora::webgpu::utils { -class SwapChainImplMTL { -public: - using WSIContext = DawnWSIContextMetal; - - explicit SwapChainImplMTL(SDL_Window *window) : m_view(SDL_Metal_CreateView(window)) {} - - ~SwapChainImplMTL() { SDL_Metal_DestroyView(m_view); } - - void Init(DawnWSIContextMetal *ctx) { - mMtlDevice = ctx->device; - mCommandQueue = ctx->queue; - } - - DawnSwapChainError Configure(WGPUTextureFormat format, WGPUTextureUsage usage, uint32_t width, uint32_t height) { - if (format != WGPUTextureFormat_BGRA8Unorm) { - return "unsupported format"; - } - assert(width > 0); - assert(height > 0); - - CGSize size = {}; - size.width = width; - size.height = height; - - mLayer = (__bridge CAMetalLayer *)(SDL_Metal_GetLayer(m_view)); - [mLayer setDevice:mMtlDevice]; - [mLayer setPixelFormat:MTLPixelFormatBGRA8Unorm]; - [mLayer setDrawableSize:size]; - - constexpr uint32_t kFramebufferOnlyTextureUsages = WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_Present; - bool hasOnlyFramebufferUsages = (usage & (~kFramebufferOnlyTextureUsages)) == 0u; - if (hasOnlyFramebufferUsages) { - [mLayer setFramebufferOnly:YES]; - } - - return DAWN_SWAP_CHAIN_NO_ERROR; - } - - DawnSwapChainError GetNextTexture(DawnSwapChainNextTexture *nextTexture) { - mCurrentDrawable = [mLayer nextDrawable]; - mCurrentTexture = mCurrentDrawable.texture; - nextTexture->texture.ptr = (__bridge void *)(mCurrentTexture); - return DAWN_SWAP_CHAIN_NO_ERROR; - } - - DawnSwapChainError Present() { - id commandBuffer = [mCommandQueue commandBuffer]; - [commandBuffer presentDrawable:mCurrentDrawable]; - [commandBuffer commit]; - return DAWN_SWAP_CHAIN_NO_ERROR; - } - -private: - SDL_MetalView m_view = nil; - id mMtlDevice = nil; - id mCommandQueue = nil; - - CAMetalLayer *mLayer = nullptr; - id mCurrentDrawable = nil; - id mCurrentTexture = nil; -}; - -class MetalBinding : public BackendBinding { -public: - MetalBinding(SDL_Window *window, WGPUDevice device) : BackendBinding(window, device) {} - - uint64_t GetSwapChainImplementation() override { - if (m_swapChainImpl.userData == nullptr) { - m_swapChainImpl = CreateSwapChainImplementation(new SwapChainImplMTL(m_window)); - } - return reinterpret_cast(&m_swapChainImpl); - } - - WGPUTextureFormat GetPreferredSwapChainTextureFormat() override { return WGPUTextureFormat_BGRA8Unorm; } - -private: - DawnSwapChainImplementation m_swapChainImpl{}; -}; - -BackendBinding *CreateMetalBinding(SDL_Window *window, WGPUDevice device) { return new MetalBinding(window, device); } +std::unique_ptr SetupWindowAndGetSurfaceDescriptorCocoa(SDL_Window* window) { + SDL_MetalView view = SDL_Metal_CreateView(window); + std::unique_ptr desc = + std::make_unique(); + desc->layer = SDL_Metal_GetLayer(view); + return std::move(desc); +} } // namespace aurora::webgpu::utils diff --git a/lib/gfx/common.cpp b/lib/gfx/common.cpp index f1701d2..e885957 100644 --- a/lib/gfx/common.cpp +++ b/lib/gfx/common.cpp @@ -342,6 +342,77 @@ static void pipeline_worker() { } } +// Load serialized pipeline cache +void load_pipeline_cache() { + ByteBuffer pipelineCache; + u32 pipelineCacheCount = 0; + + { + std::string path = std::string{g_config.configPath} + "/pipeline_cache.bin"; + std::ifstream file(path, std::ios::in | std::ios::binary | std::ios::ate); + if (file) { + const auto size = file.tellg(); + file.seekg(0, std::ios::beg); + constexpr size_t headerSize = sizeof(pipelineCacheCount); + if (size != -1 && size > headerSize) { + pipelineCache.append_zeroes(size_t(size) - headerSize); + file.read(reinterpret_cast(&pipelineCacheCount), headerSize); + file.read(reinterpret_cast(pipelineCache.data()), size_t(size) - headerSize); + } + } + } + + if (pipelineCacheCount > 0) { + size_t offset = 0; + while (offset < pipelineCache.size()) { + ShaderType type = *reinterpret_cast(pipelineCache.data() + offset); + offset += sizeof(ShaderType); + u32 size = *reinterpret_cast(pipelineCache.data() + offset); + offset += sizeof(u32); + switch (type) { + case ShaderType::Stream: { + if (size != sizeof(stream::PipelineConfig)) { + break; + } + const auto config = *reinterpret_cast(pipelineCache.data() + offset); + if (config.version != gx::GXPipelineConfigVersion) { + break; + } + find_pipeline( + type, config, [=]() { return stream::create_pipeline(g_state.stream, config); }, true); + } break; + case ShaderType::Model: { + if (size != sizeof(model::PipelineConfig)) { + break; + } + const auto config = *reinterpret_cast(pipelineCache.data() + offset); + if (config.version != gx::GXPipelineConfigVersion) { + break; + } + find_pipeline( + type, config, [=]() { return model::create_pipeline(g_state.model, config); }, true); + } break; + default: + Log.report(LOG_WARNING, FMT_STRING("Unknown pipeline type {}"), static_cast(type)); + break; + } + offset += size; + } + } +} + +// Write serialized pipelines to file +void save_pipeline_cache() { + const auto path = std::string{g_config.configPath} + "pipeline_cache.bin"; + std::ofstream file(path, std::ios::out | std::ios::trunc | std::ios::binary); + if (file) { + file.write(reinterpret_cast(&g_serializedPipelineCount), sizeof(g_serializedPipelineCount)); + file.write(reinterpret_cast(g_serializedPipelines.data()), g_serializedPipelines.size()); + } + g_serializedPipelines.clear(); + g_serializedPipelineCount = 0; +} + void initialize() { // No async pipelines for OpenGL (ES) if (webgpu::g_backendType == wgpu::BackendType::OpenGL || webgpu::g_backendType == wgpu::BackendType::OpenGLES || @@ -385,58 +456,7 @@ void initialize() { g_state.stream = stream::construct_state(); g_state.model = model::construct_state(); - { - // Load serialized pipeline cache - std::string path = std::string{g_config.configPath} + "/pipeline_cache.bin"; - std::ifstream file(path, std::ios::in | std::ios::binary | std::ios::ate); - if (file) { - const auto size = file.tellg(); - file.seekg(0, std::ios::beg); - constexpr size_t headerSize = sizeof(g_serializedPipelineCount); - if (size != -1 && size > headerSize) { - g_serializedPipelines.append_zeroes(size_t(size) - headerSize); - file.read(reinterpret_cast(&g_serializedPipelineCount), headerSize); - file.read(reinterpret_cast(g_serializedPipelines.data()), size_t(size) - headerSize); - } - } - } - if (g_serializedPipelineCount > 0) { - size_t offset = 0; - while (offset < g_serializedPipelines.size()) { - ShaderType type = *reinterpret_cast(g_serializedPipelines.data() + offset); - offset += sizeof(ShaderType); - u32 size = *reinterpret_cast(g_serializedPipelines.data() + offset); - offset += sizeof(u32); - switch (type) { - case ShaderType::Stream: { - if (size != sizeof(stream::PipelineConfig)) { - break; - } - const auto config = *reinterpret_cast(g_serializedPipelines.data() + offset); - if (config.version != gx::GXPipelineConfigVersion) { - break; - } - find_pipeline( - type, config, [=]() { return stream::create_pipeline(g_state.stream, config); }, false); - } break; - case ShaderType::Model: { - if (size != sizeof(model::PipelineConfig)) { - break; - } - const auto config = *reinterpret_cast(g_serializedPipelines.data() + offset); - if (config.version != gx::GXPipelineConfigVersion) { - break; - } - find_pipeline( - type, config, [=]() { return model::create_pipeline(g_state.model, config); }, false); - } break; - default: - Log.report(LOG_WARNING, FMT_STRING("Unknown pipeline type {}"), static_cast(type)); - break; - } - offset += size; - } - } + load_pipeline_cache(); } void shutdown() { @@ -446,17 +466,7 @@ void shutdown() { g_pipelineThread.join(); } - { - // Write serialized pipelines to file - const auto path = std::string{g_config.configPath} + "pipeline_cache.bin"; - std::ofstream file(path, std::ios::out | std::ios::trunc | std::ios::binary); - if (file) { - file.write(reinterpret_cast(&g_serializedPipelineCount), sizeof(g_serializedPipelineCount)); - file.write(reinterpret_cast(g_serializedPipelines.data()), g_serializedPipelines.size()); - } - g_serializedPipelines.clear(); - g_serializedPipelineCount = 0; - } + save_pipeline_cache(); gx::shutdown(); diff --git a/lib/gfx/common.hpp b/lib/gfx/common.hpp index 2b15620..6121bbd 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, - Model, + Stream = 'STRM', + Model = 'CMDL', }; void initialize(); diff --git a/lib/gfx/gx.cpp b/lib/gfx/gx.cpp index b6dc5d2..4b686a2 100644 --- a/lib/gfx/gx.cpp +++ b/lib/gfx/gx.cpp @@ -688,21 +688,21 @@ static wgpu::AddressMode wgpu_address_mode(GXTexWrapMode mode) { return wgpu::AddressMode::MirrorRepeat; } } -static std::pair wgpu_filter_mode(GXTexFilter filter) { +static std::pair wgpu_filter_mode(GXTexFilter filter) { switch (filter) { DEFAULT_FATAL("invalid filter mode {}", static_cast(filter)); case GX_NEAR: - return {wgpu::FilterMode::Nearest, wgpu::FilterMode::Linear}; + return {wgpu::FilterMode::Nearest, wgpu::MipmapFilterMode::Linear}; case GX_LINEAR: - return {wgpu::FilterMode::Linear, wgpu::FilterMode::Linear}; + return {wgpu::FilterMode::Linear, wgpu::MipmapFilterMode::Linear}; case GX_NEAR_MIP_NEAR: - return {wgpu::FilterMode::Nearest, wgpu::FilterMode::Nearest}; + return {wgpu::FilterMode::Nearest, wgpu::MipmapFilterMode::Nearest}; case GX_LIN_MIP_NEAR: - return {wgpu::FilterMode::Linear, wgpu::FilterMode::Nearest}; + return {wgpu::FilterMode::Linear, wgpu::MipmapFilterMode::Nearest}; case GX_NEAR_MIP_LIN: - return {wgpu::FilterMode::Nearest, wgpu::FilterMode::Linear}; + return {wgpu::FilterMode::Nearest, wgpu::MipmapFilterMode::Linear}; case GX_LIN_MIP_LIN: - return {wgpu::FilterMode::Linear, wgpu::FilterMode::Linear}; + return {wgpu::FilterMode::Linear, wgpu::MipmapFilterMode::Linear}; } } static u16 wgpu_aniso(GXAnisotropy aniso) { @@ -725,7 +725,7 @@ wgpu::SamplerDescriptor TextureBind::get_descriptor() const noexcept { .addressModeW = wgpu::AddressMode::Repeat, .magFilter = wgpu::FilterMode::Nearest, .minFilter = wgpu::FilterMode::Nearest, - .mipmapFilter = wgpu::FilterMode::Nearest, + .mipmapFilter = wgpu::MipmapFilterMode::Nearest, .lodMinClamp = 0.f, .lodMaxClamp = 1000.f, .maxAnisotropy = 1, diff --git a/lib/imgui.cpp b/lib/imgui.cpp index 4820ce8..71cc680 100644 --- a/lib/imgui.cpp +++ b/lib/imgui.cpp @@ -78,6 +78,7 @@ void process_event(const SDL_Event& event) noexcept { void new_frame(const AuroraWindowSize& size) noexcept { if (g_useSdlRenderer) { ImGui_ImplSDLRenderer_NewFrame(); + g_scale = size.scale; } else { if (g_scale != size.scale) { if (g_scale > 0.f) { diff --git a/lib/imgui_impl_wgpu.cpp b/lib/imgui_impl_wgpu.cpp index 119d6b4..573c0f3 100644 --- a/lib/imgui_impl_wgpu.cpp +++ b/lib/imgui_impl_wgpu.cpp @@ -438,7 +438,7 @@ static void ImGui_ImplWGPU_CreateFontsTexture() WGPUSamplerDescriptor sampler_desc = {}; sampler_desc.minFilter = WGPUFilterMode_Linear; sampler_desc.magFilter = WGPUFilterMode_Linear; - sampler_desc.mipmapFilter = WGPUFilterMode_Linear; + sampler_desc.mipmapFilter = WGPUMipmapFilterMode_Linear; sampler_desc.addressModeU = WGPUAddressMode_Repeat; sampler_desc.addressModeV = WGPUAddressMode_Repeat; sampler_desc.addressModeW = WGPUAddressMode_Repeat; diff --git a/lib/webgpu/gpu.cpp b/lib/webgpu/gpu.cpp index de526a1..d6e1b06 100644 --- a/lib/webgpu/gpu.cpp +++ b/lib/webgpu/gpu.cpp @@ -35,11 +35,10 @@ wgpu::BindGroup g_CopyBindGroup; #ifdef WEBGPU_DAWN static std::unique_ptr g_dawnInstance; static dawn::native::Adapter g_adapter; -static std::unique_ptr g_backendBinding; #else -wgpu::Instance g_instance; static wgpu::Adapter g_adapter; #endif +wgpu::Instance g_instance; static wgpu::Surface g_surface; static wgpu::AdapterProperties g_adapterProperties; @@ -81,7 +80,7 @@ TextureWithSampler create_render_texture(bool multisampled) { .addressModeW = wgpu::AddressMode::ClampToEdge, .magFilter = wgpu::FilterMode::Linear, .minFilter = wgpu::FilterMode::Linear, - .mipmapFilter = wgpu::FilterMode::Linear, + .mipmapFilter = wgpu::MipmapFilterMode::Linear, .lodMinClamp = 0.f, .lodMaxClamp = 1000.f, .maxAnisotropy = 1, @@ -130,7 +129,7 @@ static TextureWithSampler create_depth_texture() { .addressModeW = wgpu::AddressMode::ClampToEdge, .magFilter = wgpu::FilterMode::Linear, .minFilter = wgpu::FilterMode::Linear, - .mipmapFilter = wgpu::FilterMode::Linear, + .mipmapFilter = wgpu::MipmapFilterMode::Linear, .lodMinClamp = 0.f, .lodMaxClamp = 1000.f, .maxAnisotropy = 1, @@ -344,7 +343,7 @@ bool initialize(AuroraBackend auroraBackend) { g_instance = {}; // TODO use wgpuCreateInstance when supported } #endif - wgpu::BackendType backend = to_wgpu_backend(auroraBackend); + const wgpu::BackendType backend = to_wgpu_backend(auroraBackend); #ifdef EMSCRIPTEN if (backend != wgpu::BackendType::WebGPU) { Log.report(LOG_WARNING, FMT_STRING("Backend type {} unsupported"), magic_enum::enum_name(backend)); @@ -388,6 +387,12 @@ bool initialize(AuroraBackend auroraBackend) { } g_adapter = *adapterIt; } + + const auto chainedDescriptor = utils::SetupWindowAndGetSurfaceDescriptor(window); + wgpu::SurfaceDescriptor surfaceDescriptor; + surfaceDescriptor.nextInChain = chainedDescriptor.get(); + g_surface = g_instance.CreateSurface(&surfaceDescriptor); + ASSERT(g_surface, "Failed to initialize surface"); #else const WGPUSurfaceDescriptorFromCanvasHTMLSelector canvasDescriptor{ .chain = {.sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector}, @@ -476,9 +481,9 @@ bool initialize(AuroraBackend auroraBackend) { "disable_symbol_renaming", /* clang-format on */ }; - wgpu::DawnTogglesDeviceDescriptor togglesDescriptor{}; - togglesDescriptor.forceEnabledTogglesCount = enableToggles.size(); - togglesDescriptor.forceEnabledToggles = enableToggles.data(); + wgpu::DawnTogglesDescriptor togglesDescriptor{}; + togglesDescriptor.enabledTogglesCount = enableToggles.size(); + togglesDescriptor.enabledToggles = enableToggles.data(); #endif const wgpu::DeviceDescriptor deviceDescriptor{ #ifdef WEBGPU_DAWN @@ -508,12 +513,7 @@ bool initialize(AuroraBackend auroraBackend) { g_queue = g_device.GetQueue(); #if WEBGPU_DAWN - g_backendBinding = - std::unique_ptr(utils::CreateBinding(g_backendType, window, g_device.Get())); - if (!g_backendBinding) { - return false; - } - auto swapChainFormat = static_cast(g_backendBinding->GetPreferredSwapChainTextureFormat()); + auto swapChainFormat = wgpu::TextureFormat::BGRA8UnormSrgb; // TODO #else auto swapChainFormat = g_surface.GetPreferredFormat(g_adapter); #endif @@ -532,9 +532,6 @@ bool initialize(AuroraBackend auroraBackend) { .width = size.fb_width, .height = size.fb_height, .presentMode = wgpu::PresentMode::Fifo, -#ifdef WEBGPU_DAWN - .implementation = g_backendBinding->GetSwapChainImplementation(), -#endif }, .depthFormat = wgpu::TextureFormat::Depth32Float, .msaaSamples = g_config.msaa, @@ -556,11 +553,10 @@ void shutdown() { wgpuQueueRelease(g_queue.Release()); wgpuDeviceDestroy(g_device.Release()); g_adapter = {}; + g_surface = {}; #ifdef WEBGPU_DAWN - g_backendBinding.reset(); g_dawnInstance.reset(); #else - g_surface = {}; g_instance = {}; #endif } @@ -572,15 +568,7 @@ void resize_swapchain(uint32_t width, uint32_t height, bool force) { } g_graphicsConfig.swapChainDescriptor.width = width; g_graphicsConfig.swapChainDescriptor.height = height; -#ifdef WEBGPU_DAWN - if (!g_swapChain) { - g_swapChain = g_device.CreateSwapChain(g_surface, &g_graphicsConfig.swapChainDescriptor); - } - g_swapChain.Configure(g_graphicsConfig.swapChainDescriptor.format, g_graphicsConfig.swapChainDescriptor.usage, width, - height); -#else g_swapChain = g_device.CreateSwapChain(g_surface, &g_graphicsConfig.swapChainDescriptor); -#endif g_frameBuffer = create_render_texture(true); g_frameBufferResolved = create_render_texture(false); g_depthBuffer = create_depth_texture();