Graphics Reference
In-Depth Information
// Must store value of iterator in another variable
// otherwise all threads will end up using the last
// context.
var contextIndex = i;
renderTasks[i] = Task.Run(() => {
// Retrieve render context for thread
var renderContext = contextList[contextIndex];
// TODO: regular render logic goes here
// Create the command list
if (contextList[contextIndex].TypeInfo ==
DeviceContextType.Deferred)
{
commands[contextIndex] = contextList[contextIndex]
.FinishCommandList(true);
}
});
}
// Wait for all the tasks to complete
Task.WaitAll(renderTasks);
9.
Next, we need to replay command lists on the immediate context. We are applying
them in the order in which they are located within the contextList array.
// Replay the command lists on the immediate context
for (var i = 0; i < contextList.Length; i++)
{
if (contextList[i].TypeInfo ==
DeviceContextType.Deferred && commands[i] != null)
{
immediateContext.ExecuteCommandList(commands[i],
false);
commands[i].Dispose();
commands[i] = null;
}
}
10. The following code snippet shows an example of the logic that belongs to the
preceding rendering task's loop. The only difference compared to our regular
rendering process is that we are only rendering a portion of the available meshes for
the current context, optionally simulating the additional CPU load, and we are calling
the MeshRenderer.Render method with a context.
// Retrieve appropriate context
var renderContext = contextList[contextIndex];
// Create viewProjection matrix
 
Search WWH ::




Custom Search