Graphics Reference
In-Depth Information
Figure 7.3. A depiction of binding resources in a deferred context, while the contents of the resource can
be changed at a later time.
This gives us two general ways to use command list objects. The first is to generate
and use a command list within every frame. This allows for simple dynamic updates to
any state that is used in the rendering of an object, and the command list is released after
the rendering is complete. This usage is intended to allow spreading the costs of API calls
across multiple threads. The second way to use a command list is to generate it once, and
then update its resources from frame to frame, and reuse it many times. This reduces
the cost of generating the command list in every frame, at the expense of some additional
complexity to ensure that only resources contain the dynamic state for the object rendering.
7.3.4 Using the Device and Context Interfaces
With this understanding of how the deferred context works, now would be a good oppor-
tunity to consider how a rendering system could be implemented to use deferred contexts.
The general advice regarding deferred contexts is to use at most one context/thread per
core in the user system's CPU.2 Then the application would have each thread perform
some rendering work that can be queued into a command list. Once the command lists have
all been generated, the immediate context would iterate through them, executing them one by
one in the proper order. This basic setup is depicted below in Figure 7.4 for a quad core CPU.
As you can see from the figure, this new setup significantly reduces the amount of
time needed to submit the draw state change calls to the API. In addition to reducing the
overall time to submit the rendering requests, command lists are created in a format that
lets the driver quickly and efficiently play back the sequence, which will further reduce the
2 There are several ways to determine the number of CPU cores on a user's computer. The GetLogicalPro-
cessorlnformation() function has been in existence since Windows XP, but it includes hyper-threaded CPUs
as a separate core. While this is partially correct, we are more interested in the actual number of CPU cores.
Windows 7 has introduced the GetLogicalProcessorInformationEx() function, with extra flags to better specify
precisely which count to return. Since Direct3D 1 1 runs on both Windows Vista and Windows 7, it may be
necessary to use both functions, depending on which operating system is in use.
Search WWH ::




Custom Search