Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Gfx.ReadbackImage Take a lot of CPU why?????????????

Discussion in 'Scripting' started by FabrizioSpadaro, Jan 24, 2016.

  1. FabrizioSpadaro

    FabrizioSpadaro

    Joined:
    Jul 10, 2012
    Posts:
    285
    Hi guys, as you can see in this screenshot:

    The profiler linked to the build(stand alone version) shows up that my game is running at 30 fps, now the problem is that i always get 60 fps but some times i get a 30 fps drop.
    I don't know the problem but in the profiler Gfx.ReadbackImage take lot of cpu why?how can i solve this?

    PS: I use unity 5.3.1f1
     
  2. FabrizioSpadaro

    FabrizioSpadaro

    Joined:
    Jul 10, 2012
    Posts:
    285
  3. prasetion

    prasetion

    Joined:
    Apr 3, 2014
    Posts:
    17
    still there is no way to reduce Gfx.ReadbackImage ?
     
  4. anthodb

    anthodb

    Joined:
    Sep 6, 2012
    Posts:
    17
    Hey Belva, I know it's an old thread but did you find a solution for this? We've got the same issue on our side.. Massive FPS drop (spikes) with Gfx.ReadBackImage.. Unity 2017.3.1f1
     
    Alex3333 likes this.
  5. ArtyIF

    ArtyIF

    Joined:
    Oct 13, 2014
    Posts:
    21
    same. i made a custom reflection solution, but this takes like 60% of cpu usage
     
  6. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    534
    Is your solution more performant? Would you be willing to share it?
     
  7. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    16,133
    One of developers mentioned (first link) that this is due to the implementation of realtime GI. When it's enabled and you ask the engine to access the framebuffer, the CPU will wait for the GPU to finish everything up until the readback, copy the data, and then continue from there.

    https://forum.unity.com/threads/gfx-readbackimage-slowness.574327/#post-3832666

    One solution is to simply turn it off but that's a lousy solution. A better solution is to use an AsyncGPUReadbackRequest as it will handle it while allowing everything else to proceed normally. Below is a link to the scripting reference and an example of using it.

    https://docs.unity3d.com/2018.3/Documentation/ScriptReference/Rendering.AsyncGPUReadbackRequest.html
    https://github.com/keijiro/AsyncCaptureTest
     
unityunity