Search Unity

Wild, unexplained shifts in rendering performance, no obvious cause... [SOLVED]

Discussion in 'General Graphics' started by phr00t, Jun 5, 2017.

  1. phr00t

    phr00t

    Joined:
    Apr 19, 2016
    Posts:
    41
    I'm getting a nasty performance hit when looking at different directions from within a large, single procedurally generated mesh of about ~60k verts. The GPU profiler says Render.Mesh is taking a very long time when the slowdown happens. When the slowdown doesn't happen, I'm still rendering the same mesh with the same overall scene vert count...

    Album with screenshots & description:

    http://imgur.com/a/4X7Pd

    I'm kinda thinking something is corrupt with my mesh, but I don't know how to track down how or where...? Thank you for your help!

    Unity 5.6.1p2, Windows x64
     
    Last edited: Jun 5, 2017
  2. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    How many time per second are you generating the mesh? do you generate garbage to collect by c#?
     
  3. phr00t

    phr00t

    Joined:
    Apr 19, 2016
    Posts:
    41
    Thank you for the reply.

    The mesh is only generated once, well before any of these graphs. It isn't undergoing any changes or generations during the performance issues.

    Minimal garbage is created during generation, as I use pooling & reuse some data objects. As you can see in the graph, garbage collection slightly increases during the "fast" period -- not when things are running slow (in the last 2 charts).

    Something else is happening...
     
  4. phr00t

    phr00t

    Joined:
    Apr 19, 2016
    Posts:
    41
    It appears to be shadows. When I disable shadows, the whole problem goes away... not sure why shadows kills performance so wildly & is so sensitive to which way I'm looking... I was only using a single directional light.
     
  5. phr00t

    phr00t

    Joined:
    Apr 19, 2016
    Posts:
    41
    Nevermind, not shadows. Some performance issues went away, not all... still get nasty framerate drops with shadows off looking in certain directions. Performance drops look the same...
     
  6. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    412
    If you think it's your mesh then generate a mesh you know is valid with an equal number of vests/tris.
    Use a modeling tool for example.

    Then see if it has the same issue. If it's really changing performance then I think there is something that is drastically changing the number verts/pixels that are actually being drawn.

    So your fast case is actually a reduced set of data and the worst case you are actually rendering everything.

    If you have a complex pixel shader it could be a depth/z cull issue.

    Also look at the frame debugger for both cases see what unity is actually rendering. In case there is something else to the left.

    When you generate the mesh do you update the mesh bounds to be accurate?
     
  7. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Does your mesh exceed 65535 vert?
     
  8. phr00t

    phr00t

    Joined:
    Apr 19, 2016
    Posts:
    41
    In a troubleshooting effort, I cut back the generation of my mesh to about 16k verts. I construct it by putting smaller, lego-like mesh pieces together into a large List<Vector3> of verts. I then SetVerts, SetTriangles, SetUVs & RecalculateNormals. I recalculate bounds via SetTriangles (which has a bool to recalculate bounds at the same time). I've tried using RecalculateBounds separately too. Nothing seem to be working...

    BUT I HAVE SOME NEW INTERESTING INFO

    I set the shader to "Unlit", and it didn't really help that much. HOWEVER, I unselected the 16k mesh I was in, so it wouldn't draw that yellow object tint -- AND THE PROBLEM WENT AWAY. The performance literally went from 29 FPS to over 400 FPS just by unselecting the object.

    If I select the "Standard" shader when it is unselected, it is at about 60 FPS. If I select the mesh object with the "Standard" shader, it goes back down to about 29 FPS.

    Something about the mesh, when looking at it in certain angles, doesn't like being drawn with "Standard" or even the Unity "yellow selected tint" shader...

    The frame debugger wasn't very helpful, because there are so few draw steps (it is just one big mesh) & it doesn't show how long a frame step takes.
     
  9. phr00t

    phr00t

    Joined:
    Apr 19, 2016
    Posts:
    41
    Mobile shaders don't seem to have a problem (unless I select it in the editor, causing the yellow selection shade to be drawn), but then I can't use any point lights...

    ... what kinds of things could cause this type of behavior?

    EDIT: Mobile Bumped & Mobile Bumped (1-directional light) seem to be the only ones not causing problems. Mobile diffuse causes problems. Mobile Bumped ones don't seem to be affected by point lights, while diffuse do see point lights...
     
    Last edited: Jun 6, 2017
  10. phr00t

    phr00t

    Joined:
    Apr 19, 2016
    Posts:
    41
    I will also add, the slowness happens with just 1 directional light. I don't have any point lights. If I use a shader that can be affected by point lights, the slowness happens -- even when no point lights exist.
     
  11. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    412
    The frame debugger idea was to make sure unity is drawing the same thing from the different directions.

    Did you post a picture of your mesh? I just remember seeing the profiler.

    It kind of sounds like you have a pixel shader issue. The problem with a giant mesh is that it will always be drawn.
    Having not seen the mesh, I imagine if one side is very big and is early in the mesh triangles it could cover the a lot of the other parts of the mesh. So when drawing the other parts of the mesh is fast because the depth buffer culls the hidden pixels. Kind of like a front to back ordering in the mesh data.

    But now rotate it around and from what one angle is front to back now becomes back to front requiring draw every pixel multiple times. And since its back to front the depth buffer isn't much help.

    If you zoom way out so the mesh is very small on the screen does the performance still drop when looking from different sides? If the problem goes away it's probably pixel bound. And if stays then probably it's cpu or vertex bound.
     
  12. phr00t

    phr00t

    Joined:
    Apr 19, 2016
    Posts:
    41
    Here is a picture of my mesh: https://i.imgur.com/AUv34rd.png

    Here is more information, screenshots & graphs: https://imgur.com/a/7HVpL

    The problem happens with the standard shader, Lux & Mobile diffuse shaders that are affected by point lights. I couldn't reproduce the problem with Unlit & Mobile Bumped (that are not affected by point lights). No point lights are in the scene, though.

    I was able to reproduce this problem with the above mesh, which is only ~9k verts... which doesn't seem that big, even if drawn a few times.

    Still scratching my head on this one... I don't want my game to suddenly drop frames in VR due to this.

    EDIT: Seeing the problem with Mobile Bumped now, but still not with any shaders that use vertex lighting or no lighting at all.
     
    Last edited: Jun 7, 2017
  13. phr00t

    phr00t

    Joined:
    Apr 19, 2016
    Posts:
    41
    I believe I've solved this.

    When generating my mesh, I was accidentally adding the triangle list twice. So, my SetTriangles() function was getting a list twice as long as it should, and referring to the first few verts repeatedly. This resulted in a corrupted mesh that probably really confused the renderer.

    Thank you for all your help!
     
    eXonius likes this.