Append Consume Buffer

Mar 5, 2014 at 3:22 AM
Hi, I am creating a particle system using Append and consume buffers,
I am facing following problems,
When I copy the number of live particles to my indirect argument buffer, I am not getting the proper values, and i think this is messing up my DrawInstancedIndirect call( I see no particles)
Mar 6, 2014 at 1:13 AM

Are you setting the initial count on the first binding of the buffers? This initializes the hidden count in the buffer, and then you can start appending particles according to your system characteristics after that. Unfortunately if you don't manage the count correctly, you can easily underflow the counter and get out of sync very easily...

You may also find it useful to copy the count to the CPU and print it to the debug window. I have code for this in the ParticleStorm demo if you want a quick and easy way to copy the data (it has to be copied to a staging resource, then accessed on the CPU).
Mar 6, 2014 at 1:59 AM
Yes, I am initializing the indirect argument buffer, as follows
pIndirectArgsData[0] = 0;
pIndirectArgsData[1] = 1;
pIndirectArgsData[2] = 0;
pIndirectArgsData[3] = 0;

I am using a staging buffer to copy the hidden counter from the respective UAV's and I get the propervalues, but when I copy it to my Indirect argument buffer, I get erroneous value(I am checking the value using Graphics Debugging in VS2013).

I am copying the particle count as follows,
I see that the value in pIndirectArgbuffer[0] = 8, and rest of the values are junk (i.e pIndirectArgbuffer[1],pIndirectArgbuffer[2],pIndirectArgbuffer[3]).
Mar 6, 2014 at 2:07 AM
I'm not sure if the Graphics Debugger will show the contents of the buffer or not, but if the other values are not set properly then it would probably be why your draw call isn't functioning properly. To be sure, I would copy the indirect args buffer to a staging resource and access it on the CPU. This will tell you directly if the other values really are uninitialized, or if they are holding the values that you specified above.

Which of the indirect draw calls are you using?
Mar 6, 2014 at 2:36 AM
Alright, I am gonna try to read the indirect buffer to CPU and check with the values.
I am using InstancedIndirect call.
Mar 6, 2014 at 3:57 AM
I tried to write the data back to the indirect argument buffer using UpdateSubresource, and the my live particle count is proper now. But I do not get it why my copystructure count was not working earlier.

I have one more question, what should be the values in the other fields of my indirect argument buffer?
pIndirectArgsData[0] = number of live particles;
pIndirectArgsData[1] = 1;
pIndirectArgsData[2] = 0;
pIndirectArgsData[3] = 0;

are the above values correct?
Mar 6, 2014 at 10:13 AM
Edited Mar 6, 2014 at 10:15 AM
It sounds to me like your hidden counter in the UAV is not correct. Can you show the code for when you bind the UAV to the pipeline the first time, and then for each consecutive time after that?

The arguments are essentially the same as for DrawInstanced if you are using DrawInstancedIndirect. So for example, if you are only drawing the set of particles once, then I would assume the following contents for your arguments buffer: [8,1,0,0]. It looks like this is how you are already interpreting it.

To debug this whole pipeline setup, I would follow these steps:
  1. Statically initialize your particle buffer with 8 points of data.
  2. When you bind your UAV for this buffer, be sure to set the initial count to 8 (this has to be done at least once before use!).
  3. Statically initialize your argument buffer as you described above.
  4. Bind the particle buffer as an SRV and use the data to generate vertices (see Particle Storm for an example how to do this).
  5. Execute the indirect draw call.
Once you get this working, then you can start adding in the dynamic adding and removing of particles. Once again, I recommend that during your debugging phase to often copy the structure count to a staging buffer, then read it back to CPU and print the result - this will help you tremendously in debugging!

Also, are you running the graphics debugger on Windows 8 on a Store app or is it for a desktop app? This is more out of curiosity than anything else...
Mar 6, 2014 at 7:37 PM
//Inserting Particles
    m_pEffectConsumeUAVI = m_pCSInsert->GetVariableByName("PrevSimulationState")->AsUnorderedAccessView();
// Updating Particles
    m_pEffectConsumeUAVU = m_pCSUpdate->GetVariableByName("PrevSimulationState")->AsUnorderedAccessView();

    m_pEffectAppendUAVU = m_pCSUpdate->GetVariableByName("NewSimulationState")->AsUnorderedAccessView();
//Copying the Structure count to staging buffer
    pDeviceContext->CopyStructureCount(staging, 4 * temp++, m_pConsumeUAV);
    pDeviceContext->CopyStructureCount(staging, 4 * temp++, m_pAppendUAV);
I am copying the structure count after before and after each dispatch call.
I am printing the values to the console, and my particle count looks fine. But when I copy the structure count to my Indirect Argument buffer its going wrong, but it works fine when i use UpdateSubresource data.

I am using Graphics Debugger from VS2013.
Mar 7, 2014 at 11:48 AM
Hmmm. I can't immediately think of anything else to consider... Have you enabled the debug device to see if you get any error messages in the debug window? Can you also show the code for creating your append/consume buffer and its UAVs, and also the creation options used for creating your indirect arguments buffer - including the size?

Do you see the correct location changing in the arguments buffer? For example, when you do the CopyStructureCount call, is it only overwriting the desired 32-bit location within the buffer?