OpenGL: Implement the backend connection and adapter.

The OpenGL backend can't gather discover default adapters because it
needs getProc to do anything so we add DiscoverAdapters method to
Instance that takes backend-specific options.

dawn_native::opengl::CreateDevice is removed in favor of the adapter
path so OpenGLBinding is modified to create an instance locally. This is
only temporary until all backends support adapters, at which point a lot
of *Binding code will be factored.

Also contains a small fix for Result<T, E> with movable types.

BUG=dawn:29

Change-Id: I4eb3d4a14a871af73e1872132aff72b45e5fe566
Reviewed-on: https://dawn-review.googlesource.com/c/3663
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Corentin Wallez
2019-01-07 09:48:03 +00:00
committed by Commit Bot service account
parent ab8eb2d6ed
commit 90e594ee8b
14 changed files with 221 additions and 27 deletions

View File

@@ -64,6 +64,15 @@ namespace dawn_native {
AdapterBase* mImpl = nullptr;
};
// Base class for options passed to Instance::DiscoverAdapters.
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptionsBase {
public:
const BackendType backendType;
protected:
AdapterDiscoveryOptionsBase(BackendType type);
};
// Represents a connection to dawn_native and is used for dependency injection, discovering
// system adapters and injecting custom adapters (like a Swiftshader Vulkan adapter).
//
@@ -81,6 +90,10 @@ namespace dawn_native {
// adapters will later be returned by GetAdapters.
void DiscoverDefaultAdapters();
// Adds adapters that can be discovered with the options provided (like a getProcAddress).
// The backend is chosen based on the type of the options used. Returns true on success.
bool DiscoverAdapters(const AdapterDiscoveryOptionsBase* options);
// Returns all the adapters that the instance knows about.
std::vector<Adapter> GetAdapters() const;

View File

@@ -15,11 +15,16 @@
#ifndef DAWNNATIVE_OPENGLBACKEND_H_
#define DAWNNATIVE_OPENGLBACKEND_H_
#include <dawn/dawn.h>
#include <dawn_native/dawn_native_export.h>
#include <dawn_native/DawnNative.h>
namespace dawn_native { namespace opengl {
DAWN_NATIVE_EXPORT dawnDevice CreateDevice(void* (*getProc)(const char*));
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
AdapterDiscoveryOptions();
void* (*getProc)(const char*);
};
}} // namespace dawn_native::opengl
#endif // DAWNNATIVE_OPENGLBACKEND_H_