From 85beaf8888d627a7351fd63d678bd336ef9a065f Mon Sep 17 00:00:00 2001
From: foreman
Date: Thu, 7 Sep 2017 12:15:41 -0400
Subject: [PATCH] P4 to Git Change 1456230 by asalmanp@asalmanp-ocl-stg on
2017/09/07 12:00:21
SWDEV-130722 - Channel order in an interop buffer from OpenCL to OpenGL is flipped on Vega
OCL calls glGetTexLevelParameteriv_ function to get the internal GL format but this format is the one chosen by app in OGL API such as glTexImage2D.
The issue is that OGL sometimes selects a different format than defined in the glTexImage2D and this causes some issues in cl_gl interop. One example is shown below
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA/**internal format**/, width, height, 0, GL_BGRA/**external format**/, GL_UNSIGNED_BYTES, NULL);
in this case GL_RGBA is selected by app as the internal format but OGL switches to BGRA8 internally and causes an issue later in cl_gl interop (i.e., R and B channels are swapped) because OCL gets GL_RGBA as the internal format in the glGetTexLevelParameteriv_ call.
To avoid this issue, OCL needs to query the real internal gl format in wglResourceAttachAMD and adjusts the CL format accordingly.
ReviewBoardURL = http://ocltc.amd.com/reviews/r/13408/
Affected files ...
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.hpp#19 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevicegl.cpp#5 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.cpp#35 edit
[ROCm/clr commit: e8395888c53928170e9cda956f3d62a97ec7dc0c]
---
projects/clr/rocclr/runtime/device/pal/paldevice.hpp | 2 +-
projects/clr/rocclr/runtime/device/pal/paldevicegl.cpp | 4 +++-
projects/clr/rocclr/runtime/device/pal/palresource.cpp | 9 ++++++++-
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/projects/clr/rocclr/runtime/device/pal/paldevice.hpp b/projects/clr/rocclr/runtime/device/pal/paldevice.hpp
index 667bd01840..b22ed66230 100644
--- a/projects/clr/rocclr/runtime/device/pal/paldevice.hpp
+++ b/projects/clr/rocclr/runtime/device/pal/paldevice.hpp
@@ -482,7 +482,7 @@ class Device : public NullDevice {
bool initGLInteropPrivateExt(void* GLplatformContext, void* GLdeviceContext) const;
bool glCanInterop(void* GLplatformContext, void* GLdeviceContext) const;
bool resGLAssociate(void* GLContext, uint name, uint type, void** handle, void** mbResHandle,
- size_t* offset
+ size_t* offset, uint& glFormat
#ifdef ATI_OS_WIN
,
Pal::DoppDesktopInfo& doppDesktopInfo
diff --git a/projects/clr/rocclr/runtime/device/pal/paldevicegl.cpp b/projects/clr/rocclr/runtime/device/pal/paldevicegl.cpp
index e9d61ed826..e3ed052f72 100644
--- a/projects/clr/rocclr/runtime/device/pal/paldevicegl.cpp
+++ b/projects/clr/rocclr/runtime/device/pal/paldevicegl.cpp
@@ -178,7 +178,7 @@ bool Device::glDissociate(void* GLplatformContext, void* GLdeviceContext) const
}
bool Device::resGLAssociate(void* GLContext, uint name, uint type, void** handle,
- void** mbResHandle, size_t* offset
+ void** mbResHandle, size_t* offset, uint& glFormat
#ifdef ATI_OS_WIN
,
Pal::DoppDesktopInfo& doppDesktopInfo
@@ -225,6 +225,8 @@ bool Device::resGLAssociate(void* GLContext, uint name, uint type, void** handle
}
#endif
+ glFormat = static_cast(hData.format);
+
return status;
}
diff --git a/projects/clr/rocclr/runtime/device/pal/palresource.cpp b/projects/clr/rocclr/runtime/device/pal/palresource.cpp
index 6c5e85fa83..e44f511960 100644
--- a/projects/clr/rocclr/runtime/device/pal/palresource.cpp
+++ b/projects/clr/rocclr/runtime/device/pal/palresource.cpp
@@ -483,13 +483,20 @@ bool Resource::create(MemoryType memType, CreateParams* params) {
layer = oglRes->layer_;
type = oglRes->type_;
mipLevel = oglRes->mipLevel_;
+ uint glFormat = 0;
if (!dev().resGLAssociate(oglRes->glPlatformContext_, oglRes->handle_, glType_,
- &openInfo.hExternalResource, &glInteropMbRes_, &offset_,
+ &openInfo.hExternalResource, &glInteropMbRes_, &offset_, glFormat,
openInfo.doppDesktopInfo)) {
return false;
}
desc_.isDoppTexture_ = (openInfo.doppDesktopInfo.gpuVirtAddr != 0);
+ // This is a temporary workaround for SWDEV-130722
+ // 0x22 = CM_SURF_FMT_BGRA8 defined in cm_enum.h in gsl
+ if (glFormat == 0x22) {
+ desc_.format_.image_channel_order = CL_BGRA;
+ format = dev().getPalFormat(desc().format_, &channels);
+ }
} else {
D3DInteropParams* d3dRes = reinterpret_cast(params);
openInfo.hExternalResource = d3dRes->handle_;