Introduction to Deferred Contexts

This section applies only to Windows 7 and later, and Windows Server 2008 R2 and later versions of Windows operating system.

Deferred contexts are used by an application to create command lists. If a user-mode display driver indicates that it supports command lists through the D3D11DDICAPS_COMMANDLISTS_BUILD_2 flag of the D3D11DDI_THREADING_CAPS structure, it must also support the ability to create and manipulate deferred contexts. For more information about how the driver indicates threading capabilities, see Supporting Threading, Command Lists, and 3-D Pipeline. Deferred contexts differ from the immediate context in that the commands that the deferred contexts record cannot be executed until the application explicitly requests to execute the commands, by executing the generated command list. To create and use a deferred context, Direct3D version 11 provides the following new DDI functions. These functions are a subset of information that is required to create the device/immediate context combination.

The semantics of the CalcPrivateDeferredContextSize and CreateDeferredContext functions are similar to other similar DDI functions.

The Direct3D runtime passes in a new driver handle and core layer handle for each call to the driver's CreateDeferredContext function to create each deferred context. The pipeline state of each deferred context must be equivalent to the pipeline state that the immediate context has after the clear-state operation is performed on it. The driver must fill members of the D3D11DDI_DEVICEFUNCS structure that the p11ContextFuncs member of D3D11DDIARG_CREATEDEFERREDCONTEXT structure points to with a subset of the functions from its function table; the runtime uses each of the corresponding deferred context D3D10DDI_HDEVICE handle values that the hDrvContext member of D3D11DDIARG_CREATEDEFERREDCONTEXT specifies with this function table.

The driver must continue to provide functions that start with pfnCreate, pfnOpen, and pfnDestroy for the deferred context. These functions share the same threading semantics as the rest of the deferred context, and they are used to open and close context-local DDI handles as described in Using Context-Local DDI Handles. Functions that start with pfnCalcPrivate or pfnCheck are not leveraged for deferred contexts; therefore, the driver can set the members of D3D11DDI_DEVICEFUNCS for these functions to NULL when the deferred context is created. The majority of the remaining device functions are leveraged for deferred context support. The driver does not leverage its QueryGetData function, though. However, the driver leverages its ResourceMap and ResourceUnmap functions. The driver only supports the ResourceIsStagingBusy function and new DDI functions for Direct3D version 11 resource clamps on the immediate context by using immediate-context handles. For a complete list of the functions that are not leveraged for deferred contexts, see Excluding DDI Functions for Deferred Contexts.

The driver leverages the core layer callback functions that are provided in the memory block that the p11UMCallbacks member of D3D11DDIARG_CREATEDEFERREDCONTEXT points to. These core layer callback functions provide the refresh-state DDI for each deferred context. Most importantly, however, is the addition of the pfnPerformAmortizedProcessingCb callback function that is described in Changes from Direct3D 10.

The driver should not expect the pfnDisableDeferredStagingResourceDestruction callback function to which the pfnDisableDeferredStagingResourceDestruction member of D3D11DDI_CORELAYER_DEVICECALLBACKS points to be valid. The driver should have called pfnDisableDeferredStagingResourceDestruction within the CreateDevice(D3D10) function for the device/immediate context; afterward, the driver should never call pfnDisableDeferredStagingResourceDestruction with the new Direct3D version 11 DDI semantics.

The driver's RecycleCreateDeferredContext function must clear out the pipeline state for the deferred context, similar to how the driver's CreateDeferredContext clears out the pipeline state for the deferred context. After the runtime calls the driver's AbandonCommandList, CreateCommandList, or RecycleCreateCommandList, the runtime can use the deferred context handle with either the driver's DestroyDevice(D3D10) or RecycleCreateDeferredContext function. For more information about RecycleCreateDeferredContext, see Optimization for Small Command Lists.