Search Unity

GPU Instancing Particle System is not doing GPU Instancing ?

Discussion in 'General Graphics' started by Deytooh, Dec 15, 2018.

  1. Deytooh

    Deytooh

    Joined:
    Jan 14, 2015
    Posts:
    6
    Hello !
    I am currently making a GPU Instancing Particle System and I have the feeling that it is not doing GPU Instancing at all, I did use DrawMeshInstancedIndirect, wrote the #pragma multi_compile_instancing
    in the shader etc...But my particle system lags when i have around 10.000 particles (GPU Instancing lagging with only 10k ? mmmhh weird) ! Maybe I did code wrong the script I am using to update particles etc...
    I do a for loop on my particles in a script in order to update their positions etc... and then I give a TRS matrix4x4 to a buffer in a shader StructuredBuffer<float4x4> positionBuffer containing the position the scale and the rotation in order to visually update the particles.
    also, in the game window stats, saved by batching is never changing (everytime I see someone doing gpu instancing, his saved by batching value is always like 1000 or i dont know !

    Did I miss something ?

    Unity Version : 2018.2.10f1
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Have you tried using one of the "Particles/Standard" shaders to test perf with? Unity limits each drawinstanced call to about 1000 particles, so 10,000 particles will be 10 set pass calls. 10,000 particles without GPU instancing should be somewhere around 3~4 times as many drawdynamic calls.

    One thing to note, the particle system is still a CPU based system, so instancing is only removing some of the per particle drawing, but the simulation cost is the same. The upcoming VFX graph is guilt GPU based, and can handle millions of particles.
     
    Deytooh likes this.
  3. Deytooh

    Deytooh

    Joined:
    Jan 14, 2015
    Posts:
    6
    I just did test with the Particles/Standard but it is the same, yeah it limits drawinstanced "Note: You can only draw a maximum of 1023 instances at once." (In the DrawMeshInstanced doc) but with the Indirect it is not limited isnt it ? I am using DrawMeshInstancedIndirect function.

    Yeah I did try the VFX Graph and it is really awesome I love it, but how it can handle millions of particles !!
    How I could make my own GPU Instanced particle doing more than 20.000 particles without lagging, I really dont have a clue now
     
  4. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    I guess if you are using DrawMeshInstancedIndirect then your particle system is a custom one you wrote yourself. When you say you are looping around each particle in script setting positions, that is all cpu code and is probably why it’s slow. Look at the timeline Profiler to see which bits are slow. Gpu particle systems and instancing are fast because they do all their work on the gpu. If you are doing any per particle work on the cpu and uploading all your data each frame, it will be slow. Try to store your particles in a ComputeBuffer and update their positions in a compute shader, not a script. Then everything is running on the GPU.
     
    Deytooh likes this.
  5. Deytooh

    Deytooh

    Joined:
    Jan 14, 2015
    Posts:
    6
    Wow indeed I did not know that, I know I was missing something !! Really thank you I am so happy now ! Thank you :) I will try that !
     
    richardkettlewell likes this.