cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

antzrhere
Adept III

write_imageui() / write_imagei() Bug (??)

I've been doing some GL/CL interop using a GL renderbuffer made into an OpenCl image2d_t object. The format is GL_RGBA8  (same as OpenGL pixel format), but It seems changing the format makes no difference.

Basically if I use write_imageui() to write pixels (0-255) range, I get black wherever I write. Here is the line of code (Voxel.Colour is a float3 with all values between 0 and 255) 

 write_imageui( ScreenBuffer, PixelPos, (uint4)(convert_uint(Voxel.Colour.s0), convert_uint(Voxel.Colour.s1), convert_uint(Voxel.Colour.s2), 0.0f) );

Previously I was writing a OpenCL global memory array without GL sharing and blitting to screen so I know the code works 100% fine.

Initially I thought it was a bug in my code, however, if I used write_imagef (and subsequently scale all colour component values to 0.0f-1.0f), it works perfectly! Code:

 write_imagef( ScreenBuffer, PixelPos,((float4)(Voxel.Colour.s0, Voxel.Colour.s1, Voxel.Colour.s2, 0.0f ) * 0.0039215686274509803921568627451f) );

I'm happy to use this function (its more readable), but I can't understand why the integer versions don't work.

Windows 7 64bit, ATI 5870, Catalyst 11.8, AMD APP SDK 2.5.

 

 

0 Likes
6 Replies
genaganna
Journeyman III

Originally posted by: antzrhere I've been doing some GL/CL interop using a GL renderbuffer made into an OpenCl image2d_t object. The format is GL_RGBA8  (same as OpenGL pixel format), but It seems changing the format makes no difference.

Basically if I use write_imageui() to write pixels (0-255) range, I get black wherever I write. Here is the line of code (Voxel.Colour is a float3 with all values between 0 and 255) 

 write_imageui( ScreenBuffer, PixelPos, (uint4)(convert_uint(Voxel.Colour.s0), convert_uint(Voxel.Colour.s1), convert_uint(Voxel.Colour.s2), 0.0f) );

Previously I was writing a OpenCL global memory array without GL sharing and blitting to screen so I know the code works 100% fine.

Initially I thought it was a bug in my code, however, if I used write_imagef (and subsequently scale all colour component values to 0.0f-1.0f), it works perfectly! Code:

 write_imagef( ScreenBuffer, PixelPos,((float4)(Voxel.Colour.s0, Voxel.Colour.s1, Voxel.Colour.s2, 0.0f ) * 0.0039215686274509803921568627451f) );

I'm happy to use this function (its more readable), but I can't understand why the integer versions don't work.

Windows 7 64bit, ATI 5870, Catalyst 11.8, AMD APP SDK 2.5.

 



Please give us sampler details which give some more information why you are geting different things.

0 Likes
notzed
Challenger

Check the spec vis the image formats, the relevant section is 6.11.13.2, there are some non-obvious limitations (I know it snarfed me in my first few experiments).

e.g. (from the spec)

write_imagei can only be used with image objects
created with image_channel_data_type set to one of
the following values:
CL_SIGNED_INT8,
CL_SIGNED_INT16 and
CL_SIGNED_INT32.
write_imageui can only be used with image objects
created with image_channel_data_type set to one of
the following values:
CL_UNSIGNED_INT8,
CL_UNSIGNED_INT16 and
CL_UNSIGNED_INT32.

I suspect the image format you're using is CL_UNORM_INT8, for which you must use read/write_imagef.

 

0 Likes

genaganna: I would have posted some code, but for the fact that its huge and unreadable, I'll try get something together tomorrow 🙂 Basically I create a renderbuffer Object in OpenGL using:

"glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, width, height);"

then I attach the RBO to the framebuffer object I created. I check everything has been created & attached correctly by checking for gl errors and finally glCheckFrameBufferStatusEXT().
When rendering I blit the OpenCL passed framebuffer object to the default screen FBO (which uses the same R8G8B8A8 pixel format). It all works fine with write_imagef.

notzed: I don't create an image through OpenCL, but convert a GL Renderbufferobject to OpenCL mem pointer which in turn references an image2d_t object. The renderbuffer is a colour attachment created using GL_RGBA8, which I assume would be the equivelent of CL_UNSIGNED_INT8 with 4 channels and the channel order would be CL_RGBA. As I don't create images myself directly, there's not much else really going on, and as write_imagef() works perfectly, I assume the code is fine.

0 Likes

Originally posted by: antzrhere genaganna: I would have posted some code, but for the fact that its huge and unreadable, I'll try get something together tomorrow 🙂 Basically I create a renderbuffer Object in OpenGL using:

"glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, width, height);"

then I attach the RBO to the framebuffer object I created. I check everything has been created & attached correctly by checking for gl errors and finally glCheckFrameBufferStatusEXT(). When rendering I blit the OpenCL passed framebuffer object to the default screen FBO (which uses the same R8G8B8A8 pixel format). It all works fine with write_imagef.

notzed: I don't create an image through OpenCL, but convert a GL Renderbufferobject to OpenCL mem pointer which in turn references an image2d_t object. The renderbuffer is a colour attachment created using GL_RGBA8, which I assume would be the equivelent of CL_UNSIGNED_INT8 with 4 channels and the channel order would be CL_RGBA. As I don't create images myself directly, there's not much else really going on, and as write_imagef() works perfectly, I assume the code is fine.

Are you using same sampler for both write_imagef() and wirte_imageui()?  Please let me know what sampler you are using.

0 Likes

Try reading the manual, I don't know how you got this far without reading the following section.

OpenCL Specification 1.1. Section 9.8.2.1 "List of OpenCL and corresponding OpenCL Image Formats".

GL_RGBA8 maps to CL_RGBA, CL_UNORM_INT8.

 

0 Likes

Ah, thanks Notzed, you're correct. I didn't spot that section. I had looked at the spec and only saw section 5.3.2.1 for general images which said UINTs as well as UNORMs could be used with RGBA (which made sense), however, I didn't know there were seperate limits impossed on GL shared objects.

The irony of your comment is it didn't work for a while until I tried write_imagef.

Thanks for your help, I suspected it wasn't an OpenCL implementation problem, but the reasons weren't intuative.

0 Likes