From 974802d17c42dad273b98a54009308a59b8dbeb0 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Wed, 5 Apr 2023 07:23:09 +0000 Subject: [PATCH] Remove BackendBinding and its implementations. These were helpers for implementation-based swapchains that are getting removed. Bug: dawn:269 Change-Id: I44b0f9a9d221b9370c3eb2625c68e540b6e2ef46 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/126420 Kokoro: Kokoro Commit-Queue: Corentin Wallez Reviewed-by: Loko Kung Reviewed-by: Austin Eng --- src/dawn/samples/BUILD.gn | 1 - src/dawn/samples/SampleUtils.cpp | 1 - src/dawn/samples/SampleUtils.h | 1 - src/dawn/utils/BUILD.gn | 55 ------------ src/dawn/utils/BackendBinding.cpp | 77 ----------------- src/dawn/utils/BackendBinding.h | 44 ---------- src/dawn/utils/CMakeLists.txt | 30 ------- src/dawn/utils/D3D12Binding.cpp | 53 ------------ src/dawn/utils/MetalBinding.mm | 133 ------------------------------ src/dawn/utils/NullBinding.cpp | 46 ----------- src/dawn/utils/OpenGLBinding.cpp | 55 ------------ src/dawn/utils/VulkanBinding.cpp | 56 ------------- 12 files changed, 552 deletions(-) delete mode 100644 src/dawn/utils/BackendBinding.cpp delete mode 100644 src/dawn/utils/BackendBinding.h delete mode 100644 src/dawn/utils/D3D12Binding.cpp delete mode 100644 src/dawn/utils/MetalBinding.mm delete mode 100644 src/dawn/utils/NullBinding.cpp delete mode 100644 src/dawn/utils/OpenGLBinding.cpp delete mode 100644 src/dawn/utils/VulkanBinding.cpp diff --git a/src/dawn/samples/BUILD.gn b/src/dawn/samples/BUILD.gn index f78498eae3..adc7fc508f 100644 --- a/src/dawn/samples/BUILD.gn +++ b/src/dawn/samples/BUILD.gn @@ -39,7 +39,6 @@ static_library("utils") { "${dawn_root}/src/dawn/glfw", "${dawn_root}/src/dawn/native", "${dawn_root}/src/dawn/utils", - "${dawn_root}/src/dawn/utils:bindings", "${dawn_root}/src/dawn/wire", ] public_configs = [ "${dawn_root}/src/dawn/common:internal_config" ] diff --git a/src/dawn/samples/SampleUtils.cpp b/src/dawn/samples/SampleUtils.cpp index cda7839bb7..d2a61d4ca8 100644 --- a/src/dawn/samples/SampleUtils.cpp +++ b/src/dawn/samples/SampleUtils.cpp @@ -27,7 +27,6 @@ #include "dawn/common/Platform.h" #include "dawn/common/SystemUtils.h" #include "dawn/dawn_proc.h" -#include "dawn/dawn_wsi.h" #include "dawn/native/DawnNative.h" #include "dawn/utils/TerribleCommandBuffer.h" #include "dawn/wire/WireClient.h" diff --git a/src/dawn/samples/SampleUtils.h b/src/dawn/samples/SampleUtils.h index 59528bd093..2ff351c927 100644 --- a/src/dawn/samples/SampleUtils.h +++ b/src/dawn/samples/SampleUtils.h @@ -15,7 +15,6 @@ #ifndef SRC_DAWN_SAMPLES_SAMPLEUTILS_H_ #define SRC_DAWN_SAMPLES_SAMPLEUTILS_H_ -#include "dawn/dawn_wsi.h" #include "dawn/webgpu_cpp.h" bool InitSample(int argc, const char** argv); diff --git a/src/dawn/utils/BUILD.gn b/src/dawn/utils/BUILD.gn index 02820bbde6..3467ae6e1e 100644 --- a/src/dawn/utils/BUILD.gn +++ b/src/dawn/utils/BUILD.gn @@ -85,58 +85,3 @@ static_library("utils") { public_deps = [ "${dawn_root}/include/dawn:cpp_headers" ] } - -############################################################################### -# Dawn samples, only in standalone builds -############################################################################### - -if (dawn_standalone) { - # Library to handle the interaction of Dawn with GLFW windows in samples - static_library("bindings") { - configs += [ "${dawn_root}/src/dawn/common:internal_config" ] - - sources = [ - "BackendBinding.cpp", - "BackendBinding.h", - ] - - public_deps = [ "${dawn_root}/include/dawn:headers" ] - - deps = [ - "${dawn_root}/src/dawn/common", - "${dawn_root}/src/dawn/glfw", - "${dawn_root}/src/dawn/native", - ] - libs = [] - frameworks = [] - - if (dawn_enable_d3d12) { - sources += [ "D3D12Binding.cpp" ] - } - - if (dawn_enable_metal) { - sources += [ "MetalBinding.mm" ] - frameworks += [ - "Metal.framework", - "QuartzCore.framework", - ] - - # Suppress warnings that Metal isn't in the deployment target of Chrome - if (is_mac) { - cflags_objcc = [ "-Wno-unguarded-availability" ] - } - } - - if (dawn_enable_null) { - sources += [ "NullBinding.cpp" ] - } - - if (dawn_enable_opengl) { - sources += [ "OpenGLBinding.cpp" ] - } - - if (dawn_enable_vulkan) { - sources += [ "VulkanBinding.cpp" ] - } - } -} diff --git a/src/dawn/utils/BackendBinding.cpp b/src/dawn/utils/BackendBinding.cpp deleted file mode 100644 index 2aaa04798d..0000000000 --- a/src/dawn/utils/BackendBinding.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// 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. - -#include "dawn/utils/BackendBinding.h" - -#include "dawn/common/Compiler.h" - -namespace utils { - -#if defined(DAWN_ENABLE_BACKEND_D3D12) -BackendBinding* CreateD3D12Binding(GLFWwindow* window, WGPUDevice device); -#endif -#if defined(DAWN_ENABLE_BACKEND_METAL) -BackendBinding* CreateMetalBinding(GLFWwindow* window, WGPUDevice device); -#endif -#if defined(DAWN_ENABLE_BACKEND_NULL) -BackendBinding* CreateNullBinding(GLFWwindow* window, WGPUDevice device); -#endif -#if defined(DAWN_ENABLE_BACKEND_OPENGL) -BackendBinding* CreateOpenGLBinding(GLFWwindow* window, WGPUDevice device); -#endif -#if defined(DAWN_ENABLE_BACKEND_VULKAN) -BackendBinding* CreateVulkanBinding(GLFWwindow* window, WGPUDevice device); -#endif - -BackendBinding::BackendBinding(GLFWwindow* window, WGPUDevice device) - : mWindow(window), mDevice(device) {} - -BackendBinding* CreateBinding(wgpu::BackendType type, GLFWwindow* window, WGPUDevice device) { - switch (type) { -#if defined(DAWN_ENABLE_BACKEND_D3D12) - case wgpu::BackendType::D3D12: - return CreateD3D12Binding(window, device); -#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: - return nullptr; - } -} - -} // namespace utils diff --git a/src/dawn/utils/BackendBinding.h b/src/dawn/utils/BackendBinding.h deleted file mode 100644 index 7871934ab0..0000000000 --- a/src/dawn/utils/BackendBinding.h +++ /dev/null @@ -1,44 +0,0 @@ -// 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. - -#ifndef SRC_DAWN_UTILS_BACKENDBINDING_H_ -#define SRC_DAWN_UTILS_BACKENDBINDING_H_ - -#include "dawn/native/DawnNative.h" -#include "dawn/webgpu_cpp.h" - -struct GLFWwindow; - -namespace utils { - -class BackendBinding { - public: - virtual ~BackendBinding() = default; - - virtual uint64_t GetSwapChainImplementation() = 0; - virtual WGPUTextureFormat GetPreferredSwapChainTextureFormat() = 0; - - protected: - BackendBinding(GLFWwindow* window, WGPUDevice device); - - GLFWwindow* mWindow = nullptr; - WGPUDevice mDevice = nullptr; -}; - -void DiscoverAdapter(dawn::native::Instance* instance, GLFWwindow* window, wgpu::BackendType type); -BackendBinding* CreateBinding(wgpu::BackendType type, GLFWwindow* window, WGPUDevice device); - -} // namespace utils - -#endif // SRC_DAWN_UTILS_BACKENDBINDING_H_ diff --git a/src/dawn/utils/CMakeLists.txt b/src/dawn/utils/CMakeLists.txt index eddbbbec94..a4e8eedd0f 100644 --- a/src/dawn/utils/CMakeLists.txt +++ b/src/dawn/utils/CMakeLists.txt @@ -68,33 +68,3 @@ endif() if (DAWN_ENABLE_METAL) target_link_libraries(dawn_utils PRIVATE "-framework Metal") endif() - -if(DAWN_SUPPORTS_GLFW_FOR_WINDOWING) - target_sources(dawn_utils PRIVATE - "BackendBinding.cpp" - "BackendBinding.h" - ) - target_link_libraries(dawn_utils PRIVATE glfw) - - if (DAWN_ENABLE_D3D12) - target_sources(dawn_utils PRIVATE "D3D12Binding.cpp") - endif() - - if (DAWN_ENABLE_METAL) - target_sources(dawn_utils PRIVATE - "MetalBinding.mm" - ) - endif() - - if (DAWN_ENABLE_NULL) - target_sources(dawn_utils PRIVATE "NullBinding.cpp") - endif() - - if (DAWN_ENABLE_OPENGL) - target_sources(dawn_utils PRIVATE "OpenGLBinding.cpp") - endif() - - if (DAWN_ENABLE_VULKAN) - target_sources(dawn_utils PRIVATE "VulkanBinding.cpp") - endif() -endif() diff --git a/src/dawn/utils/D3D12Binding.cpp b/src/dawn/utils/D3D12Binding.cpp deleted file mode 100644 index bdf44fec7d..0000000000 --- a/src/dawn/utils/D3D12Binding.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// 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. - -#include - -#include "dawn/utils/BackendBinding.h" - -#include "dawn/common/Assert.h" -#include "dawn/native/D3D12Backend.h" - -#include "GLFW/glfw3.h" -#define GLFW_EXPOSE_NATIVE_WIN32 -#include "GLFW/glfw3native.h" - -namespace utils { - -class D3D12Binding : public BackendBinding { - public: - D3D12Binding(GLFWwindow* window, WGPUDevice device) : BackendBinding(window, device) {} - - uint64_t GetSwapChainImplementation() override { - if (mSwapchainImpl.userData == nullptr) { - HWND win32Window = glfwGetWin32Window(mWindow); - mSwapchainImpl = dawn::native::d3d12::CreateNativeSwapChainImpl(mDevice, win32Window); - } - return reinterpret_cast(&mSwapchainImpl); - } - - WGPUTextureFormat GetPreferredSwapChainTextureFormat() override { - ASSERT(mSwapchainImpl.userData != nullptr); - return dawn::native::d3d12::GetNativeSwapChainPreferredFormat(&mSwapchainImpl); - } - - private: - DawnSwapChainImplementation mSwapchainImpl = {}; -}; - -BackendBinding* CreateD3D12Binding(GLFWwindow* window, WGPUDevice device) { - return new D3D12Binding(window, device); -} - -} // namespace utils diff --git a/src/dawn/utils/MetalBinding.mm b/src/dawn/utils/MetalBinding.mm deleted file mode 100644 index ef34361768..0000000000 --- a/src/dawn/utils/MetalBinding.mm +++ /dev/null @@ -1,133 +0,0 @@ -// 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. - -#include "dawn/utils/BackendBinding.h" - -#include "dawn/common/Assert.h" -#include "dawn/common/SwapChainUtils.h" -#include "dawn/native/MetalBackend.h" - -#define GLFW_EXPOSE_NATIVE_COCOA -#include "GLFW/glfw3.h" -#include "GLFW/glfw3native.h" - -#import - -namespace utils { -class SwapChainImplMTL { - public: - using WSIContext = DawnWSIContextMetal; - - SwapChainImplMTL(id nsWindow) : mNsWindow(nsWindow) {} - - ~SwapChainImplMTL() { - [mCurrentTexture release]; - [mCurrentDrawable release]; - } - - 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); - - NSView* contentView = [mNsWindow contentView]; - [contentView setWantsLayer:YES]; - - CGSize size = {}; - size.width = width; - size.height = height; - - mLayer = [CAMetalLayer layer]; - [mLayer setDevice:mMtlDevice]; - [mLayer setPixelFormat:MTLPixelFormatBGRA8Unorm]; - [mLayer setDrawableSize:size]; - - constexpr uint32_t kFramebufferOnlyTextureUsages = - WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_Present; - bool hasOnlyFramebufferUsages = !(usage & (~kFramebufferOnlyTextureUsages)); - if (hasOnlyFramebufferUsages) { - [mLayer setFramebufferOnly:YES]; - } - - [contentView setLayer:mLayer]; - - return DAWN_SWAP_CHAIN_NO_ERROR; - } - - DawnSwapChainError GetNextTexture(DawnSwapChainNextTexture* nextTexture) { - [mCurrentDrawable release]; - mCurrentDrawable = [mLayer nextDrawable]; - [mCurrentDrawable retain]; - - [mCurrentTexture release]; - mCurrentTexture = mCurrentDrawable.texture; - [mCurrentTexture retain]; - - nextTexture->texture.ptr = reinterpret_cast(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: - id mNsWindow = nil; - id mMtlDevice = nil; - id mCommandQueue = nil; - - CAMetalLayer* mLayer = nullptr; - id mCurrentDrawable = nil; - id mCurrentTexture = nil; -}; - -class MetalBinding : public BackendBinding { - public: - MetalBinding(GLFWwindow* window, WGPUDevice device) : BackendBinding(window, device) {} - - uint64_t GetSwapChainImplementation() override { - if (mSwapchainImpl.userData == nullptr) { - mSwapchainImpl = - CreateSwapChainImplementation(new SwapChainImplMTL(glfwGetCocoaWindow(mWindow))); - } - return reinterpret_cast(&mSwapchainImpl); - } - - WGPUTextureFormat GetPreferredSwapChainTextureFormat() override { - return WGPUTextureFormat_BGRA8Unorm; - } - - private: - DawnSwapChainImplementation mSwapchainImpl = {}; -}; - -BackendBinding* CreateMetalBinding(GLFWwindow* window, WGPUDevice device) { - return new MetalBinding(window, device); -} -} // namespace utils diff --git a/src/dawn/utils/NullBinding.cpp b/src/dawn/utils/NullBinding.cpp deleted file mode 100644 index cddc0e66b3..0000000000 --- a/src/dawn/utils/NullBinding.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// 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. - -#include - -#include "dawn/utils/BackendBinding.h" - -#include "dawn/common/Assert.h" -#include "dawn/native/NullBackend.h" - -namespace utils { - -class NullBinding : public BackendBinding { - public: - NullBinding(GLFWwindow* window, WGPUDevice device) : BackendBinding(window, device) {} - - uint64_t GetSwapChainImplementation() override { - if (mSwapchainImpl.userData == nullptr) { - mSwapchainImpl = dawn::native::null::CreateNativeSwapChainImpl(); - } - return reinterpret_cast(&mSwapchainImpl); - } - WGPUTextureFormat GetPreferredSwapChainTextureFormat() override { - return WGPUTextureFormat_RGBA8Unorm; - } - - private: - DawnSwapChainImplementation mSwapchainImpl = {}; -}; - -BackendBinding* CreateNullBinding(GLFWwindow* window, WGPUDevice device) { - return new NullBinding(window, device); -} - -} // namespace utils diff --git a/src/dawn/utils/OpenGLBinding.cpp b/src/dawn/utils/OpenGLBinding.cpp deleted file mode 100644 index 9d752552c2..0000000000 --- a/src/dawn/utils/OpenGLBinding.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// 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. - -#include - -#include "dawn/utils/BackendBinding.h" - -#include "dawn/common/Assert.h" -#include "dawn/common/Platform.h" -#include "dawn/common/SwapChainUtils.h" -#include "dawn/dawn_wsi.h" -#include "dawn/native/OpenGLBackend.h" - -#include "GLFW/glfw3.h" - -namespace utils { - -class OpenGLBinding : public BackendBinding { - public: - OpenGLBinding(GLFWwindow* window, WGPUDevice device) : BackendBinding(window, device) {} - - uint64_t GetSwapChainImplementation() override { - if (mSwapchainImpl.userData == nullptr) { - mSwapchainImpl = dawn::native::opengl::CreateNativeSwapChainImpl( - mDevice, - [](void* userdata) { glfwSwapBuffers(static_cast(userdata)); }, - mWindow); - } - return reinterpret_cast(&mSwapchainImpl); - } - - WGPUTextureFormat GetPreferredSwapChainTextureFormat() override { - return dawn::native::opengl::GetNativeSwapChainPreferredFormat(&mSwapchainImpl); - } - - private: - DawnSwapChainImplementation mSwapchainImpl = {}; -}; - -BackendBinding* CreateOpenGLBinding(GLFWwindow* window, WGPUDevice device) { - return new OpenGLBinding(window, device); -} - -} // namespace utils diff --git a/src/dawn/utils/VulkanBinding.cpp b/src/dawn/utils/VulkanBinding.cpp deleted file mode 100644 index 1736de8232..0000000000 --- a/src/dawn/utils/VulkanBinding.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// 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. - -#include - -#include "dawn/utils/BackendBinding.h" - -#include "dawn/common/Assert.h" -#include "dawn/native/VulkanBackend.h" - -// Include GLFW after VulkanBackend so that it declares the Vulkan-specific functions -#include "GLFW/glfw3.h" - -namespace utils { - -class VulkanBinding : public BackendBinding { - public: - VulkanBinding(GLFWwindow* window, WGPUDevice device) : BackendBinding(window, device) {} - - uint64_t GetSwapChainImplementation() override { - if (mSwapchainImpl.userData == nullptr) { - VkSurfaceKHR surface = VK_NULL_HANDLE; - if (glfwCreateWindowSurface(dawn::native::vulkan::GetInstance(mDevice), mWindow, - nullptr, &surface) != VK_SUCCESS) { - ASSERT(false); - } - - mSwapchainImpl = dawn::native::vulkan::CreateNativeSwapChainImpl(mDevice, surface); - } - return reinterpret_cast(&mSwapchainImpl); - } - WGPUTextureFormat GetPreferredSwapChainTextureFormat() override { - ASSERT(mSwapchainImpl.userData != nullptr); - return dawn::native::vulkan::GetNativeSwapChainPreferredFormat(&mSwapchainImpl); - } - - private: - DawnSwapChainImplementation mSwapchainImpl = {}; -}; - -BackendBinding* CreateVulkanBinding(GLFWwindow* window, WGPUDevice device) { - return new VulkanBinding(window, device); -} - -} // namespace utils