Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Why FPS is twice lower while objects're moving together?

Discussion in 'Graphics for ECS' started by unity_820490E98A66A662650B, Jun 5, 2023.

  1. unity_820490E98A66A662650B

    unity_820490E98A66A662650B

    Joined:
    Jun 10, 2022
    Posts:
    2
    I had a weird result when tried to spawn 7000 entities (you can see it on the images below).
    This was the order of actions:

    1. 7000 entities are spawn from code at the same position.
    2. Then, the objects're going to the random point (all together with the same speed to the one (the same) point).
    3. Then, every object generates his own unique target point - and start moving to it separatelly.

    So, the question is:

    Why FPS is twice lower while the objects're moving together to the same point (which looks like it's the only one object)?
     

    Attached Files:

    • 1.PNG
      1.PNG
      File size:
      39 KB
      Views:
      61
    • 2.PNG
      2.PNG
      File size:
      155.5 KB
      Views:
      59
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,242
    Do the objects have colliders?
    Did you check the profiler?
     
  3. unity_820490E98A66A662650B

    unity_820490E98A66A662650B

    Joined:
    Jun 10, 2022
    Posts:
    2
    No colliders, just usual components like LocalToWorld and moving aspect.
    Profiler shows only big Gfx.WaitForPresentOnGfxThread difference (30 ms vs 7 ms).
     

    Attached Files:

    • 3.PNG
      3.PNG
      File size:
      15 KB
      Views:
      45
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,242
    What are the differences in the hierarchy of the inspector?
    Is vsync enabled? Maybe it just slightly tips to the next vsync tier, making it seem like a huge difference
     
  5. lilacsky824

    lilacsky824

    Joined:
    May 19, 2018
    Posts:
    163
    Seems like a GPU issue, as there is significant overdraw caused by a large number of overlapping objects.
     
    DevDunk likes this.
  6. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    223
    Overdrawing the same object 7000 times, vs. drawing the object 7000 times in a different location, does not explain why the FPS is tanked. I'm curious about this one.
     
  7. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,242
    The render thread clearly is higher. Overdraw can be more expensive than drawing next to eachother.
    Did you try in a build?
    Drawing instanced from the CPU might be worth trying to improve performance as well
     
  8. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    223

    I don't get it - on a technical level, why should drawing the object in the same spot be slower than drawing the object next to each other? It's doing the same z-tests, the same geometry, etc. In forward mode, it would be doing the same number of lit pixels. In deferred, again, all the same number of lit pixels.

    Do you have a solid explanation in terms of buffers/tests and GPU architecture?

    It's one thing to say that it is slower because they are drawn in the same spot (which we can infer from the results and conditions), but quite another to explain why. I'm genuinely curious to learn the answer.
     
  9. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,242
    I work a lot with mobile, and tiled GPUs can be very picky on certain depth optimizations. When stuff overlaps it will often run the pixel shader for that pixel multiple times (where everything side by side would be once per pixel).
    I am not fully sure how this translates to regular GPUs however, but I think this can also make sure the same pixel shader is ran multiple times which might break some optimizations. (or some optimizations being broken in general because of it?)
    This is purely speculation however
    You could try the rendering debugger and frame debugger to test out some stuff and see how that changes your performance.
     
  10. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    223
    Oh this is not my issue (I'm not the OP), I'm just butting in because the problem is annoying me :)
     
    DevDunk likes this.