Indirect Compute Shader

Direct means CPU tells GPU to execute work, amount of work is given by CPU

Indirect means CPU tells GPU to execute work, amount of work is calculated in GPU

Scenario:

I have a maximum no. of cats (say 10000 cats).
Since they all get hungry at different times so I should only feed the cats that are hungry.

Steps:

Compute Buffer and Compute Shader (20170703)

  1. CPU creates 2 compute buffers. Data buffer knows it can takes up to 10000 data.
    • Data buffer : no. of cats = 0
  2. CPU pass the number 10000 to GPU to run the direct dispatch, which will add the hungry cats to data buffer.
    • Data buffer : no. of cats = no. of hungry cats
  3. So now we have hungry cats filtered out!
  4. Pass the no. of hungry cats from data buffer to args buffer. So that we know we have to feed how many cats.
  5. Run indirect dispatch according to no. of hungry cats from args buffer. That is, too feed them!

 

From the arrows in the diagram you can see there is no read or write data back to CPU (which wastes time and resources) during the whole cat filtering and feeding process. It’s very good isn’t it :D?

 

Download unity package to try it out 🙂 or visit https://github.com/cinight/MinimalCompute

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s