Merge "SWDEV-276625 - Add implicit glFinish() for cl_khr_gl_event" into amd-staging

Этот коммит содержится в:
German Andryeyev
2021-03-23 14:32:21 -04:00
коммит произвёл Gerrit Code Review
родитель 2727d7047a c4cde09339
Коммит f4cc6cf84f
2 изменённых файлов: 49 добавлений и 2 удалений
+31 -1
Просмотреть файл
@@ -1963,11 +1963,18 @@ cl_int clEnqueueAcquireExtObjectsAMD(cl_command_queue command_queue, cl_uint num
amd::HostQueue& hostQueue = *queue;
if (cmd_type == CL_COMMAND_ACQUIRE_GL_OBJECTS) {
GLFunctions* gl_functions = hostQueue.context().glenv();
// Verify context init'ed for interop
if (!hostQueue.context().glenv() || !hostQueue.context().glenv()->isAssociated()) {
if (!gl_functions || !gl_functions->isAssociated()) {
LogWarning("\"amdContext\" is not created from GL context or share list");
return CL_INVALID_CONTEXT;
}
// If the cl_khr_gl_event extension is supported, then the OpenCL implementation will ensure
// that any such pending OpenGL operations are complete for an OpenGL context bound
// to the same thread as the OpenCL context.
if (hostQueue.device().settings().checkExtension(ClKhrGlEvent)) {
gl_functions->WaitCurrentGlContext(hostQueue.context().info());
}
}
std::vector<amd::Memory*> memObjects;
@@ -2082,6 +2089,21 @@ cl_int clEnqueueReleaseExtObjectsAMD(cl_command_queue command_queue, cl_uint num
}
}
#endif //_WIN32
// If the cl_khr_gl_event extension is supported, then the OpenCL implementation will ensure
// that any pending OpenCL operations are complete for an OpenGL context bound
// to the same thread as the OpenCL context.
if (cmd_type == CL_COMMAND_RELEASE_GL_OBJECTS) {
GLFunctions* gl_functions = hostQueue.context().glenv();
// Verify context init'ed for interop
if (!gl_functions || !gl_functions->isAssociated()) {
LogWarning("\"amdContext\" is not created from GL context or share list");
return CL_INVALID_CONTEXT;
}
if (hostQueue.device().settings().checkExtension(ClKhrGlEvent) &&
gl_functions->IsCurrentGlContext(hostQueue.context().info())) {
command->awaitCompletion();
}
}
*not_null(event) = as_cl(&command->event());
@@ -2224,6 +2246,8 @@ GLFunctions::GLFunctions(HMODULE h, bool isEGL)
if (isEGL_) {
GetProcAddress_ = (PFN_xxxGetProcAddress)GETPROCADDRESS(h, "eglGetProcAddress");
eglGetCurrentContext_ = (PFN_eglGetCurrentContext)GETPROCADDRESS(h, "eglGetCurrentContext");
VERIFY_POINTER(eglGetCurrentContext_)
} else {
GetProcAddress_ = (PFN_xxxGetProcAddress)GETPROCADDRESS(h, API_GETPROCADDR);
}
@@ -2299,6 +2323,12 @@ GLFunctions::~GLFunctions() {
#endif //!_WIN32
}
void GLFunctions::WaitCurrentGlContext(const amd::Context::Info& info) const {
if (IsCurrentGlContext(info)) {
glFinish_();
}
}
bool GLFunctions::init(intptr_t hdc, intptr_t hglrc) {
if (isEGL_) {
eglDisplay_ = (EGLDisplay)hdc;
+18 -1
Просмотреть файл
@@ -174,7 +174,7 @@ public:
GLsizei numSamples,
GLenum glCubemapFace = 0)
: Image(amdContext, clType, clFlags, format, width, height, depth,
Format(format).getElementSize() * width,
Format(format).getElementSize() * width,
Format(format).getElementSize() * width * depth)
, GLObject(glTarget, gluiName, gliMipLevel, glInternalFormat,
static_cast<GLint>(width), static_cast<GLint>(height),
@@ -191,6 +191,7 @@ protected:
virtual void initDeviceMemory();
};
typedef EGLContext (*PFN_eglGetCurrentContext) ();
#ifdef _WIN32
#define APICALL WINAPI
#define GETPROCADDRESS GetProcAddress
@@ -263,6 +264,7 @@ private:
EGLContext eglInternalContext_;
EGLContext eglTempContext_;
bool isEGL_;
PFN_eglGetCurrentContext eglGetCurrentContext_;
#ifdef _WIN32
HGLRC hOrigGLRC_;
@@ -307,6 +309,21 @@ public:
GLFunctions(HMODULE h, bool isEGL);
~GLFunctions();
bool IsCurrentGlContext(const amd::Context::Info& info) const {
if (isEGL_) {
return ((info.hCtx_ != nullptr) && (eglGetCurrentContext_ != nullptr) &&
(info.hCtx_ == eglGetCurrentContext_()));
} else {
#ifdef _WIN32
return ((info.hCtx_ != nullptr) && (info.hCtx_ == wglGetCurrentContext_()));
#else
return ((info.hCtx_ != nullptr) && (info.hCtx_ == glXGetCurrentContext_()));
#endif // _WIN32
}
}
void WaitCurrentGlContext(const amd::Context::Info& info) const;
// Query CL-GL context association
bool isAssociated() const
{