1 / 51

Achieving high performance 2D graphics with Direct2D

PLAT-769T. Achieving high performance 2D graphics with Direct2D. Megha Jain Program Manager II Microsoft Corporation. Agenda. What makes your 2D graphics app run faster in Windows 8? What are the performance points your app might be sensitive to?

liz
Download Presentation

Achieving high performance 2D graphics with Direct2D

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PLAT-769T Achieving high performance 2D graphics with Direct2D Megha Jain Program Manager II Microsoft Corporation

  2. Agenda • What 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?

  3. Faster 2D graphics on Windows 8

  4. demo BasicTextAnimation sample

  5. Faster text rendering

  6. demo GeometryRealization sample

  7. Faster geometry rendering

  8. Your app will run faster on Windows 8

  9. demo DirectX magazine sample

  10. Think about opportunities for app-specific optimizations.

  11. How to write the fastest Direct2D app

  12. How to… • Animate complex content fast • Clip content to an arbitrary shape fast • Draw text fast • Render Direct2D effects fast • Scale performance on multiple cores • Draw mixed 2D/3D content fast

  13. How to… • Animate complex content fast • Clip content to an arbitrary shape fast • Draw text fast • Render Direct2D effects fast • Scale performance on multiple cores • Draw mixed 2D/3D content fast

  14. Caching techniques • Full scene caching using a color bitmap • Per primitive caching using an A8 bitmap and FillOpacityMask() API

  15. Full scene caching • // create a bitmap • m_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 target • ComPtr<ID2D1Image> oldTarget; • m_d2dContext->GetTarget(&oldTarget);

  16. Full scene caching • // render to the sceneBitmap • m_d2dContext->SetTarget(sceneBitmap.Get()); • m_d2dContext->BeginDraw(); • … • m_d2dContext->EndDraw(); • // render sceneBitmap to oldTarget • m_d2dContext->SetTarget(oldTarget.Get()); • m_d2dContext->DrawBitmap(sceneBitmap.Get());

  17. Per 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

  18. Per primitive caching using FillOpacityMask() • // create an opacity bitmap • m_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 target • ComPtr<ID2D1Image> oldTarget; • m_d2dContext->GetTarget(&oldTarget);

  19. Per primitive caching using FillOpacityMask() • // render to the opacityBitmap • m_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);

  20. Handling scroll animation • // enables rasterizing only the changed content • IDXGISwapChain1::Present1(UINT SyncInterval, UINT PresentFlags, DXGI_PRESENT_PARAMETERS* pPresentParameters); • structDXGI_PRESENT_PARAMETERS{ UINT DirtyRectsCount; RECT* pDirtyRects; RECT* pScrollRect; POINT* pScrollOffset;}

  21. Printing and caching • Consistent API for both render and print path • Use command list for caching printing commands • Keep the same drawing path for both screen and print

  22. Use bitmaps for caching display outputUse command list for caching print output.

  23. How to… • Animate complex content fast • Clip content to an arbitrary shape fast • Draw text fast • Render Direct2D effects fast • Scale performance on multiple cores • Draw mixed 2D/3D content fast

  24. Clipping to an arbitrary shape

  25. Clipping to arbitrary geometry- layers • // create the layer resource • ComPtr<ID2D1Layer> m_layer; • m_d2dContext->CreateLayer(&m_layer); • // render to the layer with the clipping geometry • m_d2dContext->PushLayer( • D2D1::LayerParameters( • boundsRect, • geometricMask), • m_layer.Get());

  26. Clipping 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());

  27. Use ID2D1Layer instead of intermediate surfaces whenever possible.Use NULL layers when possible

  28. How to… • Animate complex content fast • Clip content to an arbitrary shape fast • Draw text fast • Render Direct2D effects fast • Scale performance on multiple cores • Draw mixed 2D/3D content fast

  29. Draw text fast Cache text layout Explicitly set text rendering mode to grayscale Cache text

  30. Cache text layout • // Create text layout once • m_dWriteFactory->CreateTextLayout( • text, • length, • m_textFormat.Get(), • maxWidth, maxHeight, • &m_textlayout); • // draw the text layout repeatedly • m_d2dContext->DrawTextLayout(origin, • m_textlayout.Get(), • brush.Get());

  31. GrayScaletext rendering mode • Set the rendering mode to grayscale explicitly • SetTextAntiAliasMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE)

  32. Use full scene or per primitive bitmap caching as described in previous slides.

  33. How to… • Animate complex content fast • Clip content to an arbitrary shape fast • Draw text fast • Render Direct2D effects fast • Scale performance on multiple cores • Draw mixed 2D/3D content fast

  34. Render Direct2D effects fast Cache effect output Group rendering of effects together

  35. Caching effect output • Use ID2D1Properties::SetValue(D2D1_PROPERTY_CACHED, TRUE)

  36. Grouping effect rendering Button 2 Button 1 Button 3 Button 4

  37. Render glow effect first

  38. Render the buttons

  39. Render button text Button 2 Button 1 Button 3 Button 4

  40. How to… • Animate complex content fast • Clip content to an arbitrary shape fast • Draw text fast • Render Direct2D effects fast • Scale performance on multiple cores • Draw mixed 2D/3D content fast

  41. Enable multi-threaded optimizations • m_d2dDevice->CreateDeviceContext( • D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS, • m_d2dContext);

  42. How to… • Animate complex content fast • Clip content to an arbitrary shape fast • Draw text fast • Render Direct2D effects fast • Scale performance on multiple cores • Draw mixed 2D/3D content fast

  43. Mixing 2D and 3D content • Reduce state transitions • Minimize switching between 2D and 3D drawing

  44. Recap • Animate complex content fast • Clip content to an arbitrary shape fast • Draw text fast • Render Direct2D effects fast • Scale performance on multiple cores • Draw mixed 2D/3D content fast

  45. Wrap up • Assess unique app performance needs…profile • Apply performance tips and techniques • Go build your fastest 2D graphics app!

  46. Related 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 tools

  47. Further reading and documentation • Channel 9 PDC’10 talk: Adopting D2D and Dwrite for hardware acceleration in Native Windows Applications • Channel 9 PDC=09 talk: Advanced graphics functionality using DirectX

  48. thank you Feedback and questions http://forums.dev.windows.com Session feedbackhttp://bldw.in/SessionFeedback

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

More Related