Using cuda array in vertex shader

hi…

I have to perform some computation on GPU using cuda then I want to use the result of that (which is in some array on GPU only) in my vertex shader.

some suggested me to use texture buffer or something but can we write into texture buffer by cuda?

if yes then how to bind that texture to use in vertex shader?

thanx

Hi,

you can read/write PBO in cuda as any arrays.
You can also access texture in read-only in cuda, but on my experience it only works for a reduced number of formats and it is hard to do something with.
Check the cuda examples based on opengl interoperability.

(I never try, but there is also a directx interoperability maybe more developed)

– pium

1.) The safest way might be to store your cuda data in linear device memory.
2.) In OpenGL, allocate a texture big enough to hold this data.
3.) Use the Cuda-OpenGL interop to get the OpenGL texture mapped as cuda array ( cudaGraphicsMapResources, cudaGraphicsSubResourceGetMappedArray)
4.) Use cudaMemcpyToArray to copy the linear data to the mapped OpenGL array.
5.) Unmap the texture (cudaGraphicsUnmapResources)
6.) Render using texture access in the vertex shader.

It is theoretical possible to write directly to the mapped array, however this caused a lot of headache for me a few months ago(worked with older drivers(v197.xx), was broken with newer ones). Maybe it works now.

Or, as an alternative, there is the sample “SimpleGL” in the SDK which updates Vertex Buffer Objects by cuda before rendering.

Thanks both of you…

I have done this using PBO.
a good explanation with example code about mapping pbo to opengl texture is here…
http://www.songho.ca/opengl/gl_pbo.html

steps:
create texture and PBO,
register and map PBO to cuda,

update PBO using cuda,
unpack(mapping) PBO to texure,
input texture to shader and do processing accordingly.