Login  Register

Re: JOCL texture generation

Posted by Wade Walker on Mar 30, 2014; 8:17pm
URL: https://forum.jogamp.org/JOCL-texture-generation-tp4031853p4032081.html

I finished the C++ interoperability test, and have some good news!

Initially it didn't work on my GeForce GTX 660. So after working on it a while and making sure I hadn't missed anything obvious, I put in my old ATI Radeon HD 5450 that I use for testing. That didn't work either! But it failed in a different way -- the texture was getting set to black.

So I tried changing write_imageui() in the OpenCL kernel to write_imagei(), which didn't work any better. But then when I tried write_imagef(), it worked like a charm! I also tried it on my MacBook Air's GeForce 320M, and it works on that too, so it's not just ATI cards.

But why does this work? I created the OpenGL texture as GL_RGBA with type GL_UNSIGNED_BYTE. Surely this should be written by write_imageui(). But if you look at table 9.4 on page 324 of the OpenCL 1.1 spec (http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf), it says that the GL internal format GL_RGBA maps to the CL format CL_RGBA with channel type CL_UNORM_INT8. And in the spec for write_image (http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/write_image.html), the only function that writes channel type CL_UNORM_INT8 is write_imagef()! It even says "Appropriate data format conversion will be done to convert channel data from a floating-point value to actual data format in which the channels are stored." So the cards are doing exactly what the spec says, we just weren't using the API correctly

write_imageui() can write to channel type CL_UNSIGNED_INT8, but apparently that's not compatible with CL_UNORM_INT8, even though the binary values in them should be exactly equal. Perhaps this is because normalized integer textures in GL resolve to floats inside GL shaders, whereas integer textures in GL resolve to integers inside GL shaders.

Please give this a try on your hardware and let me know what happens. I'll write a unit test for JOCL to preserve this solution.