Re: [osg-users] [osgCompute] Use an osgCuda::Texture2D in a shader

2011-10-28 Thread Jens Orthmann
Hi Aurelien,

have you tried to uncomment

Code:

...
pCudaTexture-setUsage(osgCompute::GL_TARGET_COMPUTE_TARGET); 



because what you really need is:

Code:

...
pCudaTexture-setUsage(osgCompute::GL_SOURCE_COMPUTE_TARGET); 



which is set by default.
Another option is to take a look at our osgTexDemo.

Best regards,
Jens[/code]

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=43614#43614





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] [osgCompute] Use an osgCuda::Texture2D in a shader

2011-10-17 Thread J.P. Delport

Hi Aurelien,

I'm not sure how to get you manual method working. It might have to do 
with multiple contexts? How are you running the shader? In pre-render 
pass? If so, you'll have to make sure the cuda code also executes in the 
pre-render stage.


All I can add is that I'm mixing GLSL passes and osgCuda passes (with 
some GLSL after cuda and some before) currently and it works. See here too:

http://thread.gmane.org/gmane.comp.graphics.openscenegraph.user/71276

cheers
jp

On 14/10/2011 18:37, Aurelien Albert wrote:

Hi,

I'm working on the port of a OpenGL / Cuda application to OSG / osgCuda.

(OSG 3.0.1 with osgCuda from trunk)

One of our class use Cuda to compute a buffer and then :
- copy this buffer to a texture buffer (using cudaMemcpy)
- bind this texture to a texture unit (using glBindTexture)
- use this texture unit in a shader

I'm trying to do the same using OSG / osgCuda.
I don't use Computation classes for the moment, because we need a lot of time 
to port our Cuda code architecture to osgCuda.

So, we do :

- create an osgCuda::Texture2D as follow (our computed Cuda buffer contains 
float3 data) :


Code:

osg::ref_ptrosgCuda::Texture2D  pCudaTexture = new osgCuda::Texture2D();

pCudaTexture-setDataVariance(osg::Object::DYNAMIC);
pCudaTexture-setNumMipmapLevels(0);
pCudaTexture-setUseHardwareMipMapGeneration(false);
pCudaTexture-setFilter(osg::Texture::MIN_FILTER , osg::Texture::LINEAR);
pCudaTexture-setFilter(osg::Texture::MAG_FILTER , osg::Texture::LINEAR);
pCudaTexture-setResizeNonPowerOfTwoHint(false);
pCudaTexture-setWrap(osg::Texture::WRAP_R, osg::Texture::REPEAT);
pCudaTexture-setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
pCudaTexture-setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
pCudaTexture-setInternalFormat(GL_RGB32F_ARB);
pCudaTexture-setSourceFormat(GL_RGB);
pCudaTexture-setSourceType(GL_FLOAT);
pCudaTexture-setTextureSize(m_width, m_height);
pCudaTexture-setUsage(osgCompute::GL_TARGET_COMPUTE_TARGET);




- use this texture as a StateAttribute :


Code:
pNode-getOrCreateStateSet()-setTextureAttribute(0, pCudaTexture, 
osg::StateAttribute::ON);



Then before rendering each frame :

- call our Cuda code, which fill a Cuda buffer =  this part is working
- copy this buffer to the osgCuda::Texture2D : (dSourceCuda is a pointer to our 
computed Cuda buffer)


Code:
osgCompute::Memory* pMemory = pCudaTexture-getMemory();
void* dDestCuda = pMemory-map();

CUDA_SAFE_CALL( cudaMemcpy(dDestCuda, dSourceCuda, size, 
cudaMemcpyDeviceToDevice) );

pMemory-unmap();




This part seems to work : if we write the content of dSourceCuda buffer and 
dDestCuda buffer to a file, the data are identical and computed correctly by our Cuda 
code.


But the texture unit seems to always have 0.0 values : when we have a look to 
our textureUnit with GDebugger, it always contains only 0.0 values.


Is there any way to use the content of our computed Cuda buffer into a texture 
unit ?


Regards,
Aurelien

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=43419#43419





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.


This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] [osgCompute] Use an osgCuda::Texture2D in a shader

2011-10-17 Thread Aurelien Albert
Hi,

The Shader is executed as a normal osg shader program : by setting it on the 
node stateset.

The Cuda code is executed before any rendering (before the pViewer-frame() 
call)

By diggging in the osgCuda code source, it seems like 
cudaGraphicsMapResources and cudaGraphicsGLRegisterImage functions are 
never called...

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=43432#43432





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] [osgCompute] Use an osgCuda::Texture2D in a shader

2011-10-17 Thread J.P. Delport

Hi,

On 17/10/2011 15:26, Aurelien Albert wrote:

Hi,

The Shader is executed as a normal osg shader program : by setting
it on the node stateset.

