Graphics Reference
In-Depth Information
constant buffer that we will use in this simulation update. These parameters will be dis-
cussed individually in the following sections as needed.
With the resources declared, we move on to the declaration of the thread group size
and the group shared memory. The size of the area that is being updated with this thread
group is defined with the size_x and size_y parameters. The corresponding padded size
is then declared with an extra 1 on both sides of it, to represent the additional pe-
rimeter of threads around the thread group. We use this padded size to declare both
the number of threads to use in this thread group and the group shared memory array of
GridPoint structures. The ability to declare a structure as the array element type for the
group shared memory is a nice feature, and it demonstrates the flexibility of GSM usage to
represent the various data types that are needed. With this layout, we can access the group
shared memory with the same array-like syntax that we use with the structured buffers,
which further simplifies the shader program.
With all of the needed memory and resources allocated, the algorithm can begin. As
mentioned above, the current state of the simulation must be loaded into the group shared
memory. Each thread in the thread group, including the extra perimeter of threads, will
load the state of the fluid column that it represents. The individual states that correspond
to a thread can be visualized in Figure 12.6. The calculation of the proper index to load
must take into account the fact that the dispatch thread ID will no longer be a one-to-
one mapping with the simulation grid, because of the additional perimeter threads. This is
shown in Listing 12.3 with the calculation of the location variable, which provides the
2D location in the simulation grid for the current thread based on the sizes provided in the
DispatchSize variable. This variable is provided by the application through a constant
buffer and provides the dispatch size as well as the overall simulation grid dimensions.
The location is then flattened into the 1D buffer index with the textureindex variable.
The data at the textureindex offset is loaded by each thread, then stored directly into the
group shared memory for use later in the shader. Once the data is loaded, we perform a
memory barrier with a group synchronization, to ensure that the entire thread group has
loaded its data into the GSM before proceeding.
// Grid size - this matches your dispatch call size!
int gridsize_x = DispatchSize.x;
int gridsize_y = DispatchSize.y;
// The total texture size
int totalsize_x = DispatchSize.z;
int totalsize_y = DispatchSize.w;
// Perform all texture accesses here and load the group shared memory with
// last frame's height and flow. These parameters are initialized to zero to
// account for 'out of bounds'texels.
Search WWH ::




Custom Search