3 Replies Latest reply on Jul 30, 2010 12:39 PM by danbartlett@ntlworld.com

    clCreateFromGLTexture2D + GL textures without mipmaps

    danbartlett@ntlworld.com

      If you create a GL texture, then try to create a CL image from this texture, it seems to fail unless the GL texture has mipmaps.

      clCreateFromGLTexture2D also returns error -4 (CL_MEM_OBJECT_ALLOCATION_FAILURE) which isn't listed in the spec as a possible error for this function.

       

      // ------------ fails ------------- glGenTextures(1, &GLTex); glBindTexture(GL_TEXTURE_2D, GLTex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); mem = clCreateFromGLTexture2D(CLContext, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, GLTex, &errcode); // errCode is -4 (CL_MEM_OBJECT_ALLOCATION_FAILURE) // ------------ succeeds ------------- glGenTextures(1, &GLTex); glBindTexture(GL_TEXTURE_2D, GLTex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); glGenerateMipmap(GL_TEXTURE_2D); // <==== mem = clCreateFromGLTexture2D(CLContext, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, GLTex, &errcode); // errCode is 0 (CL_SUCCESS)

        • clCreateFromGLTexture2D + GL textures without mipmaps
          omkaranathan

           

          Originally posted by: danbartlett@ntlworld.com If you create a GL texture, then try to create a CL image from this texture, it seems to fail unless the GL texture has mipmaps.

           

          This is working for me without any issues. Seems you are doing something else wrong. Could you provide a test-case which reproduces the problem?

            • clCreateFromGLTexture2D + GL textures without mipmaps
              omkaranathan

              Could you try this code and let me know if you are facing any issues?

              glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); /* Set parameters */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)WINDOW_WIDTH, (GLsizei)WINDOW_HEIGHT, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0); glBindTexture(GL_TEXTURE_2D, 0); // Create output buffer to render using GL outputBuffer = clCreateFromGLTexture2D(context, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, tex, &status);

                • clCreateFromGLTexture2D + GL textures without mipmaps
                  danbartlett@ntlworld.com

                  Thanks.  I see now the OpenCL spec does say "The texture object must be a complete texture as per OpenGL rules on texture completeness", which it wouldn't be without changing GL_TEXTURE_MIN_FILTER from the default GL_NEAREST_MIPMAP_LINEAR value.

                  In particular, adding the line:

                  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

                  makes the texture complete, so fixes the issue.

                  There's still an issue that the function returns CL_MEM_OBJECT_ALLOCATION_FAILURE which isn't a listed error message for glCreateFromGLTexture2D/clCreateFromGLXXX() in the spec though - although it is listed for clCreateImage/clCreateBuffer etc.  CL_MEM_OBJECT_ALLOCATION_FAILURE should maybe be added to the list of error messages for CL/GL functions.  If it returned something like CL_INVALID_GL_OBJECT + the spec mentioned that this error message was also returned in the case of an incomplete GL texture it would be more helpful though.

                  [offtopic] It's now theoretically possible to use a GL texture in OpenGL that isn't texture complete, as long as the sampler object used in combination makes it complete, although this only an academic issue, since you will most likely still set the glTexParameter too.[/offtopic]

                  Another test-case that returns an invalid error message is if you use your code and try:

                      outputBuffer = clCreateFromGLTexture2D(context,
                                                             CL_MEM_WRITE_ONLY,
                                                             GL_TEXTURE_2D,
                                                             1,
                                                             tex,
                                                             &status);
                  Then you will get CL_INVALID_IMAGE_FORMAT_DESCRIPTOR instead of maybe CL_INVALID_GL_OBJECT or perhaps CL_INVALID_MIP_LEVEL.