Graphics Reference
In-Depth Information
Figure 3.44. The benefits of caching tessellated geometry for multiple rendering passes.
Stream Output as a Debugging Tool
Another potential use for the stream output stage is to tap into the pipeline data at the
geometry shader stage and retrieve a portion of the data for debugging purposes. This can
be helpful for inspecting intermediate values that would normally not be available in the
final rendered output. In this case, two different buffer resources are needed. The first is
the stream output buffer, which must be created with the default resource usage flag. The
application cannot access this type of buffer directly, since it is not possible to create buf-
fers that can be written to by the pipeline and also read from the CPU. Instead, we create a
second buffer with the staging usage flag, and then copy the streamed data from the default
usage buffer to the staging usage buffer. The application can then map the staging buffer
and read its contents.
Once the contents are accessible to the application, they can be accessed by using a
structure that identifies the layout of the streamed vertices. This is typically known well in
advance, since the stream output configurations are needed before executing the pipeline,
anyway. The number of primitives written to the buffers can be retrieved with a pipeline
query object of the type D3D11_QUERY_DATA_S0_STATISTICS (more details about how to
perform a pipeline query can be found in Appendix B). This allows the application to know
at what point in the buffer the pipeline-generated data ends, and where the default or in-
valid contents of the buffer begin.
With the buffer data accessible in an evaluated form, the application can use the data
in whatever way is needed. This can include writing the data to a file for offline inspection,
analyzing data, such as finding the axis-aligned bounding box of the new data, or even
printing statistics to the screen in real time for a live visualization of the model data being
passed through the geometry shader. These types of techniques would typically not be used
for a user-facing application, but they can provide a number of debugging options during
Search WWH ::




Custom Search