high performance in broad reach games chas. boyd principal program manager microsoft corporation

39
High Performance in Broad Reach Games Chas. Boyd Principal Program Manager Microsoft Corporation

Upload: percival-gilbert

Post on 24-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

High Performance in Broad Reach Games

Chas. BoydPrincipal Program ManagerMicrosoft Corporation

Agenda

Windows 8 hardware diversityA unified 3D API to access the power of the GPU Designing for the Broadest ReachOptimizing PerformanceTile-based rendering optimizationsRecommendations

3 Presentations Today

Step by Step through Game Development1) How to set up the game2) How to code it3) How to optimize it <- You are here

Windows 8 PC Hardware Diversity

GPU Hardware EvolutionYear Version Defining Feature1996 DirectX3 Hardware rasterization1997 DirectX5 2 Shading options to choose from1998 DirectX6 Multi-texture operations1999 DirectX7 Vertex Processing in hardware2000 DirectX8 Programmable Shaders: Vertex and Pixel2001 DirectX8.1 Longer shaders2002 DirectX9 High Level Shading Language, 32 instr2003 DirectX9c 1000s of instructions per shader2006 DirectX10 Geometry shader, Consistent shader models2009 DirectX11 Compute Shader, Tessellation

Before DirectX

After

DirectX9 HardwareVertex shadersPixel shaders8 Textures4 Render TargetsCube mapsVolume texturesAnisotropic filteringAntialiasingHDR renderingTexture compression

DirectX 10 HardwareVertex shadersPixel shaders8 Textures4 Render TargetsCube mapsVolume texturesAnisotropic filteringAntialiasingHDR renderingTexture compression

Geometry shadersStream out128 Textures per shader8 Render TargetsIntegers in shadersVertex texturesShader samplingConstant buffersAlpha-to-coverageBasic DirectComputeAsync resource creation

DirectX 11 HardwareVertex shadersPixel shaders8 Textures4 Render TargetsCube mapsVolume texturesAnisotropic filteringAntialiasingHDR renderingTexture compression

Geometry shadersStream out128 Textures per shader8 Render TargetsIntegers in shadersVertex texturesShader samplingConstant buffersAlpha-to-coverageBasic DirectComputeAsync resource creation

Full DirectComputeRandom access writesTessellation shadersNew compression formatsShader linkage

Feature Levels

Direct3D 11 provides a uniform interface to access hardware capabilities Feature Levels map to hardware capabilitiesFeature_Level_9 DirectX 9 HardwareFeature_Level_10 DirectX 10 HardwareFeature_Level_11 DirectX 11 Hardware

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 );

Development StrategyDevelop on DirectX 11 hardwareTarget Feature_Level_9 and scale upInclude calibration code in game to dynamically configure for current hardwareBe aware of Feature Level differencesTest by restricting Feature LevelTest on multiple PCs

DirectX Control Panel

Balancing Act

Chapter 1/4

Features vs Performance

DirectX 9 DirectX 10

DirectX 10.1

DirectX 11

DirectX 11.1

Rela

tive P

erf

orm

ance

Opposing Directions

Prune features and image quality to meet performance goals on low-end hardware

Add features and image quality to differentiate your app on high-end hardware

Development Strategy

Develop on DirectX 11 hardwareTarget Feature_Level_9 and scale upInclude calibration code in game to dynamically configure for current hardwareAdjust to maintain performance

Be aware of Feature Level differencesTest by restricting Feature LevelTest on multiple PCs

Differentiation

Increase Visual QualityHigher resolution texturesUse bump maps

Texture Quality Control

Balance visual quality with performanceScale back on size via mipmap levelsUse block-compressed texture formatsLoader code skips mip levels 512 x 512

256 x 256

1024 x 1024

Optimization Techniques

Tune Anisotropic filter qualitySimple scalar value

MultiSampling AntiAliasing (MSAA)Reduce sample count to maintain frame rate

Render to a lower resolution and scale up for final imageFor best image quality, do not scale 2D text

GeometryFeature_Level_11 – use tessellation for more polygon count controlConsider lower-resolution (lower vertex count) meshes

Basic Performance ChecksBe sure you are not setting state and loading data that doesn’t change every frameSet breakpoint in the render codeWe’ve seen some apps drawing twice per frame

Make sure that the game loop routines are still in the right orderCheck to see if you are CPU bound, or GPU bound.If GPU, check to see if you are fill-rate or vertex bound.

Use PIX

PIX is a profiler mode for Visual Studio 11You can use it to step-through DirectX API callsAnd display:

event historypixel historyDX rendering pipelinethe DX object table, andcall stacks

More Optimizations

Chapter 3/4

More OptimizationsPure performance helps low-end hardwareBut if image quality is not impacted, high-end hardware benefits too

Minimum Precision is a new capability in Windows 8 HLSL

Minimum PrecisionReduce the number of bits of precision in shader calculationsHints to the graphics driver where optimizations can be doneSpecifies minimum rather than actual precisionmin16floatmin12int 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

Chapter 2/4

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 StrategiesAvoid mid-scene flushesAvoid swapping back and forth between RenderTargetsUse scissors when updating small portions of a RenderTargetUse DISCARD and NO_OVERWRITE when possible

Tile-based Rendering OptimizationsGPUs 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

Recommendations

Chapter 4/4

Conclusion

Windows 8 Runs on the broadest graphics hardware diversity everDesigned 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 for Indie Devs

Design for Feature_Level_9Adjust at runtime for actual Feature LevelUse advanced features to differentiate when availableDynamically calibrate for smooth performance

Use new Direct3D 11 features to better utilize hardware Minimum precisionTile-based rendering optimizations

Time to ActBiggest opportunity. Ever.

Windows 8 Consumer Preview is now available.

Check out the store.

Go build great games.

http://dev.windows.com

Q & A

© 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.

© 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.