DirectX 11 Technology Update US
DirectX 11 Technology Update US
DirectX 11 Technology Update US
Gamefest 2008
Graphics Track
Introduction to the Direct3D 11 Graphics Pipeline Direct3D 11 Tessellation High Level Shader Language (HLSL) UpdateIntroducing Version 5.0 Multithreaded Rendering for Games
Partners Track
Advanced Topics in GPU Tessellation (AMD) Water-Tight, Textured, Displaced Subdivision Surface Tessellation Using Direct3D 11 (NVIDIA)
DirectX 11 Overview
Direct3D 11 is based on Direct3D 10.1
Similar API design & rendering pipeline
Enables new DirectX 11 hardware features Supports existing DirectX 10 and 10.1 hardware
Enables some new features as well
Supports a subset of DirectX 9 SM 2.0+ hardware Supported on Windows 7, Windows Vista, Windows Server 2008, and Windows Server 2008 R2
DirectCompute
CS 5.0 on DirectX 11 HW CS 4.x on some DX10.x h/w
Hardware Tessellation
DirectX 11 HW only
Each feature level is a superset of the previous one Concept was introduced with Direct3D 10.1
ID3D10Device1::GetFeatureLevel() D3D10_FEATURE_LEVEL_10_1 D3D10_FEATURE_LEVEL_10_0
Direct3D 10.1 hardware: Shader Model 4.1, cubemap arrays, extended MSAA, optional DirectCompute (CS 4.1), all 10_0 features.
D3D_FEATURE_LEVEL_11_0 Direct3D 11 hardware: Shader Model 5.0, hull & domain shaders, (e.g. ATI Radeon HD 5000 Series) mandatory DirectCompute (CS 5.0), BC6H/BC7, all 10_1 features.
Direct3D 9 hardware: must support Shader Model 2.0 (vs_2_0/ps_2_0), occlusion queries, float formats (no blending), extended caps, all 9_1 features.
Direct3D 9 hardware: must support Shader Model 2.0 (vs_2_0/ps_2_b) with instancing, 4K textures, multiple render targets (4 MRTs), floatingpoint blending, all 9_2 features.
DirectCompute
D3D_FEATURE_LEVEL_10_0 / 10_1 support for CS 4.x is optional CS 5.0 is required for D3D_FEATURE_LEVEL_11_0
Related Technologies
DirectX Graphics Infrastructure (DXGI) 1.1
Version 1.0 introduced in Windows Vista Enumerates adapters, display modes, and outputs (e.g. monitors) New DXGI_FORMATs and improved support for remote desktops
Demo
Updated DxCapsViewer Utility
ID3D10RasterizerState
ID3D10Counter ID3D10Texture3D
ID3D10DepthStencilView
ID3D10SamplerState
ID3D10RasterizerState
ID3D10Counter ID3D10Texture3D
ID3D10DepthStencilView
ID3D10SamplerState
ID3D11RasterizerState
ID3D11Counter ID3D11Texture3D
ID3D11DepthStencilView
ID3D11SamplerState
ID3D11DeviceChild ID3D11Device
ID3D11Asynchronous
ID3D11Resource
ID3D11View
ID3D11VertexShader ID3D11GeometryShader ID3D11PixelShader ID3D11ComputeShader ID3D11DomainShader ID3D11HullShader ID3D11InputLayout ID3D11Predicate ID3D11DepthStencilState ID3D11BlendState ID3D11Texture2D ID3D11DepthStencilView ID3D11Texture1D ID3D11RenderTargetView ID3D11Query
ID3D11Buffer
ID3D11ShaderResourceView
ID3D11DeviceContext
Multi-threading Rules
ID3D11Device is thread-safe
Without driver support for Concurrent Creates, runtime will enforce thread-safety with a coarse lock Without driver support for Concurrent Creates, creating objects and rendering with the immediate context will not be concurrent (using the same coarse lock) Methods on most other objects (ID3D11DeviceChildderived) are also thread-safe Can opt-out by using D3D11_CREATE_DEVICE_SINGLETHREADED
Multi-threading Rules
ID3D11DeviceContext is not thread-safe
Typical usage is one device context per thread, one of them using immediate and the rest using deferred contexts Note that DXGI methods should not be used concurrently while rendering with the immediate device context
For example, Present() uses the immediate device context
Multi-threading Rules
ID3D11DeviceContext deferred mode limitations
Map() must be used with D3D11_MAP_WRITE_DISCARD and/or D3D11_MAP_WRITE_NO_OVERWRITE GetData() for queries is not allowed Queries can be used in conjunction with predication If executing a deferred command list with a query active and the command list itself uses the same query, then the command list submission is ignored as invalid
Multi-threading Recommendations
Concurrent creation is a no brainer
Many engines already have resource loading threads Runtime emulation is good enough for a win
Less overhead than the default Direct3D 10 M/T behavior
ConcurrentCreates driver support makes it better When creating objects with M/T driver support, providing initial data for static objects should be more efficient
i.e Use the pInitialData parameter on the Create rather than staging resources, UpdateSubResource(), or Map() when possible
Multi-threading Recommendations
Concurrent submission depends on the scenario
Useful for Triple-core, Quad-core, or more
For Dual-core, it is less likely to be worthwhile
Similar but not identical to Xbox 360 Command Buffers Driver CommandLists support is currently rare
If starting with Direct3D 10.0, will need to fix up a few minor structure differences
(11 matches the 10.1 version)
D3D10_BLEND_DESC1 D3D10_SHADER_RESOURCE_VIEW_DESC1
Change resource Map() and query Begin(), End(), & GetData() to use immediate context Create*Shader takes an additional class linkage parameter (can use NULL) *SetShader and *GetShader take an additional class instance parameter (can use NULL)
HLSL Compiler
DirectX 11 requires 4.0 or later profile shaders D3DCompile DLL contains latest HLSL compiler
Used by D3DX9, D3DX10, D3DX11, and FXC.EXE Can use directly (i.e. without using D3DX)
Note it is in its own DirectSetup CAB file in the REDIST folder
HLSL Recommendations
Use the latest compiler
Esp. avoid the in box D3D10Compile APIs
Generally use the lowest profile possible for VS/PS when supporting 10level9 For DirectCompute
prefer CS 5.0 over CS 4.x Prefer CS 4.1 over CS 4.0
Effects 10
Effects 11
D3DX11
Includes texture loaders (BMP, JPG, PNG, DDS, TIFF, GIF)
and asynchronous loaders introduced with D3DX10
D3DCSX
Optional extended D3DX DLL for Compute Shader
Resides in its own DirectSetup / REDIST CAB
ID3DX11FFT
1D, 2D, 3D support Real or Complex Forward or Inverse Transform with optional scale
XNAMath
aka xboxmath 2.0 Inline C++ SSE/SSE2 optimized math library
VMX128 optimized on Xbox
~350 functions
Focused on single-precision floating-point operations Limited integer operations Conversion to/from packed graphics formats Implemented using Visual Studio intrinsics Supports x86 and x64 native
Common 3D primitives
Vectors, matrices, planes, quaternions, etc.
DirectX 11 Deployment
DirectX 11 Runtime is included with Windows 7 and Windows Server 2008 R2 DirectX 11 Runtime can be deployed down-level to Windows Vista / Server 2008 D3DX11, D3DCSX, D3DCompile, etc. installed by DirectSetup / DX SDK REDIST
Just like D3DX9, D3DX10, XAUDIO2, etc.
DirectX 11 Runtime
Direct3D 11 DXGI 1.1 WARP10 10level9 Direct3D 10.1 Direct2D DirectWrite
New API supporting 10, 10.1, 11, 10level9, and WARP10 D3D glue library updated for new formats and WDDM 1.1 driver features 10.1 level software renderer Direct3D 9 Shader Model 2.0 h/w support (9_1, 9_2, 9_3 feature levels) Updated existing API to support WARP10, 10level9
GDI-like 2D drawing API for working on Direct3D surfaces High-quality, feature-rich font rendering API (works with Direct2D)
KB 971644
Platform Update for Windows Vista
http://go.microsoft.com/fwlink/?LinkId=160189
Deployed through Windows Update Requires Windows Vista / Server 2008 SP2 to be installed
See the D3D11InstallHelper sample in the DirectX SDK for detection, applying the KB, and messaging for RTM / SP1
KB 971512
For corporate network environments using Windows Server Update Servers (WSUS), KB 971644 is not available Use this update instead
Windows Graphics, Imaging, and XPS Library
http://support.microsoft.com/kb/971512/
Local IT admin will need to approve the update through the managed WSUS servers Requires Windows Vista / Server 2008 SP2 to be installed
Recommendations
Update your existing Direct3D 10.x code path to use Direct3D 11
This requires some installer/deployment work Your DX11 code path will require Windows Vista SP2+ or Windows 7
For Windows Vista / Windows 7 titles 10level9 feature levels can provide more hardware support, so you dont need a Direct3D9 code path For titles that need Windows XP support, you will need a legacy Direct3D9 code path
Recommendations
If you still only have a legacy Direct3D 9 code path
Nows the time to invest in DirectX 11 Take advantage of the existing resources Lessons learned moving from D3D9 -> D3D10 all apply to moving from D3D9 -> D3D11
Direct3D 11 provides
the latest hardware features new features for existing 10.x hardware and supports the majority of video cards with WDDM drivers
Resources
Latest DirectX SDK
http://msdn.microsoft.com/directx
APPENDIX
#include d3d10.h IDXGISwapChain *g_pSwapChain = NULL; ID3D10Device *g_pDevice = NULL; DXGI_SWAP_CHAIN_DESC sd; // Set to desired values HRESULT res = D3D10CreateDeviceAndSwapChain( NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &sd, &g_pSwapChain, &g_pDevice ); if ( FAILED(res) ) // Error Handling // Bind render target from swap chain // Set up viewport
#include d3d10_1.h IDXGISwapChain *g_pSwapChain = NULL; ID3D10Device1 *g_pDevice = NULL; DXGI_SWAP_CHAIN_DESC sd; // Set to desired values HRESULT res = D3D10CreateDeviceAndSwapChain1( NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_FEATURE_LEVEL_10_1, D3D10_1_SDK_VERSION, &sd, &g_pSwapChain, &g_pDevice ); if ( FAILED(res) ) { res = D3D10CreateDeviceAndSwapChain1( NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_FEATURE_LEVEL_10_0, D3D10_1_SDK_VERSION, &sd, &g_pSwapChain, &g_pDevice ); }
if // // //
( FAILED(res) ) // Error Handling Bind render target from swap chain Set up viewport
use g_pDevice->GetFeatureLevel() to check for 10_1; can otherwise assume 10_0
#include d3d11.h IDXGISwapChain *g_pSwapChain = NULL; ID3D11Device *g_pDevice = NULL; ID3D11DeviceContext* g_pContext = NULL; DXGI_SWAP_CHAIN_DESC sd; // Set to desired values D3D_FEATURE_LEVEL flvl[] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL 10_0 }; D3D_FEATURE_LEVEL fl; HRESULT res = D3D11CreateDeviceAndSwapChain( NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, flvl, sizeof(flvl)/sizeof(D3D_FEATURE_LEVEL), D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pDevice, &fl, &g_pContext );
if // // // //
( FAILED(res) ) // Error Handling Bind render target from swap chain Set up viewport
use g_pDevice->GetFeatureLevel() (or remember fl above) to check for 11_0 or 10_1, assume 10_0 otherwise
#include d3d11.h IDXGISwapChain *g_pSwapChain = NULL; ID3D11Device *g_pDevice = NULL; ID3D11DeviceContext* g_pContext = NULL; DXGI_SWAP_CHAIN_DESC sd; // Set to desired values D3D_FEATURE_LEVEL flvl[] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL 10_0, D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1 }; D3D_FEATURE_LEVEL fl; HRESULT res = D3D11CreateDeviceAndSwapChain( NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, flvl, sizeof(flvl)/sizeof(D3D_FEATURE_LEVEL), D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pDevice, &fl, &g_pContext ); if // // // ( FAILED(res) ) // Error Handling Bind render target from swap chain Set up viewport
#include d3d11.h IDXGISwapChain *g_pSwapChain = NULL; ID3D11Device *g_pDevice = NULL; ID3D11DeviceContext* g_pContext = NULL; DXGI_SWAP_CHAIN_DESC sd; // Set to desired values HRESULT res = D3D11CreateDeviceAndSwapChain( NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pDevice, NULL, &g_pContext ); if // // // ( FAILED(res) ) // Error Handling Bind render target from swap chain Set up viewport
DirectX 11 Debugging
DirectX SDK provides debugging layer Enabled through code (D3D11_CREATE_DEVICE_DEBUG) or the DirectX Control Panel utility
Control panel controls the 10 and 11 debugging layer through the same settings Unlike Direct3D 9, it is per application not a global setting
DirectX 11 Debugging
Make sure your application runs debug layer clean
ERROR and CORRUPTION reports are critical to fix Tools like PIX for Windows assume this level of correctness
www.microsoftgamefest.com