Search Unity

Async Graphics.Blit?

Discussion in 'Scripting' started by The-Oddler, Jun 30, 2016.

  1. The-Oddler

    The-Oddler

    Joined:
    Nov 26, 2010
    Posts:
    133
    I'm using Graphics.Blit to do some water simulations on the GPU. However, Graphics.Blit is a blocking call, so it takes away time from the CPU where it shouldn't.

    I was looking at CommandBuffers, making each of my Graphics.Blit calls a command. However, I can't seems to find how to properly execute the buffer. I found Graphics.ExecuteCommandBuffer but it looks like it is also blocking (though haven't gotten as far as testing it yet).

    So I was wondering, are CommandBuffers the way to go? And if so, how/where should I execute them? Or is there something else that can make my simulation not block the CPU thread?
     
  2. Nanoxin

    Nanoxin

    Joined:
    Mar 25, 2015
    Posts:
    3
    I'm currently also looking into Graphics.Blit and on how to remove the CPU stall.
    From a short conversation with The-Oddler, I do know that he also did not find a solution yet, so we're both still looking for a solution.
    If somebody has any knowledge on how to do it, we'd both be happy! :)

    Thanks!
     
    The-Oddler likes this.
  3. fra3point

    fra3point

    Joined:
    Aug 20, 2012
    Posts:
    269
    Hello,

    I know I'm 3 years late, but I just came across the same problem and I was wondering if someone has ever found a solution.

    I was looking at Graphics.ExecuteCommandBufferAsync but it doesn't support Blit operations....

    Thanks you,
    Francesco
     
  4. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    727
    any updates here?
     
  5. sirleto

    sirleto

    Joined:
    Sep 9, 2019
    Posts:
    146
    Same here. It is so cool, the amount of things that can be done with Graphics.Blit and nice shaders ... BUT all of them boil down to me right now thinking: why not run that (slower) on CPU (but another thread/on another core than the main thread) ... to free up main cpu (which seems to be a lot of bottleneck in unity already, anyway.

    i tried googling this, but to no success so far ...
     
  6. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    727
    This has nothing to do with CPU cost btw. It has to do with async GPU compute queues. Basically some GPUs support compute running "in the background" while other graphics work is happening. But this is all on the GPU.
     
  7. sirleto

    sirleto

    Joined:
    Sep 9, 2019
    Posts:
    146
    well, if you count CPU cost at "watts used" then you are right, its not about cpu cost. the main thread is just idly waiting for the GPU to finish graphics.blit

    BUT if you count CPU cost as milliseconds spend doing something, then the main thread is blocked while graphics.blit waits for the gpu work to finish, and having these async is a true win.

    i am still reading documentation to understand how to handle this in ways that can be async (obviously only to some extend, as sooner or later main thread will be waiting for render resources to work "synchronously" and finish jobs).

    maybe i should explain that i am talking about situations like global illumination with 20+ heavy (4k res) graphics.blit in one OnRenderImage() ... if thats the situation (taking merely multiple milliseconds of main thread cpu, per frame) then i think its clear how important it is to get any ms back to be used on main thread while gpu does async work.
     
    joshuacwilde likes this.