Results 1 to 3 of 3

Thread: clCreateFromGLTexture2D returns CL_INVALID_IMAGE_FORMAT_DESC

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Posts
    16

    clCreateFromGLTexture2D returns CL_INVALID_IMAGE_FORMAT_DESC

    Hi,

    I'm trying to process textures that are rendered to using FBOs. The rendering part works fine, but when I try to use clCreateFromGLTexture2D it returns CL_INVALID_IMAGE_FORMAT_DESCRIPTOR. I assumed that maybe the texture's internal format is wrong, but when I switched to GL_RGB the problem didn't disappear.

    I'm using kUbuntu 11.10 64bit with Catalyst 11.12 and APP SDK 2.6

    here's the code:

    OpenCL initialization:
    Code :
      GLXContext the_glx_context = glXGetCurrentContext();
     
      if ( the_glx_context == 0 )
      {
        std::cerr << "Error getting the current glX context.\n";
        objs::get()->conf.the_window.Close();
        exit( 1 );
      }
     
      cl_int error = CL_SUCCESS;
     
      if ( !clGetGLContextInfoKHR )
      {
        clGetGLContextInfoKHR = ( clGetGLContextInfoKHR_fn )clGetExtensionFunctionAddress( "clGetGLContextInfoKHR" );
     
        if ( !clGetGLContextInfoKHR )
        {
          std::cerr << "Error getting clGetGLContextInfoKHR function ptr.\n";
          objs::get()->conf.the_window.Close();
          exit( 1 );
        }
      }
     
      cl_uint num_platfroms;
     
      error = clGetPlatformIDs( 1, &the_platform, &num_platfroms );
      objs::get()->get_opencl_error(error);
     
      cl_context_properties the_context_properties[] =
      {
        CL_CONTEXT_PLATFORM,
        ( cl_context_properties )the_platform,
        CL_GLX_DISPLAY_KHR,
        ( intptr_t )glXGetCurrentDisplay(),
        CL_GL_CONTEXT_KHR,
        ( intptr_t )the_glx_context,
        0
      };
     
      error = clGetGLContextInfoKHR( the_context_properties, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, sizeof( cl_device_id ), &the_device, 0 );
      objs::get()->get_opencl_error(error);
     
      the_context = clCreateContext( the_context_properties, 1, &the_device, 0, 0, &error );
      objs::get()->get_opencl_error(error);
     
      the_command_queue = clCreateCommandQueue( the_context, the_device, 0, &error );
      objs::get()->get_opencl_error(error);

    FBO initialization:
    Code :
      float w = objs::get()->conf.SCREEN_WIDTH;
      float h = objs::get()->conf.SCREEN_HEIGHT;
     
      fbo.create();
      fbo.bind();
     
      GLenum modes[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
      glDrawBuffers( 2, modes );
     
      albedo.create();
      normals.create();
      depth.create();
     
      glActiveTexture( GL_TEXTURE5 );
      albedo.bind();
      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_LINEAR );
      glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
      glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB16F, w, h, 0, GL_RGBA, GL_FLOAT, 0 );
      albedo.width = w;
      albedo.height = h;
     
      glActiveTexture( GL_TEXTURE6 );
      normals.bind();
      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_LINEAR );
      glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
      glTexImage2D( GL_TEXTURE_2D, 0, GL_RG16F, w, h, 0, GL_RGBA, GL_FLOAT, 0 );
      normals.width = w;
      normals.height = h;
     
      glActiveTexture( GL_TEXTURE7 );
      depth.bind();
      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_DEPTH_COMPONENT, w, h, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0 );
      depth.width = w;
      depth.height = h;
     
      rbo.create();
      rbo.bind();
      rbo.set_storage_format( GL_DEPTH_COMPONENT, w, h );
      rbo.width = w;
      rbo.height = h;
      rbo.attach_to_frame_buffer( GL_DEPTH_ATTACHMENT, &fbo );
     
      glActiveTexture( GL_TEXTURE0 );
     
      albedo.attach_to_frame_buffer( GL_COLOR_ATTACHMENT0, &fbo );
      normals.attach_to_frame_buffer( GL_COLOR_ATTACHMENT1, &fbo );
      depth.attach_to_frame_buffer( GL_DEPTH_ATTACHMENT, &fbo );
     
      if ( fbo.check() == false )
      {
        std::cerr << "FBO not complete, DIE!\n";
        objs::get()->conf.the_window.Close();
        exit( 1 );
      }
     
      fbo.unbind();
     
      cl_int error;
      albedo_cl = clCreateFromGLTexture2D(objs::get()->the_compute_context.the_context, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, albedo.data, &error);
      objs::get()->get_opencl_error(error); //This throws CL_INVALID_IMAGE_FORMAT_DESCRIPTOR 
      normals_cl = clCreateFromGLTexture2D(objs::get()->the_compute_context.the_context, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, normals.data, &error);
      objs::get()->get_opencl_error(error);
      depth_cl = clCreateFromGLTexture2D(objs::get()->the_compute_context.the_context, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, depth.data, &error);
      objs::get()->get_opencl_error(error);

    any ideas what might went wrong?

    Best regards,
    Yours3!f

  2. #2
    Junior Member
    Join Date
    Aug 2010
    Posts
    16

    Re: clCreateFromGLTexture2D returns CL_INVALID_IMAGE_FORMAT_

    ok, so I tried to make a small code that demonstrates my problem, but the problem surprisingly didn't come up, and I don't know why. I'm trying to read AND write a single image2d_t in a kernel, but it doesn't recognize the __read_write qualifier for the kernel argument

    here's the program:
    https://docs.google.com/open?id=0B2X...g0NGIxYzA2ODFj

    here's the compiler error:
    /tmp/OCL6fVNEf.cl(1): error: identifier "__read_write" is undefined
    __kernel void main(__read_write image2d_t texture)
    ^
    /tmp/OCL6fVNEf.cl(1): error: expected a ")"
    __kernel void main(__read_write image2d_t texture)
    ^
    /tmp/OCL6fVNEf.cl(7): error: identifier "texture" is undefined
    float4 color = read_imagef(texture, the_sampler, coords);
    ^
    3 errors detected in the compilation of "/tmp/OCL6fVNEf.cl".
    Internal error: clc compiler invocation failed.

  3. #3
    Junior Member
    Join Date
    Aug 2010
    Posts
    16

    Re: clCreateFromGLTexture2D returns CL_INVALID_IMAGE_FORMAT_

    ok, I solved it, I figured out from the specs that image2d_t can only be read_only or write_only

Similar Threads

  1. clCreateFromGLTexture2D returns CL_INVALID_GL_OBJECT (-60)
    By kaesemeister in forum Interoperability issues
    Replies: 0
    Last Post: 06-13-2012, 08:19 PM
  2. Problem with clCreateFromGLTexture2D
    By PnotNP in forum OpenCL
    Replies: 3
    Last Post: 03-26-2012, 02:59 AM
  3. Deprecated in 1.2 (clCreateFromGLTexture2D)
    By kalx in forum Interoperability issues
    Replies: 1
    Last Post: 03-14-2012, 11:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •