Search Unity

Resolved Unmanaged Compute Buffer Variant

Discussion in 'DOTS Dev Blitz Day 2022 - Q&A' started by Kmsxkuse, Dec 8, 2022.

  1. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    306
    Has there been any work done to create a structure based compute buffer that can be located on a component data? From what I can see, compute buffers are just an pointer and atomic safety handle, much like a native array.

    Compute Buffers in managed class based components seems to be breaking the stable type hash between editor and runtime so an unmanaged variant is necessary.
     
  2. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    Both ComputeBuffer and GraphicsBuffer (which is a superset of ComputeBuffer) are managed classes and contain APIs that take other managed classes, so a complete unmanaged replacement is not possible.

    It might be possible to make a limited (i.e. only some buffer APIs supported) unmanaged version, but as far as I know this is not currently planned.

    What I would currently recommend is to place the managed objects (e.g. GraphicsBuffers) in an array, and then put an integer array index to that array inside a component (which can also be an unmanaged IComponentData in this case, unless there are other managed things in the component).
     
    Kmsxkuse likes this.
  3. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    306
    That's what I'm doing now except with a dictionary with entity as key.

    Ugh, guess I'll just keep this temporary solution as a more permanent fixture.
     
  4. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    If you haven't done so already, I would definitely recommend filing a bug about buffer classes breaking the stable type hash, as this seems like a legitimate use case to me.
     
    Kmsxkuse likes this.
  5. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    306
    Definitely. I just been lazy because I don't want to open a new project and sit through reimporting.
     
  6. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    306
    Alright, i stopped being lazy and slapped together a simple reproducable:

    IN-25314
     
    JussiKnuuttila likes this.