faster 2d graphics on windows 8 your app will run faster on windows 8

Download Faster 2D graphics on Windows 8 Your app will run faster on Windows 8

Post on 28-Dec-2015

216 views

Category:

Documents

1 download

Embed Size (px)

TRANSCRIPT

PLAT-769T: Achieving high performance 2D graphics with Direct2D

Achieving high performance 2D graphics with Direct2DMegha JainProgram Manager IIMicrosoft CorporationPLAT-769Twww.buildwindows.com9/15/2011 4:22 PM1 2010 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.AgendaWhat makes your 2D graphics app run faster in Windows 8?

What are the performance points your app might be sensitive to?

How to make your app deliver the best graphics performance with Direct2D?www.buildwindows.com2Faster 2D graphics on Windows 83BasicTextAnimation sampledemowww.buildwindows.com4Faster text renderingwww.buildwindows.com5GeometryRealization sampledemowww.buildwindows.com6Faster geometry renderingwww.buildwindows.com7Your app will run faster on Windows 8www.buildwindows.com8DirectX magazine sampledemowww.buildwindows.com9Think about opportunities for app-specific optimizations.www.buildwindows.com10How to write the fastest Direct2D app11How toAnimate complex content fastClip content to an arbitrary shape fastDraw text fastRender Direct2D effects fastScale performance on multiple coresDraw mixed 2D/3D content fastwww.buildwindows.com12How toAnimate complex content fastClip content to an arbitrary shape fastDraw text fastRender Direct2D effects fastScale performance on multiple coresDraw mixed 2D/3D content fastwww.buildwindows.com13Caching techniquesFull scene caching using a color bitmap

Per primitive caching using an A8 bitmap and FillOpacityMask() APIwww.buildwindows.com14Full scene caching// create a bitmapm_d2dContext->CreateBitmap(size, nullptr, 0,D2D1::BitmapProperties(D2D1_BITMAP_OPTIONS_TARGET,D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM,D2D1_ALPHA_MODE_PREMULTIPLIED),dpiX, dpiY),&sceneBitmap);// preserve pre-existing targetComPtr oldTarget;m_d2dContext->GetTarget(&oldTarget);

15Full scene caching// render to the sceneBitmapm_d2dContext->SetTarget(sceneBitmap.Get());m_d2dContext->BeginDraw();m_d2dContext->EndDraw();

// render sceneBitmap to oldTargetm_d2dContext->SetTarget(oldTarget.Get());m_d2dContext->DrawBitmap(sceneBitmap.Get());

16Per primitive caching using FillOpacityMask() Reuse pre-rendered static geometry/text

Works for caching anti-aliased content

Works with changing brush types

Create the bitmap alpha only

17Per primitive caching using FillOpacityMask() // create an opacity bitmapm_d2dContext->CreateBitmap(size, nullptr, 0,D2D1::BitmapProperties(D2D1_BITMAP_OPTIONS_TARGET,D2D1::PixelFormat(DXGI_FORMAT_A8_UNORM,D2D1_ALPHA_MODE_PREMULTIPLIED),dpiX, dpiY),&opacityBitmap);// preserve pre-existing targetComPtr oldTarget;m_d2dContext->GetTarget(&oldTarget);

18Per primitive caching using FillOpacityMask() // render to the opacityBitmapm_d2dContext->SetTarget(opacityBitmap.Get());m_d2dContext->BeginDraw();m_d2dContext->EndDraw();

// call FillOpacityBitmap() m_d2dContext->SetTarget(oldTarget.Get());m_d2dContext->FillOpacityMask(opacityBitmap.Get(),m_contentBrush().Get(),D2D1_OPACITY_MASK_CONTENT_GRAPHICS);

19// enables rasterizing only the changed contentIDXGISwapChain1::Present1(UINT SyncInterval, UINT PresentFlags, DXGI_PRESENT_PARAMETERS* pPresentParameters);

struct DXGI_PRESENT_PARAMETERS{UINT DirtyRectsCount;RECT* pDirtyRects;RECT* pScrollRect;POINT* pScrollOffset;}

Handling scroll animation20Printing and cachingConsistent API for both render and print path

Use command list for caching printing commands

