Memory Usage Optimizations for GPU rendering

Introduction

In this article, we explore optimizing GPU memory usage for V-Ray GPU. The entire scene being rendered (Geometry, textures, buffers, etc) must fully fit into GPU memory when using either CUDA or RTX engines. Not having enough GPU memory for your scene might slow down rendering considerably or crash with out-of-memory errors.

  • Slower rendering because of not having enough GPU memory Indicated by this error in the V-Ray Log, this error shouldn't be ignored as it slows down rendering considerably. We recommend optimizing the GPU memory usage for your scene using the tips in this article if you encounter this warning.
    Code:
    Num samples per thread reduced to xxxxx, rendering might be slower

Screenshot_126.png

 

  • Out-of-memory errors indicated by this error, or sometimes a hang of the DCC host application.
    Code:
    [GPU Light Cache]couldn't allocate buffer of size xxxMB

 

GPU memory optimization for V-Ray GPU

We explore each of the items in detail:

  • Progressive Image Sampler.
  • V-Ray GPU CUDA engine.
  • Compressed Textures.
  • Out-Of-Core Textures.
  • GPU Light Cache Subdivs​.
  • Render Elements.
  • Rendering with V-Ray Standalone.
  • Having a separate device for Viewport performance.
  • Displacement.
  • V-Ray GPU CUDA-x86 engine..
  • Chaos Cloud Closing.
  • other applications that use GPU memory.

Progressive Image Sampler

We recommend using Progressive Image Sampler for rendering with V-Ray GPU, not only it uses less GPU memory but it is usually faster than Bucket mode. Using Progressive Image Sampler reduces GPU memory usage by around 2 GB in our testing.

Screenshot_165.png

 

V-Ray GPU CUDA engine

Swapping engines from RTX to CUDA will reduce GPU memory usage, by around 2 to 3 GB depending on the scene. This doesn't mean the CUDA engine is better than the RTX engine, we recommend testing your scene with the RTX engine(if you are not running into GPU memory issues) to see which engine renders your scene faster.

Screenshot_166.png

 

Compressed Texture mode(V-Ray 6.1 and later)

This mode uses special compression for your bitmaps to reduce memory usage significantly, without sacrificing quality. It could be very useful for scenes and assets using many high-resolution bitmaps. Not all textures are compressed using this option and exceptions are made based on the bitmap usage:

  • If a bitmap is used for both normal/bump and color maps, as compression for normal maps is generally not good for color maps, and vice versa.
  • Bitmaps used for displacement.
  • Bitmaps used for lens effects.​

The Texture compression happens in a pre-pass before the rendering process starts, this mode affects rendering performance slightly for machines with a single GPU.

Screenshot_168.png

Note: Compressed Textures mode works well for animation rendering, reducing flickering.

 

Out-Of-Core Textures(V-Ray 6.2 and later)

V-Ray GPU is able to offload Textures to system memory, to lower GPU memory usage significantly with little impact on performance. You can enable OOC Textures in the UI by enabling Use System Memory for Textures, more on this feature here.

Screenshot_167.png

 

GPU Light Cache Subdivs

Higher values will use more GPU memory. Ideally, the LC Subdivs should be between 1000 to 3000 based on rendering resolution, for 4k rendering or for animations 3000 should be ideal.

Render Elements ​

Using more render elements, especially Light Mix will increase GPU memory usage. Try to use the least amount of Render Elements possible, anything that is not needed for the final frame should be deleted.

Rendering with V-Ray Standalone

Host Applications just like V-Ray GPU need some VRAM to keep the scene open. Depending on scene complexity Host Application may occupy a few gigabytes of VRAM which could be very valuable for V-Ray GPU in case there isn't enough Memory for the Rendering. Exporting the scene to a .vrscene file and rendering it with V-Ray Standalone will minimize VRAM consumption by excluding the Host Application.

From the V-Ray menu click on export .vrscene:

Screenshot_169.png

Code:

"C:\ProgramData\Autodesk\ApplicationPlugins\VRay3dsMax2023\bin\vray.exe" -sceneFile=""""C:\Users\muham\Desktop\NewFolder\GPU_CAM_B_MH_002.vrscene"""" -rtEngine=7 -display=1 -verboseLevel=3 -showProgress=1
  • Replace the first path with the Vray.exe path, in this case, the V-Ray for 3Ds Max 2023 path is demonstrated.
  • Replace the second path with your .vrscene path(which you exported from your host DCC)
  • -rtEngine=7 is for the RTX engine, and -rtEngine=5 is for the CUDA engine
  • Copy and paste the text to a text document and change the extension to .bat, here is an example file ( double-click on the file to launch Vray standalone).

Note: use the Device Selector tool to set your rendering devices for Vray standalone.

 

Having a separate device for Viewport performance

Adding a mid-range GPU like the RTX 3060 12 GB to your workstation could be helpful to connect your monitors to, this GPU will be highlighted by sign in the Device Selector tool. This way host DCCs like 3Ds Max (and any other open applications) will not use the GPU memory on your rendering devices.

If you have more than one GPU, you can set one of your GPUs to be used for Viewport Performance. Open NVIDIA Control Panel, and set OpenGL rendering GPU to this device(in this case I have 2x 3090s in my workstation) Note, applications like 3Ds max, Maya, Cinema 4D, and Houdini will use this device for viewport performance.

Note: applications like 3Ds max, Maya, Cinema 4D, and Houdini will use this device for viewport performance.

Screenshot_1001.png

 

Another way to set a GPU device for viewport performance is using Windows Settings, type Graphics Settings in Start, then click on Change Default Graphics Settings. Now change Default High-performance GPU to your preferred device:

Screenshot_170.png

 

Displacement

Displacement and Subdivision objects tend to consume a lot of GPU memory and they are dependable on the image resolution, the higher the resolution is the higher the memory consumption will be. Make sure the geometry generated by these features is with reasonable polygon count otherwise, it could fairly easily eat the whole memory. Especially if you have your displacement set to View-Dependent.

You can disable/enable displacement from Global Swatches in the Settings tab to see the impact on GPU memory usage.

Screenshot_172.png

 

V-Ray GPU CUDA-x86 engine

This is not an effective approach in terms of render times since V-Ray GPU won't benefit from using your fast GPUs. However, if the scene is massive and there is no way to fit it into the GPU memory, it is still possible to render with V-Ray GPU by using the CUDA-x86 engine, which uses system memory (paging is supported) More about this option here.

Screenshot_173.png

 

In the same way, a V-Ray GPU scene could be rendered on a CPU farm using the CUDA-x86 engine, producing perceptually identical results to the CUDA and RTX engines.

 

Chaos Cloud

Chaos Cloud is a brilliant option to render projects that can't fit into a local machine's memory. It's a one-click solution that will help you render the scene without investing in additional hardware or losing time to optimize the scene. Currently, Chaos Cloud uses Nvidia Tesla T4 16 GB GPUs, so it is limited to 16 GB of GPU memory.

 

Closing other applications that use GPU memory

It's not unusual to have multiple applications open when working on a project. Although it's very handy to have all the needed apps up and running, this will also reduce the amount of GPU memory available for the V-Ray GPU. Applications like Substance Painter or Nuke use huge amounts of GPU memory This approach will reduce VRAM usage from the GPU devices connected to monitors as mentioned above.

Was this article helpful?
7 out of 9 found this helpful