Reply – CLBuffer<ByteBuffer> is all zero's in the kernel
Your Name
Subject
Message
or Cancel
In Reply To
CLBuffer<ByteBuffer> is all zero's in the kernel
— by viperld002@gmail.com viperld002@gmail.com
Hello.

I'm currently attempting to take a byte buffer full of image data, pass it into a kernel, and work with it a bit to return a value through another buffer.

I'm able to return values just fine (the global ID for instance), but for some reason my image data byte buffer is zero in the kernel and none of the data I set for it shows up.

Here is me getting the image data...

ByteBuffer bb = ByteBuffer.allocate(800*600*4);
            gl.glBindTexture(gl.GL_TEXTURE_2D, texSelection.getTextureObject());
            gl.glGetTexImage(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, gl.GL_BYTE, bb);
            gl.glBindTexture(gl.GL_TEXTURE_2D, 0);

            byte[] pixelsRGBA = new byte[bb.capacity()];
            bb.get(pixelsRGBA );

...and here is me using it with JOCL...

        CLBuffer<ByteBuffer> buffer_selection_image = cl_context.createByteBuffer( 800*600*4, Mem.READ_ONLY);
        buffer_selection_image.getBuffer().put( pixelsRGBA );
        buffer_selection_image.getBuffer().rewind();
        .
        .
        .
        // Set the arguments.
        kernel.putArg(buffer_selection_image)
                .putArg( buffer_allInstances_positionX)
                .putArg( buffer_allInstances_positionY)
                .putArg( buffer_allInstances_index)
                .putArg( buffer_selectedInstances_index)
                .putArg( buffer_numberSelected)
                .rewind();
       
        // Run the kernel.
        cg_command_queue.put1DRangeKernel(kernel, 0, 36, 6);
       
        // Read the results.
        cg_command_queue.putReadBuffer(buffer_selectedInstances_index, true);

        // Return our results.
        ArrayList<Integer> ret = new ArrayList<Integer>();
        while( ib.hasRemaining() ){                
            int value = ib.get();
            ret.add( value );
           
        }
        return ret;

... and my simple kernel to check if a pixel is black or non-black...

__kernel
void groupingSelection_kernel (
             __global const char*  selection_texture,
             __global const float* instance_positionX,
             __global const float* instance_positionY,
             __global const uint* instance_index,          
             __global uint*       instance_index_selected,
             __global uint*       num_selected)
{
    int  globalId = get_global_id(0);
       
    if( globalId < 5 ){

   
        instance_index_selected[globalId] = globalId;
        num_selected[globalId] = 0;
   
        // Image width:height = 800:600. RGBA.
        //int index = ((int)instance_positionX[globalId] * 4) + ((int)instance_positionY[globalId] * 800 ) ;
        char col_r = selection_texture[ 0 ];
        instance_index_selected[globalId] = (uint)col_r;
       

        // If the texture color is not black here...
        if( col_r != 0 ){
            instance_index_selected[globalId] = 99;
            num_selected[globalId] = 99;
        }
    }
       
   
}

... So yea. When I check the image data buffer after filling it the values are definitely all there ( 127 everywhere ). These values just don't seem to make it into the kernel though.

Am I using an incorrect type in my kernel? Or perhaps setting the kernel arguments incorrectly?

Any help would be greatly appreciated. Thank you for your time.