Skip to content

Instantly share code, notes, and snippets.

@supertask
Last active April 22, 2022 03:56
Show Gist options
  • Save supertask/6110dec92354b4b4c67e55476cb3db38 to your computer and use it in GitHub Desktop.
Save supertask/6110dec92354b4b4c67e55476cb3db38 to your computer and use it in GitHub Desktop.
Debug compute buffer
//
// Debug Compute Buffer
// When you define a struct/class,
// please use override ToString(), public override string ToString() => $"MpmParticle(position={position}, velocity={velocity})";
//
// debugging range is startIndex <= x < endIndex
// example:
// Util.PrintBuffer<uint2>(this.particlesBuffer, 1024, 1027);
//
public static void PrintBuffer<T>(ComputeBuffer buffer, int startIndex, int endIndex) where T : struct
{
int N = endIndex - startIndex;
T[] array = new T[N];
buffer.GetData(array, 0, startIndex, N);
for (int i = 0; i < N; i++)
{
Debug.LogFormat("index={0}: {1}", startIndex + i, array[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment