Jump to content
  • Advertisement
Sign in to follow this  
Martin Perry

OpenGL OpenGL / OpenCL - DXT texture from buffer

This topic is 2150 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

 

I have texture compressed with DXT. I have them inside OpenCL buffer. I need to know, if I can copy them to OpenGL so I can read from them in my Pixel Shader (with texetFetch). I dont need filtering, but only to be able read decompressed values inside Pixel Shader unit. Can it be done ? If so, any hints, because OpenCL image format is not supporting DXT compression formart and glTexBuffer neither

 

Thanks

Share this post


Link to post
Share on other sites
Advertisement

Use ::glCompressedTexImage2D() with GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, or GL_COMPRESSED_RGBA_S3TC_DXT5_EXT as the internal format.

 

 

L. Spiro

Share this post


Link to post
Share on other sites

Currently, I don't think there is anyway around having to copying the data. I don't think OpenCL currently have the ability to create a CL buffer from a pixel buffer object, however, you can still use a PBO to offset the cost of copying the data to the texture. So you would copy the buffer with your compressed data, into the PBO and use it to asynchronously upload the texture data.

Share this post


Link to post
Share on other sites

I am currently trying to do it this way. I thought that maybe I overlooked something. Anyway, it should be faster to copy data from OpenCL to texture (VRAM - VRAM) than copy data from RAM to VRAM in every frame.

Share this post


Link to post
Share on other sites

It would be faster, if the ability exist, but currently the functionality is not exposed via OpenCL. If the textures are relatively small in size, then it shouldn't be much of a perf impact if you can use the asynchronous upload to mask the hit. Another approach you could take on a platform that have some kind of unified memory support is to source the PBO data store with the unified memory pointer and also use the said pointer to create the OpenCL buffer, if that makes sense.

Share this post


Link to post
Share on other sites

I have tried PBO access. Fo future readers

 

I have based my solution on example from AMD SDK samples

 

      unsigned int pbo;

    /*

     * Create pixel-buffer object

     */

    glGenBuffers(1, &pbo);

    glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);

 

    // initialize buffer object

    unsigned int size = width * height * sizeof(cl_uchar4);

 

    // buffer data

    glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, size, NULL, GL_STREAM_DRAW_ARB);

    glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

 

    // Create OpenCL buffer from GL PBO

    outputImageBuffer = clCreateFromGLBuffer(context,

                        CL_MEM_WRITE_ONLY,

                        pbo,

                        &status);

    CHECK_OPENCL_ERROR(status, "clCreateFromGLBuffer failed. (outputImageBuffer)");

 

 

// Acquire GL buffer

    cl_event acquireEvt;

    status = clEnqueueAcquireGLObjects(commandQueue,

                                       1,

                                       &outputImageBuffer,

                                       0,

                                       0,

                                       &acquireEvt);

    CHECK_OPENCL_ERROR(status, "clEnqueueAcquireGLObjects failed.");

 

// outBuffer imager

    status = clSetKernelArg(

                 horizontalKernel,

                 1,

                 sizeof(cl_mem),

                 &outputImageBuffer);

    CHECK_OPENCL_ERROR(status, "clSetKernelArg failed. (outputImageBuffer)");

 

..... kick off OpenCL kernel

 

// Now OpenGL gets control of outputImageBuffer

    cl_event releaseGLEvt;

    status = clEnqueueReleaseGLObjects(commandQueue,

                                       1,

                                       &outputImageBuffer,

                                       0,

                                       0,

                                       &releaseGLEvt);

    CHECK_OPENCL_ERROR(status, "clEnqueueReleaseGLObjects failed.");

 

// Bind PBO and texture

                glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);

                glBindTexture(GL_TEXTURE_2D, textureID);

 

                // Copy pixels from pbo to texture

                glTexSubImage2D(GL_TEXTURE_2D,

                                0,

                                0,

                                0,

                                width,

                                height,

                                GL_RGBA,

                                GL_UNSIGNED_BYTE,

                                NULL);

Edited by Martin Perry

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!