Search Unity

Compute shader - Retrieving data is expensive

Discussion in 'General Graphics' started by RemiRigal, Dec 22, 2020.

  1. RemiRigal

    RemiRigal

    Joined:
    Nov 20, 2020
    Posts:
    1
    Hi everyone,

    I'm currently implementing a disc packing algorithm with discs of varying radius, see the attached image.

    The implementation in C# works fine but is slow (~200ms for 500 points). I then wanted to try implementing it with a compute shader, and it worked great, even though it's a single thread compute shader as the task is not really feasible with multiple threads. My compute shader can now calculate 1000 points in less than 0.5 ms, it's not really impressive but it's enough for me.

    I managed to sped up the computation part but I realized that retrieving all the data (a float3 for each disc containing the position of the center and the radius) takes a very long time (~500ms for 1000 points).

    What could I possibly do to tackle this ? Is it even relevant to use a compute shader here ?
    Overall I would like some advice on when to use a compute shader and when not, what is a good rule of thumb ?

    Any help will be much appreciated.
     

    Attached Files:

  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    I would only use compute shaders when:
    - you can do work in parallel
    - you do not need to get the data back to the cpu immediately (“a bit later” is ok via AsyncGPUReadback)
     
    RemiRigal and Arycama like this.