diff --git a/projects/clr/opencl/amdocl/cl_gl.cpp b/projects/clr/opencl/amdocl/cl_gl.cpp index b94cab192e..a6a2851d11 100644 --- a/projects/clr/opencl/amdocl/cl_gl.cpp +++ b/projects/clr/opencl/amdocl/cl_gl.cpp @@ -1163,6 +1163,8 @@ cl_mem clCreateFromGLTextureAMD(Context& amdContext, cl_mem_flags clFlags, GLenu cl_mem_object_type clType; cl_gl_object_type clGLType; GLsizei numSamples = 1; + GLint gliTexMaxLevel; + bool wholeMipmap = false; // Verify context init'ed for interop if (!amdContext.glenv() || !amdContext.glenv()->isAssociated()) { @@ -1280,7 +1282,6 @@ cl_mem clCreateFromGLTextureAMD(Context& amdContext, cl_mem_flags clFlags, GLenu if (image) { // Check mipmap level for "texture" name GLint gliTexBaseLevel; - GLint gliTexMaxLevel; clearGLErrors(amdContext); amdContext.glenv()->glGetTexParameteriv_(glTarget, GL_TEXTURE_BASE_LEVEL, &gliTexBaseLevel); @@ -1296,6 +1297,8 @@ cl_mem clCreateFromGLTextureAMD(Context& amdContext, cl_mem_flags clFlags, GLenu LogWarning("Cannot get max mipmap level of a GL \"texture\" object"); return static_cast(0); } + wholeMipmap = miplevel < 0; + miplevel = wholeMipmap ? gliTexBaseLevel : miplevel; if ((gliTexBaseLevel > miplevel) || (miplevel > gliTexMaxLevel)) { *not_null(errcode_ret) = CL_INVALID_MIP_LEVEL; LogWarning("\"miplevel\" is not a valid mipmap level of the GL \"texture\" object"); @@ -1431,10 +1434,17 @@ cl_mem clCreateFromGLTextureAMD(Context& amdContext, cl_mem_flags clFlags, GLenu target = (glTarget == GL_TEXTURE_CUBE_MAP) ? target : 0; - pImageGL = new (amdContext) - ImageGL(amdContext, clType, clFlags, clImageFormat, static_cast(gliTexWidth), + if (wholeMipmap) { + pImageGL = new (amdContext) + ImageGL(amdContext, clType, clFlags, clImageFormat, static_cast(gliTexWidth), + static_cast(gliTexHeight), static_cast(gliTexDepth), glTarget, + texture, miplevel, glInternalFormat, clGLType, numSamples, gliTexMaxLevel, target); + } else { + pImageGL = new (amdContext) + ImageGL(amdContext, clType, clFlags, clImageFormat, static_cast(gliTexWidth), static_cast(gliTexHeight), static_cast(gliTexDepth), glTarget, texture, miplevel, glInternalFormat, clGLType, numSamples, target); + } if (!pImageGL) { *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; diff --git a/projects/clr/rocclr/platform/interop_gl.hpp b/projects/clr/rocclr/platform/interop_gl.hpp index 646d2e0c0d..f7ab95804b 100644 --- a/projects/clr/rocclr/platform/interop_gl.hpp +++ b/projects/clr/rocclr/platform/interop_gl.hpp @@ -182,6 +182,34 @@ public: setInteropObj(this); } + //! ImageGL constructor for mipmapped image, + //! just calls constructors of base classes to pass down the parameters + ImageGL( + Context& amdContext, + cl_mem_object_type clType, + cl_mem_flags clFlags, + const Format& format, + size_t width, + size_t height, + size_t depth, + GLenum glTarget, + GLuint gluiName, + GLint gliMipLevel, + GLenum glInternalFormat, + cl_gl_object_type clGLType, + GLsizei numSamples, + cl_int num_mip_levels, + GLenum glCubemapFace = 0) + : Image(amdContext, clType, clFlags, format, width, height, depth, + Format(format).getElementSize() * width, + Format(format).getElementSize() * width * depth, num_mip_levels) + , GLObject(glTarget, gluiName, gliMipLevel, glInternalFormat, + static_cast(width), static_cast(height), + static_cast(depth), clGLType, glCubemapFace,numSamples) + { + setInteropObj(this); + } + virtual ~ImageGL() {} protected: