[osg-users] 3D osg::Image allocation size problem

Robert Osfield robert.osfield at gmail.com
Fri Jul 22 10:20:25 PDT 2016


Hi Josiah,

Without a stack trace it's very hard to know exactly what is amiss.
My best guess is memory allocation error that isn't being handling
elegantly.  Have a look into the Image::allocateImage() implementation
to see what is happening during the allocation.

As check on paper how much memory your allocation will require on the
CPU and GPU. Please note that the driver keeps a copy of the texture
object in driver memory so you'll need to double the memory costs in
main memory when doing your calculations.  This calculation should
give you an ideal of what you can do in main memory without using
paging.

For the settings you listed in your email the calculation would be:

   1024x1024x1024 x 4 x 4

Which is... 16GB just for the osg::Image, then double this for driver
copy and you then require 32GB, and the graphics card will need more
than 16GB as well...

So.... you have to be realistic about what you can achieve....



Robert.

On 22 July 2016 at 12:00, Josiah Jideani <josh.jideani at gmail.com> wrote:
> Hi,
>
> I am developing a scientific visualization application using Qt and Openscenegraph.  I am trying to create a 3D osg::Image to add to an osgVolume.  I am having problems allocating the image data when I call the allocateImage member function (see the code snippet below).
>
> The allocation works for equal dimensions less than 640.
>
> When I try to allocate anything above 640x640x640 but less than 800x800x800, it seems to allocate successfully because image_s, image_t and image_r hold the correct sizes however when I try to write to the image data (the nested for loops) a segmentation fault is thrown at data[0] = 0.0f when s = 0; t = 0; and r = some random but valid number.
>
> I can allocate and write to the image data with sizes between 800x800x800 and 1024x1024x1024, but a segmentation fault is thrown from the object code after the call to the viewer's frame() method.
>
> And finally for sizes above 1024 the allocation completely fails as image_s image_t and image_r all hold 0.
>
> Any clue on how to solve this? It was my understanding that the maximum size of the image is limited by the maximum 3D texture size of the graphics card which for the Quadro K4200 that I'm using is 4096x4096x4096.  So why am I only able to allocate a 640x640x640 image?
>
> These are the specifications of my system:
> Operating system: Opensuse Leap 42.1
> RAM: 128GB
> Graphics Card: Quadro K4200
> Qt: Qt 4.7.1
> OSG version: 3.2.3
>
>
>
> Thank you!
>
> Cheers,
> Josiah
>
>
> Code:
>
> osg::ref_ptr<osg::Image> image = new osg::Image
> image->allocateImage(1024, 1024, 1024, GL_RGBA, GL_FLOAT);
>
> int image_s = image->s();
> int image_t = image->t();
> int image_r = image->r();
>
> for(int s = 0; s < image_s; s++)
> {
>     for(int t = 0; t < image_t; t++)
>     {
>         for(int r = 0; r < image_r; r++)
>         {
>             float* data = (float*) image->data(s,t,r);
>             data[0] = 0.0f;
>             data[1] = 0.0f;
>             data[2] = 1.0f;
>             data[3] = 0.1f;
>         }
>     }
> }
>
>
>
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=68195#68195
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



More information about the osg-users mailing list