OpenGL / OpenCL - DXT texture from buffer

Started by
5 comments, last by Martin Perry 10 years, 4 months ago

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

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

I know that, but problem is, that those textures can not be bind to OpenCL image

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.

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.

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.

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);

This topic is closed to new replies.

Advertisement