Remove access to global platform from cl_gl api
Related-To: NEO-4207 Change-Id: I27fd4e824f347820609e5b4d646f2d29301d6542 Signed-off-by: Andrzej Swierczynski <andrzej.swierczynski@intel.com>
This commit is contained in:
parent
2b6fa20e12
commit
6b9d85d2b6
|
@ -316,13 +316,16 @@ cl_int CL_API_CALL clGetGLContextInfoKHR(const cl_context_properties *properties
|
|||
uint32_t GLHDCHandle = 0;
|
||||
uint32_t propertyType = 0;
|
||||
uint32_t propertyValue = 0;
|
||||
Platform *platform = nullptr;
|
||||
|
||||
if (properties != nullptr) {
|
||||
while (*properties != 0) {
|
||||
propertyType = static_cast<uint32_t>(properties[0]);
|
||||
propertyValue = static_cast<uint32_t>(properties[1]);
|
||||
properties += 2;
|
||||
switch (propertyType) {
|
||||
case CL_CONTEXT_PLATFORM: {
|
||||
platform = castToObject<Platform>(reinterpret_cast<cl_platform_id>(properties[1]));
|
||||
} break;
|
||||
case CL_GL_CONTEXT_KHR:
|
||||
GLHGLRCHandle = propertyValue;
|
||||
break;
|
||||
|
@ -330,6 +333,7 @@ cl_int CL_API_CALL clGetGLContextInfoKHR(const cl_context_properties *properties
|
|||
GLHDCHandle = propertyValue;
|
||||
break;
|
||||
}
|
||||
properties += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -346,7 +350,11 @@ cl_int CL_API_CALL clGetGLContextInfoKHR(const cl_context_properties *properties
|
|||
}
|
||||
|
||||
if (paramName == CL_DEVICES_FOR_GL_CONTEXT_KHR || paramName == CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR) {
|
||||
info.set<cl_device_id>(::platform()->getClDevice(0));
|
||||
if (platform) {
|
||||
info.set<cl_device_id>(platform->getClDevice(0));
|
||||
} else {
|
||||
info.set<cl_device_id>(platformsImpl[0]->getClDevice(0));
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,12 @@
|
|||
*/
|
||||
|
||||
#include "shared/source/helpers/hw_info.h"
|
||||
#include "shared/source/os_interface/device_factory.h"
|
||||
|
||||
#include "opencl/source/device/cl_device.h"
|
||||
#include "opencl/test/unit_test/api/cl_api_tests.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_device.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_platform.h"
|
||||
#include "opencl/test/unit_test/os_interface/windows/gl/gl_dll_helper.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
@ -17,7 +20,7 @@ typedef api_tests clGetGLContextInfoKHR_;
|
|||
|
||||
namespace ULT {
|
||||
|
||||
TEST_F(clGetGLContextInfoKHR_, success) {
|
||||
TEST_F(clGetGLContextInfoKHR_, successWithDefaultPlatform) {
|
||||
auto expectedDevice = ::platform()->getClDevice(0);
|
||||
cl_device_id retDevice = 0;
|
||||
size_t retSize = 0;
|
||||
|
@ -36,6 +39,35 @@ TEST_F(clGetGLContextInfoKHR_, success) {
|
|||
EXPECT_EQ(sizeof(cl_device_id), retSize);
|
||||
}
|
||||
|
||||
using clGetGLContextInfoKHRNonDefaultPlatform = ::testing::Test;
|
||||
|
||||
TEST_F(clGetGLContextInfoKHRNonDefaultPlatform, successWithNonDefaultPlatform) {
|
||||
platformsImpl.clear();
|
||||
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
|
||||
auto nonDefaultPlatform = std::make_unique<MockPlatform>();
|
||||
nonDefaultPlatform->initializeWithNewDevices();
|
||||
cl_platform_id nonDefaultPlatformCl = nonDefaultPlatform.get();
|
||||
|
||||
auto expectedDevice = nonDefaultPlatform->getClDevice(0);
|
||||
size_t retSize = 0;
|
||||
cl_device_id retDevice = 0;
|
||||
|
||||
const cl_context_properties properties[] = {CL_GL_CONTEXT_KHR, 1, CL_WGL_HDC_KHR, 2, CL_CONTEXT_PLATFORM, reinterpret_cast<cl_context_properties>(nonDefaultPlatformCl), 0};
|
||||
retVal = clGetGLContextInfoKHR(properties, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, sizeof(cl_device_id), &retDevice, &retSize);
|
||||
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
EXPECT_EQ(expectedDevice, retDevice);
|
||||
EXPECT_EQ(sizeof(cl_device_id), retSize);
|
||||
|
||||
retVal = clGetGLContextInfoKHR(properties, CL_DEVICES_FOR_GL_CONTEXT_KHR, sizeof(cl_device_id), &retDevice, &retSize);
|
||||
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
EXPECT_EQ(expectedDevice, retDevice);
|
||||
EXPECT_EQ(sizeof(cl_device_id), retSize);
|
||||
}
|
||||
|
||||
TEST_F(clGetGLContextInfoKHR_, invalidParam) {
|
||||
cl_device_id retDevice = 0;
|
||||
size_t retSize = 0;
|
||||
|
@ -86,10 +118,6 @@ TEST_F(clGetGLContextInfoKHR_, GivenIncorrectPropertiesWhenCallclGetGLContextInf
|
|||
const cl_context_properties propertiesLackOfCLGlContextKhr[] = {CL_WGL_HDC_KHR, 2, 0};
|
||||
retVal = clGetGLContextInfoKHR(propertiesLackOfCLGlContextKhr, 0, sizeof(cl_device_id), &retDevice, &retSize);
|
||||
EXPECT_EQ(CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR, retVal);
|
||||
|
||||
const cl_context_properties propertiesWithOutRequiredProperties[] = {CL_CONTEXT_PLATFORM, 3, 0};
|
||||
retVal = clGetGLContextInfoKHR(propertiesWithOutRequiredProperties, 0, sizeof(cl_device_id), &retDevice, &retSize);
|
||||
EXPECT_EQ(CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR, retVal);
|
||||
}
|
||||
|
||||
} // namespace ULT
|
||||
|
|
Loading…
Reference in New Issue