5ba83829e2
SWDEV-94640 - Re-submit CL#1292110 after integration from fsa_foundation: - [OCL-LC-ROCm] OpenCL Runtime Library Implements OpenCL runtime API. Add HSA virtual device to ORCA. Rename hsa_foundation to ROCm Affected files ... ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/Makefile#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/build/Makefile#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/build/Makefile.rocm#1 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/mesa_glinterop.h#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocappprofile.cpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocappprofile.hpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocbinary.cpp#1 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocbinary.hpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocblit.cpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocblit.hpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccompiler.cpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccompilerlib.cpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccompilerlib.hpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdefs.hpp#4 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.cpp#4 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.hpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocglinterop.cpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocglinterop.hpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rockernel.cpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rockernel.hpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roclib.cpp#1 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roclib.h#1 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocmemory.cpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocmemory.hpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprintf.cpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprintf.hpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.hpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocregisters.hpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocsettings.cpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocsettings.hpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocvirtual.cpp#3 add ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocvirtual.hpp#3 add
121 satır
2.9 KiB
C++
121 satır
2.9 KiB
C++
//
|
|
// Copyright (c) 2016 Advanced Micro Devices, Inc. All rights reserved.
|
|
//
|
|
|
|
#ifndef WITHOUT_HSA_BACKEND
|
|
|
|
#include "os/os.hpp"
|
|
#include "utils/debug.hpp"
|
|
#include "utils/flags.hpp"
|
|
#include "device/rocm/rocglinterop.hpp"
|
|
|
|
#if !defined(_WIN32)
|
|
#include <dlfcn.h>
|
|
#endif
|
|
|
|
namespace roc
|
|
{
|
|
|
|
#if !defined(_WIN32)
|
|
static PFNMESAGLINTEROPGLXQUERYDEVICEINFOPROC GlxInfo = nullptr;
|
|
static PFNMESAGLINTEROPGLXEXPORTOBJECTPROC GlxExport = nullptr;
|
|
static PFNMESAGLINTEROPEGLQUERYDEVICEINFOPROC EglInfo = nullptr;
|
|
static PFNMESAGLINTEROPEGLEXPORTOBJECTPROC EglExport = nullptr;
|
|
#endif
|
|
|
|
std::atomic<uint32_t> MesaInterop::refCount(0);
|
|
|
|
bool MesaInterop::Supported()
|
|
{
|
|
#ifdef _WIN32
|
|
return false;
|
|
#else
|
|
return true;
|
|
#endif
|
|
}
|
|
|
|
//Attempt to locate Mesa interop APIs. Return which of glx/egl are supported.
|
|
bool MesaInterop::Bind(MESA_INTEROP_KIND Kind, const DisplayHandle& Display, const ContextHandle& Context)
|
|
{
|
|
#if defined(_WIN32)
|
|
return false;
|
|
#else
|
|
if(Kind==MESA_INTEROP_NONE)
|
|
return false;
|
|
|
|
if(kind!=MESA_INTEROP_NONE)
|
|
{
|
|
LogError("Error - MesaInterop Bind while already bound.");
|
|
return false;
|
|
}
|
|
|
|
void* glxinfo=dlsym(RTLD_DEFAULT, "MesaGLInteropGLXQueryDeviceInfo");
|
|
void* eglinfo=dlsym(RTLD_DEFAULT, "MesaGLInteropEGLQueryDeviceInfo");
|
|
|
|
if(((glxinfo!=GlxInfo) || (eglinfo!=EglInfo)) && (refCount!=0))
|
|
LogWarning("Warning - Mesa changed while holding interop contexts.");
|
|
|
|
GlxInfo=(PFNMESAGLINTEROPGLXQUERYDEVICEINFOPROC)glxinfo;
|
|
EglInfo=(PFNMESAGLINTEROPEGLQUERYDEVICEINFOPROC)eglinfo;
|
|
|
|
GlxExport=(PFNMESAGLINTEROPGLXEXPORTOBJECTPROC)dlsym(RTLD_DEFAULT, "MesaGLInteropGLXExportObject");
|
|
EglExport=(PFNMESAGLINTEROPEGLEXPORTOBJECTPROC)dlsym(RTLD_DEFAULT, "MesaGLInteropEGLExportObject");
|
|
|
|
uint32_t ret=MESA_INTEROP_NONE;
|
|
if(GlxInfo && GlxExport)
|
|
ret|=MESA_INTEROP_GLX;
|
|
if(EglInfo && EglExport)
|
|
ret|=MESA_INTEROP_EGL;
|
|
|
|
kind = MESA_INTEROP_KIND(ret & Kind);
|
|
display=Display;
|
|
context=Context;
|
|
|
|
if(kind!=MESA_INTEROP_NONE)
|
|
{
|
|
refCount++;
|
|
return true;
|
|
}
|
|
return false;
|
|
|
|
#endif
|
|
}
|
|
|
|
bool MesaInterop::GetInfo(mesa_glinterop_device_info& info) const
|
|
{
|
|
#ifdef _WIN32
|
|
return false;
|
|
#else
|
|
switch(kind)
|
|
{
|
|
case MESA_INTEROP_GLX:
|
|
return GlxInfo(display.glxDisplay, context.glxContext, &info)==MESA_GLINTEROP_SUCCESS;
|
|
case MESA_INTEROP_EGL:
|
|
return EglInfo(display.eglDisplay, context.eglContext, &info)==MESA_GLINTEROP_SUCCESS;
|
|
default:
|
|
return false;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
bool MesaInterop::Export (mesa_glinterop_export_in& in, mesa_glinterop_export_out& out) const
|
|
{
|
|
#ifdef _WIN32
|
|
return false;
|
|
#else
|
|
switch(kind)
|
|
{
|
|
case MESA_INTEROP_GLX:
|
|
return GlxExport(display.glxDisplay, context.glxContext, &in, &out)==MESA_GLINTEROP_SUCCESS;
|
|
case MESA_INTEROP_EGL:
|
|
return EglExport(display.eglDisplay, context.eglContext, &in, &out)==MESA_GLINTEROP_SUCCESS;
|
|
default:
|
|
return false;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
}
|
|
|
|
#endif // WITHOUT_HSA_BACKEND
|