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. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Would changing a GO-game, to entities+HRv1, help decrease gpu usage/rendering load?

Discussion in 'Graphics for ECS' started by mailfromthewilds, May 14, 2021.

  1. mailfromthewilds

    mailfromthewilds

    Joined:
    Jan 31, 2020
    Posts:
    214
    * i know that HRv2 is better but my shaders are not compatible and I failed to convert them manually

    * i know that Entities are mainly a thing to decrease CPU load, by dividing the job on every single thread youre not maxxing one thread but instead having every thread work very little, it decreases load on main cpu thread and results in high fps

    * but what about gpu?

    * i have newest unity + HRv1 + default rendering pipeline, the reason why not using universal pipeline is my failure to convert shaders
     
  2. miknios

    miknios

    Joined:
    Sep 12, 2017
    Posts:
    6
    Entities are mainly for optimising your memory access time, by structuring your data in linear way in arrays where same components are laid out one after another, so you can have less CPU idle times when it awaits for another cache line of data, because you can already have the data you need in cache line loaded to your CPU's cache.

    This decrease CPU times, but in practice you just make your CPU work more in less time, because of less time it has to wait for the data to be copied from RAM to CPU cache, so it can perform some operations on it.

    On top of that you have Job System which is nicely integrated into ECS systems. Maybe too nice, because at first it's not obvious what happens when you do Entities.Foreach().ScheduleParallel(). Either way it makes it easier to write safe parallel code.

    And then on top of that you have Burst Compiler which can make your Job code "magically" faster. Thanks to ECS using Job System and Burst behind it you can utilize all this power for iterating over your entities.

    It's of course possible to use Jobs and Burst for some performance heavy places with normal MonoBehaviour based game, but it often requires you to prepare the data you use in correct way. Entities makes it a bit easier, because data in IComponentData structs don't require any special preparation if you use them in Entities.ForEach().Schedule() or ScheduleParallel().
     
    mailfromthewilds likes this.
  3. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,907
    HR V1 does a better job batching draw calls than traditional GameObjects if your renderers are static. For dynamic objects, it may be more of a wash. They optimized it since I last experimented with it by adding a property cache, so it might still be a win for dynamic objects, but not by much.

    As for actual GPU performance (assuming you aren't draw-call bound), no. Entities do not help in any way unless you can write an algorithm that reduces the amount of work the GPU does. HR V1 already does frustum culling. HR V2 does occlusion culling, which you might be able to port to HR V1. HLODs are a new feature to DOTS that may be worth exploring. You can more efficiently swap meshes with imposters facing the camera, since that type of operation can now be run in Burst jobs. But you are never going to increase your polygon budget using DOTS.
     
    mailfromthewilds likes this.
  4. SebastianAaltonen

    SebastianAaltonen

    Unity Technologies

    Joined:
    Feb 21, 2020
    Posts:
    112
    HRV1 is pretty slow for dynamic objects. In your case all the pieces would be dynamic, as you can't bake them to the scene.
     
  5. mailfromthewilds

    mailfromthewilds

    Joined:
    Jan 31, 2020
    Posts:
    214
    hey man, according to this:
    DOTS Hybrid Renderer | Hybrid Renderer | 0.11.0-preview.43 (unity3d.com)

    v1 doesnt have dynamic occlussion culling, and v2 has, but thats occlussion culling, so objects behind other objects, are not rendererd.

    but in my case i see massive performance improvements when i deactivate rendermesh of entities outside the frustrum/camera view aka frustrum culling

    do you have any info about frustrum culling for dots (for both hr1 and hr2)?
    because id swear it doesnt work
     
  6. apkdev

    apkdev

    Joined:
    Dec 12, 2015
    Posts:
    261
    Has anyone had any success with the HRv2 occlusion culling? I tried and failed getting it to work a couple of times. It would be very helpful on some of the subscenes I work with (runtime performance is sometimes even worse than with purely GO-based scenes).

    It definitely works. The implementation is in HybridV2Culling.cs. You should be able to see it at work in the profiler under job workers like this:

    upload_2021-6-14_12-46-19.png

    Have you measured whether these improvements are on the CPU or the GPU side? I think dynamic entities can be pretty slow at the moment (even when outside the camera frustum), are you using the StaticOptimizeEntity component (it saves a lot of CPU time)? Hybrid components are currently pretty slow as well.
     
    Last edited: Jun 14, 2021
  7. mailfromthewilds

    mailfromthewilds

    Joined:
    Jan 31, 2020
    Posts:
    214
    so is the implenentation in V2 only?
     
  8. apkdev

    apkdev

    Joined:
    Dec 12, 2015
    Posts:
    261
    I'm fairly sure that the frustum culling is always present and enabled in all Hybrid Renderer versions. I don't think it's even possible to disable it. The Megacity demo wouldn't work without it.

    Occlusion culling is disabled by default and requires HRv2:

    #if ENABLE_UNITY_OCCLUSION && ENABLE_HYBRID_RENDERER_V2 && UNITY_2020_2_OR_NEWER && (HDRP_9_0_0_OR_NEWER || URP_9_0_0_OR_NEWER)