| 1 |
/* |
| 2 |
* Copyright (C) 2018-2023 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#define _GDI32_ // It causes that definitions of functions are not loaded from dll in file wingdi.h because they are in this file. |
| 9 |
|
| 10 |
#include "opencl/test/unit_test/helpers/windows/mock_function.h" |
| 11 |
#include "opencl/test/unit_test/mocks/gl/windows/mock_gl_sharing_windows.h" |
| 12 |
|
| 13 |
#include "GL/gl.h" |
| 14 |
|
| 15 |
#include <string.h> |
| 16 |
|
| 17 |
extern "C" { |
| 18 |
const char *glString = "Intel"; |
| 19 |
const char *glVersion = "4.0"; |
| 20 |
const char *arrayStringi[2]{"GL_OES_framebuffer_object", "GL_EXT_framebuffer_object"}; |
| 21 |
int glAcquireSharedBufferCalled = 0; |
| 22 |
int glAcquireSharedRenderBufferCalled = 0; |
| 23 |
int glAcquireSharedTextureCalled = 0; |
| 24 |
int glDeleteContextCalled = 0; |
| 25 |
int glGetCurrentContextCalled = 0; |
| 26 |
int glGetCurrentDisplayCalled = 0; |
| 27 |
int glGetSyncivCalled = 0; |
| 28 |
int glMakeCurrentCalled = 0; |
| 29 |
int glReleaseSharedBufferCalled = 0; |
| 30 |
int glReleaseSharedRenderBufferCalled = 0; |
| 31 |
int glReleaseSharedTextureCalled = 0; |
| 32 |
int glReleaseSyncCalled = 0; |
| 33 |
int glRetainSyncCalled = 0; |
| 34 |
int wglCreateContextCalled = 0; |
| 35 |
int wglDeleteContextCalled = 0; |
| 36 |
int wglShareListsCalled = 0; |
| 37 |
CL_GL_BUFFER_INFO bufferInfoInput = {0}; |
| 38 |
CL_GL_BUFFER_INFO bufferInfoOutput = {0}; |
| 39 |
CL_GL_RESOURCE_INFO textureInfoInput = {0}; |
| 40 |
CL_GL_RESOURCE_INFO textureInfoOutput = {0}; |
| 41 |
NEO::GLMockReturnedValues glMockReturnedValues = {0}; |
| 42 |
GLboolean glSetSharedOCLContextStateReturnedValue = 1u; |
| 43 |
bool glGetLuidFuncAvailable = true; |
| 44 |
int glGetLuidCalled = 0; |
| 45 |
|
| 46 |
const unsigned char *WINAPI glGetString(unsigned int name) { |
| 47 |
if (name == GL_VENDOR) |
| 48 |
return reinterpret_cast<const unsigned char *>(glString); |
| 49 |
if (name == GL_VERSION) |
| 50 |
return reinterpret_cast<const unsigned char *>(glVersion); |
| 51 |
return reinterpret_cast<const unsigned char *>(""); |
| 52 |
}; |
| 53 |
GLboolean WINAPI wglSetSharedOCLContextStateINTELMock(HDC hdcHandle, HGLRC contextHandle, unsigned char state, |
| 54 |
void *pContextInfo) { |
| 55 |
((NEO::ContextInfo *)pContextInfo)->contextHandle = 1; |
| 56 |
((NEO::ContextInfo *)pContextInfo)->deviceHandle = 2; |
| 57 |
return glSetSharedOCLContextStateReturnedValue; |
| 58 |
}; |
| 59 |
GLboolean WINAPI mockGLAcquireSharedBuffer(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { |
| 60 |
|
| 61 |
auto pBufferInfo = (CL_GL_BUFFER_INFO *)pResourceInfo; |
| 62 |
bufferInfoInput = *pBufferInfo; |
| 63 |
pBufferInfo->bufferSize = bufferInfoOutput.bufferSize; |
| 64 |
pBufferInfo->globalShareHandle = bufferInfoOutput.globalShareHandle; |
| 65 |
pBufferInfo->pGmmResInfo = bufferInfoOutput.pGmmResInfo; |
| 66 |
pBufferInfo->bufferOffset = bufferInfoOutput.bufferOffset; |
| 67 |
glAcquireSharedBufferCalled++; |
| 68 |
return (GLboolean)1; |
| 69 |
}; |
| 70 |
GLboolean WINAPI mockGLReleaseSharedBuffer(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { |
| 71 |
bufferInfoInput = *static_cast<CL_GL_BUFFER_INFO *>(pResourceInfo); |
| 72 |
glReleaseSharedBufferCalled++; |
| 73 |
return (GLboolean)1; |
| 74 |
}; |
| 75 |
GLboolean WINAPI mockGLAcquireSharedRenderBuffer(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { |
| 76 |
auto pTextureInfo = (CL_GL_RESOURCE_INFO *)pResourceInfo; |
| 77 |
textureInfoInput = *pTextureInfo; |
| 78 |
pTextureInfo->globalShareHandle = textureInfoOutput.globalShareHandle; |
| 79 |
pTextureInfo->pGmmResInfo = textureInfoOutput.pGmmResInfo; |
| 80 |
pTextureInfo->glInternalFormat = GL_RGBA8; |
| 81 |
glAcquireSharedRenderBufferCalled++; |
| 82 |
return (GLboolean)1; |
| 83 |
}; |
| 84 |
GLboolean WINAPI mockGLReleaseSharedRenderBuffer(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { |
| 85 |
textureInfoInput = *static_cast<CL_GL_RESOURCE_INFO *>(pResourceInfo); |
| 86 |
glReleaseSharedRenderBufferCalled++; |
| 87 |
return (GLboolean)1; |
| 88 |
}; |
| 89 |
GLboolean WINAPI mockGLAcquireSharedTexture(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { |
| 90 |
auto pTextureInfo = (CL_GL_RESOURCE_INFO *)pResourceInfo; |
| 91 |
textureInfoInput = *pTextureInfo; |
| 92 |
pTextureInfo->globalShareHandle = textureInfoOutput.globalShareHandle; |
| 93 |
pTextureInfo->globalShareHandleMCS = textureInfoOutput.globalShareHandleMCS; |
| 94 |
if (pTextureInfo->target == GL_TEXTURE_BUFFER) { |
| 95 |
// size and width for texture buffer are queried from textureInfo - not from gmm |
| 96 |
pTextureInfo->textureBufferSize = textureInfoOutput.textureBufferSize; |
| 97 |
pTextureInfo->textureBufferWidth = textureInfoOutput.textureBufferWidth; |
| 98 |
} |
| 99 |
pTextureInfo->pGmmResInfo = textureInfoOutput.pGmmResInfo; |
| 100 |
pTextureInfo->glInternalFormat = textureInfoOutput.glInternalFormat ? textureInfoOutput.glInternalFormat : GL_RGBA8; |
| 101 |
pTextureInfo->glHWFormat = textureInfoOutput.glHWFormat; |
| 102 |
pTextureInfo->textureBufferOffset = textureInfoOutput.textureBufferOffset; |
| 103 |
pTextureInfo->numberOfSamples = textureInfoOutput.numberOfSamples; |
| 104 |
pTextureInfo->isAuxEnabled = textureInfoOutput.isAuxEnabled; |
| 105 |
glAcquireSharedTextureCalled++; |
| 106 |
return (GLboolean)1; |
| 107 |
}; |
| 108 |
GLboolean WINAPI mockGLReleaseSharedTexture(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { |
| 109 |
textureInfoInput = *static_cast<CL_GL_RESOURCE_INFO *>(pResourceInfo); |
| 110 |
glReleaseSharedTextureCalled++; |
| 111 |
return (GLboolean)1; |
| 112 |
}; |
| 113 |
GLboolean WINAPI mockGlRetainSync(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, |
| 114 |
GLvoid *pSyncInfo) { |
| 115 |
glRetainSyncCalled++; |
| 116 |
GL_CL_SYNC_INFO *syncInfo = (GL_CL_SYNC_INFO *)(pSyncInfo); |
| 117 |
syncInfo->pSync = (void *)0x123; |
| 118 |
return GL_TRUE; |
| 119 |
}; |
| 120 |
GLboolean WINAPI mockGlReleaseSync(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, |
| 121 |
GLvoid *pSync) { |
| 122 |
glReleaseSyncCalled++; |
| 123 |
return GL_TRUE; |
| 124 |
}; |
| 125 |
void WINAPI mockGlGetSynciv(GLvoid *pSync, GLenum pname, GLint *value) { |
| 126 |
glGetSyncivCalled++; |
| 127 |
*value = glMockReturnedValues.syncivRetVal; |
| 128 |
}; |
| 129 |
const unsigned char *_stdcall glGetStringiMock(unsigned int name, unsigned int index) { return reinterpret_cast<const unsigned char *>(arrayStringi[index]); }; |
| 130 |
GLDisplay WINAPI mockGLGetCurrentDisplay() { |
| 131 |
glGetCurrentDisplayCalled++; |
| 132 |
return glMockReturnedValues.currentDisplay; |
| 133 |
}; |
| 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 |
|
| 148 |
PROC WINAPI wglGetProcAddress(LPCSTR name) { |
| 149 |
if (strcmp(name, "wglSetSharedOCLContextStateINTEL") == 0) { |
| 150 |
return reinterpret_cast<PROC>(*wglSetSharedOCLContextStateINTELMock); |
| 151 |
} |
| 152 |
if (strcmp(name, "wglAcquireSharedBufferINTEL") == 0) { |
| 153 |
return reinterpret_cast<PROC>(*mockGLAcquireSharedBuffer); |
| 154 |
} |
| 155 |
if (strcmp(name, "wglReleaseSharedBufferINTEL") == 0) { |
| 156 |
return reinterpret_cast<PROC>(*mockGLReleaseSharedBuffer); |
| 157 |
} |
| 158 |
if (strcmp(name, "wglAcquireSharedRenderBufferINTEL") == 0) { |
| 159 |
return reinterpret_cast<PROC>(*mockGLAcquireSharedRenderBuffer); |
| 160 |
} |
| 161 |
if (strcmp(name, "wglReleaseSharedRenderBufferINTEL") == 0) { |
| 162 |
return reinterpret_cast<PROC>(*mockGLReleaseSharedRenderBuffer); |
| 163 |
} |
| 164 |
if (strcmp(name, "wglAcquireSharedTextureINTEL") == 0) { |
| 165 |
return reinterpret_cast<PROC>(*mockGLAcquireSharedTexture); |
| 166 |
} |
| 167 |
if (strcmp(name, "wglReleaseSharedTextureINTEL") == 0) { |
| 168 |
return reinterpret_cast<PROC>(*mockGLReleaseSharedTexture); |
| 169 |
} |
| 170 |
if (strcmp(name, "wglRetainSyncINTEL") == 0) { |
| 171 |
return reinterpret_cast<PROC>(*mockGlRetainSync); |
| 172 |
} |
| 173 |
if (strcmp(name, "wglReleaseSyncINTEL") == 0) { |
| 174 |
return reinterpret_cast<PROC>(*mockGlReleaseSync); |
| 175 |
} |
| 176 |
if (strcmp(name, "wglGetSyncivINTEL") == 0) { |
| 177 |
return reinterpret_cast<PROC>(*mockGlGetSynciv); |
| 178 |
} |
| 179 |
if (strcmp(name, "glGetStringi") == 0) { |
| 180 |
return reinterpret_cast<PROC>(*glGetStringiMock); |
| 181 |
} |
| 182 |
if (strcmp(name, "wglGetLuidINTEL") == 0 && glGetLuidFuncAvailable) { |
| 183 |
return reinterpret_cast<PROC>(wglGetLuidMock); |
| 184 |
} |
| 185 |
return nullptr; |
| 186 |
} |
| 187 |
HGLRC WINAPI wglGetCurrentContext() { |
| 188 |
glGetCurrentContextCalled++; |
| 189 |
return glMockReturnedValues.currentContext; |
| 190 |
}; |
| 191 |
HDC WINAPI wglGetCurrentDC() { return mockGLGetCurrentDisplay(); }; |
| 192 |
HGLRC WINAPI wglCreateContext(HDC arg1) { |
| 193 |
wglCreateContextCalled++; |
| 194 |
return (GLContext)0x101; |
| 195 |
}; |
| 196 |
BOOL WINAPI wglDeleteContext(HGLRC arg1) { |
| 197 |
wglDeleteContextCalled++; |
| 198 |
glDeleteContextCalled++; |
| 199 |
return (GLboolean)1; |
| 200 |
}; |
| 201 |
void WINAPI glGetIntegerv(GLenum pname, GLint *params) { return NEO::MockGLSharingFunctions::glGetIntegervTest(pname, params); }; |
| 202 |
BOOL WINAPI wglShareLists(HGLRC arg1, HGLRC arg2) { |
| 203 |
wglShareListsCalled++; |
| 204 |
return 1; |
| 205 |
}; |
| 206 |
|
| 207 |
BOOL WINAPI wglMakeCurrent(HDC arg1, HGLRC arg2) { |
| 208 |
glMakeCurrentCalled++; |
| 209 |
glMockReturnedValues.madeCurrentContext = arg2; |
| 210 |
if (glMockReturnedValues.forceMakeCurrentCallFail) { |
| 211 |
if (glMockReturnedValues.failsCounter < glMockReturnedValues.numberOfCallFails) { |
| 212 |
glMockReturnedValues.failsCounter++; |
| 213 |
return GL_FALSE; |
| 214 |
} |
| 215 |
} |
| 216 |
return (GLboolean)1; |
| 217 |
}; |
| 218 |
PROC __stdcall mockLoader(const char *name) { |
| 219 |
if (strcmp(name, "realFunction") == 0) { |
| 220 |
return reinterpret_cast<PROC>(*realFunction); |
| 221 |
} |
| 222 |
return 0u; |
| 223 |
}; |
| 224 |
void resetParam(const char *name) { |
| 225 |
if (strcmp(name, "glAcquireSharedBufferCalled") == 0) { |
| 226 |
glAcquireSharedBufferCalled = 0; |
| 227 |
} |
| 228 |
if (strcmp(name, "glAcquireSharedRenderBufferCalled") == 0) { |
| 229 |
glAcquireSharedRenderBufferCalled = 0; |
| 230 |
} |
| 231 |
if (strcmp(name, "glAcquireSharedTextureCalled") == 0) { |
| 232 |
glAcquireSharedTextureCalled = 0; |
| 233 |
} |
| 234 |
if (strcmp(name, "glDeleteContextCalled") == 0) { |
| 235 |
glDeleteContextCalled = 0; |
| 236 |
} |
| 237 |
if (strcmp(name, "glGetCurrentContextCalled") == 0) { |
| 238 |
glGetCurrentContextCalled = 0; |
| 239 |
} |
| 240 |
if (strcmp(name, "glGetCurrentDisplayCalled") == 0) { |
| 241 |
glGetCurrentDisplayCalled = 0; |
| 242 |
} |
| 243 |
if (strcmp(name, "glGetSyncivCalled") == 0) { |
| 244 |
glGetSyncivCalled = 0; |
| 245 |
} |
| 246 |
if (strcmp(name, "glMakeCurrentCalled") == 0) { |
| 247 |
glMakeCurrentCalled = 0; |
| 248 |
} |
| 249 |
if (strcmp(name, "glReleaseSharedBufferCalled") == 0) { |
| 250 |
glReleaseSharedBufferCalled = 0; |
| 251 |
} |
| 252 |
if (strcmp(name, "glReleaseSharedRenderBufferCalled") == 0) { |
| 253 |
glReleaseSharedRenderBufferCalled = 0; |
| 254 |
} |
| 255 |
if (strcmp(name, "glReleaseSharedTextureCalled") == 0) { |
| 256 |
glReleaseSharedTextureCalled = 0; |
| 257 |
} |
| 258 |
if (strcmp(name, "glReleaseSyncCalled") == 0) { |
| 259 |
glReleaseSyncCalled = 0; |
| 260 |
} |
| 261 |
if (strcmp(name, "glRetainSyncCalled") == 0) { |
| 262 |
glRetainSyncCalled = 0; |
| 263 |
} |
| 264 |
if (strcmp(name, "wglCreateContextCalled") == 0) { |
| 265 |
wglCreateContextCalled = 0; |
| 266 |
} |
| 267 |
if (strcmp(name, "wglDeleteContextCalled") == 0) { |
| 268 |
wglDeleteContextCalled = 0; |
| 269 |
} |
| 270 |
if (strcmp(name, "wglShareListsCalled") == 0) { |
| 271 |
wglShareListsCalled = 0; |
| 272 |
} |
| 273 |
if (strcmp(name, "") == 0) { |
| 274 |
glAcquireSharedBufferCalled = 0; |
| 275 |
glAcquireSharedRenderBufferCalled = 0; |
| 276 |
glAcquireSharedTextureCalled = 0; |
| 277 |
glDeleteContextCalled = 0; |
| 278 |
glGetCurrentContextCalled = 0; |
| 279 |
glGetCurrentDisplayCalled = 0; |
| 280 |
glGetSyncivCalled = 0; |
| 281 |
glMakeCurrentCalled = 0; |
| 282 |
glReleaseSharedBufferCalled = 0; |
| 283 |
glReleaseSharedRenderBufferCalled = 0; |
| 284 |
glReleaseSharedTextureCalled = 0; |
| 285 |
glReleaseSyncCalled = 0; |
| 286 |
glRetainSyncCalled = 0; |
| 287 |
wglCreateContextCalled = 0; |
| 288 |
wglDeleteContextCalled = 0; |
| 289 |
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; |
| 301 |
} |
| 302 |
}; |
| 303 |
int getParam(const char *name) { |
| 304 |
if (strcmp(name, "glAcquireSharedBufferCalled") == 0) { |
| 305 |
return glAcquireSharedBufferCalled; |
| 306 |
} |
| 307 |
if (strcmp(name, "glAcquireSharedRenderBufferCalled") == 0) { |
| 308 |
return glAcquireSharedRenderBufferCalled; |
| 309 |
} |
| 310 |
if (strcmp(name, "glAcquireSharedTextureCalled") == 0) { |
| 311 |
return glAcquireSharedTextureCalled; |
| 312 |
} |
| 313 |
if (strcmp(name, "glDeleteContextCalled") == 0) { |
| 314 |
return glDeleteContextCalled; |
| 315 |
} |
| 316 |
if (strcmp(name, "glGetCurrentContextCalled") == 0) { |
| 317 |
return glGetCurrentContextCalled; |
| 318 |
} |
| 319 |
if (strcmp(name, "glGetCurrentDisplayCalled") == 0) { |
| 320 |
return glGetCurrentDisplayCalled; |
| 321 |
} |
| 322 |
if (strcmp(name, "glGetSyncivCalled") == 0) { |
| 323 |
return glGetSyncivCalled; |
| 324 |
} |
| 325 |
if (strcmp(name, "glMakeCurrentCalled") == 0) { |
| 326 |
return glMakeCurrentCalled; |
| 327 |
} |
| 328 |
if (strcmp(name, "glReleaseSharedBufferCalled") == 0) { |
| 329 |
return glReleaseSharedBufferCalled; |
| 330 |
} |
| 331 |
if (strcmp(name, "glReleaseSharedRenderBufferCalled") == 0) { |
| 332 |
return glReleaseSharedRenderBufferCalled; |
| 333 |
} |
| 334 |
if (strcmp(name, "glReleaseSharedTextureCalled") == 0) { |
| 335 |
return glReleaseSharedTextureCalled; |
| 336 |
} |
| 337 |
if (strcmp(name, "glReleaseSyncCalled") == 0) { |
| 338 |
return glReleaseSyncCalled; |
| 339 |
} |
| 340 |
if (strcmp(name, "glRetainSyncCalled") == 0) { |
| 341 |
return glRetainSyncCalled; |
| 342 |
} |
| 343 |
if (strcmp(name, "wglCreateContextCalled") == 0) { |
| 344 |
return wglCreateContextCalled; |
| 345 |
} |
| 346 |
if (strcmp(name, "wglDeleteContextCalled") == 0) { |
| 347 |
return wglDeleteContextCalled; |
| 348 |
} |
| 349 |
if (strcmp(name, "wglShareListsCalled") == 0) { |
| 350 |
return wglShareListsCalled; |
| 351 |
} |
| 352 |
if (strcmp(name, "glGetLuidCalled") == 0) { |
| 353 |
return glGetLuidCalled; |
| 354 |
} |
| 355 |
return 0; |
| 356 |
}; |
| 357 |
CL_GL_BUFFER_INFO getBufferInfo() { return bufferInfoInput; }; |
| 358 |
CL_GL_RESOURCE_INFO getTextureInfo() { return textureInfoInput; }; |
| 359 |
void memParam() { |
| 360 |
memset(&bufferInfoInput, 0, sizeof(CL_GL_BUFFER_INFO)); |
| 361 |
memset(&bufferInfoOutput, 0, sizeof(CL_GL_BUFFER_INFO)); |
| 362 |
memset(&textureInfoInput, 0, sizeof(CL_GL_RESOURCE_INFO)); |
| 363 |
memset(&textureInfoOutput, 0, sizeof(CL_GL_RESOURCE_INFO)); |
| 364 |
memset(&glMockReturnedValues, 0, sizeof(NEO::GLMockReturnedValues)); |
| 365 |
}; |
| 366 |
void loadBuffer(CL_GL_BUFFER_INFO buff) { bufferInfoOutput = buff; }; |
| 367 |
void loadTexture(CL_GL_RESOURCE_INFO texture) { textureInfoOutput = texture; }; |
| 368 |
NEO::GLMockReturnedValues getGlMockReturnedValues() { return glMockReturnedValues; }; |
| 369 |
void setGlMockReturnedValues(NEO::GLMockReturnedValues value) { glMockReturnedValues = value; }; |
| 370 |
void setGetSyncivReturnValue(int val) { glMockReturnedValues.syncivRetVal = val; } |
| 371 |
void glSetString(const char *name, unsigned int var) { |
| 372 |
if (var == GL_VENDOR) { |
| 373 |
glString = name; |
| 374 |
} else if (var == GL_VERSION) { |
| 375 |
glVersion = name; |
| 376 |
} |
| 377 |
}; |
| 378 |
void glSetStringi(const char *name, unsigned int index) { arrayStringi[index] = name; }; |
| 379 |
void setGLSetSharedOCLContextStateReturnedValue(GLboolean value) { glSetSharedOCLContextStateReturnedValue = static_cast<GLboolean>(value); }; |
| 380 |
GLboolean getGLSetSharedOCLContextStateReturnedValue() { return glSetSharedOCLContextStateReturnedValue; }; |
| 381 |
} |