Search Unity

Compute shader, append type issues (not always returning buffer)

Discussion in 'Shaders' started by harvz16, Feb 1, 2014.

  1. harvz16

    harvz16

    Joined:
    Dec 10, 2012
    Posts:
    12
    Hello,

    Lately I've been experimenting with using the compute shader to do procedural generation. Originally I was using the default type to return the results (textures or geometry) to the CPU which would work fine for the most part but when it came to geometry, I would have to do some cleaning before setting it as the mesh.

    When I went on to the append type, the results don't always seem to be returned when I call GetData(), sometimes Ill run it and it works perfectly (I'm using 2 append buffers, one for vertices and another to keep track of the number of verts being returned) so the mesh is created and other times they'll return all 0's, no error from the function itself, just when it attempts to apply it to the mesh.

    sample of how i'm using the buffer in the .compute
    Code (csharp):
    1. AppendStructuredBuffer<float3> verts1 : register(u0);
    2. AppendStructuredBuffer<int> count : register(u1);
    3. ...
    4. count.Append(c);
    and the .cs
    Code (csharp):
    1. verts1 = new ComputeBuffer(chunkSize[0] * chunkSize[1] * chunkSize[2], 12 * 15, ComputeBufferType.Append);
    2. cs.SetBuffer(k[kernels.CSMarch], "verts1", verts1);
    3. count = new ComputeBuffer(chunkSize[0] * chunkSize[1] * chunkSize[2], 4, ComputeBufferType.Append);
    4. cs.SetBuffer(k[kernels.CSMarch], "count", count);
    5. ...
    6. int[] c = new int[chunkSize[0] * chunkSize[1] * chunkSize[2]];
    7. count.GetData(c);
    If anyone has any idea what this may be caused by or a solution, any help would be greatly appreciated.
     
  2. mysteryDate

    mysteryDate

    Joined:
    Feb 2, 2015
    Posts:
    11
    Same problem here. 75% of the time I get what's expected (an append buffer count of 2). The rest of the time my count is either 10,002 or 0. It's totally erratic.
     
  3. sirshelley

    sirshelley

    Joined:
    Aug 14, 2014
    Posts:
    26
    Yup same here.
    I'm switching down to direct again :l