Files
compute-runtime/opencl/source/sharings/gl/gl_sharing.h
Mateusz Jablonski 4919c7c9fb feature: add experimental support for cl-gl sharing on Linux
based on 'clgl-fork' branch from https://github.com/kallaballa/compute-runtime

EGL headers taken from https://github.com/KhronosGroup/EGL-Registry
revision: 57b4876de0f33677ece92dd9de0ef105ce69139d

Related-To: NEO-3599

Fixes https://github.com/intel/compute-runtime/issues/166

Co-authored-by: Jacek Danecki <jacek.danecki@intel.com>
Co-authored-by: Amir Hassan <amir@viel-zu.org>

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
2023-03-20 12:49:52 +01:00

85 lines
2.4 KiB
C++

/*
* Copyright (C) 2018-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/os_interface/os_library.h"
#include "opencl/source/sharings/sharing.h"
#include "CL/cl.h"
#include "GL/gl.h"
#include "GL/glext.h"
#include <functional>
#include <mutex>
#include <unordered_map>
struct _tagCLGLSyncInfo;
typedef struct _tagCLGLSyncInfo CL_GL_SYNC_INFO, *PCL_GL_SYNC_INFO;
namespace NEO {
class Event;
class GlArbSyncEvent;
class GLSharingFunctions;
class OSInterface;
class OsContext;
class DriverModel;
typedef unsigned int OS_HANDLE;
typedef struct CLGLContextInfo {
OS_HANDLE DeviceHandle;
OS_HANDLE ContextHandle;
} ContextInfo;
class GLSharingFunctions : public SharingFunctions {
public:
GLSharingFunctions() = default;
uint32_t getId() const override {
return GLSharingFunctions::sharingId;
}
static const uint32_t sharingId;
static cl_int getSupportedFormats(cl_mem_flags flags,
cl_mem_object_type imageType,
size_t numEntries,
cl_GLenum *formats,
uint32_t *numImageFormats);
static std::unique_ptr<GLSharingFunctions> create();
virtual bool isHandleCompatible(const DriverModel &driverModel, uint32_t handle) const { return true; }
virtual bool isGlHdcHandleMissing(uint32_t handle) const { return false; }
virtual GLboolean initGLFunctions() = 0;
virtual bool isOpenGlSharingSupported() = 0;
};
class GlSharing : public SharingHandler {
public:
GlSharing(GLSharingFunctions *sharingFunctions, unsigned int glObjectType, unsigned int glObjectId)
: sharingFunctions(sharingFunctions), clGlObjectType(glObjectType), clGlObjectId(glObjectId){};
GLSharingFunctions *peekFunctionsHandler() { return sharingFunctions; }
void getGlObjectInfo(unsigned int *pClGlObjectType, unsigned int *pClGlObjectId) {
if (pClGlObjectType) {
*pClGlObjectType = clGlObjectType;
}
if (pClGlObjectId) {
*pClGlObjectId = clGlObjectId;
}
}
static const std::unordered_map<GLenum, const cl_image_format> glToCLFormats;
protected:
int synchronizeHandler(UpdateData &updateData) override;
GLSharingFunctions *sharingFunctions = nullptr;
unsigned int clGlObjectType = 0u;
unsigned int clGlObjectId = 0u;
};
} // namespace NEO