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 <noreply+kokoro@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez 2023-04-05 07:23:09 +00:00 committed by Dawn LUCI CQ
parent dfa84d95c5
commit 974802d17c
12 changed files with 0 additions and 552 deletions

View File

@ -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" ]

View File

@ -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"

View File

@ -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);

View File

@ -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" ]
}
}
}

View File

@ -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

View File

@ -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_

View File

@ -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()

View File

@ -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 <memory>
#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<uint64_t>(&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

View File

@ -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 <QuartzCore/CAMetalLayer.h>
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<void*>(mCurrentTexture);
return DAWN_SWAP_CHAIN_NO_ERROR;
}
DawnSwapChainError Present() {
id<MTLCommandBuffer> commandBuffer = [mCommandQueue commandBuffer];
[commandBuffer presentDrawable:mCurrentDrawable];
[commandBuffer commit];
return DAWN_SWAP_CHAIN_NO_ERROR;
}
private:
id mNsWindow = nil;
id<MTLDevice> mMtlDevice = nil;
id<MTLCommandQueue> mCommandQueue = nil;
CAMetalLayer* mLayer = nullptr;
id<CAMetalDrawable> mCurrentDrawable = nil;
id<MTLTexture> 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<uint64_t>(&mSwapchainImpl);
}
WGPUTextureFormat GetPreferredSwapChainTextureFormat() override {
return WGPUTextureFormat_BGRA8Unorm;
}
private:
DawnSwapChainImplementation mSwapchainImpl = {};
};
BackendBinding* CreateMetalBinding(GLFWwindow* window, WGPUDevice device) {
return new MetalBinding(window, device);
}
} // namespace utils

View File

@ -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 <memory>
#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<uint64_t>(&mSwapchainImpl);
}
WGPUTextureFormat GetPreferredSwapChainTextureFormat() override {
return WGPUTextureFormat_RGBA8Unorm;
}
private:
DawnSwapChainImplementation mSwapchainImpl = {};
};
BackendBinding* CreateNullBinding(GLFWwindow* window, WGPUDevice device) {
return new NullBinding(window, device);
}
} // namespace utils

View File

@ -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 <cstdio>
#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<GLFWwindow*>(userdata)); },
mWindow);
}
return reinterpret_cast<uint64_t>(&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

View File

@ -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 <memory>
#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<uint64_t>(&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