Hi everyone. First off, I'm using OpenCL 1.2 on a Radeon HD 7750 with Catalyst version 12.8. I'm trying to create an OpenCL kernel that generates mipmap pyramids for OpenGL 3D textures. Since OpenCL does not support mipmaps, I need to create a cl image for each mipmap layer and send these images as arguments to the kernel.
It's creating the cl images for each layer that is the problem. To tell OpenCL to share texture images with OpenGL, I use the command clCreateFromGLTexture. Everything works fine when I create a cl image from the first mipmap layer (i.e. miplevel = 0). However, when I create cl images from the higher layers (miplevel > 0), all I get are empty images. No errors are generated during the process.
Here's a breakdown of my code:
First I create the GL texture with two mipmap layers, and fill each layer with some data:
const unsigned int sideLength = 8;
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
glTexStorage3D(GL_TEXTURE_3D, 2, GL_RGBA8, sideLength, sideLength, sideLength);
std::vector<glm::u8vec4> data(sideLength*sideLength*sideLength, glm::u8vec4(255,255,255,255));
glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, sideLength, sideLength, sideLength, GL_RGBA, GL_UNSIGNED_BYTE, &data);
glTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, sideLength/2, sideLength/2, sideLength/2, GL_RGBA, GL_UNSIGNED_BYTE, &data);
Then afterwards I do some glGetTexImage calls to verify that the data inside each image is correct. I get the results (255,255,255,255) for both layers, which is good.
Now I create CL images from both layers of the texture:
cl_mem clTextureMip0 = clCreateFromGLTexture(clGPUContext, CL_MEM_READ_ONLY, GL_TEXTURE_3D, 0, texture3d, &clError);
cl_mem clTextureMip1 = clCreateFromGLTexture(clGPUContext, CL_MEM_READ_ONLY, GL_TEXTURE_3D, 1, texture3d, &clError);
No errors are reported (clError = 0)
Now to test the content of each image, I call glFinish, acquire the GL objects, and call clEnqueueReadImage on each CL image and examine the results. The data from the first image is correct (255,255,255,255). However, the data from the second image is incorrect (0,0,0,0). They should both read (255,255,255,255). Once again, no errors are generated.
So somehow the second mipmap is not created into a proper CL image despite the fact that no errors are generated. I've looked online trying to find code samples where other people create cl images from gl mipmap layers, but I can't find anything. I have also tried 2d textures, which give me the same problems.