I’ll try again… anyone have any thoughts? I’ve explored this chain quite thoroughly, but googling hasn’t given me much information, besides some vague thoughts on C code that would reset it through methods I’m not quite clear on.
I noticed that append buffer work as expected when using Graphics.Blit(), but not when using DrawProcedural(). The counter would simply not reset for some reason. Therefore I had the idea to perform a “dummy” blit in order to force the append buffer to reset the counter, and it worked.
I made an extension so that the buffer can be cleared easily.
public static class MyExtensions
{
public static void ClearAppendBuffer(this ComputeBuffer appendBuffer)
{
// This resets the append buffer buffer to 0
var dummy1 = RenderTexture.GetTemporary(8, 8, 24, RenderTextureFormat.ARGB32);
var dummy2 = RenderTexture.GetTemporary(8, 8, 24, RenderTextureFormat.ARGB32);
var active = RenderTexture.active;
Graphics.SetRandomWriteTarget(1, appendBuffer);
Graphics.Blit(dummy1, dummy2);
Graphics.ClearRandomWriteTargets();
RenderTexture.active = active;
dummy1.Release();
dummy2.Release();
}
}
Then do something like this:
var appendBuffer = new ComputeBuffer(1000, sizeof(float) * 3, ComputeBufferType.Append);
appendBuffer.ClearAppendBuffer();
Strangely the dummy blit also solves other issues. I managed to make a texture work with Graphics.SetRandomWriteTarget() by doing a dummy blit afterwards, and it made my stuffs work all smoothly.
Keep in mind that the buffer must also be cleared before its first use in the application, because the count may sometimes be initialized to a random value which can crash the GPU driver