Note that there are some explanatory texts on larger screens.

plurals
  1. POWrong OpenGL Texture Format Type for CL/GL-Interop?
    primarykey
    data
    text
    <p>I'm trying the OpenCL-OpenGL interop for textures on my Geforce 330M with CUDA Toolkit 4.0.</p> <p>I want to capture a frame, use that data as an input image (<code>Image2D</code>) to a OpenCL Kernel. The Kernel should manipulate the data and write it to an <code>Image2DGL</code>, which is an image object with an attached OpenGL texture. Basically it looks like that:</p> <pre><code> _______________ RGB _______________ | | uint8* | | CL_RGBA / CL_UNORM_INT8 | Grabber | ------------&gt; | Image2D | -------------------------. | avcodec | | [input] | | |_______________| |_______________| | | V _______________ _______________ _______________ | | | | | | | Texture | ------------&gt; | Image2DGL | &lt;-----------------&gt; | Kernel | |_______________| | [output] | |_______________| |_______________| Internal Format: GL_RGBA Format: GL_RGBA Type: ? </code></pre> <p>I'm initializing the texture like that:</p> <pre><code>GLuint tex = 0; void initTexture( int width, int height ) { glGenTextures(1, &amp;tex); glBindTexture(GL_TEXTURE_RECTANGLE, tex); // now here is where I need assistance: The type parameter of the Texture (GL_FLOAT) glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, NULL ); } </code></pre> <p><hr> <strong>EDIT:</strong> I can have a type of <code>GL_UNSIGNED_INT</code> as well.</p> <hr> <p>Then I create the shared image (<code>Image2DGL</code>):</p> <pre><code>texMems.push_back(Image2DGL(clw-&gt;context, CL_MEM_READ_WRITE, GL_TEXTURE_RECTANGLE, 0, tex, &amp;err)); </code></pre> <p>Then I create the source image (input image): </p> <pre><code>ImageFormat format; format.image_channel_data_type = CL_UNORM_INT8; format.image_channel_order = CL_RGBA; srcImgBuffer = Image2D(clw-&gt;context, CL_MEM_READ_WRITE, format, width, height, 0, NULL, &amp;err); </code></pre> <p>In every render loop I'm writing the data into the <code>srcImgBuffer</code>:</p> <pre><code>// write the frame to the image buffer clw-&gt;queue.enqueueWriteImage(srcImgBuffer, CL_TRUE, origin, region, 0, 0, (void*)data, NULL, NULL); </code></pre> <p>Also I'm setting the arguments for the kernel:</p> <pre><code>tex_kernel.setArg(0, texMems[0]); tex_kernel.setArg(1, srcImgBuffer); tex_kernel.setArg(2, width); tex_kernel.setArg(3, height); </code></pre> <p>Before and after I do acquire and release the GL objects. The testing kernel looks like that:</p> <pre><code>__kernel void init_texture_kernel(__write_only image2d_t out, __read_only image2d_t in, int w, int h) { const sampler_t smp = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; int2 coords = { get_global_id(0), get_global_id(1) }; float4 pixel = read_imagef(in, smp, coords); float4 test = { (float)coords.x/(float)w , 0, 0, 1}; write_imagef( out, coords, pixel ); } </code></pre> <p>The <code>image_channel_data_type</code> can be read as float in the kernel and is interpreted as normalized value. The output image looks not right, I've got a sliced picture (linewise), obviously because of the wrong data interpretation. As I mentioned I assume the error is within the initialization of the texture's type. I tried GL_FLOAT (as I'm writing as float to the image in the kernel).</p> <p><img src="https://i.stack.imgur.com/QeG7t.png" alt="Results: Image as PPM dump from the decoder (left), Texture output scattered (right)"></p> <p>The left one is a <code>PPM</code> out of the decoder, the right one is what I'm getting back on my output texture.</p> <p>If someone actually read up to here: Do you have suggestions regarding the texture's type to resolve the issue?</p> <p><hr> <strong>EDIT:</strong> If I bind the captured frames to the texture directly, the video plays ok. So it must be related to the CL-GL interface somehow. </p> <hr>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload