Add check that Intel OpenGl is used

before return device_id in clGetGlContextInfoKHR
Change-Id: Ic6dce407a1666909d468d89a8576c907abc63b61
This commit is contained in:
Katarzyna Cencelewska
2019-01-03 16:31:40 +01:00
committed by sys_ocldev
parent cdd77a34fa
commit 72f17d6435
12 changed files with 127 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018 Intel Corporation * Copyright (C) 2018-2019 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -90,12 +90,12 @@ bool GLSharingFunctions::isOpenGlExtensionSupported(const char *pExtensionString
bool GLSharingFunctions::isOpenGlSharingSupported() { bool GLSharingFunctions::isOpenGlSharingSupported() {
const char *Vendor = reinterpret_cast<const char *>(glGetString(GL_VENDOR)); const char *Vendor = reinterpret_cast<const char *>(glGetString(GL_VENDOR));
if ((Vendor == NULL) || (strcmp(Vendor, "Intel") != 0)) { if ((Vendor == nullptr) || (strcmp(Vendor, "Intel") != 0)) {
return false; return false;
} }
const char *Version = reinterpret_cast<const char *>(glGetString(GL_VERSION)); const char *Version = reinterpret_cast<const char *>(glGetString(GL_VERSION));
if (Version == NULL) { if (Version == nullptr) {
return false; return false;
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018 Intel Corporation * Copyright (C) 2018-2019 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -21,6 +21,7 @@
#include "runtime/mem_obj/mem_obj.h" #include "runtime/mem_obj/mem_obj.h"
#include "runtime/platform/platform.h" #include "runtime/platform/platform.h"
#include "runtime/sharings/gl/gl_buffer.h" #include "runtime/sharings/gl/gl_buffer.h"
#include "runtime/sharings/gl/gl_sharing.h"
#include "runtime/sharings/gl/gl_sync_event.h" #include "runtime/sharings/gl/gl_sync_event.h"
#include "runtime/sharings/gl/gl_texture.h" #include "runtime/sharings/gl/gl_texture.h"
#include "runtime/utilities/api_intercept.h" #include "runtime/utilities/api_intercept.h"
@@ -297,10 +298,18 @@ cl_int CL_API_CALL clGetGLContextInfoKHR(const cl_context_properties *properties
return retVal; return retVal;
} }
std::unique_ptr<GLSharingFunctions> glSharing(new GLSharingFunctions);
glSharing->initGLFunctions();
if (glSharing->isOpenGlSharingSupported() == false) {
retVal = CL_INVALID_CONTEXT;
return retVal;
}
if (paramName == CL_DEVICES_FOR_GL_CONTEXT_KHR || paramName == CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR) { if (paramName == CL_DEVICES_FOR_GL_CONTEXT_KHR || paramName == CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR) {
info.set<cl_device_id>(::platform()->getDevice(0)); info.set<cl_device_id>(::platform()->getDevice(0));
return retVal; return retVal;
} }
retVal = CL_INVALID_VALUE; retVal = CL_INVALID_VALUE;
return retVal; return retVal;
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018 Intel Corporation * Copyright (C) 2018-2019 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018 Intel Corporation * Copyright (C) 2018-2019 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -9,6 +9,7 @@
#include "runtime/helpers/options.h" #include "runtime/helpers/options.h"
#include "runtime/helpers/hw_info.h" #include "runtime/helpers/hw_info.h"
#include "unit_tests/api/cl_api_tests.h" #include "unit_tests/api/cl_api_tests.h"
#include "unit_tests/os_interface/windows/gl/gl_dll_helper.h"
using namespace OCLRT; using namespace OCLRT;
@@ -46,6 +47,32 @@ TEST_F(clGetGLContextInfoKHR_, invalidParam) {
EXPECT_EQ(0u, retSize); EXPECT_EQ(0u, retSize);
} }
TEST_F(clGetGLContextInfoKHR_, givenContextFromNoIntelOpenGlDriverWhenCallClGetGLContextInfoKHRThenReturnClInvalidContext) {
cl_device_id retDevice = 0;
size_t retSize = 0;
const cl_context_properties properties[] = {CL_GL_CONTEXT_KHR, 1, CL_WGL_HDC_KHR, 2, 0};
glDllHelper setDllParam;
setDllParam.glSetString("NoIntel", GL_VENDOR);
retVal = clGetGLContextInfoKHR(properties, 0, sizeof(cl_device_id), &retDevice, &retSize);
EXPECT_EQ(CL_INVALID_CONTEXT, retVal);
EXPECT_EQ(nullptr, retDevice);
EXPECT_EQ(0u, retSize);
}
TEST_F(clGetGLContextInfoKHR_, givenNullVersionFromIntelOpenGlDriverWhenCallClGetGLContextInfoKHRThenReturnClInvalidContext) {
cl_device_id retDevice = 0;
size_t retSize = 0;
const cl_context_properties properties[] = {CL_GL_CONTEXT_KHR, 1, CL_WGL_HDC_KHR, 2, 0};
glDllHelper setDllParam;
setDllParam.glSetString("", GL_VERSION);
retVal = clGetGLContextInfoKHR(properties, 0, sizeof(cl_device_id), &retDevice, &retSize);
EXPECT_EQ(CL_INVALID_CONTEXT, retVal);
EXPECT_EQ(nullptr, retDevice);
EXPECT_EQ(0u, retSize);
}
TEST_F(clGetGLContextInfoKHR_, GivenIncorrectPropertiesWhenCallclGetGLContextInfoKHRThenReturnClInvalidGlShareGroupRererencKhr) { TEST_F(clGetGLContextInfoKHR_, GivenIncorrectPropertiesWhenCallclGetGLContextInfoKHRThenReturnClInvalidGlShareGroupRererencKhr) {
cl_device_id retDevice = 0; cl_device_id retDevice = 0;
size_t retSize = 0; size_t retSize = 0;

View File

@@ -58,6 +58,7 @@ set(IGDRCL_SRCS_tests_helpers_windows
${CMAKE_CURRENT_SOURCE_DIR}/windows/kmd_notify_windows_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/windows/kmd_notify_windows_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/windows/gl_helper_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/windows/gl_helper_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/windows/mock_function.h ${CMAKE_CURRENT_SOURCE_DIR}/windows/mock_function.h
${CMAKE_CURRENT_SOURCE_DIR}/windows/mock_function.cpp
) )
set(IGDRCL_SRCS_tests_helpers_linux set(IGDRCL_SRCS_tests_helpers_linux

View File

@@ -0,0 +1,10 @@
/*
* Copyright (C) 2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "mock_function.h"
const char *realFunction() { return "value"; }

View File

@@ -1,8 +1,8 @@
/* /*
* Copyright (C) 2018 Intel Corporation * Copyright (C) 2019 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
*/ */
const char *realFunction() { return "value"; } const char *realFunction();

View File

@@ -1,5 +1,5 @@
# #
# Copyright (C) 2017-2018 Intel Corporation # Copyright (C) 2017-2019 Intel Corporation
# #
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
# #
@@ -16,9 +16,13 @@ if(WIN32)
set(IGDRCL_SRCS_mock_opengl32 set(IGDRCL_SRCS_mock_opengl32
${CMAKE_CURRENT_SOURCE_DIR}/mock_opengl32.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_opengl32.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_opengl32.def ${CMAKE_CURRENT_SOURCE_DIR}/mock_opengl32.def
${IGDRCL_SOURCE_DIR}/unit_tests/helpers/windows/mock_function.cpp
) )
add_library(mock_opengl32 SHARED ${IGDRCL_SRCS_mock_opengl32}) add_library(mock_opengl32 SHARED ${IGDRCL_SRCS_mock_opengl32})
add_dependencies(unit_tests mock_opengl32) add_dependencies(unit_tests mock_opengl32)
set_target_properties(mock_opengl32 PROPERTIES FOLDER "test mocks") set_target_properties(mock_opengl32 PROPERTIES FOLDER "test mocks")
target_include_directories(mock_opengl32 PRIVATE $<TARGET_PROPERTY:${NEO_MOCKABLE_LIB_NAME},INTERFACE_INCLUDE_DIRECTORIES>)
target_compile_definitions(mock_opengl32 PRIVATE $<TARGET_PROPERTY:${NEO_MOCKABLE_LIB_NAME},INTERFACE_COMPILE_DEFINITIONS>)
endif() endif()

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018 Intel Corporation * Copyright (C) 2018-2019 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -7,9 +7,33 @@
#include <string.h> #include <string.h>
#include "unit_tests/helpers/windows/mock_function.h" #include "unit_tests/helpers/windows/mock_function.h"
#include "GL/gl.h"
#undef wglGetProcAddress
#pragma warning(disable : 4273)
extern "C" { extern "C" {
void *__stdcall wglGetProcAddress(const char *name) { return nullptr; } const char *glString = "Intel";
const char *glVersion = "4.0";
const unsigned char *_stdcall glGetString(unsigned int name) {
if (name == GL_VENDOR)
return reinterpret_cast<const unsigned char *>(glString);
if (name == GL_VERSION)
return reinterpret_cast<const unsigned char *>(glVersion);
return reinterpret_cast<const unsigned char *>("");
};
void glSetString(const char *name, unsigned int var) {
if (var == GL_VENDOR) {
glString = name;
} else if (var == GL_VERSION) {
glVersion = name;
}
};
PROC WINAPI wglGetProcAddress(LPCSTR name) {
return nullptr;
}
void *__stdcall mockLoader(const char *name) { void *__stdcall mockLoader(const char *name) {
if (strcmp(name, "realFunction") == 0) { if (strcmp(name, "realFunction") == 0) {
return *realFunction; return *realFunction;

View File

@@ -20,5 +20,7 @@
LIBRARY "gdi32_mock" LIBRARY "gdi32_mock"
EXPORTS EXPORTS
glGetString
wglGetProcAddress wglGetProcAddress
glSetString
mockLoader mockLoader

View File

@@ -1,5 +1,5 @@
# #
# Copyright (C) 2017-2018 Intel Corporation # Copyright (C) 2017-2019 Intel Corporation
# #
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
# #
@@ -9,6 +9,7 @@ if(WIN32)
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/gl_os_sharing_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gl_os_sharing_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gl_options.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gl_options.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gl_dll_helper.h
) )
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_os_interface_windows_gl}) target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_os_interface_windows_gl})
endif() endif()

View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "runtime/os_interface/os_library.h"
#include "Gl/gl.h"
using namespace OCLRT;
namespace Os {
extern const char *openglDllName;
}
typedef void (*GLString)(const char *, unsigned int);
struct glDllHelper {
public:
glDllHelper() {
glDllLoad.reset(OsLibrary::load(Os::openglDllName));
if (glDllLoad) {
glSetString = (*glDllLoad)["glSetString"];
UNRECOVERABLE_IF(glSetString == nullptr);
}
}
~glDllHelper() {
if (glDllLoad) {
glSetString("Intel", GL_VENDOR);
glSetString("4.0", GL_VERSION);
}
}
GLString glSetString = nullptr;
private:
std::unique_ptr<OsLibrary> glDllLoad;
};