Note that much of the content of this tips page applies to options in standalone mental ray®, and that each OEM integration may or may not implement them as we suggest, because of its unique use of memory, and how it handles scene complexity. We hope to provide a foundation for understanding the issues. Much of this material has been put together from a variety of sources, including the on-line manual and training class material development.
The overriding factor to consider in mental ray memory usage is that it is designed from the ground up as a shared database so that it can leverage multiple processors working simultaneously on a render. Because of this, data may flow from one process to another, and from one render host to another, in a non-sequential execution process.
Computer system terminology with a bow toward understanding mental ray's use of resources.
Let us further define some mental ray terminology.
Examining a render report can help you understand what happens in the various phases of the render. First the scene data base is constructed. Then, mental ray performs various pre-computing phases such as photon tracing and final gather point creation.
Once these are ready, the eye ray samples are calculated for each tile and filtered into pixels. Confusingly, we often call this the 'rendering' phase, but more accurately, it is the tile rendering phase. See Samples Tips for more details.
There are many references on the web to show how memory is laid out typically in a computer. We will keep it simple and focus on the shared memory between threads in a given process called the heap. Note also that the memory address space will also contain the place the threads use for executing instructions called the stack.
The scene data base is constructed in the shared memory or heap and we call that the Scene cache. During scene input and preprocessing, we store the scene data including all the lights, cameras, objects, instances, options one sees in the scene description. Either this is read in from the scene file with standalone, or it is constructed directly through the mental ray api from a 3D application.
The scene data includes the basic object descriptions as defined in the scene file or the api. This is how the objects are represented before they may undergo tessellation to approximate either a surface, a subdivision surface, or a displacement. We call this pre-tessellated data the source geometry and it is part of the scene DAG data we read in or construct from the application.
After that, tessellation occurs, as well as BSP tree construction.
As shaders require image-based textures, they are also loaded into the scene cache.
Most of this data is permanently stored in shared memory, unless one specifies ways to make this data flushable. A flushable piece of data must be reconstructable, in case it is needed again.
What is using this data? The threads that are executing instructions. At tile rendering time, these threads are shooting rays and running material shaders, among other things. To remind ourselves, we'll include the thread area back in our next diagram for reference, noting that they also create thread-specific data. Below we show two threads, indicating either two processors, or a single dual-core processor.
It's getting crowded in there. Of course, your memory available may be much larger than your scene data, but if your scene data is larger than memory available, we need to make it flushable.
By using placeholders, we can construct source geometry on-demand, and thus make them flushable.
By using fine approximation, the tessellation of source geometry can also be reconstruced and made flushable.
The BSP tree itself can be made flushable if one uses the Large BSP tree.
Finally, if textures are tiled, they automatically become part of the texture cache which can flush and restore just the needed portion of a texture for a given set of samples.
Now all the memory used by the green sections are flushable. When does it know to flush something? This is where the memory limit comes into play.
When a render job in a thread needs to create more scene data, i.e., allocate a chunk of shared memory, it checks to see if adding the chunk will exceed this limit. If so, the mental ray cache manager will look to flush data which is classified as flushable.
So now think of memory limit as a warning track for any new chunk of scene data that has to be put in shared memory. Here we simplify our diagram a bit, showing our flushable data on the top of our heap
If a new chunk of scene data is small enough to fit under the limit, the cache manager puts it in the heap.
But when a new chunk does not fit under the limit (blue chunk in diagram below), ...
the cache manager must flush some chunks of flushable scene data.
Then, it puts the new chunk in the heap. It is possible that the new chunk would not be flushable, in which case it would limit the flushable area more.
In our diagram, we assume we have made this also flushable.
Now as you may now see, bigger chunks may require more work by the cache manager.
More flushable chunks will need to be cleared.
And now the bigger chunk can be put in place.
And we hope that it is also flushable!
Flushing memory - Without turning on flushable, reusable memory options in a scene, memory will continue to fill up to the limit with geometry and textures. The basic ways to turn on flushable resources include:
Be careful with glossy effects. Lots of glossy rays could require loading a lot of the scene into memory.