Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

There is no overload for method 'Graphics.DrawMeshInstanced' that takes NativeArray<Matrix4x4>

Discussion in '2018.3 Beta' started by pcysl5edgo, Sep 15, 2018.

  1. pcysl5edgo

    pcysl5edgo

    Joined:
    Jun 3, 2018
    Posts:
    65
    If the overload existed, there shouldn't be any unnecessary allocations and I could write programs as below.

    unsafe
    {
    using(var renderMatrices = new NativeArray<Matrix4x4>(114514, Allocator.Temp))
    {
    InitializeArray(renderMatrices);
    var renderMatrixPtr = (Matrix4x4*)NativeArrayUnsafeUtility.GetUnsafeReadOnlyPtr(renderMatrices);
    for(int consumed = 0; consumed != renderMatrices.Length;)
    {
    int tryToConsume = Math.Min(1023, renderMatrices.Length - consumed);
    var tryToConsumeArray = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray((void*)(renderMatrixPtr + consumed), tryToConsume, Allocator.None);
    #if ENABLE_UNITY_COLLECTIONS_CHECKS
    NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref tryToConsumeArray, AtomicSafetyHandle.GetTempUnsafePtrSliceHandle());
    #endif
    Graphics.DrawMeshInstanced(mesh, subMeshIndex, material, tryToConsumeArray, properties, castShadows, receiveShadows, layer, camera, lightProbeUsag, lightProbeProxyVolume);
    consumed += tryToConsume;
    }
    }
    }


    There is no allocation.
    I hope the Unity Team to implement this overload as soon as possible.
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Hi, this will be coming (maybe not for 18.3), but it's on our roadmap.
     
  3. pcysl5edgo

    pcysl5edgo

    Joined:
    Jun 3, 2018
    Posts:
    65
    Thank you for replying.
    I am very happy to hear what you said.
     
  4. Arathorn_J

    Arathorn_J

    Joined:
    Jan 13, 2018
    Posts:
    51
    Is it possible Graphics.DrawMeshInstanced would also be available to call from inside a job in the future?