From ca062c81b4381bed801cdaec21af82f7266a449e Mon Sep 17 00:00:00 2001
From: foreman
Date: Thu, 10 Mar 2016 15:21:20 -0500
Subject: [PATCH] P4 to Git Change 1246105 by cpaquot@hog-ocl on 2016/03/10
15:13:37
SWDEV-89711 - Adding EGL interop capability:
- Remove Context::Info::type_ and only use flags_, it's more accurate and type_ was just redundant
- Plumbing work for EGL at the top of the API layer.
ReviewBoardURL = http://ocltc.amd.com/reviews/r/9965/diff/
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d10.cpp#11 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d11.cpp#18 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d9.cpp#28 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_gl.cpp#48 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_gl_amd.hpp#18 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/cpu/cpudevice.hpp#94 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#269 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.cpp#542 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.hpp#157 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsadevice.cpp#56 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsadevice.hpp#25 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/context.cpp#40 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/context.hpp#24 edit
---
opencl/api/opencl/amdocl/cl_d3d10.cpp | 2 +-
opencl/api/opencl/amdocl/cl_d3d11.cpp | 2 +-
opencl/api/opencl/amdocl/cl_d3d9.cpp | 10 +--
opencl/api/opencl/amdocl/cl_gl.cpp | 115 ++++++++++++++++---------
opencl/api/opencl/amdocl/cl_gl_amd.hpp | 18 +++-
5 files changed, 98 insertions(+), 49 deletions(-)
diff --git a/opencl/api/opencl/amdocl/cl_d3d10.cpp b/opencl/api/opencl/amdocl/cl_d3d10.cpp
index 634472596d..2bbfbbf0e7 100644
--- a/opencl/api/opencl/amdocl/cl_d3d10.cpp
+++ b/opencl/api/opencl/amdocl/cl_d3d10.cpp
@@ -117,7 +117,7 @@ RUNTIME_ENTRY(cl_int, clGetDeviceIDsFromD3D10KHR, (
for (cl_uint i = 0; i < num_gpu_devices; ++i) {
cl_device_id device = gpu_devices[i];
if (is_valid(device) &&
- as_amd(device)->bindExternalDevice(CL_CONTEXT_D3D10_DEVICE_KHR, d3d10_device, NULL, VALIDATE_ONLY)) {
+ as_amd(device)->bindExternalDevice(amd::Context::Flags::D3D10DeviceKhr, d3d10_device, NULL, VALIDATE_ONLY)) {
compatible_devices.push_back(as_amd(device));
}
}
diff --git a/opencl/api/opencl/amdocl/cl_d3d11.cpp b/opencl/api/opencl/amdocl/cl_d3d11.cpp
index aceef1cdfa..2d50a63e61 100644
--- a/opencl/api/opencl/amdocl/cl_d3d11.cpp
+++ b/opencl/api/opencl/amdocl/cl_d3d11.cpp
@@ -119,7 +119,7 @@ RUNTIME_ENTRY(cl_int, clGetDeviceIDsFromD3D11KHR, (
for (cl_uint i = 0; i < num_gpu_devices; ++i) {
cl_device_id device = gpu_devices[i];
if (is_valid(device) &&
- as_amd(device)->bindExternalDevice(CL_CONTEXT_D3D11_DEVICE_KHR, d3d11_device, NULL, VALIDATE_ONLY)) {
+ as_amd(device)->bindExternalDevice(amd::Context::Flags::D3D11DeviceKhr, d3d11_device, NULL, VALIDATE_ONLY)) {
compatible_devices.push_back(as_amd(device));
}
}
diff --git a/opencl/api/opencl/amdocl/cl_d3d9.cpp b/opencl/api/opencl/amdocl/cl_d3d9.cpp
index 81e9328e01..969c61be36 100644
--- a/opencl/api/opencl/amdocl/cl_d3d9.cpp
+++ b/opencl/api/opencl/amdocl/cl_d3d9.cpp
@@ -69,23 +69,23 @@ RUNTIME_ENTRY(cl_int, clGetDeviceIDsFromDX9MediaAdapterKHR, (
std::vector compatible_devices;
for (cl_uint i = 0; i < num_gpu_devices; ++i) {
cl_device_id device = gpu_devices[i];
- intptr_t context_type;
+ amd::Context::Flags context_flag;
switch (media_adapters_type[i]) {
case CL_ADAPTER_D3D9_KHR:
- context_type = CL_CONTEXT_ADAPTER_D3D9_KHR;
+ context_flag = amd::Context::Flags::D3D9DeviceKhr;
break;
case CL_ADAPTER_D3D9EX_KHR:
- context_type = CL_CONTEXT_ADAPTER_D3D9EX_KHR;
+ context_flag = amd::Context::Flags::D3D9DeviceEXKhr;
break;
case CL_ADAPTER_DXVA_KHR:
- context_type = CL_CONTEXT_ADAPTER_DXVA_KHR;
+ context_flag = amd::Context::Flags::D3D9DeviceVAKhr;
break;
}
for (cl_uint j = 0; j < num_media_adapters; ++j) {
//Since there can be multiple DX9 adapters passed in the array we need to validate interopability with each.
if (is_valid(device) && (media_adapters_type[j] == CL_ADAPTER_D3D9EX_KHR) &&
- as_amd(device)->bindExternalDevice(context_type,
+ as_amd(device)->bindExternalDevice(context_flag,
d3d9_device[j], NULL, VALIDATE_ONLY)) {
compatible_devices.push_back(as_amd(device));
}
diff --git a/opencl/api/opencl/amdocl/cl_gl.cpp b/opencl/api/opencl/amdocl/cl_gl.cpp
index f00a0a365a..b56853c9b1 100644
--- a/opencl/api/opencl/amdocl/cl_gl.cpp
+++ b/opencl/api/opencl/amdocl/cl_gl.cpp
@@ -15,6 +15,10 @@
#include
#include
+#include
+#include
+#include
+
#include "cl_common.hpp"
#include "cl_gl_amd.hpp"
@@ -915,7 +919,7 @@ RUNTIME_ENTRY(cl_int, clGetGLContextInfoKHR, (
for (cl_uint i = 0; i < num_gpu_devices; ++i) {
cl_device_id device = gpu_devices[i];
if (is_valid(device) &&
- as_amd(device)->bindExternalDevice(info.type_, info.hDev_, info.hCtx_, VALIDATE_ONLY)) {
+ as_amd(device)->bindExternalDevice(info.flags_, info.hDev_, info.hCtx_, VALIDATE_ONLY)) {
return amd::clGetInfo(
device, param_value_size, param_value, param_value_size_ret);
}
@@ -955,7 +959,7 @@ RUNTIME_ENTRY(cl_int, clGetGLContextInfoKHR, (
for (cl_uint i = 0; i < total_devices; ++i) {
cl_device_id device = devices[i];
if (is_valid(device) &&
- as_amd(device)->bindExternalDevice(info.type_, info.hDev_, info.hCtx_, VALIDATE_ONLY)) {
+ as_amd(device)->bindExternalDevice(info.flags_, info.hDev_, info.hCtx_, VALIDATE_ONLY)) {
compatible_devices.push_back(as_amd(device));
}
}
@@ -1367,6 +1371,7 @@ BufferGL::initDeviceMemory()
bool
BufferGL::mapExtObjectInCQThread()
{
+ assert(!context_().glenv()->isEGL());
GLFunctions::SetIntEnv ie(context_().glenv());
if (!ie.isValid()) {
return false;
@@ -1397,6 +1402,7 @@ BufferGL::mapExtObjectInCQThread()
bool
BufferGL::unmapExtObjectInCQThread()
{
+ assert(!context_().glenv()->isEGL());
GLFunctions::SetIntEnv ie(context_().glenv());
if (!ie.isValid()) {
return false;
@@ -1488,6 +1494,7 @@ ImageGL::initDeviceMemory()
bool
ImageGL::mapExtObjectInCQThread()
{
+ assert(!context_().glenv()->isEGL());
GLFunctions::SetIntEnv ie(context_().glenv());
if (!ie.isValid()) {
return false;
@@ -1533,6 +1540,7 @@ ImageGL::mapExtObjectInCQThread()
bool
ImageGL::unmapExtObjectInCQThread()
{
+ assert(!context_().glenv()->isEGL());
GLFunctions::SetIntEnv ie(context_().glenv());
if (!ie.isValid()) {
return false;
@@ -2390,9 +2398,14 @@ GLFunctions::SetIntEnv::~SetIntEnv()
env_->getLock().unlock();
}
-GLFunctions::GLFunctions(HMODULE h) :
+GLFunctions::GLFunctions(HMODULE h, bool isEGL) :
libHandle_(h),
missed_(0),
+ eglDisplay_(EGL_NO_DISPLAY),
+ eglOriginalContext_(EGL_NO_CONTEXT),
+ eglInternalContext_(EGL_NO_CONTEXT),
+ eglTempContext_(EGL_NO_CONTEXT),
+ isEGL_(isEGL),
#ifdef _WIN32
hOrigGLRC_(0),
hDC_(0),
@@ -2415,57 +2428,65 @@ GLFunctions::GLFunctions(HMODULE h) :
glXMakeCurrent_(NULL)
#endif //!_WIN32
{
- GetProcAddress_ = (PFN_xxxGetProcAddress) GETPROCADDRESS(h, API_GETPROCADDR);
-
#define VERIFY_POINTER(p) if (NULL == p) {missed_++;}
+ if (isEGL_)
+ {
+ GetProcAddress_ = (PFN_xxxGetProcAddress) GETPROCADDRESS(h, "eglGetProcAddress");
+ }
+ else {
+ GetProcAddress_ = (PFN_xxxGetProcAddress) GETPROCADDRESS(h, API_GETPROCADDR);
+ }
#ifndef _WIN32
// Initialize pointers to X11/GLX functions
// We can not link with these functions on compile time since we need to support
// console mode. In console mode X server and X server components may be absent.
// Hence linking with X11 or libGL will fail module image loading in console mode.-tzachi cohen
- glXGetCurrentDrawable_ = (PFNglXGetCurrentDrawable)GETPROCADDRESS(h,"glXGetCurrentDrawable");
- VERIFY_POINTER(glXGetCurrentDrawable_)
- glXGetCurrentDisplay_ = (PFNglXGetCurrentDisplay)GETPROCADDRESS(h,"glXGetCurrentDisplay");
- VERIFY_POINTER(glXGetCurrentDisplay_)
- glXGetCurrentContext_ = (PFNglXGetCurrentContext) GETPROCADDRESS(h,"glXGetCurrentContext");
- VERIFY_POINTER(glXGetCurrentContext_)
- glXChooseVisual_ = (PFNglXChooseVisual)GETPROCADDRESS(h,"glXChooseVisual");
- VERIFY_POINTER(glXChooseVisual_)
- glXCreateContext_ = (PFNglXCreateContext)GETPROCADDRESS(h,"glXCreateContext");
- VERIFY_POINTER(glXCreateContext_)
- glXDestroyContext_ = (PFNglXDestroyContext) GETPROCADDRESS(h,"glXDestroyContext");
- VERIFY_POINTER(glXDestroyContext_)
- glXMakeCurrent_ = (PFNglXMakeCurrent) GETPROCADDRESS(h,"glXMakeCurrent");
- VERIFY_POINTER(glXMakeCurrent_)
+ if (!isEGL_) {
+ glXGetCurrentDrawable_ = (PFNglXGetCurrentDrawable)GETPROCADDRESS(h,"glXGetCurrentDrawable");
+ VERIFY_POINTER(glXGetCurrentDrawable_)
+ glXGetCurrentDisplay_ = (PFNglXGetCurrentDisplay)GETPROCADDRESS(h,"glXGetCurrentDisplay");
+ VERIFY_POINTER(glXGetCurrentDisplay_)
+ glXGetCurrentContext_ = (PFNglXGetCurrentContext) GETPROCADDRESS(h,"glXGetCurrentContext");
+ VERIFY_POINTER(glXGetCurrentContext_)
+ glXChooseVisual_ = (PFNglXChooseVisual)GETPROCADDRESS(h,"glXChooseVisual");
+ VERIFY_POINTER(glXChooseVisual_)
+ glXCreateContext_ = (PFNglXCreateContext)GETPROCADDRESS(h,"glXCreateContext");
+ VERIFY_POINTER(glXCreateContext_)
+ glXDestroyContext_ = (PFNglXDestroyContext) GETPROCADDRESS(h,"glXDestroyContext");
+ VERIFY_POINTER(glXDestroyContext_)
+ glXMakeCurrent_ = (PFNglXMakeCurrent) GETPROCADDRESS(h,"glXMakeCurrent");
+ VERIFY_POINTER(glXMakeCurrent_)
- HMODULE hXModule = (HMODULE) Os::loadLibrary("libX11.so.6");
- if (NULL != hXModule) {
- XOpenDisplay_ = (PFNXOpenDisplay)GETPROCADDRESS(hXModule,"XOpenDisplay");
- VERIFY_POINTER(XOpenDisplay_)
- XCloseDisplay_= (PFNXCloseDisplay)GETPROCADDRESS(hXModule,"XCloseDisplay");
- VERIFY_POINTER(XCloseDisplay_)
+ HMODULE hXModule = (HMODULE) Os::loadLibrary("libX11.so.6");
+ if (NULL != hXModule) {
+ XOpenDisplay_ = (PFNXOpenDisplay)GETPROCADDRESS(hXModule,"XOpenDisplay");
+ VERIFY_POINTER(XOpenDisplay_)
+ XCloseDisplay_= (PFNXCloseDisplay)GETPROCADDRESS(hXModule,"XCloseDisplay");
+ VERIFY_POINTER(XCloseDisplay_)
+ }
+ else {
+ missed_ += 2;
+ }
}
- else{
- missed_ += 2;
- }
-
// Initialize pointers to GL functions
#include "gl_functions.hpp"
#else
- wglCreateContext_ = (PFN_wglCreateContext)GETPROCADDRESS(h,"wglCreateContext");
- VERIFY_POINTER(wglCreateContext_)
- wglGetCurrentContext_ = (PFN_wglGetCurrentContext)GETPROCADDRESS(h,"wglGetCurrentContext");
- VERIFY_POINTER(wglGetCurrentContext_)
- wglGetCurrentDC_ = (PFN_wglGetCurrentDC)GETPROCADDRESS(h,"wglGetCurrentDC");
- VERIFY_POINTER(wglGetCurrentDC_)
- wglDeleteContext_ = (PFN_wglDeleteContext)GETPROCADDRESS(h,"wglDeleteContext");
- VERIFY_POINTER(wglDeleteContext_)
- wglMakeCurrent_ = (PFN_wglMakeCurrent)GETPROCADDRESS(h,"wglMakeCurrent");
- VERIFY_POINTER(wglMakeCurrent_)
- wglShareLists_ = (PFN_wglShareLists)GETPROCADDRESS(h,"wglShareLists");
- VERIFY_POINTER(wglShareLists_)
+ if (!isEGL_) {
+ wglCreateContext_ = (PFN_wglCreateContext)GETPROCADDRESS(h,"wglCreateContext");
+ VERIFY_POINTER(wglCreateContext_)
+ wglGetCurrentContext_ = (PFN_wglGetCurrentContext)GETPROCADDRESS(h,"wglGetCurrentContext");
+ VERIFY_POINTER(wglGetCurrentContext_)
+ wglGetCurrentDC_ = (PFN_wglGetCurrentDC)GETPROCADDRESS(h,"wglGetCurrentDC");
+ VERIFY_POINTER(wglGetCurrentDC_)
+ wglDeleteContext_ = (PFN_wglDeleteContext)GETPROCADDRESS(h,"wglDeleteContext");
+ VERIFY_POINTER(wglDeleteContext_)
+ wglMakeCurrent_ = (PFN_wglMakeCurrent)GETPROCADDRESS(h,"wglMakeCurrent");
+ VERIFY_POINTER(wglMakeCurrent_)
+ wglShareLists_ = (PFN_wglShareLists)GETPROCADDRESS(h,"wglShareLists");
+ VERIFY_POINTER(wglShareLists_)
+ }
#endif
}
@@ -2493,6 +2514,11 @@ GLFunctions::~GLFunctions()
bool
GLFunctions::init(intptr_t hdc, intptr_t hglrc)
{
+ if (isEGL_) {
+ eglDisplay_ = (EGLDisplay)hdc;
+ eglOriginalContext_ = (EGLContext)hglrc;
+ return true;
+ }
#ifdef _WIN32
DWORD err;
@@ -2574,6 +2600,9 @@ GLFunctions::init(intptr_t hdc, intptr_t hglrc)
bool
GLFunctions::setIntEnv()
{
+ if (isEGL_) {
+ return true;
+ }
#ifdef _WIN32
// Save current DC and GLRC
tempDC_ = wglGetCurrentDC_();
@@ -2606,6 +2635,10 @@ GLFunctions::setIntEnv()
bool
GLFunctions::restoreEnv()
{
+ if (isEGL_) {
+ // eglMakeCurrent( );
+ return true;
+ }
#ifdef _WIN32
// Restore original DC and GLRC
if (!wglMakeCurrent_(tempDC_, tempGLRC_)) {
diff --git a/opencl/api/opencl/amdocl/cl_gl_amd.hpp b/opencl/api/opencl/amdocl/cl_gl_amd.hpp
index d8efdb2cec..332bd95d28 100644
--- a/opencl/api/opencl/amdocl/cl_gl_amd.hpp
+++ b/opencl/api/opencl/amdocl/cl_gl_amd.hpp
@@ -17,6 +17,11 @@
#ifndef _WIN32
#include
#endif //!_WIN32
+
+#include
+#include
+#include
+
#include "platform/context.hpp"
#include "platform/command.hpp"
@@ -255,6 +260,12 @@ private:
amd::Monitor lock_;
+ EGLDisplay eglDisplay_;
+ EGLContext eglOriginalContext_;
+ EGLContext eglInternalContext_;
+ EGLContext eglTempContext_;
+ bool isEGL_;
+
#ifdef _WIN32
HGLRC hOrigGLRC_;
HDC hDC_;
@@ -295,12 +306,13 @@ public:
#endif
public:
- GLFunctions(HMODULE h);
+ GLFunctions(HMODULE h, bool isEGL);
~GLFunctions();
// Query CL-GL context association
bool isAssociated() const
{
+ if (isEGL_ && eglDisplay_ && eglOriginalContext_) return true;
#ifdef _WIN32
if(hDC_ && hOrigGLRC_) return true;
#else //!_WIN32
@@ -308,6 +320,10 @@ public:
#endif //!_WIN32
return false;
}
+ bool isEGL() const
+ {
+ return isEGL_;
+ }
// Accessor methods
#ifdef _WIN32
HGLRC getOrigGLRC() const {return hOrigGLRC_;}