Having problem with BufferChecks while invoking clCreateImage2D

Started by hkn, October 11, 2015, 18:32:54

Previous topic - Next topic

hkn

Hi,

I am trying to create a cl image backed with a FloatBuffer but having buffersize exception. The code is like below
FloatBuffer buffer = BufferUtils.createFloatBuffer(image.getHeight() * image.getWidth());

//I put some data into the buffer before this part
CLImageFormat format = new CLImageFormat(CL_LUMINANCE, CL_FLOAT);
imageFormat.putInt(0, format.getChannelOrder());
imageFormat.putInt(4, format.getChannelType());
CLMem clImage = clCreateImage2D(fContext, CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR, imageFormat, image.getWidth(), image.getHeight(), 0, buffer, null);


and the exception is:
Quote
at org.lwjgl.BufferChecks.throwBufferSizeException(BufferChecks.java:162)
   at org.lwjgl.BufferChecks.checkBufferSize(BufferChecks.java:189)
   at org.lwjgl.BufferChecks.checkBuffer(BufferChecks.java:258)
   at org.lwjgl.opencl.CL10.clCreateImage2D(CL10.java:902)

CL10 class compares length of the float buffer with an on the fly calculated length of a bytebuffer inside.
// CL10#clCreateImage2D(CLContext context, long flags, ByteBuffer image_format, long image_width, long image_height, long image_row_pitch, FloatBuffer host_ptr, IntBuffer errcode_ret)
if(host_ptr != null) {
    BufferChecks.checkBuffer(host_ptr, CLChecks.calculateImage2DSize(image_format, image_width, image_height, image_row_pitch));
}

CLChecks.calculateImage2DSize returns length of a byte buffer. shouldn't it be the float element size since image_format addresses a float type? Or  am I missing sth fundemantal?

spasi

Thanks, the bug will be fixed in the next nightly build.

Do you have a good reason to be using LWJGL 2? LWJGL 3 is getting finalized soon and it's much better in many aspects.

hkn

I can definitely go on with LWGL 3. Thanks! But as a modest comment, I would like to find more documentation/examples for LWGL OpenCL. Is there any plan that you will provide more documentation?

spasi

Quote from: hkn on October 11, 2015, 21:05:37I would like to find more documentation/examples for LWGL OpenCL. Is there any plan that you will provide more documentation?

The OpenCL bindings are no different than other bindings. There's no LWJGL-specific APIs to learn except the CLPlatform and CLDevice classes. Those are basically a convenience, they hide the complexity around creating CLCapabilities instances. So if you're familiar with OpenCL, you shouldn't have any trouble. Obviously, you're welcome to post here if you have any specific questions.

You can find some example code in the source repository, here.