Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Competing command buffers?

Discussion in 'Data Oriented Technology Stack' started by thelebaron, Jan 10, 2019.

  1. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    243
    Do command buffers compete with each other in the sense of if you have one system+barrier applying a command, and then another system+barrier applying another command to the same component, will one override the other or do they both get applied in order of system update?

    For reference I'm asking as I have an issue with a system where a command buffer doesnt appear to do anything, if I uncomment the code and ignore the commandbuffer job and update the ComponentDataArray separately it works.

    full code https://hastebin.com/uhayijodav.cs with snippets of the job and what works but doesnt get jobified below.

    Code (CSharp):
    1.         private struct CommandBufferJob : IJob
    2.         {
    3.             [ReadOnly] public EntityCommandBuffer commandBuffer;
    4.             [ReadOnly] public EntityArray seeker_entity;
    5.             [ReadOnly] public ComponentDataArray<Target> target_buffer;
    6.            
    7.             public void Execute()
    8.             {
    9.                 for (int i = 0; i < seeker_entity.Length; i++)
    10.                 {
    11.                     var entity = target_buffer[i].entity;
    12.                     if (target_buffer[i].health <= 0)
    13.                         entity = Entity.Null;
    14.                    
    15.                    
    16.                     commandBuffer.SetComponent(seeker_entity[i], new Target
    17.                     {
    18.                         entity = entity,
    19.                         position = target_buffer[i].position,
    20.                         health = target_buffer[i].health,
    21.                         canSee = target_buffer[i].canSee,
    22.                         blockedSightTime = target_buffer[i].blockedSightTime,
    23.                         raycastTimer = target_buffer[i].raycastTimer
    24.                     });
    25.                 }
    26.             }
    27.         }
    Code (CSharp):
    1.  
    2.             for (int i = 0; i < seeker_entity.Length; i++)
    3.             {
    4.                 var entity = seeker_target_buffer[i].entity;
    5.                 if (seeker_target_buffer[i].health <= 0)
    6.                     entity = Entity.Null;
    7.  
    8.                 var targ = new Target
    9.                 {
    10.                     entity = entity,
    11.                     position = seeker_target_buffer[i].position,
    12.                     health = seeker_target_buffer[i].health,
    13.                     canSee = seeker_target_buffer[i].canSee,
    14.                     blockedSightTime = seeker_target_buffer[i].blockedSightTime,
    15.                     raycastTimer = seeker_target_buffer[i].raycastTimer
    16.                 };
    17.                 seeker_target[i] = targ;
    18.  
    19.  
    20.             }
     
  2. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,181
    They are applied in the order of barrier update if your 2 barriers are not the same.

    If your have 1 barrier but commands from 2 systems applying to the same component, they are ordered by the order of `barrier.CreateCommandBuffer` call. Each ECB created gets a playback order from that.
     
  3. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    243
    Thanks, does PostUpdateCommands work in the same way then?
     
  4. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,181
    PostUpdateCommands is already an ECB, you cannot create more of it. Multiple access to PostUpdateCommands at a different time during Update goes to the same ECB. There is no barrier, this ECB Playback at the end of Update like the name says. Then the only ordering you have is the command queueing order. No CreateCommandBuffer or Barrier order.