mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 14:55:24 +08:00
Revert "feature: add experimental support for cl-gl sharing on Linux"
This reverts commit 9b35ba5e50.
Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
a1e2eca9e8
commit
e118e35290
@@ -30,7 +30,6 @@ set(RUNTIME_SRCS_HELPERS_BASE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/enqueue_properties.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/error_mappers.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/get_info_status_mapper.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_helper.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gmm_types_converter.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gmm_types_converter.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/hardware_commands_helper.h
|
||||
@@ -62,7 +61,14 @@ if(SUPPORT_PVC_AND_LATER)
|
||||
list(APPEND RUNTIME_SRCS_HELPERS_BASE ${CMAKE_CURRENT_SOURCE_DIR}/cl_gfx_core_helper_pvc_and_later.inl)
|
||||
endif()
|
||||
|
||||
set(RUNTIME_SRCS_HELPERS_WINDOWS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/windows/gl_helper.h
|
||||
)
|
||||
|
||||
target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_HELPERS_BASE})
|
||||
if(WIN32)
|
||||
target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_HELPERS_WINDOWS})
|
||||
endif()
|
||||
|
||||
set_property(GLOBAL PROPERTY RUNTIME_SRCS_HELPERS_BASE ${RUNTIME_SRCS_HELPERS_BASE})
|
||||
|
||||
|
||||
@@ -5,23 +5,30 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shared/source/os_interface/os_library.h"
|
||||
|
||||
#include "GL/gl.h"
|
||||
#include "gl_types.h"
|
||||
|
||||
namespace Os {
|
||||
extern const char *openglDllName;
|
||||
}
|
||||
|
||||
namespace NEO {
|
||||
class GlFunctionHelper {
|
||||
public:
|
||||
GlFunctionHelper(OsLibrary *glLibrary, const std::string &functionName) {
|
||||
GlFunctionHelper::GlFunctionHelper(OsLibrary *glLibrary, const std::string &functionName) {
|
||||
glFunctionPtr = (*glLibrary)[functionName];
|
||||
}
|
||||
|
||||
ConvertibleProcAddr operator[](const char *name) {
|
||||
return ConvertibleProcAddr{reinterpret_cast<void *>(glFunctionPtr(name))};
|
||||
return ConvertibleProcAddr{glFunctionPtr(name)};
|
||||
}
|
||||
|
||||
protected:
|
||||
GLFunctionType glFunctionPtr = nullptr;
|
||||
// clang-format off
|
||||
PROC(__stdcall *glFunctionPtr)(LPCSTR arg1) = nullptr;
|
||||
// clang-format on
|
||||
};
|
||||
}; // namespace NEO
|
||||
@@ -17,10 +17,6 @@ target_include_directories(${SHARINGS_ENABLE_LIB_NAME} PRIVATE
|
||||
${THIRD_PARTY_DIR}
|
||||
)
|
||||
|
||||
if(UNIX AND NOT DISABLE_WDDM_LINUX)
|
||||
target_include_directories(${SHARINGS_ENABLE_LIB_NAME} PUBLIC ${WDK_INCLUDE_PATHS})
|
||||
endif()
|
||||
|
||||
set(RUNTIME_SRCS_SHARINGS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sharing.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sharing.h
|
||||
|
||||
@@ -4,23 +4,23 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
set(RUNTIME_SRCS_SHARINGS_GL
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cl_gl_api_intel.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cl_gl_api.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_arb_sync_event.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_buffer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_cl_image_format.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_context_guard.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_sync_event.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_texture.h
|
||||
)
|
||||
target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_SHARINGS_GL})
|
||||
|
||||
add_subdirectories()
|
||||
if(WIN32)
|
||||
set(RUNTIME_SRCS_SHARINGS_GL
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cl_gl_api_intel.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_arb_sync_event.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_buffer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_cl_image_format.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_context_guard.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_sync_event.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_texture.h
|
||||
)
|
||||
target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_SHARINGS_GL})
|
||||
|
||||
add_subdirectories()
|
||||
|
||||
set(ADDITIONAL_EXPORTS
|
||||
"clEnqueueMarkerWithSyncObjectINTEL"
|
||||
"clGetCLObjectInfoINTEL"
|
||||
|
||||
@@ -28,7 +28,6 @@ class GlArbSyncEvent;
|
||||
class GLSharingFunctions;
|
||||
class OSInterface;
|
||||
class OsContext;
|
||||
class DriverModel;
|
||||
|
||||
typedef unsigned int OS_HANDLE;
|
||||
|
||||
@@ -52,9 +51,6 @@ class GLSharingFunctions : public SharingFunctions {
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -37,7 +37,6 @@ class GlTexture : GlSharing {
|
||||
static uint32_t getClObjectType(cl_GLenum glType, bool returnClGlObjectType);
|
||||
|
||||
void releaseResource(MemObj *memObject, uint32_t rootDeviceIndex) override;
|
||||
void resolveGraphicsAllocationChange(osHandle currentSharedHandle, UpdateData *updateData) override;
|
||||
|
||||
cl_GLenum target;
|
||||
cl_GLint miplevel;
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
if(UNIX)
|
||||
|
||||
set(RUNTIME_SRCS_SHARINGS_GL_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cl_gl_api_helper.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/gl_types.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lin_enable_gl.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_arb_sync_event_linux.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_buffer_linux.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_context_guard_linux.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_library_linux.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing_linux.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing_linux.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_sync_event_linux.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_texture_linux.cpp
|
||||
)
|
||||
|
||||
target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_SHARINGS_GL_LINUX})
|
||||
|
||||
set(RUNTIME_SRCS_SHARINGS_GL_ENABLE_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lin_enable_gl.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lin_enable_gl.h
|
||||
)
|
||||
target_sources(${SHARINGS_ENABLE_LIB_NAME} PRIVATE ${RUNTIME_SRCS_SHARINGS_GL_ENABLE_LINUX})
|
||||
endif()
|
||||
@@ -1,15 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "opencl/source/sharings/gl/linux/gl_sharing_linux.h"
|
||||
|
||||
namespace NEO {
|
||||
std::unique_ptr<GLSharingFunctions> GLSharingFunctions::create() {
|
||||
return std::make_unique<GLSharingFunctionsLinux>();
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/command_stream/command_stream_receiver.h"
|
||||
#include "shared/source/device/device.h"
|
||||
#include "shared/source/os_interface/os_interface.h"
|
||||
|
||||
#include "opencl/extensions/public/cl_gl_private_intel.h"
|
||||
#include "opencl/source/command_queue/command_queue.h"
|
||||
#include "opencl/source/context/context.h"
|
||||
#include "opencl/source/helpers/base_object.h"
|
||||
#include "opencl/source/sharings/gl/gl_arb_sync_event.h"
|
||||
#include "opencl/source/sharings/gl/linux/gl_sharing_linux.h"
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
void cleanupArbSyncObject(OSInterface &osInterface, CL_GL_SYNC_INFO *glSyncInfo) {}
|
||||
|
||||
bool setupArbSyncObject(GLSharingFunctions &sharing, OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void signalArbSyncObject(OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo) {}
|
||||
|
||||
void serverWaitForArbSyncObject(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) {}
|
||||
|
||||
GlArbSyncEvent::GlArbSyncEvent(Context &context)
|
||||
: Event(&context, nullptr, CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR, CompletionStamp::notReady, CompletionStamp::notReady),
|
||||
glSyncInfo(std::make_unique<CL_GL_SYNC_INFO>()) {
|
||||
}
|
||||
|
||||
bool GlArbSyncEvent::setBaseEvent(Event &ev) {
|
||||
UNRECOVERABLE_IF(this->baseEvent != nullptr);
|
||||
UNRECOVERABLE_IF(ev.getContext() == nullptr);
|
||||
UNRECOVERABLE_IF(ev.getCommandQueue() == nullptr);
|
||||
auto cmdQueue = ev.getCommandQueue();
|
||||
auto osInterface = cmdQueue->getGpgpuCommandStreamReceiver().getOSInterface();
|
||||
UNRECOVERABLE_IF(osInterface == nullptr);
|
||||
if (false == ctx->getSharing<GLSharingFunctionsLinux>()->glArbSyncObjectSetup(*osInterface, *glSyncInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->baseEvent = &ev;
|
||||
this->cmdQueue = cmdQueue;
|
||||
this->cmdQueue->incRefInternal();
|
||||
this->baseEvent->incRefInternal();
|
||||
this->osInterface = osInterface;
|
||||
ev.addChild(*this);
|
||||
return true;
|
||||
}
|
||||
|
||||
GlArbSyncEvent::~GlArbSyncEvent() {
|
||||
if (baseEvent != nullptr) {
|
||||
ctx->getSharing<GLSharingFunctionsLinux>()->glArbSyncObjectCleanup(*osInterface, glSyncInfo.get());
|
||||
baseEvent->decRefInternal();
|
||||
}
|
||||
}
|
||||
|
||||
GlArbSyncEvent *GlArbSyncEvent::create(Event &baseEvent) {
|
||||
if (baseEvent.getContext() == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
auto arbSyncEvent = new GlArbSyncEvent(*baseEvent.getContext());
|
||||
if (false == arbSyncEvent->setBaseEvent(baseEvent)) {
|
||||
delete arbSyncEvent;
|
||||
arbSyncEvent = nullptr;
|
||||
}
|
||||
|
||||
return arbSyncEvent;
|
||||
}
|
||||
|
||||
void GlArbSyncEvent::unblockEventBy(Event &event, TaskCountType taskLevel, int32_t transitionStatus) {
|
||||
DEBUG_BREAK_IF(&event != this->baseEvent);
|
||||
if ((transitionStatus > CL_SUBMITTED) || (transitionStatus < 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->getSharing<GLSharingFunctionsLinux>()->glArbSyncObjectSignal(event.getCommandQueue()->getGpgpuCommandStreamReceiver().getOsContext(), *glSyncInfo);
|
||||
ctx->getSharing<GLSharingFunctionsLinux>()->glArbSyncObjectWaitServer(*osInterface, *glSyncInfo);
|
||||
}
|
||||
} // namespace NEO
|
||||
|
||||
extern "C" CL_API_ENTRY cl_int CL_API_CALL
|
||||
clEnqueueMarkerWithSyncObjectINTEL(cl_command_queue commandQueue,
|
||||
cl_event *event,
|
||||
cl_context *context) {
|
||||
return CL_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
extern "C" CL_API_ENTRY cl_int CL_API_CALL
|
||||
clGetCLObjectInfoINTEL(cl_mem memObj,
|
||||
void *pResourceInfo) {
|
||||
return CL_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
extern "C" CL_API_ENTRY cl_int CL_API_CALL
|
||||
clGetCLEventInfoINTEL(cl_event event, PCL_GL_SYNC_INFO *pSyncInfoHandleRet, cl_context *pClContextRet) {
|
||||
if ((nullptr == pSyncInfoHandleRet) || (nullptr == pClContextRet)) {
|
||||
return CL_INVALID_ARG_VALUE;
|
||||
}
|
||||
|
||||
auto neoEvent = NEO::castToObject<NEO::Event>(event);
|
||||
if (nullptr == neoEvent) {
|
||||
return CL_INVALID_EVENT;
|
||||
}
|
||||
|
||||
if (neoEvent->getCommandType() != CL_COMMAND_RELEASE_GL_OBJECTS) {
|
||||
*pSyncInfoHandleRet = nullptr;
|
||||
*pClContextRet = static_cast<cl_context>(neoEvent->getContext());
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
auto sharing = neoEvent->getContext()->getSharing<NEO::GLSharingFunctionsLinux>();
|
||||
if (sharing == nullptr) {
|
||||
return CL_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
NEO::GlArbSyncEvent *arbSyncEvent = sharing->getOrCreateGlArbSyncEvent(*neoEvent);
|
||||
if (nullptr == arbSyncEvent) {
|
||||
return CL_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
neoEvent->updateExecutionStatus();
|
||||
CL_GL_SYNC_INFO *syncInfo = arbSyncEvent->getSyncInfo();
|
||||
*pSyncInfoHandleRet = syncInfo;
|
||||
*pClContextRet = static_cast<cl_context>(neoEvent->getContext());
|
||||
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
extern "C" CL_API_ENTRY cl_int CL_API_CALL
|
||||
clReleaseGlSharedEventINTEL(cl_event event) {
|
||||
auto neoEvent = NEO::castToObject<NEO::Event>(event);
|
||||
if (nullptr == neoEvent) {
|
||||
return CL_INVALID_EVENT;
|
||||
}
|
||||
auto arbSyncEvent = neoEvent->getContext()->getSharing<NEO::GLSharingFunctionsLinux>()->getGlArbSyncEvent(*neoEvent);
|
||||
neoEvent->getContext()->getSharing<NEO::GLSharingFunctionsLinux>()->removeGlArbSyncEventMapping(*neoEvent);
|
||||
if (nullptr != arbSyncEvent) {
|
||||
arbSyncEvent->release();
|
||||
}
|
||||
neoEvent->release();
|
||||
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
@@ -1,181 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/execution_environment/root_device_environment.h"
|
||||
#include "shared/source/gmm_helper/gmm.h"
|
||||
#include "shared/source/helpers/get_info.h"
|
||||
#include "shared/source/memory_manager/allocation_properties.h"
|
||||
#include "shared/source/memory_manager/memory_manager.h"
|
||||
|
||||
#include "opencl/extensions/public/cl_gl_private_intel.h"
|
||||
#include "opencl/source/cl_device/cl_device.h"
|
||||
#include "opencl/source/context/context.h"
|
||||
#include "opencl/source/mem_obj/buffer.h"
|
||||
#include "opencl/source/sharings/gl/gl_buffer.h"
|
||||
#include "opencl/source/sharings/gl/linux/gl_sharing_linux.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
Buffer *GlBuffer::createSharedGlBuffer(Context *context, cl_mem_flags flags, unsigned int bufferId, cl_int *errcodeRet) {
|
||||
ErrorCodeHelper errorCode(errcodeRet, CL_SUCCESS);
|
||||
CL_GL_BUFFER_INFO bufferInfo = {0};
|
||||
bufferInfo.bufferName = bufferId;
|
||||
|
||||
GLSharingFunctionsLinux *sharingFunctions = context->getSharing<GLSharingFunctionsLinux>();
|
||||
if (sharingFunctions->acquireSharedBufferINTEL(&bufferInfo) == GL_FALSE) {
|
||||
errorCode.set(CL_INVALID_GL_OBJECT);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto graphicsAllocation = GlBuffer::createGraphicsAllocation(context, bufferId, bufferInfo);
|
||||
if (!graphicsAllocation) {
|
||||
errorCode.set(CL_INVALID_GL_OBJECT);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto glHandler = new GlBuffer(sharingFunctions, bufferId);
|
||||
auto rootDeviceIndex = graphicsAllocation->getRootDeviceIndex();
|
||||
auto multiGraphicsAllocation = MultiGraphicsAllocation(rootDeviceIndex);
|
||||
multiGraphicsAllocation.addAllocation(graphicsAllocation);
|
||||
|
||||
return Buffer::createSharedBuffer(context, flags, glHandler, std::move(multiGraphicsAllocation));
|
||||
}
|
||||
|
||||
void GlBuffer::synchronizeObject(UpdateData &updateData) {
|
||||
auto sharingFunctions = static_cast<GLSharingFunctionsLinux *>(this->sharingFunctions);
|
||||
|
||||
CL_GL_BUFFER_INFO bufferInfo = {};
|
||||
bufferInfo.bufferName = this->clGlObjectId;
|
||||
sharingFunctions->acquireSharedBufferINTEL(&bufferInfo);
|
||||
|
||||
auto graphicsAllocation = updateData.memObject->getGraphicsAllocation(updateData.rootDeviceIndex);
|
||||
|
||||
updateData.sharedHandle = bufferInfo.globalShareHandle;
|
||||
updateData.synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL;
|
||||
graphicsAllocation->setAllocationOffset(bufferInfo.bufferOffset);
|
||||
|
||||
const auto currentSharedHandle = graphicsAllocation->peekSharedHandle();
|
||||
if (currentSharedHandle != updateData.sharedHandle) {
|
||||
updateData.updateData = new CL_GL_BUFFER_INFO(bufferInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void GlBuffer::resolveGraphicsAllocationChange(osHandle currentSharedHandle, UpdateData *updateData) {
|
||||
const auto memObject = updateData->memObject;
|
||||
if (currentSharedHandle != updateData->sharedHandle) {
|
||||
const auto bufferInfo = std::unique_ptr<CL_GL_BUFFER_INFO>(static_cast<CL_GL_BUFFER_INFO *>(updateData->updateData));
|
||||
|
||||
auto oldGraphicsAllocation = memObject->getGraphicsAllocation(updateData->rootDeviceIndex);
|
||||
popGraphicsAllocationFromReuse(oldGraphicsAllocation);
|
||||
|
||||
Context *context = memObject->getContext();
|
||||
auto newGraphicsAllocation = createGraphicsAllocation(context, clGlObjectId, *bufferInfo);
|
||||
if (newGraphicsAllocation == nullptr) {
|
||||
updateData->synchronizationStatus = SynchronizeStatus::SYNCHRONIZE_ERROR;
|
||||
memObject->removeGraphicsAllocation(updateData->rootDeviceIndex);
|
||||
} else {
|
||||
updateData->synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL;
|
||||
memObject->resetGraphicsAllocation(newGraphicsAllocation);
|
||||
}
|
||||
|
||||
if (updateData->synchronizationStatus == SynchronizeStatus::ACQUIRE_SUCCESFUL) {
|
||||
memObject->getGraphicsAllocation(updateData->rootDeviceIndex)->setAllocationOffset(bufferInfo->bufferOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GlBuffer::popGraphicsAllocationFromReuse(GraphicsAllocation *graphicsAllocation) {
|
||||
auto sharingFunctions = static_cast<GLSharingFunctionsLinux *>(this->sharingFunctions);
|
||||
|
||||
std::unique_lock<std::mutex> lock(sharingFunctions->mutex);
|
||||
|
||||
auto &graphicsAllocations = sharingFunctions->graphicsAllocationsForGlBufferReuse;
|
||||
auto foundIter = std::find_if(graphicsAllocations.begin(), graphicsAllocations.end(),
|
||||
[&graphicsAllocation](const std::pair<unsigned int, GraphicsAllocation *> &entry) {
|
||||
return entry.second == graphicsAllocation;
|
||||
});
|
||||
if (foundIter != graphicsAllocations.end()) {
|
||||
std::iter_swap(foundIter, graphicsAllocations.end() - 1);
|
||||
graphicsAllocations.pop_back();
|
||||
}
|
||||
graphicsAllocation->decReuseCount();
|
||||
}
|
||||
|
||||
void GlBuffer::releaseReusedGraphicsAllocation() {
|
||||
auto sharingFunctions = static_cast<GLSharingFunctionsLinux *>(this->sharingFunctions);
|
||||
|
||||
std::unique_lock<std::mutex> lock(sharingFunctions->mutex);
|
||||
|
||||
auto &allocationsVector = sharingFunctions->graphicsAllocationsForGlBufferReuse;
|
||||
auto itEnd = allocationsVector.end();
|
||||
for (auto it = allocationsVector.begin(); it != itEnd; it++) {
|
||||
if (it->first == clGlObjectId) {
|
||||
it->second->decReuseCount();
|
||||
if (it->second->peekReuseCount() == 0) {
|
||||
std::iter_swap(it, itEnd - 1);
|
||||
allocationsVector.pop_back();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GraphicsAllocation *GlBuffer::createGraphicsAllocation(Context *context, unsigned int bufferId, _tagCLGLBufferInfo &bufferInfo) {
|
||||
GLSharingFunctionsLinux *sharingFunctions = context->getSharing<GLSharingFunctionsLinux>();
|
||||
auto &allocationsVector = sharingFunctions->graphicsAllocationsForGlBufferReuse;
|
||||
GraphicsAllocation *graphicsAllocation = nullptr;
|
||||
bool reusedAllocation = false;
|
||||
|
||||
std::unique_lock<std::mutex> lock(sharingFunctions->mutex);
|
||||
auto endIter = allocationsVector.end();
|
||||
|
||||
auto foundIter =
|
||||
std::find_if(allocationsVector.begin(), endIter,
|
||||
[&bufferId](const std::pair<unsigned int, GraphicsAllocation *> &entry) { return entry.first == bufferId; });
|
||||
|
||||
if (foundIter != endIter) {
|
||||
graphicsAllocation = foundIter->second;
|
||||
reusedAllocation = true;
|
||||
}
|
||||
|
||||
if (!graphicsAllocation) {
|
||||
AllocationProperties properties = {context->getDevice(0)->getRootDeviceIndex(),
|
||||
false, // allocateMemory
|
||||
0u, // size
|
||||
AllocationType::SHARED_BUFFER,
|
||||
false, // isMultiStorageAllocation
|
||||
context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())};
|
||||
// couldn't find allocation for reuse - create new
|
||||
graphicsAllocation =
|
||||
context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(bufferInfo.globalShareHandle, properties, true, false, false);
|
||||
}
|
||||
|
||||
if (!graphicsAllocation) {
|
||||
return nullptr;
|
||||
}
|
||||
graphicsAllocation->incReuseCount(); // decremented in releaseReusedGraphicsAllocation() called from MemObj destructor
|
||||
|
||||
if (!reusedAllocation) {
|
||||
sharingFunctions->graphicsAllocationsForGlBufferReuse.push_back(std::make_pair(bufferId, graphicsAllocation));
|
||||
if (bufferInfo.pGmmResInfo) {
|
||||
DEBUG_BREAK_IF(graphicsAllocation->getDefaultGmm() != nullptr);
|
||||
auto helper = context->getDevice(0)->getRootDeviceEnvironment().getGmmHelper();
|
||||
graphicsAllocation->setDefaultGmm(new Gmm(helper, bufferInfo.pGmmResInfo));
|
||||
}
|
||||
}
|
||||
|
||||
return graphicsAllocation;
|
||||
}
|
||||
|
||||
void GlBuffer::releaseResource(MemObj *memObject, uint32_t rootDeviceIndex) {
|
||||
auto sharingFunctions = static_cast<GLSharingFunctionsLinux *>(this->sharingFunctions);
|
||||
CL_GL_BUFFER_INFO bufferInfo = {};
|
||||
bufferInfo.bufferName = this->clGlObjectId;
|
||||
sharingFunctions->releaseSharedBufferINTEL(&bufferInfo);
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "opencl/source/sharings/gl/gl_context_guard.h"
|
||||
#include "opencl/source/sharings/gl/linux/gl_sharing_linux.h"
|
||||
|
||||
namespace NEO {
|
||||
GLContextGuard::GLContextGuard(GLSharingFunctions &sharingFcns) : sharingFunctions(&sharingFcns) {
|
||||
auto &sharing = *static_cast<GLSharingFunctionsLinux *>(sharingFunctions);
|
||||
|
||||
currentContextHandle = sharing.getCurrentContext();
|
||||
currentDisplayHandle = sharing.getCurrentDisplay();
|
||||
auto ctxToMakeCurrent = sharing.getContextHandle();
|
||||
|
||||
if (currentContextHandle == 0) {
|
||||
ctxToMakeCurrent = sharing.getBackupContextHandle();
|
||||
}
|
||||
|
||||
if (currentContextHandle != sharing.getContextHandle() && currentContextHandle != sharing.getBackupContextHandle()) {
|
||||
if (sharing.makeCurrent(ctxToMakeCurrent) == GL_FALSE) {
|
||||
while (sharing.makeCurrent(sharing.getBackupContextHandle()) == GL_FALSE) {
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GLContextGuard::~GLContextGuard() {
|
||||
auto &sharing = *static_cast<GLSharingFunctionsLinux *>(sharingFunctions);
|
||||
if (currentContextHandle != sharing.getContextHandle()) {
|
||||
sharing.makeCurrent(currentContextHandle, currentDisplayHandle);
|
||||
}
|
||||
}
|
||||
} // namespace NEO
|
||||
@@ -1,13 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Os {
|
||||
const char *eglDllName = "libEGL.so.1";
|
||||
const char *openglDllName = "libGL.so.1";
|
||||
} // namespace Os
|
||||
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "opencl/source/sharings/gl/linux/gl_sharing_linux.h"
|
||||
|
||||
#include "opencl/source/context/context.inl"
|
||||
#include "opencl/source/helpers/gl_helper.h"
|
||||
#include "opencl/source/sharings/gl/gl_arb_sync_event.h"
|
||||
|
||||
namespace Os {
|
||||
extern const char *eglDllName;
|
||||
extern const char *openglDllName;
|
||||
} // namespace Os
|
||||
|
||||
namespace NEO {
|
||||
GLSharingFunctionsLinux::GLSharingFunctionsLinux(GLType glhdcType, GLContext glhglrcHandle, GLContext glhglrcHandleBkpCtx, GLDisplay glhdcHandle)
|
||||
: glHDCType(glhdcType), glHGLRCHandle(glhglrcHandle), glHGLRCHandleBkpCtx(glhglrcHandleBkpCtx), glHDCHandle(glhdcHandle) {
|
||||
GLSharingFunctionsLinux::initGLFunctions();
|
||||
updateOpenGLContext();
|
||||
}
|
||||
GLSharingFunctionsLinux::~GLSharingFunctionsLinux() = default;
|
||||
|
||||
bool GLSharingFunctionsLinux::isGlSharingEnabled() {
|
||||
static bool oglLibAvailable = std::unique_ptr<OsLibrary>(OsLibrary::load(Os::eglDllName)).get() != nullptr;
|
||||
return oglLibAvailable;
|
||||
}
|
||||
|
||||
void GLSharingFunctionsLinux::createBackupContext() {
|
||||
if (pfnEglCreateContext) {
|
||||
glHGLRCHandleBkpCtx = pfnEglCreateContext(glHDCHandle);
|
||||
pfnEglShareLists(glHGLRCHandle, glHGLRCHandleBkpCtx);
|
||||
}
|
||||
}
|
||||
|
||||
GLboolean GLSharingFunctionsLinux::setSharedOCLContextState() {
|
||||
ContextInfo contextInfo{};
|
||||
GLboolean retVal = glSetSharedOCLContextState(glHDCHandle, glHGLRCHandle, CL_TRUE, &contextInfo);
|
||||
if (retVal == GL_FALSE) {
|
||||
return GL_FALSE;
|
||||
}
|
||||
glContextHandle = contextInfo.ContextHandle;
|
||||
glDeviceHandle = contextInfo.DeviceHandle;
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool GLSharingFunctionsLinux::isOpenGlExtensionSupported(const unsigned char *pExtensionString) {
|
||||
if (glGetStringi == nullptr || glGetIntegerv == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cl_int numberOfExtensions = 0;
|
||||
glGetIntegerv(GL_NUM_EXTENSIONS, &numberOfExtensions);
|
||||
for (cl_int i = 0; i < numberOfExtensions; i++) {
|
||||
std::basic_string<unsigned char> pString = glGetStringi(GL_EXTENSIONS, i);
|
||||
if (pString == pExtensionString) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GLSharingFunctionsLinux::isOpenGlSharingSupported() {
|
||||
|
||||
std::basic_string<unsigned char> vendor = glGetString(GL_VENDOR);
|
||||
const unsigned char intelVendor[] = "Intel";
|
||||
|
||||
if ((vendor.empty()) || (vendor != intelVendor)) {
|
||||
return false;
|
||||
}
|
||||
std::basic_string<unsigned char> version = glGetString(GL_VERSION);
|
||||
if (version.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isOpenGLES = false;
|
||||
const unsigned char versionES[] = "OpenGL ES";
|
||||
if (version.find(versionES) != std::string::npos) {
|
||||
isOpenGLES = true;
|
||||
}
|
||||
|
||||
if (isOpenGLES == true) {
|
||||
const unsigned char versionES1[] = "OpenGL ES 1.";
|
||||
if (version.find(versionES1) != std::string::npos) {
|
||||
const unsigned char supportGLOES[] = "GL_OES_framebuffer_object";
|
||||
if (isOpenGlExtensionSupported(supportGLOES) == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (version[0] < '3') {
|
||||
const unsigned char supportGLEXT[] = "GL_EXT_framebuffer_object";
|
||||
if (isOpenGlExtensionSupported(supportGLEXT) == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
GlArbSyncEvent *GLSharingFunctionsLinux::getGlArbSyncEvent(Event &baseEvent) {
|
||||
std::lock_guard<std::mutex> lock{glArbEventMutex};
|
||||
auto it = glArbEventMapping.find(&baseEvent);
|
||||
if (it != glArbEventMapping.end()) {
|
||||
return it->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void GLSharingFunctionsLinux::removeGlArbSyncEventMapping(Event &baseEvent) {
|
||||
std::lock_guard<std::mutex> lock{glArbEventMutex};
|
||||
auto it = glArbEventMapping.find(&baseEvent);
|
||||
if (it == glArbEventMapping.end()) {
|
||||
DEBUG_BREAK_IF(it == glArbEventMapping.end());
|
||||
return;
|
||||
}
|
||||
glArbEventMapping.erase(it);
|
||||
}
|
||||
|
||||
GLboolean GLSharingFunctionsLinux::initGLFunctions() {
|
||||
eglLibrary.reset(OsLibrary::load(Os::eglDllName));
|
||||
glLibrary.reset(OsLibrary::load(Os::openglDllName));
|
||||
|
||||
if (eglLibrary->isLoaded()) {
|
||||
GlFunctionHelper eglGetProc(eglLibrary.get(), "eglGetProcAddress");
|
||||
glGetCurrentContext = eglGetProc["eglGetCurrentContext"];
|
||||
glGetCurrentDisplay = eglGetProc["eglGetCurrentDisplay"];
|
||||
pfnEglCreateContext = eglGetProc["eglCreateContext"];
|
||||
pfnEglDeleteContext = eglGetProc["eglDestroyContext"];
|
||||
eglMakeCurrent = eglGetProc["eglMakeCurrent"];
|
||||
eglCreateImage = eglGetProc["eglCreateImage"];
|
||||
eglDestroyImage = eglGetProc["eglDestroyImage"];
|
||||
glAcquireSharedTexture = eglGetProc["eglExportDMABUFImageMESA"];
|
||||
}
|
||||
if (glLibrary->isLoaded()) {
|
||||
glGetString = (*glLibrary)["glGetString"];
|
||||
glGetStringi = (*glLibrary)["glGetStringi"];
|
||||
glGetIntegerv = (*glLibrary)["glGetIntegerv"];
|
||||
glGetTexLevelParameteriv = (*glLibrary)["glGetTexLevelParameteriv"];
|
||||
}
|
||||
this->pfnGlArbSyncObjectCleanup = cleanupArbSyncObject;
|
||||
this->pfnGlArbSyncObjectSetup = setupArbSyncObject;
|
||||
this->pfnGlArbSyncObjectSignal = signalArbSyncObject;
|
||||
this->pfnGlArbSyncObjectWaitServer = serverWaitForArbSyncObject;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
template GLSharingFunctionsLinux *Context::getSharing<GLSharingFunctionsLinux>();
|
||||
|
||||
} // namespace NEO
|
||||
@@ -1,221 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "opencl/extensions/public/cl_gl_private_intel.h"
|
||||
#include "opencl/source/sharings/gl/gl_sharing.h"
|
||||
#include "opencl/source/sharings/gl/linux/include/gl_types.h"
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
namespace NEO {
|
||||
// OpenGL API names
|
||||
typedef GLboolean (*PFNOGLSetSharedOCLContextStateINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLboolean state, GLvoid *pContextInfo);
|
||||
typedef GLboolean (*PFNOGLAcquireSharedBufferINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pBufferInfo);
|
||||
typedef GLboolean (*PFNOGLAcquireSharedRenderBufferINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pResourceInfo);
|
||||
typedef GLboolean (*PFNOGLReleaseSharedBufferINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pBufferInfo);
|
||||
typedef GLboolean (*PFNOGLReleaseSharedRenderBufferINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pResourceInfo);
|
||||
typedef GLboolean (*PFNOGLReleaseSharedTextureINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pResourceInfo);
|
||||
typedef GLContext (*PFNOGLGetCurrentContext)();
|
||||
typedef GLDisplay (*PFNOGLGetCurrentDisplay)();
|
||||
typedef GLboolean (*PFNOGLMakeCurrent)(GLDisplay hdcHandle, void *draw, void *read, GLContext contextHandle);
|
||||
typedef GLboolean (*PFNOGLRetainSyncINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pSyncInfo);
|
||||
typedef GLboolean (*PFNOGLReleaseSyncINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pSync);
|
||||
typedef void (*PFNOGLGetSyncivINTEL)(GLvoid *pSync, GLenum pname, GLint *value);
|
||||
|
||||
typedef const GLubyte *(*PFNglGetString)(GLenum name);
|
||||
typedef const GLubyte *(*PFNglGetStringi)(GLenum name, GLuint index);
|
||||
typedef void (*PFNglGetIntegerv)(GLenum pname, GLint *params);
|
||||
typedef void (*PFNglBindTexture)(GLenum target, GLuint texture);
|
||||
typedef void (*PFNglGetTexLevelParameteriv)(GLenum target, GLint level, GLenum pname, GLint *params);
|
||||
|
||||
// egl
|
||||
typedef unsigned char (*PFNeglMakeCurrent)(void *, void *);
|
||||
typedef GLContext (*PFNeglCreateContext)(GLDisplay hdcHandle);
|
||||
typedef int (*PFNeglShareLists)(GLContext contextHandle, GLContext backupContextHandle);
|
||||
typedef EGLBoolean (*PFNeglDeleteContext)(EGLDisplay dpy, EGLContext ctx);
|
||||
|
||||
typedef bool (*PFNglArbSyncObjectSetup)(GLSharingFunctions &sharing, OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo);
|
||||
typedef void (*PFNglArbSyncObjectCleanup)(OSInterface &osInterface, CL_GL_SYNC_INFO *glSyncInfo);
|
||||
typedef void (*PFNglArbSyncObjectSignal)(OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo);
|
||||
typedef void (*PFNglArbSyncObjectWaitServer)(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo);
|
||||
|
||||
typedef EGLImage (*PFNeglCreateImage)(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attribList);
|
||||
typedef EGLBoolean (*PFNeglDestroyImage)(EGLDisplay dpy, EGLImage image);
|
||||
|
||||
class GLSharingFunctionsLinux : public GLSharingFunctions {
|
||||
public:
|
||||
GLSharingFunctionsLinux() = default;
|
||||
GLSharingFunctionsLinux(GLType glhdcType, GLContext glhglrcHandle, GLContext glhglrcHandleBkpCtx, GLDisplay glhdcHandle);
|
||||
~GLSharingFunctionsLinux() override;
|
||||
|
||||
OS_HANDLE getGLDeviceHandle() const { return glDeviceHandle; }
|
||||
OS_HANDLE getGLContextHandle() const { return glContextHandle; }
|
||||
|
||||
GLboolean initGLFunctions() override;
|
||||
bool isOpenGlSharingSupported() override;
|
||||
static bool isGlSharingEnabled();
|
||||
|
||||
// Arb sync event
|
||||
template <typename EventType = GlArbSyncEvent>
|
||||
auto getOrCreateGlArbSyncEvent(Event &baseEvent) -> decltype(EventType::create(baseEvent));
|
||||
GlArbSyncEvent *getGlArbSyncEvent(Event &baseEvent);
|
||||
void removeGlArbSyncEventMapping(Event &baseEvent);
|
||||
|
||||
// Gl functions
|
||||
GLboolean acquireSharedBufferINTEL(GLvoid *pBufferInfo) {
|
||||
return glAcquireSharedBuffer(glHDCHandle, glHGLRCHandle, glHGLRCHandleBkpCtx, pBufferInfo);
|
||||
}
|
||||
GLboolean releaseSharedBufferINTEL(GLvoid *pBufferInfo) {
|
||||
return glReleaseSharedBuffer(glHDCHandle, glHGLRCHandle, glHGLRCHandleBkpCtx, pBufferInfo);
|
||||
}
|
||||
GLboolean acquireSharedRenderBuffer(GLvoid *pResourceInfo) {
|
||||
return glAcquireSharedRenderBuffer(glHDCHandle, glHGLRCHandle, glHGLRCHandleBkpCtx, pResourceInfo);
|
||||
}
|
||||
GLboolean releaseSharedRenderBuffer(GLvoid *pResourceInfo) {
|
||||
return glReleaseSharedRenderBuffer(glHDCHandle, glHGLRCHandle, glHGLRCHandleBkpCtx, pResourceInfo);
|
||||
}
|
||||
EGLBoolean acquireSharedTexture(CL_GL_RESOURCE_INFO *pResourceInfo) {
|
||||
int fds;
|
||||
int stride, offset;
|
||||
int miplevel = 0;
|
||||
|
||||
EGLAttrib attribList[] = {EGL_GL_TEXTURE_LEVEL, miplevel, EGL_NONE};
|
||||
EGLImage image = eglCreateImage(glHDCHandle, glHGLRCHandle, EGL_GL_TEXTURE_2D, reinterpret_cast<EGLClientBuffer>(static_cast<uintptr_t>(pResourceInfo->name)), &attribList[0]);
|
||||
if (image == EGL_NO_IMAGE) {
|
||||
return EGL_FALSE;
|
||||
}
|
||||
|
||||
EGLBoolean ret = glAcquireSharedTexture(glHDCHandle, image, &fds, &stride, &offset);
|
||||
if (ret == EGL_TRUE && fds > 0) {
|
||||
pResourceInfo->globalShareHandle = fds;
|
||||
} else {
|
||||
eglDestroyImage(glHDCHandle, image);
|
||||
ret = EGL_FALSE;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
GLboolean releaseSharedTexture(GLvoid *pResourceInfo) {
|
||||
return 1;
|
||||
}
|
||||
GLboolean retainSync(GLvoid *pSyncInfo) {
|
||||
return glRetainSync(glHDCHandle, glHGLRCHandle, glHGLRCHandleBkpCtx, pSyncInfo);
|
||||
}
|
||||
GLboolean releaseSync(GLvoid *pSync) {
|
||||
return glReleaseSync(glHDCHandle, glHGLRCHandle, glHGLRCHandleBkpCtx, pSync);
|
||||
}
|
||||
void getSynciv(GLvoid *pSync, GLenum pname, GLint *value) {
|
||||
return glGetSynciv(pSync, pname, value);
|
||||
}
|
||||
GLContext getCurrentContext() {
|
||||
return glGetCurrentContext();
|
||||
}
|
||||
GLDisplay getCurrentDisplay() {
|
||||
return glGetCurrentDisplay();
|
||||
}
|
||||
GLboolean makeCurrent(GLContext contextHandle, GLDisplay displayHandle = 0) {
|
||||
if (displayHandle == 0) {
|
||||
displayHandle = glHDCHandle;
|
||||
}
|
||||
return this->eglMakeCurrent(displayHandle, contextHandle);
|
||||
}
|
||||
GLContext getBackupContextHandle() {
|
||||
return glHGLRCHandleBkpCtx;
|
||||
}
|
||||
GLContext getContextHandle() {
|
||||
return glHGLRCHandle;
|
||||
}
|
||||
bool glArbSyncObjectSetup(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) {
|
||||
return pfnGlArbSyncObjectSetup(*this, osInterface, glSyncInfo);
|
||||
}
|
||||
void glArbSyncObjectCleanup(OSInterface &osInterface, CL_GL_SYNC_INFO *glSyncInfo) {
|
||||
pfnGlArbSyncObjectCleanup(osInterface, glSyncInfo);
|
||||
}
|
||||
void glArbSyncObjectSignal(OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo) {
|
||||
pfnGlArbSyncObjectSignal(osContext, glSyncInfo);
|
||||
}
|
||||
void glArbSyncObjectWaitServer(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) {
|
||||
pfnGlArbSyncObjectWaitServer(osInterface, glSyncInfo);
|
||||
}
|
||||
// Buffer reuse
|
||||
std::mutex mutex;
|
||||
std::vector<std::pair<unsigned int, GraphicsAllocation *>> graphicsAllocationsForGlBufferReuse;
|
||||
|
||||
PFNglGetTexLevelParameteriv glGetTexLevelParameteriv = nullptr;
|
||||
|
||||
protected:
|
||||
void updateOpenGLContext() {
|
||||
if (glSetSharedOCLContextState) {
|
||||
setSharedOCLContextState();
|
||||
}
|
||||
}
|
||||
GLboolean setSharedOCLContextState();
|
||||
void createBackupContext();
|
||||
bool isOpenGlExtensionSupported(const unsigned char *pExtentionString);
|
||||
|
||||
// Handles
|
||||
GLType glHDCType = 0;
|
||||
GLContext glHGLRCHandle = 0;
|
||||
GLContext glHGLRCHandleBkpCtx = 0;
|
||||
GLDisplay glHDCHandle = 0;
|
||||
OS_HANDLE glDeviceHandle = 0;
|
||||
OS_HANDLE glContextHandle = 0;
|
||||
|
||||
// GL functions
|
||||
std::unique_ptr<OsLibrary> glLibrary;
|
||||
std::unique_ptr<OsLibrary> eglLibrary;
|
||||
PFNOGLSetSharedOCLContextStateINTEL glSetSharedOCLContextState = nullptr;
|
||||
PFNOGLAcquireSharedBufferINTEL glAcquireSharedBuffer = nullptr;
|
||||
PFNOGLReleaseSharedBufferINTEL glReleaseSharedBuffer = nullptr;
|
||||
PFNOGLAcquireSharedRenderBufferINTEL glAcquireSharedRenderBuffer = nullptr;
|
||||
PFNOGLReleaseSharedRenderBufferINTEL glReleaseSharedRenderBuffer = nullptr;
|
||||
PFNEGLEXPORTDMABUFIMAGEMESAPROC glAcquireSharedTexture = nullptr;
|
||||
PFNOGLReleaseSharedTextureINTEL glReleaseSharedTexture = nullptr;
|
||||
PFNOGLGetCurrentContext glGetCurrentContext = nullptr;
|
||||
PFNOGLGetCurrentDisplay glGetCurrentDisplay = nullptr;
|
||||
PFNglGetString glGetString = nullptr;
|
||||
PFNglGetStringi glGetStringi = nullptr;
|
||||
PFNglGetIntegerv glGetIntegerv = nullptr;
|
||||
PFNeglCreateContext pfnEglCreateContext = nullptr;
|
||||
PFNeglMakeCurrent eglMakeCurrent = nullptr;
|
||||
PFNeglShareLists pfnEglShareLists = nullptr;
|
||||
PFNeglDeleteContext pfnEglDeleteContext = nullptr;
|
||||
PFNOGLRetainSyncINTEL glRetainSync = nullptr;
|
||||
PFNOGLReleaseSyncINTEL glReleaseSync = nullptr;
|
||||
PFNOGLGetSyncivINTEL glGetSynciv = nullptr;
|
||||
PFNglArbSyncObjectSetup pfnGlArbSyncObjectSetup = nullptr;
|
||||
PFNglArbSyncObjectCleanup pfnGlArbSyncObjectCleanup = nullptr;
|
||||
PFNglArbSyncObjectSignal pfnGlArbSyncObjectSignal = nullptr;
|
||||
PFNglArbSyncObjectWaitServer pfnGlArbSyncObjectWaitServer = nullptr;
|
||||
PFNeglCreateImage eglCreateImage = nullptr;
|
||||
PFNeglDestroyImage eglDestroyImage = nullptr;
|
||||
// support for GL_ARB_cl_event
|
||||
std::mutex glArbEventMutex;
|
||||
std::unordered_map<Event *, GlArbSyncEvent *> glArbEventMapping;
|
||||
};
|
||||
|
||||
template <typename EventType>
|
||||
inline auto GLSharingFunctionsLinux::getOrCreateGlArbSyncEvent(Event &baseEvent) -> decltype(EventType::create(baseEvent)) {
|
||||
std::lock_guard<std::mutex> lock{glArbEventMutex};
|
||||
auto it = glArbEventMapping.find(&baseEvent);
|
||||
if (it != glArbEventMapping.end()) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
auto arbEvent = EventType::create(baseEvent);
|
||||
if (nullptr == arbEvent) {
|
||||
return arbEvent;
|
||||
}
|
||||
glArbEventMapping[&baseEvent] = arbEvent;
|
||||
return arbEvent;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/command_stream/command_stream_receiver.h"
|
||||
#include "shared/source/device/device.h"
|
||||
#include "shared/source/helpers/get_info.h"
|
||||
#include "shared/source/helpers/timestamp_packet.h"
|
||||
|
||||
#include "opencl/extensions/public/cl_gl_private_intel.h"
|
||||
#include "opencl/source/context/context.h"
|
||||
#include "opencl/source/event/async_events_handler.h"
|
||||
#include "opencl/source/event/event_builder.h"
|
||||
#include "opencl/source/platform/platform.h"
|
||||
#include "opencl/source/sharings/gl/gl_context_guard.h"
|
||||
#include "opencl/source/sharings/gl/gl_sync_event.h"
|
||||
#include "opencl/source/sharings/gl/linux/gl_sharing_linux.h"
|
||||
|
||||
namespace NEO {
|
||||
GlSyncEvent::GlSyncEvent(Context &context, const GL_CL_SYNC_INFO &sync)
|
||||
: Event(&context, nullptr, CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR, CompletionStamp::notReady, CompletionStamp::notReady),
|
||||
glSync(std::make_unique<GL_CL_SYNC_INFO>(sync)) {
|
||||
transitionExecutionStatus(CL_SUBMITTED);
|
||||
}
|
||||
|
||||
GlSyncEvent::~GlSyncEvent() {
|
||||
ctx->getSharing<GLSharingFunctionsLinux>()->releaseSync(glSync->pSync);
|
||||
}
|
||||
|
||||
GlSyncEvent *GlSyncEvent::create(Context &context, cl_GLsync sync, cl_int *errCode) {
|
||||
GLContextGuard guard(*context.getSharing<GLSharingFunctionsLinux>());
|
||||
|
||||
ErrorCodeHelper err(errCode, CL_SUCCESS);
|
||||
GL_CL_SYNC_INFO syncInfo = {sync, nullptr};
|
||||
|
||||
context.getSharing<GLSharingFunctionsLinux>()->retainSync(&syncInfo);
|
||||
DEBUG_BREAK_IF(!syncInfo.pSync);
|
||||
|
||||
EventBuilder eventBuilder;
|
||||
eventBuilder.create<GlSyncEvent>(context, syncInfo);
|
||||
return static_cast<GlSyncEvent *>(eventBuilder.finalizeAndRelease());
|
||||
}
|
||||
|
||||
void GlSyncEvent::updateExecutionStatus() {
|
||||
GLContextGuard guard(*ctx->getSharing<GLSharingFunctionsLinux>());
|
||||
int retVal = 0;
|
||||
|
||||
ctx->getSharing<GLSharingFunctionsLinux>()->getSynciv(glSync->pSync, GL_SYNC_STATUS, &retVal);
|
||||
if (retVal == GL_SIGNALED) {
|
||||
setStatus(CL_COMPLETE);
|
||||
}
|
||||
}
|
||||
|
||||
TaskCountType GlSyncEvent::getTaskLevel() {
|
||||
if (peekExecutionStatus() == CL_COMPLETE) {
|
||||
return 0;
|
||||
}
|
||||
return CompletionStamp::notReady;
|
||||
}
|
||||
} // namespace NEO
|
||||
@@ -1,294 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/execution_environment/root_device_environment.h"
|
||||
#include "shared/source/gmm_helper/gmm.h"
|
||||
#include "shared/source/gmm_helper/gmm_helper.h"
|
||||
#include "shared/source/gmm_helper/resource_info.h"
|
||||
#include "shared/source/helpers/aligned_memory.h"
|
||||
#include "shared/source/helpers/get_info.h"
|
||||
#include "shared/source/helpers/gfx_core_helper.h"
|
||||
#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/product_helper.h"
|
||||
|
||||
#include "opencl/extensions/public/cl_gl_private_intel.h"
|
||||
#include "opencl/source/cl_device/cl_device.h"
|
||||
#include "opencl/source/context/context.h"
|
||||
#include "opencl/source/helpers/gmm_types_converter.h"
|
||||
#include "opencl/source/mem_obj/image.h"
|
||||
#include "opencl/source/sharings/gl/gl_texture.h"
|
||||
#include "opencl/source/sharings/gl/linux/gl_sharing_linux.h"
|
||||
|
||||
#include "CL/cl_gl.h"
|
||||
#include "config.h"
|
||||
#include <GL/gl.h>
|
||||
|
||||
namespace NEO {
|
||||
Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture,
|
||||
cl_int *errcodeRet) {
|
||||
ErrorCodeHelper errorCode(errcodeRet, CL_INVALID_GL_OBJECT);
|
||||
auto memoryManager = context->getMemoryManager();
|
||||
cl_image_desc imgDesc = {};
|
||||
ImageInfo imgInfo = {};
|
||||
cl_image_format imgFormat = {};
|
||||
McsSurfaceInfo mcsSurfaceInfo = {};
|
||||
|
||||
CL_GL_RESOURCE_INFO texInfo = {};
|
||||
texInfo.name = texture;
|
||||
texInfo.target = getBaseTargetType(target);
|
||||
if (texInfo.target != GL_TEXTURE_2D) {
|
||||
printf("target %x not supported\n", target);
|
||||
errorCode.set(CL_INVALID_GL_OBJECT);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32_t qPitch = 0;
|
||||
uint32_t cubeFaceIndex = __GMM_NO_CUBE_MAP;
|
||||
int imageWidth = 0, imageHeight = 0, internalFormat = 0;
|
||||
|
||||
GLSharingFunctionsLinux *sharingFunctions = context->getSharing<GLSharingFunctionsLinux>();
|
||||
|
||||
sharingFunctions->glGetTexLevelParameteriv(target, miplevel, GL_TEXTURE_WIDTH, &imageWidth);
|
||||
sharingFunctions->glGetTexLevelParameteriv(target, miplevel, GL_TEXTURE_HEIGHT, &imageHeight);
|
||||
sharingFunctions->glGetTexLevelParameteriv(target, miplevel, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat);
|
||||
|
||||
imgDesc.image_width = imageWidth;
|
||||
imgDesc.image_height = imageHeight;
|
||||
switch (internalFormat) {
|
||||
case GL_RGBA:
|
||||
case GL_RGBA8:
|
||||
case GL_RGBA16F:
|
||||
case GL_RGB:
|
||||
texInfo.glInternalFormat = internalFormat;
|
||||
break;
|
||||
default:
|
||||
printf("internal format %x not supported\n", internalFormat);
|
||||
errorCode.set(CL_INVALID_GL_OBJECT);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
imgInfo.imgDesc.imageWidth = imgDesc.image_width;
|
||||
imgInfo.imgDesc.imageType = ImageType::Image2D;
|
||||
imgInfo.imgDesc.imageHeight = imgDesc.image_height;
|
||||
|
||||
if (target == GL_RENDERBUFFER_EXT) {
|
||||
sharingFunctions->acquireSharedRenderBuffer(&texInfo);
|
||||
} else {
|
||||
if (sharingFunctions->acquireSharedTexture(&texInfo) != EGL_TRUE) {
|
||||
errorCode.set(CL_INVALID_GL_OBJECT);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
errorCode.set(CL_SUCCESS);
|
||||
|
||||
if (setClImageFormat(texInfo.glInternalFormat, imgFormat) == false) {
|
||||
errorCode.set(CL_INVALID_GL_OBJECT);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto surfaceFormatInfoAddress = Image::getSurfaceFormatFromTable(flags, &imgFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
|
||||
if (!surfaceFormatInfoAddress) {
|
||||
errorCode.set(CL_INVALID_GL_OBJECT);
|
||||
return nullptr;
|
||||
}
|
||||
auto surfaceFormatInfo = *surfaceFormatInfoAddress;
|
||||
imgInfo.surfaceFormat = &surfaceFormatInfo.surfaceFormat;
|
||||
AllocationProperties allocProperties(context->getDevice(0)->getRootDeviceIndex(),
|
||||
false, // allocateMemory
|
||||
imgInfo,
|
||||
AllocationType::SHARED_IMAGE,
|
||||
context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex()));
|
||||
auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandle, allocProperties, false, false, false);
|
||||
|
||||
if (alloc == nullptr) {
|
||||
errorCode.set(CL_INVALID_GL_OBJECT);
|
||||
return nullptr;
|
||||
}
|
||||
memoryManager->closeSharedHandle(alloc);
|
||||
|
||||
auto gmm = alloc->getDefaultGmm();
|
||||
|
||||
imgDesc.image_type = getClMemObjectType(target);
|
||||
if (target == GL_TEXTURE_BUFFER) {
|
||||
imgDesc.image_width = texInfo.textureBufferWidth;
|
||||
imgDesc.image_row_pitch = texInfo.textureBufferSize;
|
||||
} else {
|
||||
imgDesc.image_width = gmm->gmmResourceInfo->getBaseWidth();
|
||||
imgDesc.image_row_pitch = gmm->gmmResourceInfo->getRenderPitch();
|
||||
if (imgDesc.image_row_pitch == 0) {
|
||||
size_t alignedWidth = alignUp(imgDesc.image_width, gmm->gmmResourceInfo->getHAlign());
|
||||
size_t bpp = gmm->gmmResourceInfo->getBitsPerPixel() >> 3;
|
||||
imgDesc.image_row_pitch = alignedWidth * bpp;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t numSamples = static_cast<uint32_t>(gmm->gmmResourceInfo->getNumSamples());
|
||||
imgDesc.num_samples = getValidParam(numSamples, 0u, 1u);
|
||||
imgDesc.image_height = gmm->gmmResourceInfo->getBaseHeight();
|
||||
imgDesc.image_array_size = gmm->gmmResourceInfo->getArraySize();
|
||||
if (target == GL_TEXTURE_3D) {
|
||||
imgDesc.image_depth = gmm->gmmResourceInfo->getBaseDepth();
|
||||
}
|
||||
|
||||
if (imgDesc.image_array_size > 1 || imgDesc.image_depth > 1) {
|
||||
GMM_REQ_OFFSET_INFO gmmReqInfo = {};
|
||||
gmmReqInfo.ArrayIndex = imgDesc.image_array_size > 1 ? 1 : 0;
|
||||
gmmReqInfo.Slice = imgDesc.image_depth > 1 ? 1 : 0;
|
||||
gmmReqInfo.ReqLock = 1;
|
||||
gmm->gmmResourceInfo->getOffset(gmmReqInfo);
|
||||
imgDesc.image_slice_pitch = gmmReqInfo.Lock.Offset;
|
||||
} else {
|
||||
imgDesc.image_slice_pitch = alloc->getUnderlyingBufferSize();
|
||||
}
|
||||
|
||||
cubeFaceIndex = GmmTypesConverter::getCubeFaceIndex(target);
|
||||
|
||||
qPitch = gmm->queryQPitch(gmm->gmmResourceInfo->getResourceType());
|
||||
|
||||
GraphicsAllocation *mcsAlloc = nullptr;
|
||||
|
||||
imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
imgInfo.imgDesc = Image::convertDescriptor(imgDesc);
|
||||
|
||||
imgInfo.surfaceFormat = &surfaceFormatInfo.surfaceFormat;
|
||||
imgInfo.qPitch = qPitch;
|
||||
|
||||
auto glTexture = new GlTexture(sharingFunctions, getClGlObjectType(target), texture, texInfo, target, std::max(miplevel, 0));
|
||||
|
||||
if (texInfo.isAuxEnabled && alloc->getDefaultGmm()->unifiedAuxTranslationCapable()) {
|
||||
const auto &hwInfo = context->getDevice(0)->getHardwareInfo();
|
||||
const auto &productHelper = context->getDevice(0)->getRootDeviceEnvironment().getHelper<ProductHelper>();
|
||||
alloc->getDefaultGmm()->isCompressionEnabled = productHelper.isPageTableManagerSupported(hwInfo) ? memoryManager->mapAuxGpuVA(alloc)
|
||||
: true;
|
||||
}
|
||||
auto multiGraphicsAllocation = MultiGraphicsAllocation(context->getDevice(0)->getRootDeviceIndex());
|
||||
multiGraphicsAllocation.addAllocation(alloc);
|
||||
|
||||
return Image::createSharedImage(context, glTexture, mcsSurfaceInfo, std::move(multiGraphicsAllocation), mcsAlloc, flags, 0, &surfaceFormatInfo, imgInfo, cubeFaceIndex,
|
||||
std::max(miplevel, 0), imgInfo.imgDesc.numMipLevels);
|
||||
} // namespace NEO
|
||||
|
||||
void GlTexture::synchronizeObject(UpdateData &updateData) {
|
||||
auto sharingFunctions = static_cast<GLSharingFunctionsLinux *>(this->sharingFunctions);
|
||||
CL_GL_RESOURCE_INFO resourceInfo = {0};
|
||||
resourceInfo.name = this->clGlObjectId;
|
||||
if (target == GL_RENDERBUFFER_EXT) {
|
||||
sharingFunctions->acquireSharedRenderBuffer(&resourceInfo);
|
||||
} else {
|
||||
if (sharingFunctions->acquireSharedTexture(&resourceInfo) == EGL_TRUE) {
|
||||
// Set texture buffer offset acquired from OpenGL layer in graphics allocation
|
||||
updateData.memObject->getGraphicsAllocation(updateData.rootDeviceIndex)->setAllocationOffset(resourceInfo.textureBufferOffset);
|
||||
} else {
|
||||
updateData.synchronizationStatus = SynchronizeStatus::SYNCHRONIZE_ERROR;
|
||||
return;
|
||||
}
|
||||
}
|
||||
updateData.sharedHandle = resourceInfo.globalShareHandle;
|
||||
updateData.synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL;
|
||||
}
|
||||
|
||||
cl_int GlTexture::getGlTextureInfo(cl_gl_texture_info paramName, size_t paramValueSize, void *paramValue, size_t *paramValueSizeRet) const {
|
||||
GetInfoHelper info(paramValue, paramValueSize, paramValueSizeRet);
|
||||
|
||||
if (paramName == CL_GL_TEXTURE_TARGET) {
|
||||
info.set<GLenum>(target);
|
||||
} else if (paramName == CL_GL_MIPMAP_LEVEL) {
|
||||
info.set<GLenum>(miplevel);
|
||||
} else if (paramName == CL_GL_NUM_SAMPLES) {
|
||||
info.set<GLsizei>(textureInfo.numberOfSamples > 1 ? textureInfo.numberOfSamples : 0);
|
||||
} else {
|
||||
return CL_INVALID_VALUE;
|
||||
}
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
cl_mem_object_type GlTexture::getClMemObjectType(cl_GLenum glType) {
|
||||
return static_cast<cl_mem_object_type>(getClObjectType(glType, false));
|
||||
}
|
||||
cl_gl_object_type GlTexture::getClGlObjectType(cl_GLenum glType) {
|
||||
return static_cast<cl_gl_object_type>(getClObjectType(glType, true));
|
||||
}
|
||||
|
||||
uint32_t GlTexture::getClObjectType(cl_GLenum glType, bool returnClGlObjectType) {
|
||||
// return cl_gl_object_type if returnClGlObjectType is ture, otherwise cl_mem_object_type
|
||||
uint32_t retValue = 0;
|
||||
switch (glType) {
|
||||
case GL_TEXTURE_1D:
|
||||
retValue = returnClGlObjectType ? CL_GL_OBJECT_TEXTURE1D : CL_MEM_OBJECT_IMAGE1D;
|
||||
break;
|
||||
case GL_TEXTURE_1D_ARRAY:
|
||||
retValue = returnClGlObjectType ? CL_GL_OBJECT_TEXTURE1D_ARRAY : CL_MEM_OBJECT_IMAGE1D_ARRAY;
|
||||
break;
|
||||
case GL_TEXTURE_2D:
|
||||
case GL_TEXTURE_RECTANGLE:
|
||||
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
|
||||
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
|
||||
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
|
||||
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
|
||||
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
|
||||
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
|
||||
case GL_TEXTURE_2D_MULTISAMPLE:
|
||||
retValue = returnClGlObjectType ? CL_GL_OBJECT_TEXTURE2D : CL_MEM_OBJECT_IMAGE2D;
|
||||
break;
|
||||
case GL_TEXTURE_2D_ARRAY:
|
||||
case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
|
||||
retValue = returnClGlObjectType ? CL_GL_OBJECT_TEXTURE2D_ARRAY : CL_MEM_OBJECT_IMAGE2D_ARRAY;
|
||||
break;
|
||||
case GL_TEXTURE_3D:
|
||||
retValue = returnClGlObjectType ? CL_GL_OBJECT_TEXTURE3D : CL_MEM_OBJECT_IMAGE3D;
|
||||
break;
|
||||
case GL_TEXTURE_BUFFER:
|
||||
retValue = returnClGlObjectType ? CL_GL_OBJECT_TEXTURE_BUFFER : CL_MEM_OBJECT_IMAGE1D_BUFFER;
|
||||
break;
|
||||
case GL_RENDERBUFFER_EXT:
|
||||
retValue = returnClGlObjectType ? CL_GL_OBJECT_RENDERBUFFER : CL_MEM_OBJECT_IMAGE2D;
|
||||
break;
|
||||
default:
|
||||
retValue = 0;
|
||||
break;
|
||||
}
|
||||
return retValue;
|
||||
}
|
||||
|
||||
cl_GLenum GlTexture::getBaseTargetType(cl_GLenum target) {
|
||||
cl_GLenum returnTarget = 0;
|
||||
switch (target) {
|
||||
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
|
||||
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
|
||||
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
|
||||
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
|
||||
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
|
||||
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
|
||||
returnTarget = GL_TEXTURE_CUBE_MAP_ARB;
|
||||
break;
|
||||
default:
|
||||
returnTarget = target;
|
||||
break;
|
||||
}
|
||||
return returnTarget;
|
||||
}
|
||||
|
||||
void GlTexture::releaseResource(MemObj *memObject, uint32_t rootDeviceIndex) {
|
||||
auto sharingFunctions = static_cast<GLSharingFunctionsLinux *>(this->sharingFunctions);
|
||||
if (target == GL_RENDERBUFFER_EXT) {
|
||||
sharingFunctions->releaseSharedRenderBuffer(&textureInfo);
|
||||
} else {
|
||||
sharingFunctions->releaseSharedTexture(&textureInfo);
|
||||
auto memoryManager = memObject->getMemoryManager();
|
||||
memoryManager->closeSharedHandle(memObject->getGraphicsAllocation(rootDeviceIndex));
|
||||
}
|
||||
}
|
||||
void GlTexture::resolveGraphicsAllocationChange(osHandle currentSharedHandle, UpdateData *updateData) {
|
||||
const auto memObject = updateData->memObject;
|
||||
auto graphicsAllocation = memObject->getGraphicsAllocation(updateData->rootDeviceIndex);
|
||||
graphicsAllocation->setSharedHandle(updateData->sharedHandle);
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
@@ -1,13 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include <EGL/egl.h>
|
||||
|
||||
using GLDisplay = EGLDisplay;
|
||||
using GLContext = EGLContext;
|
||||
using GLType = uint32_t;
|
||||
using GLFunctionType = decltype(&eglGetProcAddress);
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "opencl/source/sharings/gl/linux/lin_enable_gl.h"
|
||||
|
||||
#include "shared/source/debug_settings/debug_settings_manager.h"
|
||||
|
||||
#include "opencl/source/context/context.h"
|
||||
#include "opencl/source/context/context.inl"
|
||||
#include "opencl/source/sharings/gl/cl_gl_api_intel.h"
|
||||
#include "opencl/source/sharings/gl/linux/gl_sharing_linux.h"
|
||||
#include "opencl/source/sharings/sharing_factory.h"
|
||||
#include "opencl/source/sharings/sharing_factory.inl"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
struct GlCreateContextProperties {
|
||||
GLType glHDCType = 0;
|
||||
GLContext glHGLRCHandle = 0;
|
||||
GLDisplay glHDCHandle = 0;
|
||||
};
|
||||
|
||||
GlSharingContextBuilder::GlSharingContextBuilder() = default;
|
||||
GlSharingContextBuilder::~GlSharingContextBuilder() = default;
|
||||
|
||||
bool GlSharingContextBuilder::processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue) {
|
||||
if (!contextData)
|
||||
contextData = std::make_unique<GlCreateContextProperties>();
|
||||
|
||||
switch (propertyType) {
|
||||
case CL_GL_CONTEXT_KHR:
|
||||
contextData->glHGLRCHandle = reinterpret_cast<GLContext>(propertyValue);
|
||||
return true;
|
||||
case CL_EGL_DISPLAY_KHR:
|
||||
contextData->glHDCType = static_cast<GLType>(CL_EGL_DISPLAY_KHR);
|
||||
contextData->glHDCHandle = reinterpret_cast<GLDisplay>(propertyValue);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GlSharingContextBuilder::finalizeProperties(Context &context, int32_t &errcodeRet) {
|
||||
if (contextData == nullptr)
|
||||
return true;
|
||||
|
||||
if (contextData->glHGLRCHandle) {
|
||||
context.registerSharing(new GLSharingFunctionsLinux(contextData->glHDCType, contextData->glHGLRCHandle,
|
||||
nullptr, contextData->glHDCHandle));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<SharingContextBuilder> GlSharingBuilderFactory::createContextBuilder() {
|
||||
return std::make_unique<GlSharingContextBuilder>();
|
||||
};
|
||||
|
||||
void GlSharingBuilderFactory::fillGlobalDispatchTable() {
|
||||
icdGlobalDispatchTable.clCreateFromGLBuffer = clCreateFromGLBuffer;
|
||||
icdGlobalDispatchTable.clCreateFromGLTexture = clCreateFromGLTexture;
|
||||
icdGlobalDispatchTable.clCreateFromGLTexture2D = clCreateFromGLTexture2D;
|
||||
icdGlobalDispatchTable.clCreateFromGLTexture3D = clCreateFromGLTexture3D;
|
||||
icdGlobalDispatchTable.clCreateFromGLRenderbuffer = clCreateFromGLRenderbuffer;
|
||||
icdGlobalDispatchTable.clGetGLObjectInfo = clGetGLObjectInfo;
|
||||
icdGlobalDispatchTable.clGetGLTextureInfo = clGetGLTextureInfo;
|
||||
icdGlobalDispatchTable.clEnqueueAcquireGLObjects = clEnqueueAcquireGLObjects;
|
||||
icdGlobalDispatchTable.clEnqueueReleaseGLObjects = clEnqueueReleaseGLObjects;
|
||||
icdGlobalDispatchTable.clCreateEventFromGLsyncKHR = clCreateEventFromGLsyncKHR;
|
||||
icdGlobalDispatchTable.clGetGLContextInfoKHR = clGetGLContextInfoKHR;
|
||||
}
|
||||
|
||||
std::string GlSharingBuilderFactory::getExtensions(DriverInfo *driverInfo) {
|
||||
if (DebugManager.flags.AddClGlSharing.get()) {
|
||||
return "cl_khr_gl_sharing "
|
||||
"cl_khr_gl_depth_images "
|
||||
"cl_khr_gl_event "
|
||||
"cl_khr_gl_msaa_sharing ";
|
||||
} else if (GLSharingFunctionsLinux::isGlSharingEnabled()) {
|
||||
return "cl_khr_gl_sharing "
|
||||
"cl_khr_gl_depth_images "
|
||||
"cl_khr_gl_event "
|
||||
"cl_khr_gl_msaa_sharing ";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void *GlSharingBuilderFactory::getExtensionFunctionAddress(const std::string &functionName) {
|
||||
if (DebugManager.flags.EnableFormatQuery.get() &&
|
||||
functionName == "clGetSupportedGLTextureFormatsINTEL") {
|
||||
return ((void *)(clGetSupportedGLTextureFormatsINTEL));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static SharingFactory::RegisterSharing<GlSharingBuilderFactory, GLSharingFunctionsLinux> glSharing;
|
||||
} // namespace NEO
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "opencl/source/sharings/sharing_factory.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace NEO {
|
||||
class Context;
|
||||
struct GlCreateContextProperties;
|
||||
|
||||
class GlSharingContextBuilder : public SharingContextBuilder {
|
||||
public:
|
||||
GlSharingContextBuilder();
|
||||
~GlSharingContextBuilder() override;
|
||||
bool processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue) override;
|
||||
bool finalizeProperties(Context &context, int32_t &errcodeRet) override;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<GlCreateContextProperties> contextData;
|
||||
};
|
||||
|
||||
class GlSharingBuilderFactory : public SharingBuilderFactory {
|
||||
public:
|
||||
std::unique_ptr<SharingContextBuilder> createContextBuilder() override;
|
||||
std::string getExtensions(DriverInfo *driverInfo) override;
|
||||
void fillGlobalDispatchTable() override;
|
||||
void *getExtensionFunctionAddress(const std::string &functionName) override;
|
||||
};
|
||||
} // namespace NEO
|
||||
@@ -7,7 +7,7 @@
|
||||
if(WIN32)
|
||||
set(RUNTIME_SRCS_SHARINGS_GL_WINDOWS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cl_gl_api_helper.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cl_gl_api.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_arb_sync_event_windows.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_buffer_windows.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gl_context_guard_windows.cpp
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "shared/source/execution_environment/root_device_environment.h"
|
||||
#include "shared/source/helpers/get_info.h"
|
||||
#include "shared/source/os_interface/os_interface.h"
|
||||
#include "shared/source/os_interface/windows/wddm/wddm.h"
|
||||
#include "shared/source/utilities/api_intercept.h"
|
||||
|
||||
#include "opencl/source/api/api.h"
|
||||
@@ -25,6 +26,7 @@
|
||||
#include "opencl/source/sharings/gl/gl_buffer.h"
|
||||
#include "opencl/source/sharings/gl/gl_sync_event.h"
|
||||
#include "opencl/source/sharings/gl/gl_texture.h"
|
||||
#include "opencl/source/sharings/gl/windows/gl_sharing_windows.h"
|
||||
#include "opencl/source/tracing/tracing_notify.h"
|
||||
#include "opencl/source/utilities/cl_logger.h"
|
||||
|
||||
@@ -315,8 +317,8 @@ cl_int CL_API_CALL clGetGLContextInfoKHR(const cl_context_properties *properties
|
||||
fileLoggerInstance().getInput(paramValueSizeRet, 0));
|
||||
GetInfoHelper info(paramValue, paramValueSize, paramValueSizeRet);
|
||||
|
||||
uint32_t glHglrcHandle = 0;
|
||||
uint32_t glHdcHandle = 0;
|
||||
uint32_t GLHGLRCHandle = 0;
|
||||
uint32_t GLHDCHandle = 0;
|
||||
uint32_t propertyType = 0;
|
||||
uint32_t propertyValue = 0;
|
||||
Platform *platform = nullptr;
|
||||
@@ -330,23 +332,22 @@ cl_int CL_API_CALL clGetGLContextInfoKHR(const cl_context_properties *properties
|
||||
platform = castToObject<Platform>(reinterpret_cast<cl_platform_id>(properties[1]));
|
||||
} break;
|
||||
case CL_GL_CONTEXT_KHR:
|
||||
glHglrcHandle = propertyValue;
|
||||
GLHGLRCHandle = propertyValue;
|
||||
break;
|
||||
case CL_WGL_HDC_KHR:
|
||||
glHdcHandle = propertyValue;
|
||||
GLHDCHandle = propertyValue;
|
||||
break;
|
||||
}
|
||||
properties += 2;
|
||||
}
|
||||
}
|
||||
|
||||
auto glSharing = GLSharingFunctions::create();
|
||||
|
||||
if ((glHglrcHandle == 0) || glSharing->isGlHdcHandleMissing(glHdcHandle)) {
|
||||
if ((GLHDCHandle == 0) || (GLHGLRCHandle == 0)) {
|
||||
retVal = CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
auto glSharing = std::make_unique<GLSharingFunctionsWindows>();
|
||||
glSharing->initGLFunctions();
|
||||
if (glSharing->isOpenGlSharingSupported() == false) {
|
||||
retVal = CL_INVALID_CONTEXT;
|
||||
@@ -361,7 +362,7 @@ cl_int CL_API_CALL clGetGLContextInfoKHR(const cl_context_properties *properties
|
||||
ClDevice *deviceToReturn = nullptr;
|
||||
for (auto i = 0u; i < platform->getNumDevices(); i++) {
|
||||
auto device = platform->getClDevice(i);
|
||||
if (glSharing->isHandleCompatible(*device->getRootDeviceEnvironment().osInterface->getDriverModel(), glHglrcHandle)) {
|
||||
if (device->getRootDeviceEnvironment().osInterface->getDriverModel()->as<Wddm>()->verifyAdapterLuid(glSharing->getAdapterLuid(reinterpret_cast<GLContext>(static_cast<uintptr_t>(GLHGLRCHandle))))) {
|
||||
deviceToReturn = device;
|
||||
break;
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/os_interface/windows/wddm/wddm.h"
|
||||
|
||||
#include "opencl/source/sharings/gl/windows/gl_sharing_windows.h"
|
||||
|
||||
namespace NEO {
|
||||
std::unique_ptr<GLSharingFunctions> GLSharingFunctions::create() {
|
||||
return std::make_unique<GLSharingFunctionsWindows>();
|
||||
}
|
||||
|
||||
bool GLSharingFunctionsWindows::isHandleCompatible(const DriverModel &driverModel, uint32_t handle) const {
|
||||
|
||||
return driverModel.as<const Wddm>()->verifyAdapterLuid(getAdapterLuid(reinterpret_cast<GLContext>(static_cast<uintptr_t>(handle))));
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
@@ -8,13 +8,9 @@
|
||||
#include "opencl/source/sharings/gl/windows/gl_sharing_windows.h"
|
||||
|
||||
#include "opencl/source/context/context.inl"
|
||||
#include "opencl/source/helpers/gl_helper.h"
|
||||
#include "opencl/source/helpers/windows/gl_helper.h"
|
||||
#include "opencl/source/sharings/gl/gl_arb_sync_event.h"
|
||||
|
||||
namespace Os {
|
||||
extern const char *openglDllName;
|
||||
}
|
||||
|
||||
namespace NEO {
|
||||
GLSharingFunctionsWindows::GLSharingFunctionsWindows(GLType glhdcType, GLContext glhglrcHandle, GLContext glhglrcHandleBkpCtx, GLDisplay glhdcHandle)
|
||||
: GLHDCType(glhdcType), GLHGLRCHandle(glhglrcHandle), GLHGLRCHandleBkpCtx(glhglrcHandleBkpCtx), GLHDCHandle(glhdcHandle) {
|
||||
|
||||
@@ -57,8 +57,6 @@ class GLSharingFunctionsWindows : public GLSharingFunctions {
|
||||
|
||||
GLboolean initGLFunctions() override;
|
||||
bool isOpenGlSharingSupported() override;
|
||||
bool isHandleCompatible(const DriverModel &driverModel, uint32_t handle) const override;
|
||||
bool isGlHdcHandleMissing(uint32_t handle) const override { return handle == 0u; }
|
||||
static bool isGlSharingEnabled();
|
||||
|
||||
// Arb sync event
|
||||
|
||||
@@ -267,8 +267,4 @@ void GlTexture::releaseResource(MemObj *memObject, uint32_t rootDeviceIndex) {
|
||||
}
|
||||
}
|
||||
|
||||
void GlTexture::resolveGraphicsAllocationChange(osHandle currentSharedHandle, UpdateData *updateData) {
|
||||
GlSharing::resolveGraphicsAllocationChange(currentSharedHandle, updateData);
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
#define OSAPI WINAPI
|
||||
|
||||
using GLType = uint32_t;
|
||||
using GLDisplay = HDC;
|
||||
using GLContext = HGLRC;
|
||||
using GLFunctionType = PROC(__stdcall *)(LPCSTR arg1);
|
||||
typedef uint32_t GLType;
|
||||
typedef HDC GLDisplay;
|
||||
typedef HGLRC GLContext;
|
||||
|
||||
@@ -7527,6 +7527,8 @@ class ClWaitForEventsTracer {
|
||||
tracing_notify_state_t state = TRACING_NOTIFY_STATE_NOTHING_CALLED;
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
class ClCreateFromGlBufferTracer {
|
||||
public:
|
||||
ClCreateFromGlBufferTracer() {}
|
||||
@@ -8150,4 +8152,6 @@ class ClGetGlTextureInfoTracer {
|
||||
tracing_notify_state_t state = TRACING_NOTIFY_STATE_NOTHING_CALLED;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace HostSideTracing
|
||||
|
||||
Reference in New Issue
Block a user