Date post: | 12-Jan-2016 |
Category: |
Documents |
Upload: | lesley-parker |
View: | 229 times |
Download: | 0 times |
Developing Metro style games on the Full Range of Windows 8 Devices
Dan McLachlanPrincipal Program Manager Lead Direct3DMicrosoft Corporation
Agenda
Windows 8 hardware diversity A unified 3D API to access the power of the GPU Designing for the Broadest Reach Strategies for dynamic calibration Tile-based rendering optimizations Recommendations
Windows 8 Hardware Diversity
Hardware Landscape
Wider range of hardwareimplies reconsideration of
your design point
New Category of Windows PCs
New design point Always on, always connected System on a chip Battery is primary power source Focus on low power
Both x86/x64 and ARM-based systems Covers a range of form factors
A Unified 3D API
DirectX Versions
Windows XP DirectX 9 Hardware Direct3D 9 API
Windows Vista DirectX 10 Hardware Direct3D 10 API
Windows 7 DirectX 11 Hardware Direct3D 11 API
How do you design your software for all this hardware?
Feature Levels
Direct3D 11 provides a uniform interface to access hardware capabilities
Feature Levels map to hardware capabilities Feature_Level_9 DirectX 9 Hardware Feature_Level_10 DirectX 10 Hardware Feature_Level_11 DirectX 11 Hardware
Direct3D 11 is the APIfor driving graphics hardware
Direct3D Features (all Feature Levels)
HLSL shader programming Low-precision and high-precision instructions Consistent implementation on all devices
Feature Level 9(Available on ALL hardware)
• Vertex shaders• Pixel shaders• 8 Textures• 4 Render Targets• Cube maps• Volume textures• Anisotropic filtering• Antialiasing• HDR rendering• Texture compression
Feature Level 10(Available on DirectX 10 and later hardware)
• Vertex shaders• Pixel shaders• 8 Textures• 4 Render Targets• Cube maps• Volume textures• Anisotropic filtering• Antialiasing• HDR rendering• Texture compression
• Geometry shaders• Stream out• 128 Textures per
shader• 8 Render Targets• Integers in shaders• Vertex textures• Shader sampling• Constant buffers• Alpha-to-coverage• Basic DirectCompute• Async resource
creation
Feature Level 11(Available on DirectX 11 and later hardware)
• Vertex shaders• Pixel shaders• 8 Textures• 4 Render Targets• Cube maps• Volume textures• Anisotropic filtering• Antialiasing• HDR rendering• Texture compression
• Geometry shaders• Stream out• 128 Textures per
shader• 8 Render Targets• Integers in shaders• Vertex textures• Shader sampling• Constant buffers• Alpha-to-coverage• Basic DirectCompute• Async resource
creation
• Full DirectCompute• Random access writes• Tessellation shaders• New compression
formats• Shader linkage
New Direct3D 11.1 Features
Logic operations in output merger Dynamic updates to constant buffers Low-precision math: min16_float, min10_float, min16_int
Hardware can promote silently to single-precision float UAVs at every stage Faster double-precision division instructions Video support
Graphics + Video integrated driver MSAD4 instruction Headless/Session 0
Select Feature Levels to Support
D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_1 };
UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
Create the Device and Context
ComPtr<ID3D11Device> device;ComPtr<ID3D11DeviceContext> context;D3D11CreateDevice( nullptr, // use the default adapter D3D_DRIVER_TYPE_HARDWARE, 0, // use 0 unless a software device creationFlags, // defined above featureLevels, // what app will support ARRAYSIZE(featureLevels), D3D11_SDK_VERSION, // should always be D3D11_SDK_VERSION &device, // created device &m_featureLevel, // feature level of the device &context // corresponding immediate context );
Designing for Broadest Reach
Particle Systems with Dynamic Calibration
demo
Development Strategy
Develop on DirectX 11 hardware Target Feature_Level_9 and scale up Include calibration code in game to dynamically configure
for current hardware Adjust to maintain performance
Be aware of Feature Level differences Test by restricting Feature Level Test on multiple PCs
DirectX Control Panel
Differentiation
Use advanced features when available Stereo 3D Tessellation
Left eye image Right eye image
L R
Differentiation
Increase Visual Quality Higher resolution textures Use bump maps
Texture Considerations
Balance visual quality with performance Scale back on size via mipmap levels Use block-compressed texture formats
512 x 512
256 x 256
1024 x 1024
Other Considerations
Geometry Feature_Level_11 – use tessellation for more polygon count control Consider lower-resolution (lower vertex count) meshes
MultiSampling AntiAliasing (MSAA) Reduce sample count to maintain frame rate
Render to a lower resolution and scale up for final image For best image quality, do not scale 2D text
Feature Level ≠ PerformanceDynamic calibration is critical to achieving
performance
Conventional Belief versus Reality
DirectX 9 DirectX 10 DirectX 10.1 DirectX 11 DirectX 11.1
Rela
tive P
erf
orm
an
ce
Calibration
Create device Set limits based on returned Feature Level Render a set of characteristic frames without presenting Adjust based on results
Calibrating Render Performance
Initialize a query event
Render a set of frames.
Wait until all rendering is completed.
Get elapsed time.
ComPtr<ID3D11Query> eventQuery;D3D11_QUERY_DESC queryDesc;queryDesc.Query = D3D11_QUERY_EVENT;queryDesc.MiscFlags = 0;
m_d3dDevice->CreateQuery(&queryDesc, &eventQuery);m_timer.reset();Render();
for (int i = 0; i < 18; i++){ m_d3dDeviceContext->Flush(); Render();}m_d3dDeviceContext->End(eventQuery.Get());if (S_FALSE == _d3dDeviceContext->GetData(eventQuery.Get(), NULL, 0, 0)){ while (S_FALSE == m_d3dDeviceContext->GetData(eventQuery.Get(), NULL, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH));}m_timer.tick();float elapsedTime = m_timer.getDeltaTime();
Trade-offs: PerformanceVisual Quality
Power Consumption
Increasing Performance
Reduce rendering costs Minimize shader computation complexity Minimize redundant work
Reduce rasterization work Scale final render target if pixel bound Minimize depth complexity or overdraw
Reducing Rendering Costs
New Direct3D features, especially for reducing power consumption
Available across ALL feature levels Minimum precision Tile-based rendering optimizations
Minimum Precision
Reduce the number of bits of precision in shader calculations
Hints to the graphics driver where optimizations can be done
Specifies minimum rather than actual precision min16float min12int min16int
Minimum PrecisionHLSL Code Sample
static const float brightThreshold = 0.5f;
Texture2D sourceTexture : register(t0);float4 DownScale3x3BrightPass(QuadVertexShaderOutput input) : SV_TARGET{ float3 brightColor = 0; // Gather 16 adjacent pixels (each bilinear sample reads a 2x2 region) brightColor = sourceTexture.Sample(linearSampler, input.tex, int2(-1,-1)).rgb; brightColor += sourceTexture.Sample(linearSampler, input.tex, int2( 1,-1)).rgb; brightColor += sourceTexture.Sample(linearSampler, input.tex, int2(-1, 1)).rgb; brightColor += sourceTexture.Sample(linearSampler, input.tex, int2( 1, 1)).rgb; brightColor /= 4.0f;
// Brightness thresholding brightColor = max(0, brightColor - brightThreshold);
return float4(brightColor, 1.0f);}
Minimum PrecisionHLSL Code Sample
static const min16float brightThreshold = (min16float)0.5;
Texture2D<min16float4> sourceTexture : register(t0);float4 DownScale3x3BrightPass(QuadVertexShaderOutput input) : SV_TARGET{ min16float3 brightColor = 0; // Gather 16 adjacent pixels (each bilinear sample reads a 2x2 region) brightColor = sourceTexture.Sample(linearSampler, input.tex, int2(-1,-1)).rgb; brightColor += sourceTexture.Sample(linearSampler, input.tex, int2( 1,-1)).rgb; brightColor += sourceTexture.Sample(linearSampler, input.tex, int2(-1, 1)).rgb; brightColor += sourceTexture.Sample(linearSampler, input.tex, int2( 1, 1)).rgb; brightColor /= (min16float)4.0;
// Brightness thresholding brightColor = max(0, brightColor - brightThreshold);
return float4(brightColor, 1.0f);}
Tile-based Rendering
Some graphics architectures use tile caches Cache access is much faster than GPU memory bus Goal is to keep data in the cache as long as possible Loops over the command stream once per tile
Typical Rendering
CommandBuffer1Command1Command2Command3Command4Command5Command6CommandBuffer2Command1Command2Command3Command4Command5Command6CommandBuffer3Command1Command2Command3Command4Command5Command6
Command Stream
Command stream sent to GPU
Tile Based Rendering
CommandBuffer1Command1Command2Command3Command4Command5Command6CommandBuffer2Command1Command2Command3Command4Command5Command6CommandBuffer3Command1Command2Command3Command4Command5Command6
Buffered Commands
Send Command Stream to GPUExecute Command Stream for Tile 1Execute Command Stream for Tile 2
Execute Command Stream for Tile 3Execute Command Stream for Tile 4Execute Command Stream for Tile 5Execute Command Stream for Tile 6Display the final image
Tile-based Rendering Optimizations
The Challenge: Some rendering sequences result in Direct3D needing to do multiple copies of buffers to ensure rendering correctness.
The Solution: New Direct3D APIs provide hints to avoid unnecessary copies. Make a promise about your rendering behavior
Take advantage of tile-based rendering hints and
optimizations
Tile-based Rendering Strategies
Avoid mid-scene flushes Avoid swapping back and forth between RenderTargets Use scissors when updating small portions of a
RenderTarget Use DISCARD and NO_OVERWRITE when possible
Tile-based Rendering Optimizations
GPUs with a tile-based rendering architecture can get a performance boost with a special flag:
m_swapChain->Present(1, 0); // present the image on the display
ComPtr<ID3D11View> view; m_renderTargetView.As(&view); // get the view on the RT
m_d3dContext->DiscardView(view.Get()); // release the view
Example: Dynamic Geometry
Example: Dynamic Geometry
Create vertex buffer Generate geometry data Draw Generate geometry data Draw Present
Vertex buffer
DISCARD
No Overwrite
Recommendations
System Configurations
Development machine [Asus G73 Gaming Laptop] AMD 5870M GPU (DX11) 64-bit OS, Core i7 quad core CPU, 8 GB memory
Test machine (Laptop) [HP Elitebook 2740p] DirectX 10 graphics and touch 64-bit OS, 4 GB memory
Test machine (Netbook) [HP Mini 5102T] DirectX 9.1 graphics and touch 32-bit OS, Atom processor, 1 GB to 2 GB memory
Considerations
Touch capabilities are important Minimum screen resolution of 1366 x 768 Test across a diversity of machines
Conclusion
Conclusion
Windows 8 Runs on the broadest graphics hardware diversity ever Designed for graphics hardware acceleration
Direct3D 11 is the 3D API to access the power of the GPU You can get Great Graphics Performance leveraging the
GPU AND hit the broadest markets
Strategy Recap
Design for Feature_Level_9 Adjust at runtime for actual Feature Level Use advanced features to differentiate when available Dynamically calibrate for smooth performance Use new Direct3D 11 features to better utilize hardware
Minimum precision Tile-based rendering optimizations
Further Reading and Documentation
Direct3D 11.1 FeaturesD3D11_FEATURE_DATA_D3D11_OPTIONS structure DXGIAdapter2::GetDesc2 method
DXGI 1.2 ImprovementsCreating a DirectX Game
Unlocking the GPU with Direct3D (PDC 2008)Direct3D on Downlevel Hardware (MSDN)10Level9 ID3D11Device Methods (MSDN)10Level9 ID3D11DeviceContext Methods (MSDN)Hardware Support for Direct3D 10Level9 Formats (MSDN)
Questions? Visit the forums on the Windows Dev Center at http://forums.dev.windows.com
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be
interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.