Search Unity

MeshInstance render system interaction

Discussion in 'Graphics for ECS' started by snacktime, Aug 24, 2018.

  1. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    It's apparent a lot of work went into this. Kind of surprising there is just a one liner comment.

    Is it even possible to update position/rotation/scale?

    Also curious why so many of these systems don't use injection? Kind of begs the question what's so wrong with injection that Unity doesn't use it for their own stuff so often. I'm guessing it's also why most of these systems don't show in the entity debugger correctly?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    In Preview 10 they show up in the debugger.

    Generally speaking we are finding that
    a) ComponentDataArray is not a great abstraction for performance and boilerplaty
    b) Injection is confusing

    Instead we generally use
    1) IJobProcessComponentData
    2) ArchetypeChunk API

    Both are performant and 1) is significantly less code. Eventually we think a lambda based approach to replace IJobProcessComponentData would make it really kick ass and significantly simplify. But this requires codegen work we haven't done yet.
     
    Last edited: Aug 24, 2018
    recursive, optimise and Life_Is_Good_ like this.
  3. Fido789

    Fido789

    Joined:
    Feb 26, 2013
    Posts:
    343
    Could you please be more specific about what is means? Are these obsolete? Will they be removed?
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    It means when we write code we are not using them, when we have a better solution that we are actually happy with we might look at deprecating.
     
  5. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    IJobProcessComponentData would be perfect if it could somehow pass an entityarray as well. Also some versions with 4+ generics.

    I could use it for 90% of my systems if those were implemented. It could reduce so much code.
     
  6. Fido789

    Fido789

    Joined:
    Feb 26, 2013
    Posts:
    343
    And DynamicBuffer. They all should share some common interface for this purpose I would say.
     
  7. Gen_Scorpius

    Gen_Scorpius

    Joined:
    Nov 2, 2016
    Posts:
    65
    Would be nice if there was a nice and tidy documentation page explaining the recommended way to implement these kind of performant ECS systems. The source code examples differ quite a bit and it's not easy to decipher what is currently the "best" way, especially if you are still learning ECS design patterns.

    Also I think that a documentation page is easier to keep up to date than the plethora of code examples from the ECS samples repository.
     
  8. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Code (CSharp):
    1.         struct Process4Entity  : IJobProcessComponentDataWithEntity<EcsTestData, EcsTestData2, EcsTestData3, EcsTestData4>
    2.         {
    3.             public void Execute(Entity entity, int index, [ReadOnly]ref EcsTestData src, ref EcsTestData2 dst1, ref EcsTestData3 dst2, ref EcsTestData4 dst3)
    4.             {
    5.                 dst1.value1 = dst2.value2 = dst3.value3 = src.value + index + entity.Index;
    6.             }
    7.         }
    I just added IJobProcessComponentDataWithEntity and 4 component overloads. Will be in next release.
     
    tertle and Deleted User like this.
  9. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203

    It creates too many combinations. Our plan is to solve this via lambda functions in the future. That will significantly reduce the amount of typing and simplicity of working with jobs. For now IJobProcessComponentDataWithEntity & IJobProcessComponentData covers the majority of cases...
     
  10. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    From what I know, lambda will give you performance penalty. Or your solution is try to map lambda to the generated code so the final compiled code is based on generated code instead of lambda?
     
  11. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Fortunately we own the compiler. So we can make it generate the perfect code for the use cases in system code. You can expect us to only enable it when it fits into our "Performance by default" principle.

    But as you would expect this is a lot of work to get this right. We will do it, we just aren't there yet.
     
    optimise and Gen_Scorpius like this.
  12. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    @Joachim_Ante - I was already wondering if some kind of lambda -> codegen would be in the works, since it seems like the obvious solution to a lot of problems and enables things like functional composition.

    Are there any good examples of using the ArchetypeChunk API? I know there's code in TransformSystem with the new preview packages but it's extremely verbose, I've used it a little in unit tests, but I'm wondering if there's anything comprehensive that's short and to-the-point.
     
  13. Fido789

    Fido789

    Joined:
    Feb 26, 2013
    Posts:
    343
    Maybe this could help.
     
  14. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    I like the query approach I think it's a much more natural and direct approach. If you look at generic ECS systems, the system is basically this awkward abstraction that tightly couples queries and the rest of the logic flow. Once you decouple those, IMO it almost immediately leads to better abstractions for querying/updating data.
     
  15. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    Perfect, thanks! I haven't had time to check the docs at work today.
     
  16. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    To my first question, I figured out CustomLocalToWorld does what I needed. Naming seems rather awkward atm, not a very intuitive system so without some documentation it's not actually obvious I'm even doing the right thing.
     
  17. Gen_Scorpius

    Gen_Scorpius

    Joined:
    Nov 2, 2016
    Posts:
    65
    I do like the new ArchetypeChunk api. It takes a bit of time to understand the new structure but overall it is more transparent compared to the injection system.

    Is there a way to access classic parts like game objects or transforms with this api? Or is it still necessary to use injection for these interactions?
     
  18. Deleted User

    Deleted User

    Guest

    Can you add IJobProcessComponentDataWithTransform? I develop 2d game with sprites, so i have to use hybrid ecs. A lot of my systems use Transform component, like this:

    Code (CSharp):
    1. struct MarkForRemoveJob : IJobParallelForTransform
    2.  {
    3.         [ReadOnly]
    4.         public float ViewLeftBorder;
    5.         [ReadOnly]
    6.         public ComponentDataArray<DeleteOffset> DeleteBound;
    7.         public ComponentDataArray<ItemState> State;
    8.  
    9.  
    10.         public void Execute(int index, TransformAccess transform)
    11.         {
    12.             bool outOfView = transform.position.x + DeleteBound[index].ItemWidth < ViewLeftBorder;
    13.             if (outOfView) State[index] = new ItemState { State = ItemState.RequiredRemove };
    14.         }
    15.  }
    So, jobs with transform component will be perfect for me:
    Code (CSharp):
    1. struct MarkForRemoveTransformJob : IJobProcessComponentData<TransformAccess, DeleteOffset, ItemState>
    2.  {
    3.         public void Execute([ReadOnly] ref TransformAccess transform, [ReadOnly] ref DeleteOffset deleteOffset, [WriteOnly] ref ItemState state) {.....}
    4.  }
    But i cant use TransformAccess as generic parameter in IJobProcessComponentData.