Because the data doesn't have to be marshalled between the c# and c++ side of Unity only the wrapper class (Texture2D) has to exist on the C# side, the texture itself can exist in C++ and be uploaded to the GPU without going through the mono heap. Yes, you use the asset bundle API to load the texture from the asset bundle (You can load a texture2D in the exact way you load any other asset from an asset bundle.Ģ. Only the Texture2D object exists in C# land, which is just a wrapper around the actual texture.ġ. Here, we avoid the mono heap completely, as well as most of the work on the main thread. Texture data is uploaded to the GPU in ready compressed form, asynchronously. WebRequest gets data form the server, decompresses the asset bundle, and lets you know it's ready to load (not on main thread) When you load a compressed texture from an asset bundle using WebRequest (5.3+): The main advantage here is that you avoid the PNG decompression, which can be slow, and work with textures that are many times smaller since they are compressed. Texture is between 1/4 and 1/16th the size of the PNG depending on compression format/options Texture is uploaded to the GPU in ready compressed form, asynchronously (as of 5.2?) Bytes are copied to the mono heap and sent to the asset bundle loading API (back to C++) When you load a compressed texture from an asset bundle using WWW: Once you grab the byes and send it to the loading function (usually in the same call), it's all blocking the main thread. We measured times of 100+ ms for large textures under this scenario bytes are sent to C++ side and decompressed from PNG to uncompressed texture data bytes, and you pass that to the loading API Bytes are copied to the mono heap when you call. WWW or WebRequest gets data from server Here's what happens when you download a PNG: If you give this a try, I'd love to know your findings on upload times. Loading will still happen on the main thread, causing a glitch, but likely many times faster than the png/jpg technique as it won't have to decompress the data into a large buffer, just upload the bytes. Loading will still allocate on the mono heap For uncompressed, you can likely processes it into the raw bytes of a color, but I'm not sure what it expects there. You'll need to compress the textures into each format you support (PVR, ETC, ETC2, DXT, etc). I haven't tried using LoadRawTextureData before, but we talked about it quite a bit and are considering moving some of our pipeline to it if Unity cannot fix the cache server issues soon (they've fixed several, but often Unity won't generate the same hash or upload a correct hash- this causes our project to re-import every time we build it on a new machine, which can easily take 20 hours). Texture compression is a 4:1 to 16:1 savings depending on platform/format. Memory is allocated on the mono heap for the. All loading is done on the main thread, causing aa sizable glitch (up to 100ms on our low end devices) So, we moved all of our images into asset bundles for this reason.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |