diff --git a/opencl/tests/ocltst/module/common/OCLGLCommon.cpp b/opencl/tests/ocltst/module/common/OCLGLCommon.cpp index affc74d711..dbfe453007 100644 --- a/opencl/tests/ocltst/module/common/OCLGLCommon.cpp +++ b/opencl/tests/ocltst/module/common/OCLGLCommon.cpp @@ -24,7 +24,7 @@ #include void OCLGLCommon::open(unsigned int test, char *units, double &conversion, - unsigned int deviceId) { + unsigned int &deviceId) { // OpenCL Initialization OCLTestImp::open(test, units, conversion, deviceId); CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test (%d)", error_); @@ -51,6 +51,8 @@ void OCLGLCommon::open(unsigned int test, char *units, double &conversion, CHECK_RESULT((retVal == CL_SUCCESS), "Error opening test (%d)", error_); createCLContextFromGLContext(hGL_); + // Device id may change to match the GL context. Return the id to caller + deviceId = _deviceId; } bool OCLGLCommon::IsGLEnabled(unsigned int test, char *units, diff --git a/opencl/tests/ocltst/module/common/OCLGLCommon.h b/opencl/tests/ocltst/module/common/OCLGLCommon.h index f9ed23069a..cc0d45da25 100644 --- a/opencl/tests/ocltst/module/common/OCLGLCommon.h +++ b/opencl/tests/ocltst/module/common/OCLGLCommon.h @@ -45,7 +45,7 @@ class OCLGLCommon : public OCLTestImp { // virtual interface // /////////////////////// virtual void open(unsigned int test, char* units, double& conversion, - unsigned int deviceId); + unsigned int &deviceId); virtual unsigned int close(void); static void gluPerspective(double fovy, double aspect, double zNear, double zFar); diff --git a/opencl/tests/ocltst/module/common/OCLGLCommonLinux.cpp b/opencl/tests/ocltst/module/common/OCLGLCommonLinux.cpp index 07bb9b67c0..ba5a0d8bd4 100644 --- a/opencl/tests/ocltst/module/common/OCLGLCommonLinux.cpp +++ b/opencl/tests/ocltst/module/common/OCLGLCommonLinux.cpp @@ -169,6 +169,21 @@ bool OCLGLCommon::checkAssociationDeviceWithGLContext(OCLGLHandle& hGL) { } } + // If the current device id does not work for CL GL interop, + // fall back to other devices. + if (!ret) { + for (unsigned int i = 0; i < numDevices; i++) { + for (unsigned int j = 0; j < deviceCount_; j++) { + if (interopDevices[i] == devices_[j]) { + // Found an OpenCL device work with current GL context. + _deviceId = j; + ret = true; + break; + } + } + } + } + free(interopDevices); return ret; }