AsyncGPUReadback.GetData with computeBufferType.Append
Hello here :)
I'm working on a procedural terrain generator base on the transvoxel algorithm. For generating chunks on my terrain, I implemented a compute shader which computes triangles of the chunk mesh with the marching cube algorithm.
I want to use AsyncGPUReadback to get data from the GPU back to the CPU for rendering. Without the async method I use the ComputeBuffer.CopyCount method to get the number of triangles in my buffer and then get the data with triangleBuffer.GetData :
 // Create my triangle buffer
 ComputeBuffer triangleBuffer = new ComputeBuffer(maxTriangleCount, sizeof (float) * 3 * 3, ComputeBufferType.Append);
 
 // Send data to the compute shader
 
 // Get triangle count
 ComputeBuffer triCountBuffer = new ComputeBuffer (1, sizeof (int), ComputeBufferType.Raw);
 ComputeBuffer.CopyCount(triangleBuffer, triCountBuffer, 0);
 int[] triCountArray = { 0 };
 triCountBuffer.GetData(triCountArray);
 int numTris = triCountArray[0];
 
 // Get triangle data from shader
 Triangle[] tris = new Triangle[numTris];
 triangleBuffer.GetData(tris, 0, 0, numTris);
 
               This allow me to only get the data I want from the GPU since it's impossible for me to know how many triangles the algorithm will create.
With AsyncGPUReadback I don't know how to do this since the only method that I see to get the data is
 if (request.hasError) {
       return;
  }
 
 if (request.done) {
        // Get triangle data from shader
       NativeArray<Triangle> triangles = request.GetData<Triangle>();
   
       // Generate the mesh
 
 }
 
               Someone know how to manage this ?
Nathan
Your answer