Search code examples
c++visual-studioobjectcomdirectx

Difference in usage among IDXGI and ID3D11Device and ID3D11DeviceContext


What are the differences in usage among IDXGI and ID3D11Device and ID3D11DeviceContext?

From my understanding, for creating/initializing COM objects use ID3D11Device, and when manipulating those COM objects use ID3D11DeviceContext and for determining type of hardware, drivers and all other compatibility stuff use IDXGI COM.

What other differences and usages are there?


Solution

  • DXGI is the basic infrastructure stuff for enumerating adapters & outputs, creating the swap chain, and doing the present of the frame. It's intended to be independent of the specific version of DirectX, and it's supposed to not change all that much between versions.

    Back in Direct3D 10.x, the methods were primarily in a single ID3D10Device. For Direct3D 11, this was split into two pieces:

    • ID3D11Device is all about creating objects such as textures, vertex buffers, shaders etc.
    • ID3D11DeviceContext is for setting state and drawing.

    The reason for the split is quite simple: All methods on ID3D11Device are thread-safe (i.e. can be called from multiple threads and internally uses locking), while all methods on ID3D11DeviceContext are thread-free (i.e. can only be called from a single thread at a time because the methods do not make use of locking).

    You should look at this presentation from 2010: DirectX 11 Technology Update.