This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Basics
Rendering
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Version Control
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

Asynchronous Data Streaming

Data streaming is an optimization technique intended to reduce spikes caused by loading graphic resources and compiling shaders. With this technique, not all the data is loaded into memory at once. Instead, only the required data is loaded, and the rest is loaded progressively on demand.

Resource loading is performed and transferred to the GPU in separate asynchronous threads. After that, resources are synchronized and added to the virtual scene on the CPU side.

The output of the Microprofile tool.

In UNIGINE, asynchronous data streaming is enabled by default. You can disable asynchronous data streaming in UnigineEditor or via the console:

  • In UnigineEditor, open the Settings window and go to the Streaming section. Here you can switch the streaming mode for textures and/or meshes.
  • In the console, run the corresponding commands that switch the streaming mode for textures and/or meshes.

There are two main streaming modes — asynchronous (Async) and forced (Force). The Force mode ensures force-loading of all resources required for each frame simultaneously (e.g., grabbing frame sequences, rendering node previews, warmup, etc.).

Notice
The Force mode may cause freezes, so use it only if you are sure that the resources in your world fit into the available memory.

The streaming system provides asynchronous loading of the following data to RAM:

Procedurally generated objects such as ObjectMeshClutter are generated in a separate thread, significantly reducing performance costs.

You can obtain general information on streamed resources by using the render_streaming_meshes_info and render_streaming_textures_info console commands.

The render_streaming_meshes_info output.

It is also possible to print the list of loaded resources and detailed information on them by using the render_streaming_meshes_list and render_streaming_textures_list console commands.

The render_streaming_meshes_list output.

Asynchronous Shader Compilation#

In addition to the asynchronous loading of meshes and textures, the streaming system provides asynchronous shader compilation and loading.

There are also 2 modes — asynchronous (Async) and forced (Force). In the Force mode, all shaders required for the current frame are compiled and loaded to RAM simultaneously in the current thread. By default, the asynchronous mode is used.

Notice
You can switch the compilation mode in UnigineEditor or by using the render_shaders_compile_mode console command.

The number of compiled and loaded shaders are available in the Performance Profiler tool.

Memory Usage Limits#

All memory allocations for graphic resources are limited by the committed memory size, which includes both RAM and VRAM.

You can limit the memory available to the application to avoid crashes and find the balance between performance and memory consumption. There are two main parameters for this:

  • Usage limits for RAM and VRAM that restrict memory consumption to a specified percentage of the committed memory. However, you should remember that if the streaming system exceeds the VRAM usage limit, it will start using RAM for loading graphic resources. If it exceeds the RAM usage limit, the application will crash.
  • Free space for RAM and VRAM that defines how much memory is additionally reserved for allocations per frame. These parameters ensure that there is always enough memory for resource loading in the current frame. The values should be determined empirically, depending on the application.
Notice
You can disable VRAM limits if necessary by toggling on the VRAM overcommit option. It may lead to spikes and freezes of the application but will ensure continuous loading of graphic resources. This option is unavailable for RAM, as exceeding available RAM will result in the application crash.

You can specify the usage limits and free space via UnigineEditor or the console:

Notice
For particle systems, there is a separate memory limit in percentage of the total GPU memory.

Texture Streaming#

The streaming system manages textures automatically. There are two modes of texture streaming:

  • Asynchronous mode that provides asynchronous loading of textures.
  • Forced mode for force-loading of textures required for the current frame at once.

For texture streaming optimization, you can enable texture mipmap loading, which significantly improves performance by reducing the memory consumption of texture streaming. This feature allows for the correct mipmap to be loaded at the current moment. When mipmaps loading is enabled, the textures that are not currently in use are unloaded.

To enable and configure mipmaps loading via UnigineEditor, do the following:

  1. Open the Settings window and go to the Streaming section.
  2. Toggle on the Mipmaps flag and specify the required Mipmaps Density.
Notice
You can do the same via the console using the render_streaming_textures_mipmaps and render_streaming_textures_mipmaps_density commands.

Mipmaps Density sets the density of mipmaps relative to the screen resolution and helps to define which mipmap should be loaded at the current moment. You can specify different values for different quality presets. For example, you can set the density to less than 1 for the low-quality preset. In this case, the engine will load the low-resolution mipmaps, and the textures will look blurry.

Additionally, you may need to configure the Texture Streaming Density Multiplier for each texture in some materials to achieve the desired visual effect.

Forced Streaming for Textures in Post-Effect Materials#

To ensure all textures for your post-effects are available when needed, the forced streaming mode is set for all post materials by default. You can find this setting in Material Editor.

However, if some textures in the post material continuously change (via code, Tracker, etc.), it is recommended to specify the forced streaming mode per texture:

  1. In the Material Editor, set Setting For Each Texture in the Textures Streaming Mode parameter for your post-effect material.
  2. Toggle the forced streaming on and off for each texture individually in the Parameters panel of the Material Editor.

These settings override the global texture streaming settings specified in the Settings window.

Mesh Streaming#

Meshes can be loaded to RAM and VRAM separately for more efficient work with geometry. This allows eliminating memory leaks: meshes participating in collisions and intersections can be loaded to RAM only, if they are not currently rendered.

There are two modes of mesh streaming to RAM/VRAM:

  • Asynchronous mode that provides asynchronous loading of meshes.
  • Forced mode for force-loading of meshes required for the current frame at once.

The asynchronous loading to RAM and VRAM differs. Even if a mesh hasn't been loaded to video memory in time, it doesn't affect the application behavior (you may only notice some lag). However, if a mesh hasn't been loaded to memory in time, it may lead to incorrect physical behavior of objects in the scene.

First of all, we highly recommend you to use shapes for collision and intersection detection as it is faster. If, for some reason, it doesn't suit you, use the following methods:

  • Load meshes and hold them in memory while they exist. API of some mesh-based objects provides this functionality out of the box. It may partially solve the problem with incorrect behavior, however, only a few meshes can remain loaded.
  • Use the prefetch system that allows asynchronous pre-loading of meshes participating in collisions and intersections to memory before they are used:

    1. Set the Radius prefetch mode.
    2. Specify the physics radius (for collisions) and/or the radius within which intersections are calculated.
    3. Specify the prefetch radius that should exceed the collison and intersection radius values.

    You can also preload all meshes for which collisions and intersections are calculated (the Full prefetch mode), however it will significantly increase RAM usage.

  • API of some mesh-based objects, as well as the MeshRender class API provides also methods which allow implementing a custom prefetch logic for pre-loading meshes.
Notice
It is highly recommended to use shapes for collision and intersection detection.

Asynchronously streamed meshes shouldn't be modified. The only way to change such mesh is to make it procedural. A procedural mesh is a mesh created via code, such meshes have a specific streaming mode — they are always kept in memory after creation and never unloaded until the object is destroyed via code or the mesh returns to its normal mode (streaming from a source file). The mesh-based objects API allows switching a mesh to the procedural mode and apply changes.

Last update: 2024-11-06
Build: ()