Interoperability, block texture access

Discussion in 'GPGPU Technology & Programming' started by Itun, Jan 11, 2012.

  1. Itun

    Newcomer

    Joined:
    Jan 11, 2012
    Messages:
    3
    Likes Received:
    0
    I intend to make Graphics calculation with OpenCL such as ray casting, ray marching and others. And I want to use OpenGL to display result of this calculations (pixel images). I use texture buffer attached to frame buffer. OpenCL writes the result into the texture and then I use glBlitFrameBuffer function to copy texture data to application window framebuffer.
    I met a CL/GL inter problem during the implementation of it. I wrote a simple example to show it. This example shows framebuffer object and texture object initialization, their conjunction, OpenCL buffer creation from GL texture buffer. At the end the main render loop is shown. It consists of texture writing with new data in each frame, framebuffer attachment and copying of this framebuffer.

    Texture Initialization:

    Code:
    for (int i = 0; i < data.Length; i +=4) {
                    data [i] = 255;
                 }
                 GL.BindTexture (TextureTarget.Texture2D, tboID [0]);
                 GL.TexImage2D<byte> (TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, w, h, 0,
                                      PixelFormat.Rgba, PixelType.UnsignedByte, data);
                 
                 GL.BindTexture (TextureTarget.Texture2D, 0)

    TBO+FBO Initialization:
    Code:
         GL.BindFramebuffer (FramebufferTarget.FramebufferExt, fboID [0]);
         GL.FramebufferTexture2D (FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0,
                                  TextureTarget.Texture2D, tboID [0], 0);
         GL.BindFramebuffer (FramebufferTarget.FramebufferExt, 0);
         
    CL/GL Initialization:
    Code:
        bufferID = CL.CreateFromGLTexture2D (context, MemFlags.MemReadWrite, TextureTarget.Texture2D, ((uint[])tboID.Clone()) [0], 0);
    
    Render Loop:
    Code:
        for (int i = 0; i < data.Length; i += 4) {
            data [i] = tt;
         }
         tt++;
         GL.BindTexture (TextureTarget.Texture2D, tboID [0]);
         GL.TexImage2D<byte> (TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, w, h, 0,
                              PixelFormat.Rgba, PixelType.UnsignedByte, data);
         
         GL.BindTexture (TextureTarget.Texture2D, 0);
         GL.BindFramebuffer (FramebufferTarget.FramebufferExt, fboID [0]);
         GL.FramebufferTexture2D (FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0,
                                  TextureTarget.Texture2D, tboID [0], 0);
         GL.BindFramebuffer (FramebufferTarget.FramebufferExt, 0);GL.BindFramebuffer (FramebufferTarget.ReadFramebuffer, fboID [0]);
    
         GL.ReadBuffer (ReadBufferMode.ColorAttachment0);
         GL.DrawBuffer (DrawBufferMode.Back);
    
         GL.BlitFramebuffer (0, 0, w, h, 0, 0, w, h, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Nearest);
    
         GL.BindFramebuffer (FramebufferTarget.ReadFramebuffer, 0);
    
    At the first glance this code looks weird, but it completely shows my problem. CL does not work at all here. In this application OpenCL context is created and OpenCL buffer initialization is occured.
    The work of this should be simple. The color of screen is being changed from black to red. And It does not work in this way. The color does not change from the initial red (texture initialization).
    But it works normal when I comment the CL/GL Initialization (creation of CL buffer from GL texture).
    Why is it so? Why the behavior of the GL buffer is changed depending on CL attachments? How to fix it and make it works?
     
  2. Dade

    Newcomer

    Joined:
    Dec 20, 2009
    Messages:
    206
    Likes Received:
    20
    I use OpenGL PBO for this task in my code; AMD and Nvidia examples included in SDKs uses PBO too (if I remember correctly). Any specific reason to use a texture buffer ?

    This is an example of what I'm talking: http://code.google.com/p/sfera/source/browse/src/renderer/ocl/oclrenderer.cpp#799
     
  3. Itun

    Newcomer

    Joined:
    Jan 11, 2012
    Messages:
    3
    Likes Received:
    0
    Thx, for reply I have tried PBO, but it show bad result. It's performance is the same as simply glDrawPixels from the main memory. The best is BlitBuffer and write to the texture.

    MB, our result me be different, it is not a problem to change a method (DrawPixels, DrawPixels from PBO, FBO&RBO or FBO&TBO). I have more crucial obstacle. My GL/CL interop does not work properly or I don't know something and can't find info. I want to know should my code work in the right way (see above description) or not?
     
  4. Dade

    Newcomer

    Joined:
    Dec 20, 2009
    Messages:
    206
    Likes Received:
    20
    I don't see any trace of required object locking ("cmdQueue->enqueueAcquireGLObjects(&buffs);" and "cmdQueue->enqueueReleaseGLObjects(&buffs); cmdQueue->finish();") in your code, it may be the source of your problem :idea:
     
  5. Itun

    Newcomer

    Joined:
    Jan 11, 2012
    Messages:
    3
    Likes Received:
    0
    It means I don't use OpenCL buffer at all here. I only initialize it. After doing that the use of OpenCL here is over. However I know that EnqueueAcquiare and EnqueueRelease are used only to block GL buffer for CL work.
     
Loading...

Share This Page

  • About Us

    Beyond3D has been around for over a decade and prides itself on being the best place on the web for in-depth, technically-driven discussion and analysis of 3D graphics hardware. If you love pixels and transistors, you've come to the right place!

    Beyond3D is proudly published by GPU Tools Ltd.
Loading...