gpu: implement C wrapper for Dawn Instance.discoverAdapters
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
4ebb4571ac
commit
d9ec84b327
2 changed files with 48 additions and 5 deletions
|
|
@ -1,7 +1,9 @@
|
|||
#include <dawn_native/DawnNative.h>
|
||||
#include <dawn_native/wgpu_structs_autogen.h>
|
||||
#include "utils/BackendBinding.h"
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_OPENGL)
|
||||
#include <dawn_native/OpenGLBackend.h>
|
||||
#endif
|
||||
#include "dawn_native_mach.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
@ -133,10 +135,37 @@ MACH_EXPORT void machDawnNativeInstance_discoverDefaultAdapters(MachDawnNativeIn
|
|||
dawn_native::Instance* self = reinterpret_cast<dawn_native::Instance*>(instance);
|
||||
self->DiscoverDefaultAdapters();
|
||||
}
|
||||
// TODO(dawn-native-mach):
|
||||
// // 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);
|
||||
MACH_EXPORT bool machDawnNativeInstance_discoverAdapters(MachDawnNativeInstance instance, WGPUBackendType backendType, const void* options) {
|
||||
dawn_native::Instance* self = reinterpret_cast<dawn_native::Instance*>(instance);
|
||||
switch (backendType) {
|
||||
case WGPUBackendType_OpenGL:
|
||||
#if defined(DAWN_ENABLE_BACKEND_DESKTOP_GL)
|
||||
{
|
||||
auto opt = reinterpret_cast<const MachDawnNativeAdapterDiscoveryOptions_OpenGL*>(options);
|
||||
dawn_native::opengl::AdapterDiscoveryOptions adapterOptions = dawn_native::opengl::AdapterDiscoveryOptions();
|
||||
adapterOptions.getProc = opt->getProc;
|
||||
return self->DiscoverAdapters(&adapterOptions);
|
||||
}
|
||||
#endif
|
||||
case WGPUBackendType_OpenGLES:
|
||||
#if defined(DAWN_ENABLE_BACKEND_OPENGLES)
|
||||
{
|
||||
auto opt = reinterpret_cast<const MachDawnNativeAdapterDiscoveryOptions_OpenGLES*>(options);
|
||||
dawn_native::opengl::AdapterDiscoveryOptionsES adapterOptions;
|
||||
adapterOptions.getProc = opt->getProc;
|
||||
return self->DiscoverAdapters(&adapterOptions);
|
||||
}
|
||||
#endif
|
||||
case WGPUBackendType_WebGPU:
|
||||
case WGPUBackendType_D3D11:
|
||||
case WGPUBackendType_D3D12:
|
||||
case WGPUBackendType_Metal:
|
||||
case WGPUBackendType_Null:
|
||||
case WGPUBackendType_Vulkan:
|
||||
case WGPUBackendType_Force32:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MACH_EXPORT MachDawnNativeAdapters machDawnNativeInstance_getAdapters(MachDawnNativeInstance instance) {
|
||||
dawn_native::Instance* self = reinterpret_cast<dawn_native::Instance*>(instance);
|
||||
auto cppAdapters = self->GetAdapters();
|
||||
|
|
|
|||
|
|
@ -81,11 +81,25 @@ typedef struct MachDawnNativeInstanceImpl* MachDawnNativeInstance;
|
|||
MACH_EXPORT MachDawnNativeInstance machDawnNativeInstance_init(void);
|
||||
MACH_EXPORT void machDawnNativeInstance_deinit(MachDawnNativeInstance);
|
||||
MACH_EXPORT void machDawnNativeInstance_discoverDefaultAdapters(MachDawnNativeInstance);
|
||||
|
||||
// Adds adapters that can be discovered with the options provided (like a getProcAddress).
|
||||
// You must specify a valid backend type corresponding to the type of MachDawnNativeAdapterDiscoveryOptions_
|
||||
// struct pointer you pass as options.
|
||||
// Returns true on success.
|
||||
MACH_EXPORT bool machDawnNativeInstance_discoverAdapters(MachDawnNativeInstance instance, WGPUBackendType backendType, const void* options);
|
||||
|
||||
MACH_EXPORT MachDawnNativeAdapters machDawnNativeInstance_getAdapters(MachDawnNativeInstance instance);
|
||||
|
||||
// Backend-agnostic API for dawn_native
|
||||
MACH_EXPORT const DawnProcTable* machDawnNativeGetProcs();
|
||||
|
||||
// Backend-specific options which can be passed to discoverAdapters
|
||||
typedef struct MachDawnNativeAdapterDiscoveryOptions_OpenGL {
|
||||
void* (*getProc)(const char*);
|
||||
} MachDawnNativeAdapterDiscoveryOptions_OpenGL;
|
||||
typedef struct MachDawnNativeAdapterDiscoveryOptions_OpenGLES {
|
||||
void* (*getProc)(const char*);
|
||||
} MachDawnNativeAdapterDiscoveryOptions_OpenGLES;
|
||||
|
||||
// utils
|
||||
#include <GLFW/glfw3.h>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue