Graphics Reference
In-Depth Information
Benchmarking multithreaded rendering
In this recipe, we will introduce multithreaded rendering techniques and implement a
simple benchmark application to analyze the performance of using multiple deferred
contexts. We will render the same model multiple times, comparing the results between
varying numbers of deferred contexts and the immediate context. We will introduce
additional CPU processing overhead to compare GPU-bound and CPU-bound frame times.
Getting ready
We can begin with any completed rendering loop and apply the techniques presented in this
recipe to it. However, for the purpose of this recipe, we will assume a starting point based
upon the finished result from the Animating bones recipe in Chapter 4 , Animating Meshes
with Vertex Skinning .
How to do it…
In order to support multithreaded rendering, it is necessary to pass the DeviceContext
deferred context instance that will receive the rendering commands for the renderer.
We will implement support for starting a new thread for each deferred context and
split the recording of rendering tasks between them.
1. The first change we will make to our renderer(s) is that we want it to support
executing commands on a deferred context. So that a renderer can use the provided
context, we will use the following Render override of Common.RendererBase :
public void Render(SharpDX.Direct3D11.DeviceContext context)
{
if (Show)
DoRender(context);
}
2.
Within appropriate renderer classes (for example, MeshRenderer.cs ),
we will change to the RendererBase.DoRender method override that
accepts a DeviceContext parameter.
protected override void DoRender(DeviceContext context) {
... SNIP - previous DoRender() code
}
3.
Within the D3DApp class, we need code for initializing the requested number
of deferred context DeviceContext instances. This might look similar to the
following code snippet:
DeviceContext[] contextList;
int threadCount = 2;
 
Search WWH ::




Custom Search