OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Existing OpenGL texture as source only


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> osgCompute [osgCompute]
View previous topic :: View next topic  
Author Message
J.P. Delport
Guest





PostPosted: Mon Jan 17, 2011 8:23 am    Post subject:
Existing OpenGL texture as source only
Reply with quote

Hi Mick/Jens,

our small research group is experimenting with osgCompute to expand the
capabilities of our existing GLSL framework for doing real-time image
processing.

I've looked through the examples and we made a few simple tests using
osg::Image as input like in osgTexDemo. What we'd like to do though is
use an existing texture (already uploaded to GPU and possibly already
passed through some RTT passes) as input to osgCompute. That is, we'd
like to copy data as little as possible and avoid any CPU<->GPU copies.

I've seen calls to cudaGraphicsGLRegisterImage in osgCuda/Texture, but
I'm not sure if it is possible to set a mapping in osgCompute so that an
existing texture is only used as an input and not synced or copied to
host memory at all. Is it possible?

regards
jp

--
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. MailScanner thanks Transtec Computers for their support.



------------------
Post generated by Mail2Forum
Back to top
jens.svt
User


Joined: 16 Mar 2009
Posts: 30

PostPosted: Mon Jan 17, 2011 9:33 am    Post subject:
Reply with quote

Hi J.P.,

Thanks for your interest in using osgCompute. First of all it is possible as long as your previous texture is of type osgCuda::TextureXD. There is currently no way to use osg::Textures directly. The specialization is necessary as we need to keep track of when the texture's apply( State ) method is called within the osg pipeline. If you have utilized a osg::Texture2D beforehand it is no problem to switch to a osgCuda::Texture2D as it acts like a osg::Texture2D as long as no CUDA operation is performed.

If you utilize a osgCuda::Texture2D for example, you can use myTexture->map( osgCompute::MAP_DEVICE_SOURCE ) or myTexture->map( osgCompute::MAP_DEVICE_ARRAY ). However as CUDA maps an OpenGL texture to a cudaArray* we internally copy the array's data to writeable device memory with a cudaMemcpyDeviceToDevice in case of MAP_DEVICE_SOURCE. Its fast (GPU->GPU) but still it is a copy operation. If you want to avoid any copy operation you should use MAP_DEVICE_ARRAY. This will return the cudaArray pointer directly. The decision which of them to use depends on which type of pointer your CUDA-kernel supports:

MAP_DEVICE_SOURCE:
Code:

...
cudaKernel<<< #blocks,#threads >>>( (float*) myTexture->map(osgCompute::MAP_DEVICE_SOURCE ) );
...
__global__ void cudaKernel( float* myPtr ) {
...
float val = myPtr[122];
...
}


MAP_DEVICE_ARRAY:
Code:

...
cudaBindTextureToArray( myTex, (cudaArray*)(myTexture->map(osgCompute::MAP_DEVICE_ARRAY ) ) );
...
cudaKernel<<< #blocks,#threads >>>();
...
__global__ void cudaKernel(){
...
float val = texture2D(0.3,0.3,myTex);
...
 }


Please notice that we currently only support single-threaded osg applications.


Best regards,
Jens[/code]
Back to top
View user's profile Send private message
J.P. Delport
Guest





PostPosted: Mon Jan 17, 2011 10:09 am    Post subject:
Existing OpenGL texture as source only
Reply with quote

Hi Jens,

On 17/01/11 11:33, Jens Orthmann wrote:
Quote:
Hi J.P.,

Thanks for your interest in using osgCompute. First of all it is
possible as long as your previous texture is of type
osgCuda::TextureXD. There is currently no way to use osg::Textures
directly. The specialization is necessary as we need to keep track of
when the texture's apply( State ) method is called within the osg
pipeline. If you have utilized a osg::Texture2D beforehand it is no
problem to switch to a osgCuda::Texture2D as it acts like a
osg::Texture2D as long as no CUDA operation is performed.

OK, I saw the inheritance, was just not sure if an osgCuda::Texture2D
could be made from an existing osg::Texture2D. I'll switch our texture
type and do a test.

Quote:

If you utilize a osgCuda::Texture2D for example, you can use
myTexture->map( osgCompute::MAP_DEVICE_SOURCE ) or myTexture->map(
osgCompute::MAP_DEVICE_ARRAY ). However as CUDA maps an OpenGL
texture to a cudaArray* we internally copy the array's data to
writeable device memory with a cudaMemcpyDeviceToDevice in case of
MAP_DEVICE_SOURCE. Its fast (GPU->GPU) but still it is a copy
operation. If you want to avoid any copy operation you should use
MAP_DEVICE_ARRAY. This will return the cudaArray pointer directly.
The decision which of them to use depends on which type of pointer
your CUDA-kernel supports:

MAP_DEVICE_SOURCE:

Code:

... cudaKernel<<< #blocks,#threads>>>( (float*)
myTexture->map(osgCompute::MAP_DEVICE_SOURCE ) ); ... __global__ void
cudaKernel( float* myPtr ) { ... float val = myPtr[122]; ... }




MAP_DEVICE_ARRAY:

Code:

... cudaBindTextureToArray( myTex,
(cudaArray*)(myTexture->map(osgCompute::MAP_DEVICE_ARRAY ) ) ); ...
cudaKernel<<< #blocks,#threads>>>(); ... __global__ void
cudaKernel(){ ... float val = texture2D(0.3,0.3,myTex); ... }

Thanks, I'll try one or both of these approaches.

Quote:



Please notice that we currently only support single-threaded osg
applications.
All our apps are single threaded currently, so no problem.

Thanks for your help
rgds
jp

Quote:


Best regards, Jens[/code]

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





_______________________________________________ osg-users mailing
list
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. MailScanner thanks Transtec Computers for their support.



------------------
Post generated by Mail2Forum
Back to top
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> osgCompute [osgCompute] All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Fix FBX conversion to OpenGL coordina... Farshid Lashkari Submission 0 Wed Mar 15, 2017 6:34 pm View latest post
No new posts How to use frame buffer object in exi... saedrna1 General 2 Sat Feb 18, 2017 3:54 am View latest post
No new posts Multitexture: projection a texture on... Ekaterina General 2 Mon Feb 06, 2017 1:48 pm View latest post
No new posts OSG with OpenGL ES 2.0 and Angle andxet2 Build system [build] 3 Mon Jan 23, 2017 4:36 pm View latest post
No new posts How to set texture coordinates Ekaterina General 0 Fri Jan 13, 2017 5:39 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP