OpenGL: Restore ContextExternal support

This commit is contained in:
Luke Street 2023-05-27 14:55:14 -04:00
parent 0bd776df12
commit cc359d7bbb
3 changed files with 30 additions and 8 deletions

View File

@ -97,8 +97,9 @@ ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverPhysicalDev
DAWN_INVALID_IF(options->getProc == nullptr, DAWN_INVALID_IF(options->getProc == nullptr,
"PhysicalDeviceDiscoveryOptions::getProc must be set"); "PhysicalDeviceDiscoveryOptions::getProc must be set");
Ref<PhysicalDevice> physicalDevice = AcquireRef(new PhysicalDevice( Ref<PhysicalDevice> physicalDevice = AcquireRef(
GetInstance(), static_cast<wgpu::BackendType>(optionsBase->backendType))); new PhysicalDevice(GetInstance(), static_cast<wgpu::BackendType>(optionsBase->backendType),
options->makeCurrent, options->destroy, options->userData));
DAWN_TRY(physicalDevice->InitializeGLFunctions(options->getProc)); DAWN_TRY(physicalDevice->InitializeGLFunctions(options->getProc));
DAWN_TRY(physicalDevice->Initialize()); DAWN_TRY(physicalDevice->Initialize());

View File

@ -21,6 +21,7 @@
#include "dawn/common/GPUInfo.h" #include "dawn/common/GPUInfo.h"
#include "dawn/native/Instance.h" #include "dawn/native/Instance.h"
#include "dawn/native/opengl/ContextEGL.h" #include "dawn/native/opengl/ContextEGL.h"
#include "dawn/native/opengl/ContextExternal.h"
#include "dawn/native/opengl/DeviceGL.h" #include "dawn/native/opengl/DeviceGL.h"
namespace dawn::native::opengl { namespace dawn::native::opengl {
@ -53,12 +54,21 @@ uint32_t GetVendorIdFromVendors(const char* vendor) {
} // anonymous namespace } // anonymous namespace
PhysicalDevice::PhysicalDevice(InstanceBase* instance, wgpu::BackendType backendType) PhysicalDevice::PhysicalDevice(InstanceBase* instance,
: PhysicalDeviceBase(instance, backendType) {} wgpu::BackendType backendType,
void (*makeCurrent)(void*),
void (*destroy)(void*),
void* userData)
: PhysicalDeviceBase(instance, backendType),
mMakeCurrent(makeCurrent),
mDestroy(destroy),
mUserData(userData) {}
MaybeError PhysicalDevice::InitializeGLFunctions(void* (*getProc)(const char*)) { MaybeError PhysicalDevice::InitializeGLFunctions(void* (*getProc)(const char*)) {
// Use getProc to populate the dispatch table if (mMakeCurrent == nullptr) {
mEGLFunctions.Init(getProc); // Use getProc to populate the dispatch table
mEGLFunctions.Init(getProc);
}
return mFunctions.Initialize(getProc); return mFunctions.Initialize(getProc);
} }
@ -238,7 +248,11 @@ ResultOrError<Ref<DeviceBase>> PhysicalDevice::CreateDeviceImpl(AdapterBase* ada
EGLenum api = EGLenum api =
GetBackendType() == wgpu::BackendType::OpenGL ? EGL_OPENGL_API : EGL_OPENGL_ES_API; GetBackendType() == wgpu::BackendType::OpenGL ? EGL_OPENGL_API : EGL_OPENGL_ES_API;
std::unique_ptr<Device::Context> context; std::unique_ptr<Device::Context> context;
DAWN_TRY_ASSIGN(context, ContextEGL::Create(mEGLFunctions, api)); if (mMakeCurrent != nullptr) {
DAWN_TRY_ASSIGN(context, ContextExternal::Create(mMakeCurrent, mDestroy, mUserData));
} else {
DAWN_TRY_ASSIGN(context, ContextEGL::Create(mEGLFunctions, api));
}
return Device::Create(adapter, descriptor, mFunctions, std::move(context), deviceToggles); return Device::Create(adapter, descriptor, mFunctions, std::move(context), deviceToggles);
} }

View File

@ -23,7 +23,11 @@ namespace dawn::native::opengl {
class PhysicalDevice : public PhysicalDeviceBase { class PhysicalDevice : public PhysicalDeviceBase {
public: public:
PhysicalDevice(InstanceBase* instance, wgpu::BackendType backendType); PhysicalDevice(InstanceBase* instance,
wgpu::BackendType backendType,
void (*makeCurrent)(void*),
void (*destroy)(void*),
void* userData);
MaybeError InitializeGLFunctions(void* (*getProc)(const char*)); MaybeError InitializeGLFunctions(void* (*getProc)(const char*));
@ -48,6 +52,9 @@ class PhysicalDevice : public PhysicalDeviceBase {
OpenGLFunctions mFunctions; OpenGLFunctions mFunctions;
EGLFunctions mEGLFunctions; EGLFunctions mEGLFunctions;
void (*mMakeCurrent)(void*);
void (*mDestroy)(void*);
void* mUserData;
}; };
} // namespace dawn::native::opengl } // namespace dawn::native::opengl