Search Unity

Async Compute Shaders dependant on main thread?

Discussion in 'Shaders' started by Lyve81, Apr 26, 2020.

  1. Lyve81

    Lyve81

    Joined:
    Feb 4, 2014
    Posts:
    7
    Hi,

    I'm prototyping some GPU audio processing in Unity3D, which requires to run at a very low latency. Ideally, I would like to be able to process blocks of 64 samples, which would require me to dispatch compute shaders at a rate of roughly 689 frames per second.

    Is something like this possible in Unity? I tried to switch to CommandBuffer objects to do this, but Unity complains that I can call functions on this object only from the main thread, which will push be back to a maximum of 60fps.

    Ideally, I would like to maintain a graphics framerate of 60fps but run audio stuff in a different thread that executes much faster. I thought that async command buffers and using ScriptableRenderContext.ExecuteCommandBufferAsync would help, but they do not if I'm unable to operate on these objects outside of the main thread.

    Any help is highly appreciated.

    Best,

    Lyve
     
  2. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Can't you buffer then feed 1/60th seconds worth of samples into your compute shader?
     
  3. Lyve81

    Lyve81

    Joined:
    Feb 4, 2014
    Posts:
    7
    Thats what I do at the moment to test, but will increase the latency to be at least 1/60sec, too.

    Meanwhile, I started to integrate OpenCL into Unity, which seems to work and allows me to use it independent from the main thread.