Asynchronous Texture Upload 异步贴图上传 AUP(Async Upload Pipeline) Advanced Rendering Features系列之一

Asynchronous Texture Upload 异步贴图上传 AUP(Async Upload Pipeline)

本文档主要是对Unity官方手册的个人理解与总结(其实以翻译记录为主:>)
仅作为个人学习使用,不得作为商业用途,欢迎转载,并请注明出处。
文章中涉及到的操作都是基于Unity2018.4版本
参考链接:https://docs.unity3d.com/Manual/AsyncTextureUpload.html

Asynchronous Texture Upload enables asynchronous loading of Texture Data from disk and enables time-sliced upload to GPU on the Render-thread. This reduces wait for GPU uploads in the main thread. Async Texture Upload will automatically be used for all Textures that are not read-write enabled, so to use this feature no direct action is required. You can however control some aspects of how the async upload operates, and so some understanding of the process is useful to be able to use these controls.
AUP支持从磁盘异步加载纹理数据,并支持在渲染线程上以时间片方式把纹理数据上传到GPU。这减少了纹理数据从主线程上传到GPU的等待时间。AUP将自动用于所有未启用读写的纹理,因此使用此功能不需要直接操作。不过,您可以控制AUP的一些参数,因此了解其过程有助于使用这些参数。

When the project is built, the texture data of asynchronous uploadable textures are stored in as streaming resource files and are loaded asynchronously.
在构建项目时,异步可上传纹理的纹理数据作为流资源文件存储并用于异步加载。

Simple & Full Control Over Memory / Time-Slicing 简单并全面由内存和时间片控制

A single ring-buffer is reused to load the texture data and upload it to the GPU, which reduces the amount of memory allocations required. For example, if you have 20 small textures, Unity will set up an asynchronous load request for those 20 textures in one go. If you have one huge texture, Unity will request only one.
一个环形缓冲区被重用来加载纹理数据并上传到GPU,这减少了所需的内存分配量。例如,如果你有20个小纹理,Unity会一次性为这20个纹理建立一个异步加载请求。如果你有一个巨大的纹理,那Unity只请求加载一个。

If the buffer size is not large enough for the textures being requested, it will automatically resize to accomodate, however it is always optimal to try to set the size to fit the largest sized texture that you will be uploading from the outset, so that the buffer does not need to resize for each new larger texture it encounters.
如果可请求的纹理缓冲区大小不足够大,它会自动调整适应,然而它总是设置大小为最大的纹理大小以作为最优的内存占用,这是从一开始上传就开始调整的,所以缓冲不需要为每个新遇到的更大的纹理而调整。

The time spent on texture upload each frame can be controlled, with larger values meaning the textures will become ready on the GPU sooner but with the overhead of more CPU time being used during those frames for other processing. This CPU time is only used if there are textures waiting in the buffer to be uploaded to the GPU.
花在每帧纹理上传的时间是可以被控制的,更大的值意味着纹理数据将会在GPU上更快地就绪,但这些帧的占用导致用于其他处理的CPU时间开销会更大。这个CPU时间只在缓存中有纹理数据等待上传到GPU时才会持续占用。

The size of the buffer and time-slice can be specified through the Quality settings:
缓冲区大小和时间片可以通过Quality设置来指定:
Asynchronous Texture Upload 异步贴图上传 AUP(Async Upload Pipeline) Advanced Rendering Features系列之一_第1张图片
The Async Upload settings in the Quality settings

Async Texture Upload Scripting API AUP的脚本API

We provide the ability to control the Buffer Size and the Time-Slice value from script.
我们提供了从脚本控制 缓冲区大小 和 时间片值 的功能。

Time-Slice

Sets the Time-Slice in milliseconds for CPU time spent on Asynchronous Texture Uploads per frame. Depending on the target platform and API, you may want to set this. Time is only spent on the function call if there are textures to upload, otherwise it early-exits.
设置每帧用于AUP的CPU时间片(以毫秒为单位)。根据目标平台和API的不同,您可能需要设置这个参数。只有当要上传纹理时,才会耗费时间在AUP的函数调用上,否则它会提前退出。

Buffer Size

Set the Ring Buffer Size for Asynchronous Texture Uploads. The size is in mega-bytes. Ensure that you set a reasonable size depending on the Target platform. Also please ensure that it is always sufficient to load any huge texture in your games. For example if you have a Cubemap of size 22MB and if you set the size of the RingBuffer to 16MB, the App will automatically resize the Ringbuffer to 22MB while loading that scene.
设置AUP的环形缓冲区大小。大小以MB为单位。确保根据目标平台设置合理的大小。此外,请确保它总是足够加载任何巨大的纹理在您的游戏。例如,如果您有一个22MB大小的Cubemap,并且将RingBuffer的大小设置为16MB,那么在加载该场景时,应用程序将自动将RingBuffer的大小调整为22MB。

Notes

For non-read/write enabled textures, the TextureData is part of resS (Streaming Resource) and upload now happens on Render-Thread. Availability of Texture is guaranteed during call to AwakeFromLoad just as before, so there are no changes in terms of order of loading or availability of Textures on Rendering.
对于非 读/写 的纹理,TextureData作为resS(流资源)的一部分,现在可以在渲染线程上进行上传。纹理的可用性在调用AwakeFromLoad时就得到了保证,就像以前一样,因此在加载顺序或渲染时纹理的可用性方面没有变化。

For other types of texture loading, such as read/write enabled textures, textures loaded directly with the LoadImage(byte[] data) function, or loading from the Resources folder, the Asynchronous buffer loading is not used - the older Synchronous method is used.
对于其他类型的纹理加载,比如支持 读/写 的纹理,直接用LoadImage(byte[] data)函数加载的纹理,或者从Resources文件夹加载的纹理,都不会用AUP加载而是使用旧的同步方法。

你可能感兴趣的:(Advanced,Rendering,Features,AUP,Async,Upload,Texture,Time-Slice)