Graphics Reference
In-Depth Information
a world transformation, color variations, or whatever else is used to differentiate between
the various instances of the model. This setup allows for many objects to be rendered with a
single draw call, which reduces the overall CPU overhead for rendering operations.
You can see in the diagram that each type of vertex buffer follows our general buffer
layout. Each buffer is a one-dimensional array of same-sized elements. The sizes of the
individual data elements are always the same as those of the other elements in the same
buffer, although if multiple buffers are used, they can have different element sizes. We will
see how instanced rendering is performed in more detail in Chapter 3.
Vertex buffer uses. As mentioned above, a vertex buffer's primary purpose is to provide
per-vertex information to the pipeline, either directly, in multiple buffer configurations, or
through instancing. To this end, the primary place to bind a vertex buffer to the pipeline is
in the input assembler stage, which serves as the entry point into the pipeline. In addition to
the input assembler stage, vertex buffers can also be attached to the stream output stage to
allow the rendering pipeline to stream vertex data into the buffer, so that data can be used in
subsequent rendering passes. Both of these stages of the pipeline will be discussed in more
detail in Chapter 3, "The Rendering Pipeline," but these connections points are highlighted
on the pipeline schematic in Figure 2.9 for easy reference in the future.
Creating vertex buffers. As described in the "Resource Creation" section of this chapter,
for each type of location in the pipeline that a resource can be bound to, there is a corre-
sponding bind flag that must be set at resource creation time in order to allow the resource
to be bound there. With this in mind, a vertex buffer must always have the D3D11_BIND_
VERTEX_BUFFER bind flag set. It can also optionally include the D3D11_BIND_STREAM_
OUTPUT bind flag if it will be used for streaming vertex data out of the pipeline.
In addition to the choice of bind flags, the other major consideration for vertex buffers
revolves around the usage scenario that the buffer will experience. Depending on whether or
not the vertex buffer's contents will be changing frequently or not, and on if those changes
will be coming from the CPU or GPU, different usage flags will be needed. For example, if
the data that will be loaded into the buffer will be static, the buffer resource should be cre-
ated with the D3D11_USAGE_IMMUTABLE usage flag. In this case, when the buffer is created
it will be initialized with the vertex data through the D3D11_SUBRES0URCE_DATA parameter
passed to the creation method and will never be modified again. An example of this type of
vertex buffer would be used to hold the contents for a static terrain mesh.
However, if the buffer will be updated frequently by the CPU, the buffer should be
created with D3D11_USAGE_DYNAMIC, and also with a CPU write flag for the CPU access
flag parameter. An example of this type of vertex buffer usage is when vertex transfor-
mations are performed on the CPU instead of on the GPU. These updates would then be
copied into the buffer resource every frame. This is a common technique used to condense
many draw calls into one by putting all of the model data into the same frame of reference,
which is typically either world space or view space. Still a third usage type would be to
Search WWH ::




Custom Search