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 <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski 2024-03-05 09:17:45 +00:00 committed by Compute-Runtime-Automation
parent 5f7e56e78b
commit bfbe5a048c
5 changed files with 28 additions and 42 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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<GLSharingFunctionsLinux>();

View File

@ -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;
}

View File

@ -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 {