The Cuda code is executed before any rendering (before the
pViewer-frame() call)

By diggging in the osgCuda code source, it seems like
cudaGraphicsMapResources and cudaGraphicsGLRegisterImage
functions are never called...


I know these are called in my app (at least for 
GL_TARGET_DEVICE_SOURCE), because I've traced through the code when it 
executed. AFAIK it normally happens in the map() call.


You can check out this example I've made. It uses the output texture of 
the cuda pass to display on a rect. If you set a shader on the rect it 
should work too.


http://code.google.com/p/flitr/source/browse/#svn%2Ftrunk%2Fexamples%2Fcuda_auto_contrast

Maybe you can trace through this and see what is different between the 
example and your code.


cheers
jp




-- Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=43432#43432





___ osg-users mailing
list osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.


This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] [osgCompute] Use an osgCuda::Texture2D in a shader

2011-10-17 Thread Aurelien Albert
To be more specific, I just need one function :

copyCudaBufferToOsgTexture

I thought osgCuda provide it, and I hope this is the first step for me before a 
complete migration from hand-made Cuda to osgCuda code.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=43434#43434





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] [osgCompute] Use an osgCuda::Texture2D in a shader

2011-10-17 Thread J.P. Delport

Hi,

I think search in the osgCuda code for Memcpy2D. I think the cuda 
shadow buffer that osgCuda makes is copied to the texture in the 
unmap(). There is possibly some other things like updating the texture 
dirty count as well so that OSG knows the texture has been changed.


I'm sorry I can't help more, I've not used osgCuda in the manual way 
that you are trying.


jp

On 17/10/2011 15:37, Aurelien Albert wrote:

To be more specific, I just need one function :

copyCudaBufferToOsgTexture

I thought osgCuda provide it, and I hope this is the first step for me before a complete 
migration from hand-made Cuda to osgCuda code.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=43434#43434





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.


This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] [osgCompute] Use an osgCuda::Texture2D in a shader

2011-10-14 Thread Aurelien Albert
Hi,

I'm working on the port of a OpenGL / Cuda application to OSG / osgCuda.

(OSG 3.0.1 with osgCuda from trunk)

One of our class use Cuda to compute a buffer and then :
- copy this buffer to a texture buffer (using cudaMemcpy)
- bind this texture to a texture unit (using glBindTexture)
- use this texture unit in a shader

I'm trying to do the same using OSG / osgCuda.
I don't use Computation classes for the moment, because we need a lot of time 
to port our Cuda code architecture to osgCuda.

So, we do :

- create an osgCuda::Texture2D as follow (our computed Cuda buffer contains 
float3 data) :


Code:

osg::ref_ptrosgCuda::Texture2D pCudaTexture = new osgCuda::Texture2D();

pCudaTexture-setDataVariance(osg::Object::DYNAMIC); 
pCudaTexture-setNumMipmapLevels(0);
pCudaTexture-setUseHardwareMipMapGeneration(false);
pCudaTexture-setFilter(osg::Texture::MIN_FILTER , osg::Texture::LINEAR);
pCudaTexture-setFilter(osg::Texture::MAG_FILTER , osg::Texture::LINEAR);
pCudaTexture-setResizeNonPowerOfTwoHint(false);
pCudaTexture-setWrap(osg::Texture::WRAP_R, osg::Texture::REPEAT);
pCudaTexture-setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
pCudaTexture-setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
pCudaTexture-setInternalFormat(GL_RGB32F_ARB);
pCudaTexture-setSourceFormat(GL_RGB);
pCudaTexture-setSourceType(GL_FLOAT);
pCudaTexture-setTextureSize(m_width, m_height);
pCudaTexture-setUsage(osgCompute::GL_TARGET_COMPUTE_TARGET);




- use this texture as a StateAttribute :


Code:
pNode-getOrCreateStateSet()-setTextureAttribute(0, pCudaTexture, 
osg::StateAttribute::ON);



Then before rendering each frame :

- call our Cuda code, which fill a Cuda buffer = this part is working
- copy this buffer to the osgCuda::Texture2D : (dSourceCuda is a pointer to our 
computed Cuda buffer)


Code:
osgCompute::Memory* pMemory = pCudaTexture-getMemory();
void* dDestCuda = pMemory-map();

CUDA_SAFE_CALL( cudaMemcpy(dDestCuda, dSourceCuda, size, 
cudaMemcpyDeviceToDevice) );

pMemory-unmap();




This part seems to work : if we write the content of dSourceCuda buffer and 
dDestCuda buffer to a file, the data are identical and computed correctly by 
our Cuda code.


But the texture unit seems to always have 0.0 values : when we have a look to 
our textureUnit with GDebugger, it always contains only 0.0 values.


Is there any way to use the content of our computed Cuda buffer into a texture 
unit ?


Regards,
Aurelien

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=43419#43419





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org