From bfbe5a048c2512d0ba27fb0fc5f829a2cac288c2 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Tue, 5 Mar 2024 09:17:45 +0000 Subject: [PATCH] fix: verify retVal from poll function in gl sharing sync on Linux unify logic of synchronization objects add default iniialization of gl context guard members Signed-off-by: Mateusz Jablonski --- opencl/source/sharings/gl/gl_context_guard.h | 8 +++---- .../sharings/gl/linux/gl_buffer_linux.cpp | 21 ++----------------- .../sharings/gl/linux/gl_sharing_linux.cpp | 19 +++++++++++++++++ .../sharings/gl/linux/gl_sharing_linux.h | 1 + .../sharings/gl/linux/gl_texture_linux.cpp | 21 ++----------------- 5 files changed, 28 insertions(+), 42 deletions(-) diff --git a/opencl/source/sharings/gl/gl_context_guard.h b/opencl/source/sharings/gl/gl_context_guard.h index adf54801ef..418972e73b 100644 --- a/opencl/source/sharings/gl/gl_context_guard.h +++ b/opencl/source/sharings/gl/gl_context_guard.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -19,9 +19,9 @@ class GLContextGuard { ~GLContextGuard(); protected: - GLSharingFunctions *sharingFunctions; + GLSharingFunctions *sharingFunctions = nullptr; - GLContext currentContextHandle; - GLDisplay currentDisplayHandle; + GLContext currentContextHandle{}; + GLDisplay currentDisplayHandle{}; }; } // namespace NEO diff --git a/opencl/source/sharings/gl/linux/gl_buffer_linux.cpp b/opencl/source/sharings/gl/linux/gl_buffer_linux.cpp index adc8c6b51e..ac179d96cf 100644 --- a/opencl/source/sharings/gl/linux/gl_buffer_linux.cpp +++ b/opencl/source/sharings/gl/linux/gl_buffer_linux.cpp @@ -10,7 +10,6 @@ #include "shared/source/helpers/get_info.h" #include "shared/source/memory_manager/allocation_properties.h" #include "shared/source/memory_manager/memory_manager.h" -#include "shared/source/os_interface/linux/sys_calls.h" #include "opencl/extensions/public/cl_gl_private_intel.h" #include "opencl/source/cl_device/cl_device.h" @@ -112,24 +111,8 @@ void GlBuffer::synchronizeObject(UpdateData &updateData) { syncOut.version = 1; syncOut.fence_fd = &fenceFd; - /* Call MESA interop */ - int retValue = sharingFunctions->flushObjects(1, &objIn, &syncOut); - if (retValue != MESA_GLINTEROP_SUCCESS) { - updateData.synchronizationStatus = SynchronizeStatus::SYNCHRONIZE_ERROR; - return; - } - - /* Wait on the fence fd */ - struct pollfd fp = { - .fd = fenceFd, - .events = POLLIN, - .revents = 0, - }; - SysCalls::poll(&fp, 1, 1000); - SysCalls::close(fenceFd); - - /* Done */ - updateData.synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL; + bool success = sharingFunctions->flushObjectsAndWait(1, &objIn, &syncOut); + updateData.synchronizationStatus = success ? SynchronizeStatus::ACQUIRE_SUCCESFUL : SynchronizeStatus::SYNCHRONIZE_ERROR; } void GlBuffer::resolveGraphicsAllocationChange(osHandle currentSharedHandle, UpdateData *updateData) { diff --git a/opencl/source/sharings/gl/linux/gl_sharing_linux.cpp b/opencl/source/sharings/gl/linux/gl_sharing_linux.cpp index 5d00b7e188..0dd40cac2d 100644 --- a/opencl/source/sharings/gl/linux/gl_sharing_linux.cpp +++ b/opencl/source/sharings/gl/linux/gl_sharing_linux.cpp @@ -7,6 +7,8 @@ #include "opencl/source/sharings/gl/linux/gl_sharing_linux.h" +#include "shared/source/os_interface/linux/sys_calls.h" + #include "opencl/source/context/context.inl" #include "opencl/source/helpers/gl_helper.h" #include "opencl/source/sharings/gl/gl_arb_sync_event.h" @@ -120,6 +122,23 @@ GLboolean GLSharingFunctionsLinux::initGLFunctions() { return 1; } +bool GLSharingFunctionsLinux::flushObjectsAndWait(unsigned count, struct mesa_glinterop_export_in *resources, struct mesa_glinterop_flush_out *out) { + /* Call MESA interop */ + int retValue = flushObjects(1, resources, out); + if (retValue != MESA_GLINTEROP_SUCCESS) { + return false; + } + auto fenceFd = *out->fence_fd; + /* Wait on the fence fd */ + struct pollfd fp = { + .fd = fenceFd, + .events = POLLIN, + .revents = 0, + }; + retValue = SysCalls::poll(&fp, 1, 1000); + SysCalls::close(fenceFd); + return retValue >= 0; +} template GLSharingFunctionsLinux *Context::getSharing(); diff --git a/opencl/source/sharings/gl/linux/gl_sharing_linux.h b/opencl/source/sharings/gl/linux/gl_sharing_linux.h index ca439cebe3..10c6433cce 100644 --- a/opencl/source/sharings/gl/linux/gl_sharing_linux.h +++ b/opencl/source/sharings/gl/linux/gl_sharing_linux.h @@ -95,6 +95,7 @@ class GLSharingFunctionsLinux : public GLSharingFunctions { return -ENOTSUP; } } + bool flushObjectsAndWait(unsigned count, struct mesa_glinterop_export_in *resources, struct mesa_glinterop_flush_out *out); GLContext getBackupContextHandle() { return glHGLRCHandleBkpCtx; } diff --git a/opencl/source/sharings/gl/linux/gl_texture_linux.cpp b/opencl/source/sharings/gl/linux/gl_texture_linux.cpp index 4dc1e0c5c2..46c04199eb 100644 --- a/opencl/source/sharings/gl/linux/gl_texture_linux.cpp +++ b/opencl/source/sharings/gl/linux/gl_texture_linux.cpp @@ -15,7 +15,6 @@ #include "shared/source/helpers/hw_info.h" #include "shared/source/memory_manager/allocation_properties.h" #include "shared/source/memory_manager/memory_manager.h" -#include "shared/source/os_interface/linux/sys_calls.h" #include "shared/source/os_interface/product_helper.h" #include "opencl/extensions/public/cl_gl_private_intel.h" @@ -230,24 +229,8 @@ void GlTexture::synchronizeObject(UpdateData &updateData) { syncOut.version = 1; syncOut.fence_fd = &fenceFd; - /* Call MESA interop */ - int retValue = sharingFunctions->flushObjects(1, &texIn, &syncOut); - if (retValue != MESA_GLINTEROP_SUCCESS) { - updateData.synchronizationStatus = SynchronizeStatus::SYNCHRONIZE_ERROR; - return; - } - - /* Wait on the fence fd */ - struct pollfd fp = { - .fd = fenceFd, - .events = POLLIN, - .revents = 0, - }; - SysCalls::poll(&fp, 1, 1000); - SysCalls::close(fenceFd); - - /* Done */ - updateData.synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL; + bool success = sharingFunctions->flushObjectsAndWait(1, &texIn, &syncOut); + updateData.synchronizationStatus = success ? SynchronizeStatus::ACQUIRE_SUCCESFUL : SynchronizeStatus::SYNCHRONIZE_ERROR; } cl_int GlTexture::getGlTextureInfo(cl_gl_texture_info paramName, size_t paramValueSize, void *paramValue, size_t *paramValueSizeRet) const {