0 Replies Latest reply on Aug 6, 2013 3:38 AM by Roman85

    fglrx, incorrect openGL rendering while direct data transfer to OpenCL.

    Roman85

      Hi, I am develop fast png compressor on openCL. I am trying to improve performance by directly transferring data out of OpenGL context to OpenCL kernel through read_only image2d_t. The error occurs with some opengl functions when running on Linux (in windows work fine).  Some part of image data miss in image2d_t_t (at OpenCL kernel start).) I work with java bindings JOGL and JOCL, OS kubuntu 13 x64, Radeon HD 6800  driver version 13.4.

       

      Špproximate algorithm:

      1) Initialize OpenGL context through JOGL (I am use GLOffscreenAutoDrawable)

      2) Create OpenCL context:

       

      val options = new cl_context_properties()

      options.addProperty(CL_CONTEXT_PLATFORM, OCL_PLATFORM)

      options.addProperty(CL_GL_CONTEXT_KHR, glContextHandle)

      options.addProperty(CL_GLX_DISPLAY_KHR, displayHandle)

      clCreateContext(options, 1, Array(OCL_DEVICE),null, null, null)

       

      3) Initialize OpenGL FrameBuffer

        gl.glGenRenderbuffers(1, renderBuf, 0)

        gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, renderBuf(0))

        gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fbo.getWriteFramebuffer)

        gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, GL.GL_RGBA, width, height)

        gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0, GL.GL_RENDERBUFFER, renderBuf(0))

       

      4) Wrap render buffer as OpenCL image2d_t

        CL.clCreateFromGLRenderbuffer(ctx, access.getCode, renderBuf(0), null)

       

      5) Render picture with OpenGL context to FrameBuffer

      6) Synchronize OpenGL - OpenCL

        gl.glFlush()

        gl.glFinish()

        CL.clEnqueueAcquireGLObjects(queue.queue, 1, inpArr, 0, null, null)

       

      7) Run OpenCL png compressor with read data from image2d_t

      8) Wait for OpenCL finish

        CL.clEnqueueReleaseGLObjects(queue.queue, 1, inpArr, 0, null, null)

        CL.clFinish(queue)

       

      Problems:

      1) Call of gl.glClear(GL.GL_COLOR_BUFFER_BIT) has no effect (Previous data or garbage remain in renderBuffer - image2d_t). But if call glReadPixels (At least for one pixel) before OpenCL kernel run, then previous data clear.

       

      2) Incorrect blending translucent texture: translucent pixels become dark.

        gl.glEnable(GL.GL_TEXTURE_2D)

        gl.glTexEnvf(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_MODE, GL2ES1.GL_ADD)

         val texture = AWTTextureIO.newTexture(gl.getGLProfile, img._1, true)

        texture.enable(gl)

        texture.bind(gl)

        gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)

        gl.glEnable(GL.GL_BLEND)

       

        gl.glBegin(GL2.GL_QUADS)

        gl.glTexCoord2f(0, 0)

        gl.glVertex2f(upperLeft._1, upperLeft._2)

        gl.glTexCoord2f(1, 0)

        gl.glVertex2f(upperRight._1, upperRight._2)

        gl.glTexCoord2f(1, 1)

        gl.glVertex2f(lowerRight._1, lowerRight._2)

        gl.glTexCoord2f(0, 1)

        gl.glVertex2f(lowerLeft._1, lowerLeft._2)

        gl.glEnd()

       

        texture.disable(gl)

       

      If read same renderBuffer from glReadPixels (not through openCl image2d_t), then translucent texture area look fine.