achieving high performance 2d graphics with direct2d n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Achieving high performance 2D graphics with Direct2D PowerPoint Presentation
Download Presentation
Achieving high performance 2D graphics with Direct2D

Loading in 2 Seconds...

play fullscreen
1 / 51

Achieving high performance 2D graphics with Direct2D - PowerPoint PPT Presentation


  • 938 Views
  • Uploaded on

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?

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Achieving high performance 2D graphics with Direct2D' - liz


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
achieving high performance 2d graphics with direct2d
PLAT-769T

Achieving high performance 2D graphics with Direct2D

Megha Jain

Program Manager II

Microsoft Corporation

agenda
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?
how to
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
how to1
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
caching techniques
Caching techniques
  • Full scene caching using a color bitmap
  • Per primitive caching using an A8 bitmap and FillOpacityMask() API
full s cene caching
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);
full s cene caching1
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());
per primitive caching using fillopacitymask
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
per primitive caching using fillopacitymask1
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);
per primitive caching using fillopacitymask2
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);
handling s croll animation
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;}
printing a nd caching
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
how to2
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
clipping t o a rbitrary g eometry layers
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());
clipping t o a rbitrary geometry fillgeometry
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());
use id2d1layer instead of intermediate surfaces whenever possible use null layers when possible
Use ID2D1Layer instead of intermediate surfaces whenever possible.Use NULL layers when possible
how to3
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
draw t ext fast
Draw text fast

Cache text layout

Explicitly set text rendering mode to grayscale

Cache text

cache t ext layout
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());
grayscale t ext r endering mode
GrayScaletext rendering mode
  • Set the rendering mode to grayscale explicitly
    • SetTextAntiAliasMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE)
how to4
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
render direct2d e ffects fast
Render Direct2D effects fast

Cache effect output

Group rendering of effects together

caching effect o utput
Caching effect output
  • Use ID2D1Properties::SetValue(D2D1_PROPERTY_CACHED, TRUE)
grouping effect r endering
Grouping effect rendering

Button 2

Button 1

Button 3

Button 4

render b utton text
Render button text

Button 2

Button 1

Button 3

Button 4

how to5
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
enable multi threaded o ptimizations
Enable multi-threaded optimizations
  • m_d2dDevice->CreateDeviceContext(
  • D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS,
  • m_d2dContext);
how to6
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
mixing 2d and 3d content
Mixing 2D and 3D content
  • Reduce state transitions
  • Minimize switching between 2D and 3D drawing
recap
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
wrap up
Wrap up
  • Assess unique app performance needs…profile
  • Apply performance tips and techniques
  • Go build your fastest 2D graphics app!
related sessions
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
further reading and documentation
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
feedback and q uestions http forums dev windows com session f eedback http bldw in sessionfeedback
thank you

Feedback and questions http://forums.dev.windows.com

Session feedbackhttp://bldw.in/SessionFeedback

slide50

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