Graphics Reference
In-Depth Information
particleUAVs.Add(ToDispose(CreateBufferUAV(device,
particleBuffers[1],
UnorderedAccessViewBufferFlags.Append )));
particleSRVs.Add(ToDispose(new
ShaderResourceView(device, particleBuffers[0])));
particleSRVs.Add( ...particleBuffers[1]... );
// Set the starting number of particles to 0
context.ComputeShader.SetUnorderedAccessView(0,
particleUAVs[0], 0);
context.ComputeShader.SetUnorderedAccessView(1,
particleUAVs[1], 0);
17. And finally, we will create a buffer that will store the current consume buffer's
particle count for input into the DeviceContext.DrawInstancedIndirect
function within the render loop.
// Create particle count buffers:
var bufDesc = new BufferDescription {
BindFlags = SharpDX.Direct3D11.BindFlags.ConstantBuffer,
SizeInBytes = 4 * SharpDX.Utilities.SizeOf<uint>(),
StructureByteStride = 0,
Usage = ResourceUsage.Default,
CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None,
};
// Used as input to the context.DrawInstancedIndirect
// The 4 elements represent the 4 parameters
bufDesc.OptionFlags =
ResourceOptionFlags.DrawIndirectArguments;
bufDesc.BindFlags = BindFlags.None;
indirectArgsBuffer = ToDispose(new Buffer(device,
bufDesc));
// 4 vertices per instance (i.e. quad)
device.ImmediateContext.UpdateSubresource(new uint[4] { 4,
0, 0, 0 }, particleCountIABuffer);
With all our resources initialized, we will now work on the compute shader's
update stage.
18. Then, we will create a new method named ParticleRenderer.Update ,
as shown here:
float genTime = 0f; // time since Generator last run
public void Update(string generatorCS, string updaterCS)
{
var append = particleUAVs[0];
 
Search WWH ::




Custom Search