From ef26fcdbd27adfdc5a563d280fcc077b4e37c5a8 Mon Sep 17 00:00:00 2001 From: "Xie, AlexBin" Date: Fri, 27 Jun 2025 12:25:23 -0400 Subject: [PATCH] SWDEV-530767 ocltst GL test work with GL context on 2nd GPU (#324) Change-Id: Ia3dbc661b3b9b1de71a632969707318f208131cd --- opencl/tests/ocltst/module/common/OCLGLCommon.cpp | 4 +++- opencl/tests/ocltst/module/common/OCLGLCommon.h | 2 +- .../ocltst/module/common/OCLGLCommonLinux.cpp | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) 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; }