1 / 38

Advanced Graphics Functionality on Windows Using DirectX

CL14. Advanced Graphics Functionality on Windows Using DirectX. Michael Oneppo Program Manager Microsoft Corporation. What is Advanced Graphics?. Superior 2D Rendering Performance Interoperating With Other Technologies. 2D Performance. Performance and DirectX.

job
Download Presentation

Advanced Graphics Functionality on Windows Using DirectX

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. CL14 Advanced Graphics Functionality on Windows Using DirectX Michael Oneppo Program Manager Microsoft Corporation

  2. What is Advanced Graphics? Superior 2D Rendering Performance Interoperating With Other Technologies

  3. 2D Performance

  4. Performance and DirectX • Direct2D built atop Direct3D 10 • Allocation overhead in Direct3D 10 is high Reduce: Controlling scene complexity Recycle: Repurposing already created resources Reuse: Caching intermediate data to reduce GPU work

  5. Performance and DirectX • Fill-rate bound vs. scene complexity-bound • Improving fill-rate bound cases • Improving complexity-bound cases Reduce: Controlling scene complexity

  6. Managing Scene Complexity • Smaller render target improves performance? • Fill rate bound Scene Complexity Fill Rate

  7. Improving Fill-Rate Bound Cases • Reduce render target size • Find the exact number of pixels you need to render to • Pay attention to over-draw • Rendering elements that aren’t visible • Occlusion • Clipping

  8. Occlusion & Clipping

  9. Quality vs. Performance • Scene complexity is increased by: • Anti-aliasing • Re-rendering of elements • Complex brushes & effects • Sophisticated geometries

  10. Performance and DirectX • A8 resources and grayscale caching • Mesh & mesh caching Reuse: Caching intermediate data to reduce GPU work

  11. A8 Resources • Great way to cache text, opacity maps, or otherwise grayscale content • Use CreateCompatibleRenderTarget with DXGI_PIXEL_FORMAT_A8_UNORM • Use FillOpacityMask to draw any A8 surface to a render target

  12. Text Animation Sample demo A8 Resources

  13. DirectWrite Performance: Fonts vs. Font Faces • IDWriteFontFace is the full font reference • Loads a lot of information on the font • Useful in measuring text • Querying text features • Assigning a font • IDWriteFont is a lightweight interface for getting info about a font • IDWriteFont is faster to load and takes up less memory • Useful when just listing the fonts on a system

  14. Caching Meshes • ID2D1Mesh represents (aliased) triangles • Direct2D can render these very quickly • ID2D1Mesh::Open returns an ID2D1TessellationSink • Pass this to the ID2DGeometry::Tessellate function to fill the mesh. • Use FillMesh to draw it • Manually implement the ID2D1TessellationSink if you want to see the triangles • Best way to transfer geometry to Direct3D.

  15. Geometry Realization Sample demo Caching Meshes

  16. Performance and DirectX • Surface size and performance • Using tiling or an “atlas” Recycle: Repurposing already created resources

  17. Bigger Surfaces • Seems counter-intuitive • Favor multi-purpose, larger textures over single use, smaller textures • Still only allocate what you need • Minimum size 64Kb • For 24 bpp bitmaps, this is about 150x150 • Recommended making 256x256 your global minimum

  18. Surface Size • Maximum size • Varies per card • Reasonable to assume 2048x2048, many modern cards support 4096x4096 • Find out using ID2D1RenderTarget:: GetMaximumBitmapSize() • Size is in pixels

  19. Atlasing 1024 px 1 3 2 1 5 4 2 3 2 1 4 3 5 4 5 256 px

  20. Using an Atlas • You should create an “AtlasBitmap” class or struct • Contains: • Reference to bitmap (pointer in C++) • Offset in X,Y • Size • Provides you everything you need to use the DrawBitmap function • Update atlas contents using the CopyFromBitmap function

  21. List View Sample demo Atlas Creation and Use

  22. DirectX Interoperability • Understanding Direct2D fallback • Direct2D and GDI • Direct2D and Direct3D

  23. Understanding Direct2D Fallback • Direct2D natively runs on Direct3D 10-class hardware • Utilizes Direct3D 10 Level 9 to run on Direct3D 9-class hardware • For very low end machines, Direct2D has a software fallback • If render target creation fails, pass in the flag D2D1_RENDER_TARGET_TYPE_SOFTWARE

  24. Rendering D2D Content to an HDC ID2D1Factory::CreateDCRenderTarget( D2D1_RENDER_TARGET_PROPERTIES *rtProperties, ID2D1DCRenderTarget **dcRenderTarget ); ID2D1DCRenderTarget::BindDC( HDC hDC, RECT *pSubRect);

  25. GDI/Direct2D Recommendations • Make sure you’ve called EndDraw() before returning to GDI • Batch as much as possible • Do as much as you can in D2D before switching to GDI and vice versa • Minimize the size of the updated rects • Reduces the amount of memory that needs to be copied

  26. Render D2D Content to an ID3D10Texture2D ID2D1Factory::CreateDxgiSurfaceRenderTarget( IDXGISurface *dxgiSurface, D2D1_RENDER_TARGET_PROPERTIES *rtProperties, ID2D1RenderTarget **renderTarget );

  27. Going the Other Way (D3D10  D2D) ID2D1RenderTarget::CreateSharedBitmap( REFIID riid, void *data, D2D1_BITMAP_PROPERTIES *bitmapProperties, ID2D1Bitmap **bitmap ); • Must pass an IDXGISurface into data • bitmapProperties has to match the format of the DXGI surface • Alpha is not included in this check

  28. Direct2D/Direct3D Recommendations • Device must support BGRA, D3D10.1 • Falling back to Direct3D10Level9 can mitigate this • Special flag for device creation: D3D10_CREATE_DEVICE_BGRA_SUPPORT • Render static content once and cache (sound familiar?) • Minimize transitions between Direct3D and Direct2D by batching as much as possible (also sound familiar?)

  29. 3D Text demo Putting it All Together

  30. Direct2D Debug Layer • Intercepts calls from Direct2D • Provides critical usage information as well as handy performance information • Something failed? The debug layer will tell you. • Leaves operation of Direct2D completely unchanged • May be a minor performance difference

  31. Turning on the Debug Layer • D2D1_FACTORY_OPTIONS options; • options.debugLevel = • D2D1_DEBUG_LEVEL_INFORMATION; • hr = D2D1CreateFactory( • D2D1_FACTORY_TYPE_SINGLE_THREADED, • options, • &m_pD2DFactory );

  32. Layers vs. Clips • Only use layers when alpha-blending or non-rectangular content is needed. • Clips are faster when you don’t need alpha blending or you have rectangular content • PushAxisAlignedClip/PopAxisAlignedClip • Debug layer helps you: • D1111: Using Layer When Clip Is Sufficient

  33. The Platform Update for Windows Vista • Down-level availability of key Windows 7 features on Windows Vista • Available on Windows Update • More information: • http://support.microsoft.com/kb/971644

  34. Resources • DirectX on MSDN: • http://msdn.microsoft.com/directx • Windows 7 SDK: • http://msdn.microsoft.com/windows • August 2009 DirectX SDK: • http://msdn.microsoft.com/directx/sdk • All Code Samples on Code Gallery: • http://code.msdn.microsoft.com/d2dlistview • http://code.msdn.microsoft.com/d2dtextanimation • http://code.msdn.microsoft.com/d2dgeometryreali • http://code.msdn.microsoft.com/d2dinteractive3dtext • Debug Layer on Code Gallery: • http://code.msdn.microsoft.com/Direct2DTools

  35. YOUR FEEDBACK IS IMPORTANT TO US! Please fill out session evaluation forms online at MicrosoftPDC.com

  36. Learn More On Channel 9 • Expand your PDC experience through Channel 9 • Explore videos, hands-on labs, sample code and demos through the new Channel 9 training courses channel9.msdn.com/learn Built by Developers for Developers….

More Related