Moving from DirectX 9 to DirectX 11

Hello everyone, I am currently implementing a DirectX 11 engine and I thought it would be nice to write an article about some of the most important changes I have come across with respect to DirectX 9.

This article is aimed at people who have got at least a medium level of D3D9 and want to begin programming using D3D11. Some of the topics I am going to talk about were already introduced in D3D10.


If you have done some D3D9 programming before it is most likely that you used D3DXVECTOR as your vector type. The problem now is that D3DX11, in contrast to D3DX9 and D3DX10, does not include a vector type (In addition D3DX11 is deprecated for Windows 8).

Instead, Microsoft wants you to use XNAMATH.  There’s a good reason for using XNAMATH; XNA provides a vector type called XMVECTOR which take advantage of SIMD (Single instruction, multiple data); this means that we can increase our application performance by using this new type.

Likewise, we should use XMMATRIX (XNAMATH matrix type) for matrix calculations so that we can take advantage of SIMD as well for computations involving matrices.

However there are some considerations when using these types; for instance, XMVECTOR and XMMATRIX must be 16-byte aligned, this is done automatically for local and global variables but not for class members or struct members, in these two cases it is recommended to use XMFLOAT types (XMFLOAT3, XMFLOAT4X4, …) when storing the data into a class and then transform these types into XMVECTOR and XMMATRIX before doing the calculations.  There are some other restrictions (like when passing these types as parameters to a function); you can find more information here.

Good bye onLostDevice and OnResetDevice

In D3D9 if we didn’t want our application to crash when resizing the screen, minimizing, maximizing, etc, we had to create onResetDevice and onLostDevices methods for our resources (Information here ). This issue was usually translated into a lot of extra lines of code for assets management.

In ID3D11 there’s no “device lost” so we don’t have to worry about it anymore. Nevertheless there are still some tasks we have to accomplish when resizing the window like updating the back buffer and the depth stencil buffer, but in general we don’t have to worry about the OnLostDevice and OnResetDevice methods anymore.


In DX11 there is no ID3DXMesh interface; as you might know this class had a really handy method for reading a model from a .X file (DirectX file format).

The thing is that most of the people were using a format different from the DirectX file format. It makes sense because you usually want a format that fits into your workflow and often the best way to achieve this is by creating your own format.

Because of this reason DirectX11 no longer supports .X file format and you have to find another way to load your models from files. Luckily there are some libraries like ASSIMP that you can integrate easily in your project and that allow you to read from different formats like Collada (.dae), .obj, .3ds, .X, etc. Of course you can always write your own format and create a parser for that format in your code.

Loading Effect files

For compiling shaders you can use the D3DX11CompileFromFile function. However this is not a good idea; the reason is better explained by Microsoft here : “the D3DX (D3DX 9, D3DX 10, and D3DX 11) utility library is deprecated for Windows 8 … Instead of using this function, we recommend that you compile offline by using the Fxc.exe command-line compiler”

You can find information on how to use the effect compiler (FXc.exe) here.

Textures as resources

If we want to understand how to create a texture in D3D11 first we have to learn the concept of Resources in DirectX 11. This article by Microsoft explains it.

The same article also explains that a Resource, such as a Texture resource, has to be bound to one of the stages of the rendering pipeline through something called a “Resource view”. Thus, if we want to use a texture not only as a Render Target but also as a shader parameter we have to create two Resources views (ID3D11RenderTargetView and ID3D11ShaderResourceview).

Other functionality you might miss as well

If you used the D3DX9 library extensively other functionality you might miss is Sprite and Text drawing. Luckily Frank Luna has a really good article for doing so in D3D11.

Final thoughts

I hope this article helps people to take a first step into D3D11. I know I’ve missed many things and probably I’ll write a second part of this article in the future. But I think, for now, it’s a good start.


2 thoughts on “Moving from DirectX 9 to DirectX 11

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s