[osg-users] Possible improvement for CullThreadPerCameraDrawThreadPerContext threading model

Jannik Heller scrawl at baseoftrash.de
Fri Jun 5 19:43:47 PDT 2015


I was playing around with threading models today and found something odd.

For the sake of experiment, I used a osgViewer with a master camera, a slave camera using the same graphics context as the master camera, and the CullThreadPerCameraDrawThreadPerContext threading model.

I found that the osgViewer does not commence the next frame until the last camera's draw dispatch has started. That is strange. My scene has 0 dynamic objects in it, so logically speaking the next frame could commence as soon as all the cull threads are done and the first camera's draw dispatch starts.

I attached some pictures to illustrate what I mean. The first picture is what I am seeing, the second picture is what I would have expected to see.

I fired up the debugger and found OSG was blocking in the _endDynamicDrawBlock. The block gets released in Renderer::draw, but each camera needs to get there first, i.e. start drawing.

The idea for a fix would be simple: if there are no dynamic objects in the scene, we release the block in GraphicsContext::runOperations, for each camera, before the cameras start drawing.

i.e., we move this piece of code from Renderer::draw to GraphicsContext::runOperations:


        if (sceneView->getDynamicObjectCount()==0 && state->getDynamicObjectRenderingCompletedCallback())
            // OSG_NOTICE<<"Completed in cull"<<std::endl;

In practice it may not be simple, for starters the GraphicsContext would need access to the SceneView, which is a no go as the core osg can't depend on osgViewer. Some refactoring would be needed to work around this issue, so before I dive in head first, I want to ask if anyone has an alternative suggestion, or done this kind of optimization before.


Read this topic online here:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: threading_2.png
Type: image/png
Size: 8911 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20150606/b6a56a67/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: threading_1.png
Type: image/png
Size: 8175 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20150606/b6a56a67/attachment-0005.png>

More information about the osg-users mailing list