Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

URP loses whopping 3ms of CPU time once a single Hybrid Renderer entity is spawned

Discussion in 'Entity Component System' started by Xentarok, May 25, 2022.

  1. Xentarok

    Xentarok

    Joined:
    Apr 3, 2013
    Posts:
    17
    Hello!

    I've run into a pretty big problem.

    I have a game where I use URP and a hybrid DOTS approach - most things are handled in the regular way but if there's a lot of them I use the DOTS stack.

    Since it's a city builder I spawn citizens using DOTS - a very simple 10-ish vertice model with a URP simple lit material, GPU instancing enabled, entirely spawned as an entity so rendered using the hybrid renderer (latest, v2).

    The problem is, as soon as I spawn even a single one I suddenly gain like 3ms of CPU time from URP.

    Here's the profiler screenshot before I spawn entities:


    And here's after:


    When I zoom in to the part that gained 3ms it seems that most of it is spent on culling? I tried turning off the model dynamic culling but that doesn't fix it.


    I'm pretty sure this problem came at some point after I started the project and wasn't there from the start - perhaps a setting I overlooked or a quirk in a URP update?

    Anyway, if anyone has any idea what might be causing this I'd be really grateful!
     
  2. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    982
    Make sure you have enabled Burst, safety checks off and Leak detection off before profiling anything in editor.
     
    DrBoum and MNNoxMortem like this.
  3. Xentarok

    Xentarok

    Joined:
    Apr 3, 2013
    Posts:
    17
    Thanks, turning leak detection back off fixed some lag spikes I was having - but still, with burst enabled, safety checks off and leak detection off the issue persists, even in build
     
  4. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,301
    Can you get some profiler captures with safety checks and leak detection off so we can see what the actual difference is?
     
  5. Xentarok

    Xentarok

    Joined:
    Apr 3, 2013
    Posts:
    17
    Here are the profiler screenshots post and pre spawning just 4 entities, it seems that after enabling leak detection the issue is Semaphore.WaitForSignal
    post_entity.png pre_entity.png
     
  6. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,301
    I see two things. One is that culling is taking a half a millisecond longer. But you haven't fully expanded the main thread so it is hard to see what is different. I would expect the culling to be a little longer due to BRG scheduling, but a half millisecond is surprisingly long.

    The bigger issue however is your GPU sync bottleneck. Either those meshes are really expensive or something else is causing your GPU to suffer, because there's a huge spike waiting on the graphics thread. At the end of that Semaphore.WaitForSignal, there is a little yellow vertical bar. What does that bar say?
     
  7. Xentarok

    Xentarok

    Joined:
    Apr 3, 2013
    Posts:
    17
    At the end of the Semaphore wait there's this:

    upload_2022-5-26_22-30-37.png

    The blue is ScriptableRuntimeReflectionSystemWrapper.Internal_ScriptableRuntimeReflectionSystemWrapper_TickRealtimeProbes(), the rest are Gfx.EndAsyncJobFrame, updateScene.Invoke, ReflectionProbes.Update, WaitForRenderJobs and TextRendering.CollectGarbage

    As far as I know I don't use reflection probes, maybe only from the Skybox? I disabled all environmental reflection in lighting settings and it didn't fix it though
     
  8. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,301
    Huh. That wasn't what I expected. But it seems you really are GPU-bound when entities are around. You don't have any crazy meshes or crazy shaders on those entities, do you?
     
  9. Xentarok

    Xentarok

    Joined:
    Apr 3, 2013
    Posts:
    17
    That't the thing, nothing crazy at all - a super small 10 veritce mesh with URP Lit material (also tried Simple Lit, messing with material settings etc.)
     
  10. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    982
    Looks like VSync to me. Have you turned it off?
     
  11. Xentarok

    Xentarok

    Joined:
    Apr 3, 2013
    Posts:
    17
    Yup, been turned off for a long time now
     
  12. CreationRoom

    CreationRoom

    Joined:
    Jun 23, 2019
    Posts:
    3
    Hi Xentarok and dev, sorry to necro but I have this exact same problem.
    Environment : Unity 2023.1.12f1 - URP 15.0.6 - Entities graphics 1.0.14
    Did you find a solution to your problem ?
     
  13. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    765
    I don't know if this will help, but I know that 2022.3.9 introduced a culling system fix. Maybe it will help?

    @CreationRoom - unity 2023 does not support DOTS. Only 2022 does. A lot of people have tried 2023 and ran into random bugs.
     
    bb8_1 likes this.