Keep the same drawing path for both screen and printwww.buildwindows.com21Use bitmaps for caching display outputUse command list for caching print output.www.buildwindows.com22How toAnimate complex content fastClip content to an arbitrary shape fastDraw text fastRender Direct2D effects fastScale performance on multiple coresDraw mixed 2D/3D content fastwww.buildwindows.com23Clipping to an arbitrary shape

www.buildwindows.com24// create the layer resourceComPtr m_layer;m_d2dContext->CreateLayer(&m_layer);

// render to the layer with the clipping geometrym_d2dContext->PushLayer(D2D1::LayerParameters(boundsRect,geometricMask),m_layer.Get());

Clipping to arbitrary geometry- layers25Clipping to arbitrary geometry FillGeometry()// create opacity bitmap and render content

// create opacity brush from the opacity bitmap

// call FillGeometry() by passing in the clip geometry and the opacity brush to m_d2dContext->FillGeometry( clipGeometry.Get(),brush.Get(),opacityBrush.Get()); 26Use ID2D1Layer instead of intermediate surfaces whenever possible.Use NULL layers when possible www.buildwindows.com27How toAnimate complex content fastClip content to an arbitrary shape fastDraw text fastRender Direct2D effects fastScale performance on multiple coresDraw mixed 2D/3D content fastwww.buildwindows.com28Draw text fastCache text layout

Explicitly set text rendering mode to grayscale

Cache text

www.buildwindows.com29// Create text layout oncem_dWriteFactory->CreateTextLayout(text,length,m_textFormat.Get(),maxWidth, maxHeight,&m_textlayout);

// draw the text layout repeatedlym_d2dContext->DrawTextLayout(origin, m_textlayout.Get(),brush.Get()); Cache text layout30GrayScale text rendering modeSet the rendering mode to grayscale explicitlySetTextAntiAliasMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE)

www.buildwindows.com31Use full scene or per primitive bitmap caching as described in previous slides.www.buildwindows.com32How toAnimate complex content fastClip content to an arbitrary shape fastDraw text fastRender Direct2D effects fastScale performance on multiple coresDraw mixed 2D/3D content fastwww.buildwindows.com33Render Direct2D effects fastCache effect output

Group rendering of effects together

www.buildwindows.com34Caching effect outputUse ID2D1Properties::SetValue(D2D1_PROPERTY_CACHED, TRUE)

www.buildwindows.com35Grouping effect renderingButton 1Button 4Button 3Button 2www.buildwindows.com36Render glow effect firstwww.buildwindows.com37Render the buttonswww.buildwindows.comRender button textButton 1Button 4Button 3Button 2www.buildwindows.com39How toAnimate complex content fastClip content to an arbitrary shape fastDraw text fastRender Direct2D effects fastScale performance on multiple coresDraw mixed 2D/3D content fastwww.buildwindows.com40m_d2dDevice->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS,m_d2dContext);

Enable multi-threaded optimizations41How toAnimate complex content fastClip content to an arbitrary shape fastDraw text fastRender Direct2D effects fastScale performance on multiple coresDraw mixed 2D/3D content fastwww.buildwindows.com42

Mixing 2D and 3D contentReduce state transitions

Minimize switching between 2D and 3D drawingwww.buildwindows.com44RecapAnimate complex content fastClip content to an arbitrary shape fastDraw text fastRender Direct2D effects fastScale performance on multiple coresDraw mixed 2D/3D content fastwww.buildwindows.com45Wrap upAssess unique app performance needsprofile

Apply performance tips and techniques

Go build your fastest 2D graphics app!www.buildwindows.com46Related sessions[PLAT-766T] Introduction to DirectX for Metro style apps[PLAT-750T] Build your first Metro style game[PLAT-752T] Tuning GPU usage for any form factor[PLAT-770T] Create cool image effects with Direct2D[PLAT-754T] From touch to gamepads: master player input in your Metro style game[SAC-217T] Graphics on the server[TOOL-761T] A lap around DirectX game development toolswww.buildwindows.com47Further reading and documentationChannel 9 PDC10 talk: Adopting D2D and Dwrite for hardware acceleration in Native Windows Applications

Channel 9 PDC=09 talk: Advanced graphics functionality using DirectX

www.buildwindows.com48Feedback and questions http://forums.dev.windows.com

Session feedbackhttp://bldw.in/SessionFeedback

thank youwww.buildwindows.com

2011 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.9/15/2011 4:22 PM50 2011 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 guar