Verify GL sharing based on luid from wglGetLuidINTEL function

Related-To: NEO-5016
Change-Id: I4409132ce000d6052c7f69a9b19c01389d51c2de
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2020-08-31 18:01:56 +02:00
committed by sys_ocldev
parent 8260e7c5d9
commit 98c9e3f6ca
9 changed files with 87 additions and 217 deletions

View File

@@ -358,7 +358,7 @@ cl_int CL_API_CALL clGetGLContextInfoKHR(const cl_context_properties *properties
ClDevice *deviceToReturn = nullptr;
for (auto i = 0u; i < platform->getNumDevices(); i++) {
auto device = platform->getClDevice(i);
if (device->getRootDeviceEnvironment().osInterface->get()->getWddm()->verifyAdapterLuid(glSharing->getAdapterLuid())) {
if (device->getRootDeviceEnvironment().osInterface->get()->getWddm()->verifyAdapterLuid(glSharing->getAdapterLuid(reinterpret_cast<GLContext>(static_cast<uintptr_t>(GLHGLRCHandle))))) {
deviceToReturn = device;
break;
}

View File

@@ -7,9 +7,6 @@
#include "opencl/source/sharings/gl/windows/gl_sharing_windows.h"
#include "shared/source/os_interface/windows/sys_calls.h"
#include "shared/source/os_interface/windows/wddm/wddm.h"
#include "opencl/source/context/context.inl"
#include "opencl/source/helpers/windows/gl_helper.h"
#include "opencl/source/sharings/gl/gl_arb_sync_event.h"
@@ -151,72 +148,21 @@ GLboolean GLSharingFunctionsWindows::initGLFunctions() {
GLReleaseSync = wglLibrary["wglReleaseSyncINTEL"];
GLGetSynciv = wglLibrary["wglGetSyncivINTEL"];
glGetStringi = wglLibrary["glGetStringi"];
glGetLuid = wglLibrary["wglGetLuidINTEL"];
}
this->pfnGlArbSyncObjectCleanup = cleanupArbSyncObject;
this->pfnGlArbSyncObjectSetup = setupArbSyncObject;
this->pfnGlArbSyncObjectSignal = signalArbSyncObject;
this->pfnGlArbSyncObjectWaitServer = serverWaitForArbSyncObject;
initAdapterLuid();
return 1;
}
LUID GLSharingFunctionsWindows::getAdapterLuid() const {
return adapterLuid;
}
void GLSharingFunctionsWindows::initAdapterLuid() {
if (adapterLuid.HighPart != 0 || adapterLuid.LowPart != 0) {
return;
}
WCHAR displayName[ARRAYSIZE(DISPLAY_DEVICEW::DeviceName)];
UINT iDevNum = 0u;
DISPLAY_DEVICEW dispDevice = {0};
dispDevice.cb = sizeof(dispDevice);
while (SysCalls::enumDisplayDevices(NULL, iDevNum++, &dispDevice, EDD_GET_DEVICE_INTERFACE_NAME)) {
if (dispDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
wcscpy_s(displayName, ARRAYSIZE(DISPLAY_DEVICEW::DeviceName), dispDevice.DeviceName);
break;
}
}
DXGI_ADAPTER_DESC1 OpenAdapterDesc = {{0}};
DXGI_OUTPUT_DESC outputDesc = {0};
IDXGIFactory1 *pFactory = nullptr;
IDXGIAdapter1 *pAdapter = nullptr;
bool found = false;
HRESULT hr = Wddm::createDxgiFactory(__uuidof(IDXGIFactory), (void **)(&pFactory));
if ((hr != S_OK) || (pFactory == nullptr)) {
return;
}
iDevNum = 0u;
while (pFactory->EnumAdapters1(iDevNum++, &pAdapter) != DXGI_ERROR_NOT_FOUND) {
IDXGIOutput *pOutput = nullptr;
UINT outputNum = 0;
while (pAdapter->EnumOutputs(outputNum++, &pOutput) != DXGI_ERROR_NOT_FOUND && pOutput) {
pOutput->GetDesc(&outputDesc);
if (wcscmp(outputDesc.DeviceName, displayName) == 0) {
hr = pAdapter->GetDesc1(&OpenAdapterDesc);
if (hr == S_OK) {
adapterLuid = OpenAdapterDesc.AdapterLuid;
found = true;
break;
}
}
}
pAdapter->Release();
pAdapter = nullptr;
if (found) {
break;
}
}
if (pFactory != nullptr) {
pFactory->Release();
pFactory = nullptr;
LUID GLSharingFunctionsWindows::getAdapterLuid(GLContext glhglrcHandle) const {
if (glGetLuid) {
return glGetLuid(glhglrcHandle);
}
return {};
}
template GLSharingFunctionsWindows *Context::getSharing<GLSharingFunctionsWindows>();

View File

@@ -44,6 +44,8 @@ typedef void (*PFNglArbSyncObjectCleanup)(OSInterface &osInterface, CL_GL_SYNC_I
typedef void (*PFNglArbSyncObjectSignal)(OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo);
typedef void (*PFNglArbSyncObjectWaitServer)(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo);
typedef LUID(OSAPI *PFNGLGETLUIDINTEL)(HGLRC hglrcHandle);
class GLSharingFunctionsWindows : public GLSharingFunctions {
public:
GLSharingFunctionsWindows() = default;
@@ -122,7 +124,7 @@ class GLSharingFunctionsWindows : public GLSharingFunctions {
pfnGlArbSyncObjectWaitServer(osInterface, glSyncInfo);
}
LUID getAdapterLuid() const;
LUID getAdapterLuid(GLContext glhglrcHandle) const;
// Buffer reuse
std::mutex mutex;
@@ -138,8 +140,6 @@ class GLSharingFunctionsWindows : public GLSharingFunctions {
void createBackupContext();
bool isOpenGlExtensionSupported(const unsigned char *pExtentionString);
void initAdapterLuid();
// Handles
GLType GLHDCType = 0;
GLContext GLHGLRCHandle = 0;
@@ -147,7 +147,6 @@ class GLSharingFunctionsWindows : public GLSharingFunctions {
GLDisplay GLHDCHandle = 0;
OS_HANDLE GLDeviceHandle = 0;
OS_HANDLE GLContextHandle = 0;
LUID adapterLuid{};
// GL functions
std::unique_ptr<OsLibrary> glLibrary;
@@ -174,6 +173,7 @@ class GLSharingFunctionsWindows : public GLSharingFunctions {
PFNglArbSyncObjectCleanup pfnGlArbSyncObjectCleanup = nullptr;
PFNglArbSyncObjectSignal pfnGlArbSyncObjectSignal = nullptr;
PFNglArbSyncObjectWaitServer pfnGlArbSyncObjectWaitServer = nullptr;
PFNGLGETLUIDINTEL glGetLuid = nullptr;
// support for GL_ARB_cl_event
std::mutex glArbEventMutex;