ComputeShader: Unable to read append buffer count on NV gpus

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.

I may be having a similar problem on my Nvidia PC, I’m running a GTX 560Ti and have been following this example on Scrawks blog:

http://scrawkblog.com/2014/08/14/directcompute-tutorial-for-unity-append-buffers/

and find that the args buffer doesn’t change when calling CopyCount. I’ll try it on an AMD GPU soon when I can get my hands on one.

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.

From my experience there does seem to be something buggy with append buffers but what exactly has been hard to pin down.

I did find that appending more elements than the buffers size causes the driver to crash or behave erratic but thats not too much of a surprise.

Looks like the CopyCount function maybe have issues but whether this is a bug with Unity or the GPU driver is unclear.

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!

not sure if you can look at this link but give it a try, it’s the bug report I made
http://fogbugz.unity3d.com/default.asp?626315_56383at5hm4mdohj

That’s great! nice job.

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).

My bug is still Open, so I don’t think it’s been fixed yet :\

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.

Ah sweet. I submitted a bug about resetting the count on counter buffers.

I wonder if its related to that.

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.