I’m using the following code to extract the count of an append buffer:
using (var countBuffer = new ComputeBuffer (1, 16, ComputeBufferType.DrawIndirect)) {
ComputeBuffer.CopyCount (buffer, countBuffer, 0);
var count = new int[4];
countBuffer.GetData (count);
return count [0];
}
This works fine on AMD, but on the NV gpus we have available (4xx series), It just writes out something like 0x42C5E4F8 in place of the count. The actual value written doesn’t change whether I force it to output one element, or zero.
There isn’t a lot of documentation or internet wisdom about CopyStructureCount, but it seems like what I’m doing should be acceptable, and I don’t get any warnings in the output from PIX or the NV debugging tools.
Just tried it on AMD laptop GPU and the example worked, so there does seems to be an issue with Nvidia GPU’s and AppendBuffers in 4.5 (tried 4.5.3 on Nvidia PC and 4.5.1p1 on AMD)
EDIT
Tried on another Nvidia PC (with a GTX 680) and it worked, though this was using Unity Pro, the above was using Unity Free.
I submitted a bug report and the testers at unity have managed to reproduce it on some Nvidia GPU’s so it seems to be GPU specific, lets hope theres a bug fix for it soon!
Hey, anything new about this?. Doesnt look like this bug was fixed. CopyCount works on my NV GTX 760, nevertheless are the appendbuffers buggy (only works correct on AMD).
According to your bug it has now been fixed for Unity 5.4, and it only took Unity 17 months to do so!
If you are a Pro user you can test with the latest Unity 5.4b12 release. It might also be worth checking through the release notes as it appears a few other issues were finally addressed in different betas. For example in b12 there is now a compute.SetCounterValue() function to reset the append/consume buffer counter.
Hey Scrawk, been using your excellent blog as a reference for compute stuff.
Yeah I tested this yesterday with an appendBuffer shader i’d been developing and the SetCountervalue() does allow you to reset the counter, so sequential dispatches of the shader no longer fill up or overrun the buffer when not using a consumeBuffer.
Just kind of amazed its taken Unity almost two years to address these issues.