异步数据流
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.在单独的异步线程中执行资源加载并将其传输到GPU。之后,资源被同步并添加到CPU侧的虚拟场景中。
In UNIGINE, asynchronous data streaming is enabled by default. You can disable asynchronous data streaming in UnigineEditor or via the console:在UNIGINE中,异步数据流是默认启用的。您可以在UnigineEditor或通过控制台禁用异步数据流:
- In UnigineEditor, open the Settings window and go to the Streaming section. Here you can switch the streaming mode for textures and/or meshes.在UnigineEditor中,打开Settings窗口并转到Streaming部分。在这里您可以为纹理和/或网格切换流模式。
- 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.).有两种主要的流模式:异步(Async)和强制(Force)。Force模式确保同时加载每帧所需的所有资源(例如,抓取帧序列,渲染节点预览,预热等)。
The streaming system provides asynchronous loading of the following data to RAM:流系统提供以下数据异步加载到RAM:
- All texture runtime files and textures with the Unchanged option enabled, including cubemaps, voxel probe maps, and shadow maps of baked shadows.所有纹理运行时文件和启用了Unchanged选项的纹理,包括立方体图, 体素探针图和烘烤阴影的阴影地图。
- Meshes of ObjectMeshStatic, ObjectMeshClutter, ObjectMeshCluster, ObjectGuiMesh objects, and DecalMesh.ObjectMeshStatic, ObjectMeshClutter, ObjectMeshCluster, ObjectGuiMesh对象的网格,以及DecalMesh。
Procedurally generated objects such as ObjectMeshClutter are generated in a separate thread, significantly reducing performance costs.过程生成的对象,如ObjectMeshClutter是在一个单独的线程中生成的,这大大降低了性能成本。
You can obtain general information on streamed resources by using the render_streaming_meshes_info and render_streaming_textures_info console commands.可以通过使用render_streaming_meshes_info和render_streaming_textures_info控制台命令获取流资源的一般信息。
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.还可以通过使用render_streaming_meshes_list和render_streaming_textures_list控制台命令输出已加载资源的列表和有关它们的详细信息。
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.也有2种模式:异步(Async)和强制(Force)。 在强制模式下,当前帧所需的所有着色器都在当前线程中同时编译并加载到RAM中。 默认情况下,使用异步模式。
The number of compiled and loaded shaders are available in the Performance Profiler tool.编译和加载的着色器的数量在Performance Profiler工具中可用。
Memory Usage Limits内存使用限制#
All memory allocations for graphic resources are limited by the committed memory size, which includes both RAM and VRAM.图形资源的所有内存分配都受提交内存大小的限制,其中包括RAM和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.RAM和VRAM的使用限制,将内存消耗限制在已提交内存的指定百分比内。但是,您应该记住,如果流媒体系统超过了VRAM使用限制,它将开始使用RAM加载图形资源。如果超过RAM使用限制,应用程序将崩溃。
- 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.RAM和VRAM的空闲空间,它定义了每帧额外为分配保留多少内存。这些参数确保在当前帧中总是有足够的内存来加载资源。这些值应该根据应用程序的实际情况来确定。
You can specify the usage limits and free space via UnigineEditor or the console:您可以通过UnigineEditor或控制台指定使用限制和可用空间:
- In UnigineEditor, open the Settings window, go to the Streaming section, and specify the required values.在UnigineEditor中,打开Settings窗口,转到Streaming部分,并指定所需的值。
-
In the console, pass the required values to the corresponding commands:在控制台中,将所需的值传递给相应的命令:
Texture Streaming纹理流#
The streaming system manages textures automatically. There are two modes of texture streaming:流系统自动管理纹理。 纹理流有两种模式:
- Asynchronous mode that provides asynchronous loading of textures.提供纹理异步加载的Asynchronous模式。
- Forced mode for force-loading of textures required for the current frame at once.Forced模式,用于一次强制加载当前帧所需的纹理。
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.对于纹理流优化,您可以启用纹理mipmap加载,这通过减少纹理流的内存消耗来显着提高性能。 此功能允许在当前时刻加载正确的mipmap。 启用mipmaps加载后,将卸载当前未使用的纹理。
To enable and configure mipmaps loading via UnigineEditor, do the following:要通过UnigineEditor启用和配置mipmap加载,请执行以下操作:
- Open the Settings window and go to the Streaming section.打开Settings窗口并转到Streaming部分。
- Toggle on the Mipmaps flag and specify the required Mipmaps Density.切换Mipmaps标志并指定所需的Mipmaps Density。
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.Mipmaps Density设置相对于屏幕分辨率的mipmap的密度,并帮助定义当前应该加载哪个mipmap。您可以为不同的质量预设指定不同的值。例如,对于低质量预设,可以将密度设置为小于1。在这种情况下,引擎将加载低分辨率的mipmaps,纹理将看起来模糊。
Additionally, you may need to configure the Texture Streaming Density Multiplier for each texture in some materials to achieve the desired visual effect.此外,您可能需要为某些材质中的每个纹理配置Texture Streaming Density Multiplier以实现所需的视觉效果。
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.为了确保所有后期效果的纹理在需要时可用,默认情况下为所有后期材质设置强制流模式。您可以在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:但是,如果后期素材中的一些纹理持续变化(通过代码、Tracker等),建议为每个纹理指定强制流模式:
- In the Material Editor, set Setting For Each Texture in the Textures Streaming Mode parameter for your post-effect material.在Material Editor中,在后期效果材质的Textures Streaming Mode参数中设置Setting For Each Texture。
- Toggle the forced streaming on and off for each texture individually in the Parameters panel of the Material Editor.在材质Material Editor的Parameters面板中单独切换每个纹理的强制流。
These settings override the global texture streaming settings specified in the Settings window.这些设置覆盖了在Settings窗口中指定的全局纹理流设置。
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.网格可以分别加载到RAM和VRAM中,以便更有效地处理几何图形。这允许消除内存泄漏:参与碰撞和交叉点的网格只能加载到RAM中,如果它们当前没有渲染。
There are two modes of mesh streaming to RAM/VRAM:有两种模式的网格流到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.异步加载到RAM和VRAM是不同的。即使网格没有及时加载到显存,它也不会影响应用程序的行为(您可能只会注意到一些延迟)。但是,如果网格没有及时加载到内存中,可能会导致场景中对象的物理行为不正确。
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.加载网格并在它们存在时将它们保存在内存中。一些基于网格的对象的API提供了开箱即用的功能。它可以部分解决不正确行为的问题,然而,只有少数网格可以保持加载。
-
Use the prefetch system that allows asynchronous pre-loading of meshes participating in collisions and intersections to memory before they are used:使用预取系统,允许在使用之前异步预加载参与碰撞和交叉点的网格到内存:
- Set the Radius prefetch mode.设置Radius预取模式。
- Specify the physics radius (for collisions) and/or the radius within which intersections are calculated.指定物理半径(碰撞)和/或计算交集的半径。
- 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.您也可以预加载计算碰撞和交叉的所有网格(Full预取模式),但是这会显著增加RAM的使用。
- 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.一些基于网格对象的API,以及MeshRender类API也提供了允许实现预加载网格的自定义预取逻辑的方法。
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.异步流网格不应该被修改。改变这种网格的唯一方法是使其程序化。过程网格是通过代码创建的网格,这样的网格有一个特定的流模式:它总是在创建后保存在内存中,并且永远不会卸载,直到对象被代码破坏或网格返回到其正常模式(从源文件流)。基于网格的对象API允许将网格切换到过程模式并应用更改。