Search Unity

AddJobHandleForProducer Question

Discussion in 'Entity Component System' started by RoughSpaghetti3211, Aug 29, 2019.

  1. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,709
    Can someone please explain to me when this is needed and what it actually does?

    From the doc I take it the AddJobHandleForProducer add some sort of dependance between the cmdBuffer and the job. Is this because each sys only has one cmdBuffer and it need to know when to playback the instructions for a particular job on that system? I just need someone to break this down a bit further for me

    https://docs.unity3d.com/Packages/c...Unity.Entities.EntityCommandBufferSystem.html
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Any time you pass a command buffer to a system you need to return the job handle to that the system that owns the command buffer (you can simply this and just pass the final jobhandle at end of system.)

    This is required to ensure the jobs using the command buffer are complete before the barrier system runs.
     
    deus0 likes this.
  3. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,709
    So the cmdBuffer always runs at the end of the system, not between jobs in that system?

    Also can you explain what you mean by barrier system since funnily enough im attempting to write one atm. The though was before I run my system that construct my procedural mesh i need to make sure all the systems gathering data is done and synced. I was under the impression I could do some cleanup and call inputDeps.Complete();

    Code (csharp):
    1.  
    2.     /// <summary>
    3.     /// Barries sync point for HexSphereBuild systems.
    4.     /// </summary>
    5.     //[UpdateAfter(typeof(HexSphereECSVisualizerSystem))]
    6.     [UpdateAfter(typeof(HexSphereBuildEntitiesSystem))]
    7.     public class HexSphereBuildBarrierSystem : JobComponentSystem
    8.     {
    9.  
    10.         #region FLIELDS --------------------------------------------------------
    11.  
    12.         [ReadOnly] private EntityQuery eqVertexComp;
    13.         [ReadOnly] private EntityQuery eqTriangleComp;
    14.  
    15.         #endregion
    16.  
    17.         #region METHODS --------------------------------------------------------
    18.  
    19.         /// <summary>
    20.         /// Constructor for system.
    21.         /// </summary>
    22.         protected override void OnCreate()
    23.         {
    24.             base.OnCreate();
    25.  
    26.             //
    27.             // Create Entity EntityQuery
    28.             eqVertexComp = EntityManager.CreateEntityQuery(ComponentType.ReadOnly<VertexComponent>());
    29.             eqTriangleComp = EntityManager.CreateEntityQuery(ComponentType.ReadOnly<TriangleComponent>());
    30.  
    31.         }
    32.  
    33.         #endregion
    34.  
    35.         #region MAIN THREAD ------------------------------------------------------
    36.  
    37.         protected override JobHandle OnUpdate(JobHandle inputDeps)
    38.         {
    39.             //
    40.             // Remove hex vertex and triangle components so the system doen not run jobs
    41.             EntityManager.RemoveComponent(eqVertexComp, typeof(VertexComponent));
    42.             EntityManager.RemoveComponent(eqTriangleComp, typeof(TriangleComponent));
    43.  
    44.             //
    45.             // Complete
    46.             inputDeps.Complete();
    47.  
    48.             //
    49.             // Cleanup
    50.             eqVertexComp.Dispose();
    51.             eqTriangleComp.Dispose();
    52.  
    53.             //
    54.             // Return
    55.             return inputDeps;
    56.         }
    57.  
    58.         #endregion
    59.  
     
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    No. It runs at the barrier system order, or when you call playback, not at the end of the system, at the end of the system you put dependencies by AJHFP, not more and not less. Buffer execution order depends on barrier place.
     
  5. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,709
    ok kind of getting it, so would any JobComponentSystem that inputDeps.Complete() be considered a barrier system. I think ive been too wild west shooting from the hip kinda stuff with Complete()