Search Unity

Building Asset Bundles decompresses textures

Discussion in 'Addressables' started by AlkisFortuneFish, Sep 10, 2019.

  1. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    639
    I've been investigating some slow build issues and one thing I've been coming across for a while is console spam about decompressing unsupported PVRTC textures when targeting iOS.

    Now, for a while I assumed that to be harmless but I just profiled the Unity process to find 50% of its time spent in DecompressPVRTC during asset bundle builds.

    I guess I can only summarize this question as: Why?

    These textures are already in the AssetDatabase with the appropriate target format for the build, why would the build process have to decompress and recompress them?

    Code (csharp):
    1.  
    2. Function Name    Total CPU [unit, %]    Self CPU [unit, %]    Module
    3.  + Unity.exe (PID: 14548)    178079 (100.00%)    0 (0.00%)    Multiple modules
    4. | + ntdll.dll!0x007ff9ef16a271    177280 (99.55%)    0 (0.00%)    ntdll.dll
    5. || + kernel32.dll!0x007ff9ee267974    177280 (99.55%)    0 (0.00%)    kernel32.dll
    6. ||| + Thread::RunThreadWrapper    113653 (63.82%)    0 (0.00%)    Unity.exe
    7. |||| + GfxDeviceWorker::RunGfxDeviceWorker    113217 (63.58%)    0 (0.00%)    Unity.exe
    8. ||||| + GfxDeviceWorker::RunExt    113217 (63.58%)    0 (0.00%)    Unity.exe
    9. |||||| + GfxDeviceWorker::RunCommand    113217 (63.58%)    2 (0.00%)    Unity.exe
    10. ||||||| + GfxDeviceD3D11Base::UploadTexture2D    113109 (63.52%)    1 (0.00%)    Unity.exe
    11. |||||||| + TexturesD3D11Base::UploadTexture2D    113106 (63.51%)    5 (0.00%)    Unity.exe
    12. ||||||||| + TexturesD3D11Base::UploadAll2DData    112619 (63.24%)    0 (0.00%)    Unity.exe
    13. |||||||||| + TexturesD3D11Base::Upload2DData    112615 (63.24%)    5 (0.00%)    Unity.exe
    14. ||||||||||| + ConvertCompressedTextureUpload    92416 (51.90%)    3 (0.00%)    Unity.exe
    15. |||||||||||| + DecompressNativeTextureFormatWithMipLevel    92347 (51.86%)    0 (0.00%)    Unity.exe
    16. ||||||||||||| + DecompressNativeTextureFormat    92347 (51.86%)    3 (0.00%)    Unity.exe
    17. |||||||||||||| - DecompressPVRTC<0,1>    83299 (46.78%)    50252 (28.22%)    Unity.exe
    18. |||||||||||||| - DecompressETC2_RGBA8_RGBA8888    9034 (5.07%)    0 (0.00%)    Unity.exe
    19.  
    I don't really get what business the build process for an unrelated platform has uploading all textures to the local GPU, let-alone using the lossy native format to do so.
     
    Last edited: Sep 10, 2019
  2. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    639
    Hm. I may be wrong but I think I found what is going on. Further time profiling came up with a significant amount of time being spent here:

    Code (csharp):
    1.  
    2. Function Name    Total CPU [unit, %]    Self CPU [unit, %]    Module
    3. |||||||||||||||||||||||||||||||||| + ContentBuildInterface_CUSTOM_WriteSerializedFileAssetBundle_Injected    37947 (63.83%)    0 (0.00%)    Unity.exe
    4. ||||||||||||||||||||||||||||||||||| + BuildPipeline::WriteSerializedFile    37919 (63.78%)    0 (0.00%)    Unity.exe
    5. |||||||||||||||||||||||||||||||||||| + BuildPipeline::BuildReferenceMap::ConvertToInstanceIDToBuildAsset    26731 (44.96%)    14 (0.02%)    Unity.exe
    6. ||||||||||||||||||||||||||||||||||||| + AddBuildAssetInfo    26484 (44.55%)    4 (0.01%)    Unity.exe
    7. |||||||||||||||||||||||||||||||||||||| - CalculateSortIndex    19384 (32.61%)    2 (0.00%)    Unity.exe
    8. ||||||||||||||||||||||||||||||||||||||| + PPtr<Object>::operator Object * __ptr64    19382 (32.60%)    2 (0.00%)    Unity.exe
    9. |||||||||||||||||||||||||||||||||||||||| + PersistentManager::ReadObject    19380 (32.60%)    0 (0.00%)    Unity.exe
    10. ||||||||||||||||||||||||||||||||||||||||| - PersistentManager::ReadObjectThreaded    12791 (21.52%)    0 (0.00%)    Unity.exe
    11. ||||||||||||||||||||||||||||||||||||||||| - PersistentManager::LoadAndIntegrateAllPreallocatedObjects    6585 (11.08%)    1 (0.00%)    Unity.exe
    12. ||||||||||||||||||||||||||||||||||||||||| - PersistentManager::RegisterPartiallyLoadedObjectInternal    2 (0.00%)    1 (0.00%)    Unity.exe
    13. ||||||||||||||||||||||||||||||||||||||||| + PersistentManager::Lock    1 (0.00%)    1 (0.00%)    Unity.exe
    14. ||||||||||||||||||||||||||||||||||||||||| - PersistentManager::Unlock    1 (0.00%)    0 (0.00%)    Unity.exe
    15. |||||||||||||||||||||||||||||||||||||| - GetTypeWithoutLoadingObject    7037 (11.84%)    10 (0.02%)    Unity.exe
    16.  
    Now, I can only guess what CalculateSortIndex does from its name, is it supposed to dereference the object PPtr, which results in the object being loaded into memory? It would explain why Unity would be spending 50% of its time decompressing assets it has no business decompressing.

    Any ideas, @Ryanc_unity?
     
  3. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    639
    This could very well be the cause of this.