[Unity]ComputeBuffer转NativeArray异步
using System;
using Unity.Collections;
using UnityEngine;
using UnityEngine.Rendering;
public static class IComputeBufferExtensions
{
public static void GetNativeArrayAsync<T>(this ComputeBuffer buffer, int length, Allocator allocator, Action<AsyncGPUReadbackRequest> callback) where T : struct
{
NativeArray<T> arr = new NativeArray<T>(length, allocator);
AsyncGPUReadback.RequestIntoNativeArray(ref arr, buffer, callback);
}
public static void GetNativeArrayAsync<T>(this ComputeBuffer buffer, ref NativeArray<T> arr, Action<AsyncGPUReadbackRequest> callback) where T : struct
{
AsyncGPUReadback.RequestIntoNativeArray(ref arr, buffer, callback);
}
public static void GetNativeArrayAsync<T>(this Texture texture, int length, Allocator allocator, Action<AsyncGPUReadbackRequest> callback) where T : struct
{
NativeArray<T> arr = new NativeArray<T>(length, allocator);
AsyncGPUReadback.RequestIntoNativeArray(ref arr, texture, 0, callback);
}
public static void GetNativeArrayAsync<T>(this Texture texture, ref NativeArray<T> arr, Action<AsyncGPUReadbackRequest> callback) where T : struct
{
AsyncGPUReadback.RequestIntoNativeArray(ref arr, texture, 0, callback);
}
}