Search Unity

Question Metal ScratchBuffers and DrawableProxy

Discussion in 'iOS and tvOS' started by chrismarch, Oct 13, 2020.

  1. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    472
    What aspects of a Unity project contribute to Metal ScratchBuffer usage? I'd like to cut down the 24 MB our project is devoting to these on device:
    upload_2020-10-13_11-8-31.png


    Same question for the DrawableProxy
    upload_2020-10-13_11-15-27.png

    (Unity 2019.4.10f1, URP 7.5.1)
     
    Last edited: Oct 13, 2020
  2. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    731
    I did some digging into this the other day. Pretty sure the DrawableProxy(s) are from here: https://developer.apple.com/documentation/quartzcore/cametallayer
    Basically Metal creates a pool of textures so that it can flip to writing to them when necessary as that's what gets written to the screen. That is my understanding anyway. Basically creating a pool of textures rather than creating a new texture every frame.

    As for the ScratchBuffer(s), I would imagine it is for something similar, but for meshes maybe? I think the ScratchBuffer(s) are more specific to Unity's implementation of drawing. Maybe used to move mesh memory around?? Not sure...
     
    chrismarch likes this.
  3. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    472
    Thanks for the tip. It looks like the DrawableProxy's aren't much of a concern for memory pressure in my screenshot, as their Purgeable State is Empty (no longer used and can be discarded), so it looks like I mainly need some more info on what is creating all these scratch buffers, and if I can reduce them via changing my loaded asset set.
     
    joshuacwilde likes this.
  4. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    731
    Right, afaik, they don't contribute to memory pressure as they are purgeable. Would also like to know more about the scratch buffers.
     
  5. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    731
    did you ever end up figuring anything else out here? or about ios memory optimization in general?
     
  6. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    472
    I never found a smoking gun for the scratch buffers.
    My main finding, on Metal, was that memory usage by meshes can be ramp up very quickly with vertex count. It helps to reduce the vert count as much as possible, and not export your meshes with any unneeded channels (vertex colors, for example). I haven't been able to devote more time on the subject lately.