Graphics Reference
In-Depth Information
Accessing the current simulation state. To begin the update process, we must have ac-
cess to the current state of the system. We would like to load the required information into
the group shared memory to minimize device memory reads, in much the same manner as
we saw in Chapter 10. To do this, we must declare an appropriately sized array of group
shared memory that can hold the relevant simulation state data. This declaration is shown
in Listing 12.2.
// Declare the structure that represents one fluid column's state
struct GridPoint
{
float Height;
float4 Flow;
};
II Declare the input and output resources
RWStructuredBuffer<6ridPoint> NewWaterState : register( u0 );
StructuredBuffer<6ridPoint> CurrentWaterState : register( t0 );
// Declare the constant buffer parameters
cbuffer TimeParameters
{
float4 TimeFactors;
float4 DispatchSize;
};
// Simulation Group Size
#define size_x 16
#define size_y 16
// Group size with the extra perimeter
#define padded_x (1 + size_x + 1)
#define padded_y (1 + size_y + 1)
// Declare enough shared memory for the padded group size
groupshared GridPoint loadedpoints[padded_x * padded_y];
// Declare one thread for each texel of the simulation group. This includes
// one extra texel around the entire perimeter for padding.
[numthreads(padded_x J padded_y, 1)]
Listing 1 2.2. Thread group and group shared memory size declarations.
In this listing, we can see the declaration of the GridPoint structure, whose contents
comprise the state required to represent one fluid column. We can also see that the two
structured buffer resources are declared with the GridPoint structure as the argument to
their template types. This allows us to use the structure members directly on each element
of the structured buffer, making the shader code a bit easier to read. Next, we declare the
Search WWH ::




Custom Search