Search Unity

Question Unity.Rendering.EntitiesGraphicsSystem is slow

Discussion in 'Graphics for ECS' started by CreationRoom, Sep 8, 2023.

  1. CreationRoom


    Jun 23, 2019
    Hi devs,

    I've made a simple project with :
    - one manager GameObject storing an Entity field and an int field
    - a cube prefab
    - a system responsible for instancing the cube entity
    - a system responsible of the rotation of the cube

    Buildt in an URP 14.0.8 environment with entities and entities graphics 1.0.14.

    The rotation system is a simple ISystem only scheduling one job in parallel.
    The job have only an Execute function with a ref LocalTransform parameter.
    The rotation use the LocalTransform.RotateY method.
    That's all for the context.

    Here is the problematic : when the rotation system is working, the Unity.Rendering.EntitiesGraphicsSystem spent 7ms on the GPU instead of 1ms when disabled. To be more precise, it happen when I use the ref LocalTransform parameter in the execute method from the rotation job.


    Has a consequence, the profiler record a 3ms Gfx.WaitForPresentOnGfxThread on the main thread for each frame


    With rotation system disabled :


    Is it a normal behaviour from the Unity.Rendering.EntitiesGraphicsSystem ?

    Attached Files:

  2. JussiKnuuttila


    Unity Technologies

    Jun 7, 2019
    How many cubes do you have?

    It is expected that if you modify the transform (or any other [MaterialProperty] component), Entities Graphics will run a compute shader to update that data on the GPU.

    However, that should normally not take anywhere near 7 ms, unless you have an extremely large amount of Entities that you are modifying.
  3. CreationRoom


    Jun 23, 2019
    I spawn only one cube (primitive shape, default material), a prefab instantiated with CubeManager settings.

    the scene project :

    the GPU Usage (constant value) :

    Here is the rotation system and job implementation :
    Code (CSharp):
    1.     public partial struct CubeRotationSystem : ISystem
    2.     {
    3.         [BurstCompile]
    4.         public void OnCreate(ref SystemState state)
    5.         {
    6.             state.RequireForUpdate<Cube>();
    7.             state.RequireForUpdate<ExecuteCubeRotation>();
    8.         }
    10.         [BurstCompile]
    11.         public void OnUpdate(ref SystemState state)
    12.         {
    13.             new CubeRotationJob { }.ScheduleParallel();
    14.         }
    15.     }
    17.     [BurstCompile]
    18.     public partial struct CubeRotationJob : IJobEntity
    19.     {
    20.         public void Execute(in Cube cube, ref LocalTransform transform)
    21.         {
    22.             transform = transform.RotateY(math.radians(cube.RotationSpeed));
    23.         }
    24.     }
    as reminder :

    - Unity 2023.1.12f1
    - URP 15.0.6
    - Entities graphics 1.0.14

    I tested the exact same project on another pc (way more performant) and I get the same issue/result.
    this issue seems the same as the one describe on this thread :

    thank you for having paying attention to my problem
  4. JussiKnuuttila


    Unity Technologies

    Jun 7, 2019
    If there is only a single cube, then 7 ms is definitely way higher than expected. Would it be possible for you to submit a bug report with a repro project?

    Something else you could try is to take a GPU capture of a player build of your scene, using a tool which is capable of doing GPU profiling, such as:
    - Nvidia Nsight (Nvidia GPUs only)
    - AMD Radeon GPU Profiler (AMD GPUs only)
    - Microsoft PIX (D3D12 only)

    This kind of tool will show you what exactly is taking so much time, and can offer insight into why that is happening.