Skip to content

Commit 98c9e3f

Browse files
Verify GL sharing based on luid from wglGetLuidINTEL function
Related-To: NEO-5016 Change-Id: I4409132ce000d6052c7f69a9b19c01389d51c2de Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent 8260e7c commit 98c9e3f

File tree

9 files changed

+83
-213
lines changed

9 files changed

+83
-213
lines changed

opencl/source/sharings/gl/windows/cl_gl_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ cl_int CL_API_CALL clGetGLContextInfoKHR(const cl_context_properties *properties
358358
ClDevice *deviceToReturn = nullptr;
359359
for (auto i = 0u; i < platform->getNumDevices(); i++) {
360360
auto device = platform->getClDevice(i);
361-
if (device->getRootDeviceEnvironment().osInterface->get()->getWddm()->verifyAdapterLuid(glSharing->getAdapterLuid())) {
361+
if (device->getRootDeviceEnvironment().osInterface->get()->getWddm()->verifyAdapterLuid(glSharing->getAdapterLuid(reinterpret_cast<GLContext>(static_cast<uintptr_t>(GLHGLRCHandle))))) {
362362
deviceToReturn = device;
363363
break;
364364
}

opencl/source/sharings/gl/windows/gl_sharing_windows.cpp

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
#include "opencl/source/sharings/gl/windows/gl_sharing_windows.h"
99

10-
#include "shared/source/os_interface/windows/sys_calls.h"
11-
#include "shared/source/os_interface/windows/wddm/wddm.h"
12-
1310
#include "opencl/source/context/context.inl"
1411
#include "opencl/source/helpers/windows/gl_helper.h"
1512
#include "opencl/source/sharings/gl/gl_arb_sync_event.h"
@@ -151,72 +148,21 @@ GLboolean GLSharingFunctionsWindows::initGLFunctions() {
151148
GLReleaseSync = wglLibrary["wglReleaseSyncINTEL"];
152149
GLGetSynciv = wglLibrary["wglGetSyncivINTEL"];
153150
glGetStringi = wglLibrary["glGetStringi"];
151+
glGetLuid = wglLibrary["wglGetLuidINTEL"];
154152
}
155153
this->pfnGlArbSyncObjectCleanup = cleanupArbSyncObject;
156154
this->pfnGlArbSyncObjectSetup = setupArbSyncObject;
157155
this->pfnGlArbSyncObjectSignal = signalArbSyncObject;
158156
this->pfnGlArbSyncObjectWaitServer = serverWaitForArbSyncObject;
159157

160-
initAdapterLuid();
161-
162158
return 1;
163159
}
164160

165-
LUID GLSharingFunctionsWindows::getAdapterLuid() const {
166-
return adapterLuid;
167-
}
168-
void GLSharingFunctionsWindows::initAdapterLuid() {
169-
if (adapterLuid.HighPart != 0 || adapterLuid.LowPart != 0) {
170-
return;
171-
}
172-
WCHAR displayName[ARRAYSIZE(DISPLAY_DEVICEW::DeviceName)];
173-
UINT iDevNum = 0u;
174-
DISPLAY_DEVICEW dispDevice = {0};
175-
dispDevice.cb = sizeof(dispDevice);
176-
while (SysCalls::enumDisplayDevices(NULL, iDevNum++, &dispDevice, EDD_GET_DEVICE_INTERFACE_NAME)) {
177-
if (dispDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
178-
wcscpy_s(displayName, ARRAYSIZE(DISPLAY_DEVICEW::DeviceName), dispDevice.DeviceName);
179-
break;
180-
}
181-
}
182-
183-
DXGI_ADAPTER_DESC1 OpenAdapterDesc = {{0}};
184-
DXGI_OUTPUT_DESC outputDesc = {0};
185-
IDXGIFactory1 *pFactory = nullptr;
186-
IDXGIAdapter1 *pAdapter = nullptr;
187-
bool found = false;
188-
189-
HRESULT hr = Wddm::createDxgiFactory(__uuidof(IDXGIFactory), (void **)(&pFactory));
190-
if ((hr != S_OK) || (pFactory == nullptr)) {
191-
return;
192-
}
193-
iDevNum = 0u;
194-
while (pFactory->EnumAdapters1(iDevNum++, &pAdapter) != DXGI_ERROR_NOT_FOUND) {
195-
IDXGIOutput *pOutput = nullptr;
196-
UINT outputNum = 0;
197-
while (pAdapter->EnumOutputs(outputNum++, &pOutput) != DXGI_ERROR_NOT_FOUND && pOutput) {
198-
pOutput->GetDesc(&outputDesc);
199-
if (wcscmp(outputDesc.DeviceName, displayName) == 0) {
200-
201-
hr = pAdapter->GetDesc1(&OpenAdapterDesc);
202-
if (hr == S_OK) {
203-
adapterLuid = OpenAdapterDesc.AdapterLuid;
204-
found = true;
205-
break;
206-
}
207-
}
208-
}
209-
pAdapter->Release();
210-
pAdapter = nullptr;
211-
if (found) {
212-
break;
213-
}
214-
}
215-
216-
if (pFactory != nullptr) {
217-
pFactory->Release();
218-
pFactory = nullptr;
161+
LUID GLSharingFunctionsWindows::getAdapterLuid(GLContext glhglrcHandle) const {
162+
if (glGetLuid) {
163+
return glGetLuid(glhglrcHandle);
219164
}
165+
return {};
220166
}
221167

222168
template GLSharingFunctionsWindows *Context::getSharing<GLSharingFunctionsWindows>();

opencl/source/sharings/gl/windows/gl_sharing_windows.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ typedef void (*PFNglArbSyncObjectCleanup)(OSInterface &osInterface, CL_GL_SYNC_I
4444
typedef void (*PFNglArbSyncObjectSignal)(OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo);
4545
typedef void (*PFNglArbSyncObjectWaitServer)(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo);
4646

47+
typedef LUID(OSAPI *PFNGLGETLUIDINTEL)(HGLRC hglrcHandle);
48+
4749
class GLSharingFunctionsWindows : public GLSharingFunctions {
4850
public:
4951
GLSharingFunctionsWindows() = default;
@@ -122,7 +124,7 @@ class GLSharingFunctionsWindows : public GLSharingFunctions {
122124
pfnGlArbSyncObjectWaitServer(osInterface, glSyncInfo);
123125
}
124126

125-
LUID getAdapterLuid() const;
127+
LUID getAdapterLuid(GLContext glhglrcHandle) const;
126128

127129
// Buffer reuse
128130
std::mutex mutex;
@@ -138,16 +140,13 @@ class GLSharingFunctionsWindows : public GLSharingFunctions {
138140
void createBackupContext();
139141
bool isOpenGlExtensionSupported(const unsigned char *pExtentionString);
140142

141-
void initAdapterLuid();
142-
143143
// Handles
144144
GLType GLHDCType = 0;
145145
GLContext GLHGLRCHandle = 0;
146146
GLContext GLHGLRCHandleBkpCtx = 0;
147147
GLDisplay GLHDCHandle = 0;
148148
OS_HANDLE GLDeviceHandle = 0;
149149
OS_HANDLE GLContextHandle = 0;
150-
LUID adapterLuid{};
151150

152151
// GL functions
153152
std::unique_ptr<OsLibrary> glLibrary;
@@ -174,6 +173,7 @@ class GLSharingFunctionsWindows : public GLSharingFunctions {
174173
PFNglArbSyncObjectCleanup pfnGlArbSyncObjectCleanup = nullptr;
175174
PFNglArbSyncObjectSignal pfnGlArbSyncObjectSignal = nullptr;
176175
PFNglArbSyncObjectWaitServer pfnGlArbSyncObjectWaitServer = nullptr;
176+
PFNGLGETLUIDINTEL glGetLuid = nullptr;
177177

178178
// support for GL_ARB_cl_event
179179
std::mutex glArbEventMutex;

opencl/test/unit_test/mock_gl/windows/mock_opengl32.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ CL_GL_RESOURCE_INFO textureInfoInput = {0};
4040
CL_GL_RESOURCE_INFO textureInfoOutput = {0};
4141
NEO::GLMockReturnedValues glMockReturnedValues = {0};
4242
GLboolean GLSetSharedOCLContextStateReturnedValue = 1u;
43+
bool glGetLuidFuncAvailable = true;
44+
int glGetLuidCalled = 0;
4345

4446
const unsigned char *WINAPI glGetString(unsigned int name) {
4547
if (name == GL_VENDOR)
@@ -129,6 +131,20 @@ GLDisplay WINAPI mockGLGetCurrentDisplay() {
129131
GLGetCurrentDisplayCalled++;
130132
return glMockReturnedValues.currentDisplay;
131133
};
134+
135+
LUID WINAPI wglGetLuidMock(GLContext glContext) {
136+
glGetLuidCalled++;
137+
LUID luid{};
138+
if (reinterpret_cast<GLContext>(1) == glContext) {
139+
luid.HighPart = 0x1d2e;
140+
luid.LowPart = 0x3f4a;
141+
} else if (reinterpret_cast<GLContext>(2) == glContext) {
142+
luid.HighPart = 0x5d2e;
143+
luid.LowPart = 0x3f4a;
144+
}
145+
return luid;
146+
};
147+
132148
PROC WINAPI wglGetProcAddress(LPCSTR name) {
133149
if (strcmp(name, "wglSetSharedOCLContextStateINTEL") == 0) {
134150
return reinterpret_cast<PROC>(*wglSetSharedOCLContextStateINTELMock);
@@ -163,6 +179,9 @@ PROC WINAPI wglGetProcAddress(LPCSTR name) {
163179
if (strcmp(name, "glGetStringi") == 0) {
164180
return reinterpret_cast<PROC>(*glGetStringiMock);
165181
}
182+
if (strcmp(name, "wglGetLuidINTEL") == 0 && glGetLuidFuncAvailable) {
183+
return reinterpret_cast<PROC>(wglGetLuidMock);
184+
}
166185
return nullptr;
167186
}
168187
HGLRC WINAPI wglGetCurrentContext() {
@@ -268,6 +287,17 @@ void resetParam(const char *name) {
268287
WGLCreateContextCalled = 0;
269288
WGLDeleteContextCalled = 0;
270289
WGLShareListsCalled = 0;
290+
glGetLuidCalled = 0;
291+
glGetLuidFuncAvailable = true;
292+
}
293+
if (strcmp(name, "glGetLuidCalled") == 0) {
294+
glGetLuidCalled = 0;
295+
}
296+
if (strcmp(name, "glGetLuidFuncAvailable") == 0) {
297+
glGetLuidFuncAvailable = true;
298+
}
299+
if (strcmp(name, "glGetLuidFuncNotAvailable") == 0) {
300+
glGetLuidFuncAvailable = false;
271301
}
272302
};
273303
int getParam(const char *name) {
@@ -319,6 +349,9 @@ int getParam(const char *name) {
319349
if (strcmp(name, "WGLShareListsCalled") == 0) {
320350
return WGLShareListsCalled;
321351
}
352+
if (strcmp(name, "glGetLuidCalled") == 0) {
353+
return glGetLuidCalled;
354+
}
322355
return 0;
323356
};
324357
CL_GL_BUFFER_INFO getBufferInfo() { return bufferInfoInput; };

opencl/test/unit_test/os_interface/windows/sys_calls.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,6 @@ char *getenv(const char *variableName) {
5454
}
5555
return ::getenv(variableName);
5656
}
57-
BOOL enumDisplayDevices(LPCWSTR lpDevice, DWORD iDevNum, PDISPLAY_DEVICEW lpDisplayDevice, DWORD dwFlags) {
58-
if (iDevNum == 0) {
59-
WCHAR deviceName[] = L"Display0";
60-
wcscpy_s(lpDisplayDevice->DeviceName, ARRAYSIZE(deviceName), deviceName);
61-
lpDisplayDevice->StateFlags = 0u;
62-
} else if (iDevNum == 1) {
63-
WCHAR deviceName[] = L"Display1";
64-
wcscpy_s(lpDisplayDevice->DeviceName, ARRAYSIZE(deviceName), deviceName);
65-
lpDisplayDevice->StateFlags = DISPLAY_DEVICE_PRIMARY_DEVICE;
66-
}
67-
68-
return TRUE;
69-
}
7057
} // namespace SysCalls
7158

7259
} // namespace NEO

opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.h

Lines changed: 4 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -13,115 +13,9 @@
1313
#include <dxgi.h>
1414

1515
namespace NEO {
16-
17-
struct UltIDXGIOutput : public IDXGIOutput {
18-
19-
UltIDXGIOutput(uint32_t id) : id(id) {}
20-
uint32_t id = 0;
21-
22-
HRESULT STDMETHODCALLTYPE GetDesc(_Out_ DXGI_OUTPUT_DESC *pDesc) override {
23-
24-
if (id == 0) {
25-
WCHAR deviceName[] = L"Display0";
26-
wcscpy_s(pDesc->DeviceName, ARRAYSIZE(deviceName), deviceName);
27-
} else if (id == 1) {
28-
WCHAR deviceName[] = L"Display1";
29-
wcscpy_s(pDesc->DeviceName, ARRAYSIZE(deviceName), deviceName);
30-
}
31-
32-
return S_OK;
33-
}
34-
35-
HRESULT STDMETHODCALLTYPE GetDisplayModeList(
36-
/* [in] */ DXGI_FORMAT EnumFormat,
37-
/* [in] */ UINT Flags,
38-
/* [annotation][out][in] */
39-
_Inout_ UINT *pNumModes,
40-
/* [annotation][out] */
41-
_Out_writes_to_opt_(*pNumModes, *pNumModes) DXGI_MODE_DESC *pDesc) override { return S_OK; }
42-
43-
HRESULT STDMETHODCALLTYPE FindClosestMatchingMode(
44-
/* [annotation][in] */
45-
_In_ const DXGI_MODE_DESC *pModeToMatch,
46-
/* [annotation][out] */
47-
_Out_ DXGI_MODE_DESC *pClosestMatch,
48-
/* [annotation][in] */
49-
_In_opt_ IUnknown *pConcernedDevice) override { return S_OK; }
50-
51-
HRESULT STDMETHODCALLTYPE WaitForVBlank(void) override { return S_OK; }
52-
53-
HRESULT STDMETHODCALLTYPE TakeOwnership(
54-
/* [annotation][in] */
55-
_In_ IUnknown *pDevice,
56-
BOOL Exclusive) override { return S_OK; }
57-
58-
void STDMETHODCALLTYPE ReleaseOwnership(void) override {}
59-
60-
HRESULT STDMETHODCALLTYPE GetGammaControlCapabilities(
61-
/* [annotation][out] */
62-
_Out_ DXGI_GAMMA_CONTROL_CAPABILITIES *pGammaCaps) override { return S_OK; }
63-
64-
HRESULT STDMETHODCALLTYPE SetGammaControl(
65-
/* [annotation][in] */
66-
_In_ const DXGI_GAMMA_CONTROL *pArray) override { return S_OK; }
67-
68-
HRESULT STDMETHODCALLTYPE GetGammaControl(
69-
/* [annotation][out] */
70-
_Out_ DXGI_GAMMA_CONTROL *pArray) override { return S_OK; }
71-
72-
HRESULT STDMETHODCALLTYPE SetDisplaySurface(
73-
/* [annotation][in] */
74-
_In_ IDXGISurface *pScanoutSurface) override { return S_OK; }
75-
76-
HRESULT STDMETHODCALLTYPE GetDisplaySurfaceData(
77-
/* [annotation][in] */
78-
_In_ IDXGISurface *pDestination) override { return S_OK; }
79-
80-
HRESULT STDMETHODCALLTYPE GetFrameStatistics(
81-
/* [annotation][out] */
82-
_Out_ DXGI_FRAME_STATISTICS *pStats) override { return S_OK; }
83-
84-
HRESULT STDMETHODCALLTYPE SetPrivateData(
85-
/* [annotation][in] */
86-
_In_ REFGUID Name,
87-
/* [in] */ UINT DataSize,
88-
/* [annotation][in] */
89-
_In_reads_bytes_(DataSize) const void *pData) override { return S_OK; }
90-
91-
HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
92-
/* [annotation][in] */
93-
_In_ REFGUID Name,
94-
/* [annotation][in] */
95-
_In_opt_ const IUnknown *pUnknown) override { return S_OK; }
96-
97-
HRESULT STDMETHODCALLTYPE GetPrivateData(
98-
/* [annotation][in] */
99-
_In_ REFGUID Name,
100-
/* [annotation][out][in] */
101-
_Inout_ UINT *pDataSize,
102-
/* [annotation][out] */
103-
_Out_writes_bytes_(*pDataSize) void *pData) override { return S_OK; }
104-
105-
HRESULT STDMETHODCALLTYPE GetParent(
106-
/* [annotation][in] */
107-
_In_ REFIID riid,
108-
/* [annotation][retval][out] */
109-
_COM_Outptr_ void **ppParent) override { return S_OK; }
110-
111-
HRESULT STDMETHODCALLTYPE QueryInterface(
112-
/* [in] */ REFIID riid,
113-
/* [iid_is][out] */ _COM_Outptr_ void __RPC_FAR *__RPC_FAR *ppvObject) override { return S_OK; }
114-
115-
ULONG STDMETHODCALLTYPE AddRef(void) override { return S_OK; }
116-
117-
ULONG STDMETHODCALLTYPE Release(void) override { return S_OK; }
118-
};
11916
class UltIDXGIAdapter1 : public IDXGIAdapter1 {
12017
public:
121-
uint32_t id = 0u;
122-
UltIDXGIAdapter1(uint32_t id) : id(id), output{id} {};
12318
const static wchar_t *description;
124-
UltIDXGIOutput output;
12519
// IDXGIAdapter1
12620
HRESULT STDMETHODCALLTYPE GetDesc1(
12721
_Out_ DXGI_ADAPTER_DESC1 *pDesc) {
@@ -131,21 +25,14 @@ class UltIDXGIAdapter1 : public IDXGIAdapter1 {
13125
}
13226
swprintf(pDesc->Description, 128, description);
13327
pDesc->AdapterLuid.HighPart = 0x1234;
134-
pDesc->AdapterLuid.LowPart = id;
13528
pDesc->DeviceId = 0x1234;
13629
return S_OK;
13730
}
13831

13932
// IDXGIAdapter
14033
HRESULT STDMETHODCALLTYPE EnumOutputs(
141-
UINT outputId,
34+
UINT Output,
14235
IDXGIOutput **ppOutput) {
143-
if (outputId == 0) {
144-
*ppOutput = &output;
145-
} else {
146-
*ppOutput = nullptr;
147-
return DXGI_ERROR_NOT_FOUND;
148-
}
14936
return S_OK;
15037
}
15138

@@ -210,13 +97,13 @@ extern uint32_t numRootDevicesToEnum;
21097
class UltIDXGIFactory1 : public IDXGIFactory1 {
21198
public:
21299
HRESULT STDMETHODCALLTYPE EnumAdapters1(
213-
UINT adapterId,
100+
UINT Adapter,
214101
IDXGIAdapter1 **ppAdapter) {
215-
if (adapterId >= numRootDevicesToEnum) {
102+
if (Adapter >= numRootDevicesToEnum) {
216103
*(IDXGIAdapter1 **)ppAdapter = nullptr;
217104
return DXGI_ERROR_NOT_FOUND;
218105
}
219-
*(IDXGIAdapter1 **)ppAdapter = new UltIDXGIAdapter1(adapterId);
106+
*(IDXGIAdapter1 **)ppAdapter = new UltIDXGIAdapter1;
220107
return S_OK;
221108
}
222109

0 commit comments

Comments
 (0)