dawn_native: Factor getting procs into a single function.
Now the backends only expose the creation of devices. Getting the procs is moved to DawnNative that will over time more backend-agnostic APIs.
This commit is contained in:
parent
f9f44ae289
commit
dcb71a131c
|
@ -22,6 +22,7 @@
|
|||
#include <dawn/dawn.h>
|
||||
#include <dawn/dawncpp.h>
|
||||
#include <dawn/dawn_wsi.h>
|
||||
#include <dawn_native/DawnNative.h>
|
||||
#include "GLFW/glfw3.h"
|
||||
|
||||
#include <cstring>
|
||||
|
@ -84,9 +85,8 @@ dawn::Device CreateCppDawnDevice() {
|
|||
|
||||
binding->SetWindow(window);
|
||||
|
||||
dawnDevice backendDevice;
|
||||
dawnProcTable backendProcs;
|
||||
binding->GetProcAndDevice(&backendProcs, &backendDevice);
|
||||
dawnDevice backendDevice = binding->CreateDevice();
|
||||
dawnProcTable backendProcs = dawn_native::GetProcs();
|
||||
|
||||
dawnDevice cDevice = nullptr;
|
||||
dawnProcTable procs;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "common/Assert.h"
|
||||
|
||||
#include "dawn_native/dawn_platform.h"
|
||||
#include "dawn_native/DawnNative.h"
|
||||
#include "dawn_native/ErrorData.h"
|
||||
#include "dawn_native/ValidationUtils_autogen.h"
|
||||
|
||||
|
@ -156,7 +157,7 @@ namespace dawn_native {
|
|||
{% endfor %}
|
||||
}
|
||||
|
||||
dawnProcTable GetProcs() {
|
||||
dawnProcTable GetProcsAutogen() {
|
||||
dawnProcTable table;
|
||||
{% for type in by_category["object"] %}
|
||||
{% for method in native_methods(type) %}
|
||||
|
|
|
@ -335,6 +335,7 @@ list(APPEND DAWN_NATIVE_SOURCES
|
|||
${DAWN_NATIVE_DIR}/ComputePipeline.h
|
||||
${DAWN_NATIVE_DIR}/CommandBufferStateTracker.cpp
|
||||
${DAWN_NATIVE_DIR}/CommandBufferStateTracker.h
|
||||
${DAWN_NATIVE_DIR}/DawnNative.cpp
|
||||
${DAWN_NATIVE_DIR}/DepthStencilState.cpp
|
||||
${DAWN_NATIVE_DIR}/DepthStencilState.h
|
||||
${DAWN_NATIVE_DIR}/Device.cpp
|
||||
|
@ -371,6 +372,7 @@ list(APPEND DAWN_NATIVE_SOURCES
|
|||
${DAWN_NATIVE_DIR}/Texture.h
|
||||
${DAWN_NATIVE_DIR}/ToBackend.h
|
||||
${DAWN_NATIVE_INCLUDE_DIR}/dawn_native_export.h
|
||||
${DAWN_NATIVE_INCLUDE_DIR}/DawnNative.h
|
||||
)
|
||||
|
||||
# We want to produce both a static and a shared libdawn_native library. The static one is for
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2018 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_native/DawnNative.h"
|
||||
|
||||
// Contains the entry-points into dawn_native
|
||||
|
||||
namespace dawn_native {
|
||||
|
||||
dawnProcTable GetProcsAutogen();
|
||||
|
||||
dawnProcTable GetProcs() {
|
||||
return GetProcsAutogen();
|
||||
}
|
||||
|
||||
} // namespace dawn_native
|
|
@ -39,16 +39,10 @@
|
|||
#include "dawn_native/d3d12/SwapChainD3D12.h"
|
||||
#include "dawn_native/d3d12/TextureD3D12.h"
|
||||
|
||||
namespace dawn_native {
|
||||
dawnProcTable GetProcs();
|
||||
} // namespace dawn_native
|
||||
|
||||
namespace dawn_native { namespace d3d12 {
|
||||
|
||||
void Init(dawnProcTable* procs, dawnDevice* device) {
|
||||
*device = nullptr;
|
||||
*procs = GetProcs();
|
||||
*device = reinterpret_cast<dawnDevice>(new Device());
|
||||
dawnDevice CreateDevice() {
|
||||
return reinterpret_cast<dawnDevice>(new Device());
|
||||
}
|
||||
|
||||
dawnSwapChainImplementation CreateNativeSwapChainImpl(dawnDevice device, HWND window) {
|
||||
|
|
|
@ -35,17 +35,10 @@
|
|||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace dawn_native {
|
||||
dawnProcTable GetProcs();
|
||||
} // namespace dawn_native
|
||||
|
||||
namespace dawn_native { namespace metal {
|
||||
|
||||
void Init(id<MTLDevice> metalDevice, dawnProcTable* procs, dawnDevice* device) {
|
||||
*device = nullptr;
|
||||
|
||||
*procs = GetProcs();
|
||||
*device = reinterpret_cast<dawnDevice>(new Device(metalDevice));
|
||||
dawnDevice CreateDevice(id<MTLDevice> metalDevice) {
|
||||
return reinterpret_cast<dawnDevice>(new Device(metalDevice));
|
||||
}
|
||||
|
||||
// Device
|
||||
|
|
|
@ -19,15 +19,10 @@
|
|||
|
||||
#include <spirv-cross/spirv_cross.hpp>
|
||||
|
||||
namespace dawn_native {
|
||||
dawnProcTable GetProcs();
|
||||
} // namespace dawn_native
|
||||
|
||||
namespace dawn_native { namespace null {
|
||||
|
||||
void Init(dawnProcTable* procs, dawnDevice* device) {
|
||||
*procs = GetProcs();
|
||||
*device = reinterpret_cast<dawnDevice>(new Device);
|
||||
dawnDevice CreateDevice() {
|
||||
return reinterpret_cast<dawnDevice>(new Device);
|
||||
}
|
||||
|
||||
// Device
|
||||
|
|
|
@ -32,23 +32,16 @@
|
|||
#include "dawn_native/opengl/SwapChainGL.h"
|
||||
#include "dawn_native/opengl/TextureGL.h"
|
||||
|
||||
namespace dawn_native {
|
||||
dawnProcTable GetProcs();
|
||||
} // namespace dawn_native
|
||||
|
||||
namespace dawn_native { namespace opengl {
|
||||
|
||||
void Init(void* (*getProc)(const char*), dawnProcTable* procs, dawnDevice* device) {
|
||||
*device = nullptr;
|
||||
|
||||
dawnDevice CreateDevice(void* (*getProc)(const char*)) {
|
||||
gladLoadGLLoader(reinterpret_cast<GLADloadproc>(getProc));
|
||||
|
||||
*procs = GetProcs();
|
||||
*device = reinterpret_cast<dawnDevice>(new Device);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
|
||||
|
||||
return reinterpret_cast<dawnDevice>(new Device);
|
||||
}
|
||||
|
||||
// Device
|
||||
|
|
|
@ -51,17 +51,10 @@ const char kVulkanLibName[] = "vulkan-1.dll";
|
|||
# error "Unimplemented Vulkan backend platform"
|
||||
#endif
|
||||
|
||||
namespace dawn_native {
|
||||
dawnProcTable GetProcs();
|
||||
} // namespace dawn_native
|
||||
|
||||
namespace dawn_native { namespace vulkan {
|
||||
|
||||
void Init(dawnProcTable* procs,
|
||||
dawnDevice* device,
|
||||
const std::vector<const char*>& requiredInstanceExtensions) {
|
||||
*procs = GetProcs();
|
||||
*device = reinterpret_cast<dawnDevice>(new Device(requiredInstanceExtensions));
|
||||
dawnDevice CreateDevice(const std::vector<const char*>& requiredInstanceExtensions) {
|
||||
return reinterpret_cast<dawnDevice>(new Device(requiredInstanceExtensions));
|
||||
}
|
||||
|
||||
VkInstance GetInstance(dawnDevice device) {
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include <windows.h>
|
||||
|
||||
namespace dawn_native { namespace d3d12 {
|
||||
DAWN_NATIVE_EXPORT void Init(dawnProcTable* procs, dawnDevice* device);
|
||||
DAWN_NATIVE_EXPORT dawnDevice CreateDevice();
|
||||
|
||||
DAWN_NATIVE_EXPORT dawnSwapChainImplementation CreateNativeSwapChainImpl(dawnDevice device,
|
||||
HWND window);
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright 2018 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 DAWNNATIVE_DAWNNATIVE_H_
|
||||
#define DAWNNATIVE_DAWNNATIVE_H_
|
||||
|
||||
#include <dawn/dawn.h>
|
||||
#include <dawn_native/dawn_native_export.h>
|
||||
|
||||
namespace dawn_native {
|
||||
|
||||
// Backend-agnostic API for dawn_native
|
||||
DAWN_NATIVE_EXPORT dawnProcTable GetProcs();
|
||||
|
||||
} // namespace dawn_native
|
||||
|
||||
#endif // DAWNNATIVE_DAWNNATIVE_H_
|
|
@ -23,9 +23,7 @@
|
|||
#import <QuartzCore/CAMetalLayer.h>
|
||||
|
||||
namespace dawn_native { namespace metal {
|
||||
DAWN_NATIVE_EXPORT void Init(id<MTLDevice> metalDevice,
|
||||
dawnProcTable* procs,
|
||||
dawnDevice* device);
|
||||
DAWN_NATIVE_EXPORT dawnDevice CreateDevice(id<MTLDevice> metalDevice);
|
||||
DAWN_NATIVE_EXPORT void SetNextDrawable(dawnDevice device, id<CAMetalDrawable> drawable);
|
||||
DAWN_NATIVE_EXPORT void Present(dawnDevice device);
|
||||
}} // namespace dawn_native::metal
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <dawn_native/dawn_native_export.h>
|
||||
|
||||
namespace dawn_native { namespace null {
|
||||
DAWN_NATIVE_EXPORT void Init(dawnProcTable* procs, dawnDevice* device);
|
||||
DAWN_NATIVE_EXPORT dawnDevice CreateDevice();
|
||||
}} // namespace dawn_native::null
|
||||
|
||||
#endif // DAWNNATIVE_NULLBACKEND_H_
|
||||
|
|
|
@ -19,9 +19,7 @@
|
|||
#include <dawn_native/dawn_native_export.h>
|
||||
|
||||
namespace dawn_native { namespace opengl {
|
||||
DAWN_NATIVE_EXPORT void Init(void* (*getProc)(const char*),
|
||||
dawnProcTable* procs,
|
||||
dawnDevice* device);
|
||||
DAWN_NATIVE_EXPORT dawnDevice CreateDevice(void* (*getProc)(const char*));
|
||||
}} // namespace dawn_native::opengl
|
||||
|
||||
#endif // DAWNNATIVE_OPENGLBACKEND_H_
|
||||
|
|
|
@ -24,9 +24,8 @@
|
|||
#include <vector>
|
||||
|
||||
namespace dawn_native { namespace vulkan {
|
||||
DAWN_NATIVE_EXPORT void Init(dawnProcTable* procs,
|
||||
dawnDevice* device,
|
||||
const std::vector<const char*>& requiredInstanceExtensions);
|
||||
DAWN_NATIVE_EXPORT dawnDevice
|
||||
CreateDevice(const std::vector<const char*>& requiredInstanceExtensions);
|
||||
|
||||
DAWN_NATIVE_EXPORT VkInstance GetInstance(dawnDevice device);
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "common/Assert.h"
|
||||
#include "common/Constants.h"
|
||||
#include "common/Math.h"
|
||||
#include "dawn_native/DawnNative.h"
|
||||
#include "dawn_wire/Wire.h"
|
||||
#include "utils/BackendBinding.h"
|
||||
#include "utils/DawnHelpers.h"
|
||||
|
@ -136,9 +137,8 @@ void DawnTest::SetUp() {
|
|||
|
||||
mBinding->SetWindow(testWindow);
|
||||
|
||||
dawnDevice backendDevice;
|
||||
dawnProcTable backendProcs;
|
||||
mBinding->GetProcAndDevice(&backendProcs, &backendDevice);
|
||||
dawnDevice backendDevice = mBinding->CreateDevice();
|
||||
dawnProcTable backendProcs = dawn_native::GetProcs();
|
||||
|
||||
// Choose whether to use the backend procs and devices directly, or set up the wire.
|
||||
dawnDevice cDevice = nullptr;
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include "tests/unittests/validation/ValidationTest.h"
|
||||
|
||||
#include "dawn/dawn.h"
|
||||
#include "dawn_native/DawnNative.h"
|
||||
#include "dawn_native/NullBackend.h"
|
||||
|
||||
namespace dawn_native {
|
||||
namespace null {
|
||||
|
@ -23,9 +25,8 @@ namespace dawn_native {
|
|||
}
|
||||
|
||||
ValidationTest::ValidationTest() {
|
||||
dawnProcTable procs;
|
||||
dawnDevice cDevice;
|
||||
dawn_native::null::Init(&procs, &cDevice);
|
||||
dawnProcTable procs = dawn_native::GetProcs();
|
||||
dawnDevice cDevice = dawn_native::null::CreateDevice();
|
||||
|
||||
dawnSetProcs(&procs);
|
||||
device = dawn::Device::Acquire(cDevice);
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace utils {
|
|||
virtual ~BackendBinding() = default;
|
||||
|
||||
virtual void SetupGLFWWindowHints() = 0;
|
||||
virtual void GetProcAndDevice(dawnProcTable* procs, dawnDevice* device) = 0;
|
||||
virtual dawnDevice CreateDevice() = 0;
|
||||
virtual uint64_t GetSwapChainImplementation() = 0;
|
||||
virtual dawnTextureFormat GetPreferredSwapChainTextureFormat() = 0;
|
||||
|
||||
|
|
|
@ -29,9 +29,8 @@ namespace utils {
|
|||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
}
|
||||
|
||||
void GetProcAndDevice(dawnProcTable* procs, dawnDevice* device) override {
|
||||
dawn_native::d3d12::Init(procs, device);
|
||||
mBackendDevice = *device;
|
||||
dawnDevice CreateDevice() override {
|
||||
return dawn_native::d3d12::CreateDevice();
|
||||
}
|
||||
|
||||
uint64_t GetSwapChainImplementation() override {
|
||||
|
|
|
@ -105,11 +105,9 @@ namespace utils {
|
|||
void SetupGLFWWindowHints() override {
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
}
|
||||
void GetProcAndDevice(dawnProcTable* procs, dawnDevice* device) override {
|
||||
dawnDevice CreateDevice() override {
|
||||
mMetalDevice = MTLCreateSystemDefaultDevice();
|
||||
|
||||
dawn_native::metal::Init(mMetalDevice, procs, device);
|
||||
mBackendDevice = *device;
|
||||
return dawn_native::metal::CreateDevice(mMetalDevice);
|
||||
}
|
||||
|
||||
uint64_t GetSwapChainImplementation() override {
|
||||
|
@ -126,7 +124,6 @@ namespace utils {
|
|||
|
||||
private:
|
||||
id<MTLDevice> mMetalDevice = nil;
|
||||
dawnDevice mBackendDevice = nullptr;
|
||||
dawnSwapChainImplementation mSwapchainImpl = {};
|
||||
};
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ namespace utils {
|
|||
public:
|
||||
void SetupGLFWWindowHints() override {
|
||||
}
|
||||
void GetProcAndDevice(dawnProcTable* procs, dawnDevice* device) override {
|
||||
dawn_native::null::Init(procs, device);
|
||||
dawnDevice CreateDevice() override {
|
||||
return dawn_native::null::CreateDevice();
|
||||
}
|
||||
uint64_t GetSwapChainImplementation() override {
|
||||
return 0;
|
||||
|
|
|
@ -108,15 +108,13 @@ namespace utils {
|
|||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
#endif
|
||||
}
|
||||
void GetProcAndDevice(dawnProcTable* procs, dawnDevice* device) override {
|
||||
dawnDevice CreateDevice() override {
|
||||
glfwMakeContextCurrent(mWindow);
|
||||
// Load the GL entry points in our copy of the glad static library
|
||||
gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress));
|
||||
|
||||
dawn_native::opengl::Init(reinterpret_cast<void* (*)(const char*)>(glfwGetProcAddress),
|
||||
procs, device);
|
||||
|
||||
mBackendDevice = *device;
|
||||
return dawn_native::opengl::CreateDevice(
|
||||
reinterpret_cast<void* (*)(const char*)>(glfwGetProcAddress));
|
||||
}
|
||||
|
||||
uint64_t GetSwapChainImplementation() override {
|
||||
|
@ -131,7 +129,6 @@ namespace utils {
|
|||
}
|
||||
|
||||
private:
|
||||
dawnDevice mBackendDevice = nullptr;
|
||||
dawnSwapChainImplementation mSwapchainImpl = {};
|
||||
};
|
||||
|
||||
|
|
|
@ -53,15 +53,14 @@ namespace utils {
|
|||
void SetupGLFWWindowHints() override {
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
}
|
||||
void GetProcAndDevice(dawnProcTable* procs, dawnDevice* device) override {
|
||||
dawnDevice CreateDevice() override {
|
||||
uint32_t extensionCount = 0;
|
||||
const char** glfwInstanceExtensions =
|
||||
glfwGetRequiredInstanceExtensions(&extensionCount);
|
||||
std::vector<const char*> requiredExtensions(glfwInstanceExtensions,
|
||||
glfwInstanceExtensions + extensionCount);
|
||||
|
||||
dawn_native::vulkan::Init(procs, device, requiredExtensions);
|
||||
mDevice = *device;
|
||||
return dawn_native::vulkan::CreateDevice(requiredExtensions);
|
||||
}
|
||||
uint64_t GetSwapChainImplementation() override {
|
||||
if (mSwapchainImpl.userData == nullptr) {
|
||||
|
|
Loading…
Reference in New Issue