Skip to content

Commit

Permalink
linux/clgl: Wait for fence during sync
Browse files Browse the repository at this point in the history
We need to wait for sync to actually be done

Signed-off-by: Sylvain Munaut <[email protected]>
  • Loading branch information
smunaut committed Jan 25, 2024
1 parent b4364cb commit fccda05
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
20 changes: 19 additions & 1 deletion opencl/source/sharings/gl/linux/gl_buffer_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

#include "config.h"

#include <poll.h>
#include <unistd.h>

using namespace NEO;

Buffer *GlBuffer::createSharedGlBuffer(Context *context, cl_mem_flags flags, unsigned int bufferId, cl_int *errcodeRet) {
Expand Down Expand Up @@ -102,18 +105,33 @@ void GlBuffer::synchronizeObject(UpdateData &updateData) {

/* Prepare flush request */
struct mesa_glinterop_export_in objIn = {};
struct mesa_glinterop_flush_out syncOut = {};
int fenceFd = -1;

objIn.version = 2;
objIn.target = GL_ARRAY_BUFFER;
objIn.obj = this->clGlObjectId;

syncOut.version = 1;
syncOut.fence_fd = &fenceFd;

/* Call MESA interop */
int retValue = sharingFunctions->flushObjects(1, &objIn, nullptr);
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,
};
poll(&fp, 1, 1000);
close(fenceFd);

/* Done */
updateData.synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL;
}

Expand Down
20 changes: 19 additions & 1 deletion opencl/source/sharings/gl/linux/gl_texture_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include "config.h"
#include <GL/gl.h>

#include <poll.h>
#include <unistd.h>

namespace NEO {
Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture,
cl_int *errcodeRet) {
Expand Down Expand Up @@ -219,19 +222,34 @@ void GlTexture::synchronizeObject(UpdateData &updateData) {

/* Prepare flush request */
struct mesa_glinterop_export_in texIn = {};
struct mesa_glinterop_flush_out syncOut = {};
int fenceFd = -1;

texIn.version = 2;
texIn.target = this->target;
texIn.obj = this->clGlObjectId;
texIn.miplevel = this->miplevel;

syncOut.version = 1;
syncOut.fence_fd = &fenceFd;

/* Call MESA interop */
int retValue = sharingFunctions->flushObjects(1, &texIn, nullptr);
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,
};
poll(&fp, 1, 1000);
close(fenceFd);

/* Done */
updateData.synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL;
}

Expand Down

0 comments on commit fccda05

Please sign in to comment.