Game Development Reference
int next; // next element in linked list
int prev; // previos element in linked list
int right; // right neighbor link
int upper; // upper neighbor link
Listing 1.1. Linked list entry structure.
In this example the elements 1 and 6 (2 and 5, respectively) form a single linked
list, and the first elements 1 and 2 are stored in the head buffer.
Both structures (head buffer and list element buffer) are stored as Direct3D 11
( RW ) StructuredBuffers and filled by rendering the geometry once using interlocked
operations and the buffer counter in the pixel shader. InterlockedExchange is used
to exchange the head of the linked list to ensure that we do not face any problems
The buffer counter is used to “allocate” linked list
List element buffer
Figure 1.3. We implemented the DSMs as a two-level structure that consists of a per-
pixel buffer storing the head of each linked list (head buffer) and the list element buffer
for all incoming fragments. For each fragment, we store depth and alpha values, as well
as indices of the next and the previous elements, and nearest-depth neighbor links (only
the next index is shown here for brevity).