Graphics Reference
In-Depth Information
In this listing, we see the particle structure defined as a position, velocity, and a scalar
time value. The particle structure is then used to declare the append and consume buffers.
Next is the declaration of the constant buffers that are used, which consist of the simulation
parameters and the number of particles will be stored in the PanticleCount buffer. After
these resources are specified, we declare the thread group size of [512,1,1], which means
that our granularity for instantiating threads is in 512-thread increments. In the body of the
shader, we determine the global dispatch thread ID of the current thread by flattening the
3D dispatch thread ID. It is then compared to the number of particles in the consume buffer,
which was copied into the constant buffer with the CopyStructureCount method.
This arrangement has some additional benefits besides the unordered access optimi-
zations. Since the append and consume buffers manage the counting of the total number of
elements that are present in the buffers, we can customize our processing to consider only
those buffer elements that are currently active. This decreases the application's sensitivity
to knowing how many particles are in existence, as long as the maximum number of ele-
ments is not exceeded. With this type of processing, we effectively decouple the CPU from
the GPU for this processing action and allow the GPU to perform as quickly as it is capable
of, without requiring synchronization with the CPU.
Particle Creation
Now that we know how we will store our particles, and how we will approach them from a
threading perspective, we can begin looking into how to add particles into the simulation.
There are two different methods used in this sample. The first possibility is that we can
initialize the system with a particular number of particles at startup. The second possibility
is to add particles into the simulation during runtime. We will look deeper into these two
options in the following sections.
System initialization. When we begin the simulation, we have the option to begin with a
given number of particles from the very first simulation step. This can be accomplished in
two steps. First we must initialize the contents of the structured buffers to hold our desired
data. As we have seen in Chapter 2, we can provide an initial set of data for a resource in its
creation function. For use in a particle system, this would entail filling in the initial data with
an array of particles. If we don't want to initialize the entire contents of the particle system,
we must still provide a complete set of initial data to initialize the resource. The second
step to providing the initial set of particles is to tell the unordered access view how many
particles should be considered to exist within the structured buffer. This is done through
setting the initial counts parameter in the ID3D11DeviceContext::CSSetUnordered
AccessViews() method.
Specification of how many elements exist in the buffer is only needed during the first
use of the buffers. Once the first update phase has been completed, all of the active particles
will have been updated and appended to the output buffer through the compute shader
Search WWH ::




Custom Search