diff --git a/hipamd/src/cl_gl.cpp b/hipamd/src/cl_gl.cpp index b3730f61da..241e3f20b1 100644 --- a/hipamd/src/cl_gl.cpp +++ b/hipamd/src/cl_gl.cpp @@ -2283,6 +2283,49 @@ GLFunctions::~GLFunctions() { } #endif //!_WIN32 } +// in case of HIP GL interop we want to make sure we have the updated context +bool GLFunctions::update(intptr_t hglrc) { +#ifdef _WIN32 + DWORD err; + if (hOrigGLRC_ == (HGLRC)hglrc) { + return true; + } + hOrigGLRC_ = (HGLRC)hglrc; + if (hIntGLRC_ != nullptr) { + wglDeleteContext_(hIntGLRC_); + } + if (!(hIntGLRC_ = wglCreateContext_(wglGetCurrentDC_()))) { + err = GetLastError(); + return false; + } + if (!wglShareLists_(hOrigGLRC_, hIntGLRC_)) { + err = GetLastError(); + return false; + } +#else //!_WIN32 + Dpy_ = glXGetCurrentDisplay_(); + Drawable_ = glXGetCurrentDrawable_(); + if (origCtx_ == (GLXContext)hglrc) { + return true; + } + + origCtx_ = (GLXContext)hglrc; + if (intCtx_ != nullptr) { + glXDestroyContext_(Dpy_,intCtx_); + } + + int attribList[] = {GLX_RGBA, None}; + XVisualInfo* vis; + int defaultScreen = DefaultScreen(intDpy_); + if (!(vis = glXChooseVisual_(intDpy_, defaultScreen, attribList))) { + return false; + } + if (!(intCtx_ = glXCreateContext_(intDpy_, vis, origCtx_, true))) { + return false; + } +#endif + return true; +} bool GLFunctions::init(intptr_t hdc, intptr_t hglrc) { if (isEGL_) { diff --git a/hipamd/src/cl_gl_amd.hpp b/hipamd/src/cl_gl_amd.hpp index 86ffbccd78..625082c8f9 100644 --- a/hipamd/src/cl_gl_amd.hpp +++ b/hipamd/src/cl_gl_amd.hpp @@ -310,6 +310,7 @@ public: GLFunctions(HMODULE h, bool isEGL); ~GLFunctions(); + bool update(intptr_t hglrc); bool IsCurrentGlContext(const amd::Context::Info& info) const { if (isEGL_) { return ((info.hCtx_ != nullptr) && (eglGetCurrentContext_ != nullptr) && diff --git a/hipamd/src/hip_gl.cpp b/hipamd/src/hip_gl.cpp index 7282e51636..02ff1c895a 100644 --- a/hipamd/src/hip_gl.cpp +++ b/hipamd/src/hip_gl.cpp @@ -116,8 +116,8 @@ hipError_t hipGLGetDevices(unsigned int* pHipDeviceCount, int* pHipDevices, info.hCtx_ = glenv->glXGetCurrentContext_(); #endif hip::getCurrentDevice()->asContext()->setInfo(info); + glenv->update(reinterpret_cast(info.hCtx_)); } - *pHipDeviceCount = 0; switch (deviceList) { case hipGLDeviceListCurrentFrame: