Search Unity

Collections of collections and Burst

Discussion in 'Data Oriented Technology Stack' started by Imakhiil, Dec 20, 2018.

  1. Imakhiil

    Imakhiil

    Joined:
    Oct 11, 2013
    Posts:
    34
    Is there any way to create collections of native collections and use them with Burst? For example, NativeArray<NativeArray<T>> won't compile since NativeArray<T> is not blittable and NativeArray<T>[] is a reference type.
    Is there support for this at all or should we resort to passing an array of pointers instead?
     
    Last edited: Dec 20, 2018
  2. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    591
    Look up forum posts here for DynamicBuffer<T> that can have a list elements on entities, or if your looking at a grid shape (IE, 4x4,16x16, etc), you can do your own math to map a 2d index to a 1D grid and back.
     
  3. Imakhiil

    Imakhiil

    Joined:
    Oct 11, 2013
    Posts:
    34
    Yeah, the thing is, this data is not on entities and I would like to avoid using them here.
    Using simple maths to go between 2 and 1 dimensional indices doesn't really work all that well once you start using collections different than fixed sized arrays (list of queues, array of lists, etc). It's also not the most efficient when you need a jagged array
     
  4. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    591
    I've made a post about creating jagged arrays as it seems the Native collection questions have become popular again:
    https://forum.unity.com/threads/collections-in-components.601009/#post-4019137

    That being said, it may be possible to pass an NativeArray array of struct-wrapped Pointers to other NativeArrays / containers if you're willing to ensure they're stable/ReadOnly and turn of certain safety checks. I don't know if this will get you the perf gains you're looking for since burst works best with blocks of linear data.

    It may be better manage your lists of structures only on the main thread and schedule individual jobs to deal with each sub-structure if/where processing doesn't have overlapping access (if you don't need to write to two containers at the same time).
     
  5. Razmot

    Razmot

    Joined:
    Apr 27, 2013
    Posts:
    262