Sharing texture between OpenGL and CUDA -
i sharing data between opengl , cuda follows:
gluint buffer; glgenbuffers(1, &buffer); // image bound texture buffer @ point. ... cudagraphicsresource_t cgr; checkcudaerrors(cudagraphicsglregisterbuffer(&cgr, buffer, cudagraphicsregisterflagsnone)); checkcudaerrors(cudagraphicsmapresources(1, &cgr, 0)); uchar4 * device_ptr = 0; size_t num_bytes; checkcudaerrors(cudagraphicsresourcegetmappedpointer( (void **)&device_ptr, &num_bytes, cgr));
this works fine , device_ptr not pointer cuda memory. now, @ point want resample image using bilinear interpolation. seems preferred way in cuda map device data cuda texture memory , perform interpolation using tex2d calls.
now, question imaging data exists in opengl texture memory , wonder if there way avoid calling cudabindtexture2d again , somehow use opengl texture within cuda interpolation?
yes can directly read/write opengl texture tex2d.
initialize graphic ressource
struct cudagraphicsresource *vbo_res; cudagraphicsglregisterimage(&vbo_res, gl_buffer,gl_target, cudagraphicsregisterflagssurfaceloadstore);
map ressource array (every frame)
cudaarray *array; cudagraphicsmapresources(1, &vbo_res, 0); cudagraphicssubresourcegetmappedarray(&array, vbo_res, 0,0);
bind texture array
texture<uchar4, cudatexturetype2d, cudareadmodenormalizedfloat> texref; cudabindtexturetoarray(texref, (cudaarray *)array)); texref.filtermode = cudafiltermodelinear;
note:
if texref
resides in global memory can accessed in cuda kernel float4 rgba = tex2d( texref, u,v);
Comments
Post a Comment