Last active
April 22, 2022 03:56
-
-
Save supertask/6110dec92354b4b4c67e55476cb3db38 to your computer and use it in GitHub Desktop.
Debug compute buffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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