mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-08 13:14:56 +00:00
Simplify BackendBinding following adapters.
It doesn't need to care about device creation anymore, except for the GLFW window hints and creating a GL context to discover the adapter. Also remove the non-adapter GetPCIInfo. BUG=dawn:29 Change-Id: I9bc8232536a55d2f973463ae0f2e0548dfc35456 Reviewed-on: https://dawn-review.googlesource.com/c/4381 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
5987c4e839
commit
bb5696bcd3
@@ -27,6 +27,7 @@
|
||||
#include <dawn_wire/WireServer.h>
|
||||
#include "GLFW/glfw3.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
@@ -59,6 +60,7 @@ enum class CmdBufType {
|
||||
#endif
|
||||
|
||||
static CmdBufType cmdBufType = CmdBufType::Terrible;
|
||||
static std::unique_ptr<dawn_native::Instance> instance;
|
||||
static utils::BackendBinding* binding = nullptr;
|
||||
|
||||
static GLFWwindow* window = nullptr;
|
||||
@@ -69,29 +71,45 @@ static utils::TerribleCommandBuffer* c2sBuf = nullptr;
|
||||
static utils::TerribleCommandBuffer* s2cBuf = nullptr;
|
||||
|
||||
dawn::Device CreateCppDawnDevice() {
|
||||
binding = utils::CreateBinding(backendType);
|
||||
if (binding == nullptr) {
|
||||
return dawn::Device();
|
||||
}
|
||||
|
||||
glfwSetErrorCallback(PrintGLFWError);
|
||||
if (!glfwInit()) {
|
||||
return dawn::Device();
|
||||
}
|
||||
|
||||
binding->SetupGLFWWindowHints();
|
||||
// Create the test window and discover adapters using it (esp. for OpenGL)
|
||||
utils::SetupGLFWWindowHintsForBackend(backendType);
|
||||
window = glfwCreateWindow(640, 480, "Dawn window", nullptr, nullptr);
|
||||
if (!window) {
|
||||
return dawn::Device();
|
||||
}
|
||||
|
||||
binding->SetWindow(window);
|
||||
instance = std::make_unique<dawn_native::Instance>();
|
||||
utils::DiscoverAdapter(instance.get(), window, backendType);
|
||||
|
||||
dawnDevice backendDevice = binding->CreateDevice();
|
||||
// Get an adapter for the backend to use, and create the device.
|
||||
dawn_native::Adapter backendAdapter;
|
||||
{
|
||||
std::vector<dawn_native::Adapter> adapters = instance->GetAdapters();
|
||||
auto adapterIt = std::find_if(adapters.begin(), adapters.end(),
|
||||
[](const dawn_native::Adapter adapter) -> bool {
|
||||
return adapter.GetBackendType() == backendType;
|
||||
});
|
||||
ASSERT(adapterIt != adapters.end());
|
||||
backendAdapter = *adapterIt;
|
||||
}
|
||||
|
||||
dawnDevice backendDevice = backendAdapter.CreateDevice();
|
||||
dawnProcTable backendProcs = dawn_native::GetProcs();
|
||||
|
||||
binding = utils::CreateBinding(backendType, window, backendDevice);
|
||||
if (binding == nullptr) {
|
||||
return dawn::Device();
|
||||
}
|
||||
|
||||
// Choose whether to use the backend procs and devices directly, or set up the wire.
|
||||
dawnDevice cDevice = nullptr;
|
||||
dawnProcTable procs;
|
||||
|
||||
switch (cmdBufType) {
|
||||
case CmdBufType::None:
|
||||
procs = backendProcs;
|
||||
|
||||
Reference in New Issue
Block a user