• entries
9
9
• views
8591

# Directx 9 to Directx 10

2304 views

Currently I'm moving my Theolith 3D engine from DirectX 9 to DirectX 10. It's not an easy and fast work. I realized that all architecture of my application has to be changed.

For the moment I'm working on the game's interface. So I'm just dealing with my 2d engine (sprite).

here are some stuff that I had to change:

about DXUT, there are not a lot of changes:
* of course, OnD3D9...() is now names OnD3D10...()
* I have noticed a small change: LostDevice(...) and ResetDevice(...) are now named SwapChainReleasing(...) and SwapChainResized(...)
* the CAPS has disappeared, because if a GPU can support DX10 it is supposed to support all the DX10 functionality. for example here are the resource limits
* the Surface type has disappeared

now, about the pipeline, forget what you know :)
pd3dDevice->SetRenderState,
pd3dDevice->SetSamplerState,
pd3dDevice->SetTextureStageState
...
have disappeared

Now it's time to think "shader pipeline"
the shader pipeline is now the core of my DX10 3D engine. Even if you need to render a simple sprite, you have to write a shader and to understand the pipeline.
the DX10 pipeline is here.

for example: with my sprite engine, I don't need depth, stencil and culling.
in Directx 9, it's something like that:

pd3dDevice->SetRenderState(D3DRS_ZENABLE, FALSE);pd3dDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE);

Now, in Directx 10, you have to know that depth and stencil are managed by the Output-Merger Stage and that the culling is managed by the Rasterizer Stage
so, it's something like that:

/////////AT THE BEGINNING//////////create a Rasterizer stateD3D10_RASTERIZER_DESC rasterizerState;rasterizerState.CullMode = D3D10_CULL_NONE;rasterizerState.FillMode = D3D10_FILL_SOLID;rasterizerState.FrontCounterClockwise = true;rasterizerState.DepthBias = 0;rasterizerState.DepthBiasClamp = 0.0f;rasterizerState.SlopeScaledDepthBias = 0.0f;rasterizerState.DepthClipEnable = false;rasterizerState.ScissorEnable = false;rasterizerState.MultisampleEnable = true;rasterizerState.AntialiasedLineEnable = false;ID3D10RasterizerState*  pRState;if( FAILED( pd3dDevice->CreateRasterizerState( &rasterizerState, &pRState) )){   ERROR_MESSAGE("CreateRasterizerState");}//create a Depth Stencil StateD3D10_DEPTH_STENCIL_DESC dsDesc;// Depth test parametersdsDesc.DepthEnable = false;dsDesc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;dsDesc.DepthFunc = D3D10_COMPARISON_LESS;// Stencil test parametersdsDesc.StencilEnable = false;dsDesc.StencilReadMask = 0xFF;dsDesc.StencilWriteMask = 0xFF;// Stencil operations if pixel is front-facingdsDesc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;dsDesc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_INCR;dsDesc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;dsDesc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;// Stencil operations if pixel is back-facingdsDesc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;dsDesc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_DECR;dsDesc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;dsDesc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;ID3D10DepthStencilState * pDSState;// Create depth stencil stateif( FAILED( pd3dDevice->CreateDepthStencilState(&dsDesc, &pDSState))){   ERROR_MESSAGE("CreateDepthStencilState");}/////////BEFORE RENDERING////////pd3dDevice->RSSetState(pRState);pd3dDevice->OMSetDepthStencilState(pDSState, 1);//I don't understand what does the second argument mean.../////////AT THE END////////if ( pRState ) { pRState->Release(); pRState = NULL; }if ( pDSState ) { pDSState->Release(); pDSState = NULL; }

The DX10 is heavier, but in my opinion it's very more clear than DX9. Because in DX9 you have only 3 or 4 functions to change all the pipeline states and it's very disorderly. seriously, even after a lot of years of DX9, I'm always feeling sick when i see that.
In DX10, you have to deal with more functions but each function have a precise work and it's more understandable.
moreover, each function belongs to one stage, so you have 7 families of function.

for example, before the rendering, you have to deal with
pd3dDevice->IASet...() to set the Input-Assembler Stage
pd3dDevice->VSSet...() to set the Vertex-Shader Stage
pd3dDevice->GSSet...() to set the Geometry-Shader Stage
pd3dDevice->SOSet...() to set the Stream-Output Stage
pd3dDevice->RSSet...() to set the Rasterizer Stage
pd3dDevice->PSSet...() to set the Pixel-Shader Stage
pd3dDevice->OMSet...() to set the Output-Merger Stage

To conclude this article, I'm very happy to learn DirectX 10, I think I will understand the GPU a lot more than with Directx 9. DX9 would seem to be lighter and easier but that hide a very disorderly side. In Directx 10, you are obliged to write more code, so you are obliged to understand more. A lot of outdated parts of Direct3D have been removed and it's a good thing.

http://wiki.gamedev.net/index.php/D3DBook:Quick_Start_For_Direct3D_9_Developer
http://msdn.microsoft.com/en-us/library/bb205123(v=VS.85).aspx
http://msdn.microsoft.com/en-us/library/ee416396(v=VS.85).aspx

There are no comments to display.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account