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>
diff --git a/examples/SampleUtils.cpp b/examples/SampleUtils.cpp
index 7e1e731..87f4982 100644
--- a/examples/SampleUtils.cpp
+++ b/examples/SampleUtils.cpp
@@ -27,6 +27,7 @@
 #include <dawn_wire/WireServer.h>
 #include "GLFW/glfw3.h"
 
+#include <algorithm>
 #include <cstring>
 #include <iostream>
 
@@ -59,6 +60,7 @@
 #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* 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;