Silverlight Hardware Acceleration


Caching visual elements as bitmaps allows you to take advantage of hardware accelaration. Once an object or tree of objects has been cached as a bitmap, it no longer goes through the render phase as the application refreshes, rather, the cached bitmap is rendered. The cached bitmap swapping is able to take advantage of hardware acceleration from the user’s GPU which can yield significant performance improvements for some scenarios.


 


 


 


 


 


Hardware acceleration can benefit performance for the following scenarios:



  • Blending two static layers using opacity. For example, you can mark both trees of objects as cached, and the opacity animation will be executed using Hardware Acceleration.

  • Transforming objects (e.g. stretching and rotating).

 


Note: Caching objects can hurt performance if you misuse it. See How Hardware Acceleration Works below.


How to Use Hardware Acceleration


In order to cache objects and allow them to take advantage of hardware acceleration, do the following:


 


1. Enable composition caching at the plug-in level by setting the EnableGPUAcceleration parameter to “true”.


 


<param name=”EnableGPUAcceleration” value=”true” />


 


2. You can now enable GPU acceleration on the element(s) you wish to cache by specifying a CacheMode value of BitmapCache on the object or container of objects.


 


<StackPanel CacheMode=”BitmapCache” … />


 


You can cache a single UIElement or, as in the StackPanel example above, a container UIElement and all of its children.


 


 


How Hardware Acceleration Works


 


The illustration below summarizes how Hardware Acceleration works.




 


Notice that not everything can be hardware accelerated. Effects like DropshadowEffect and OpacityMask can only be rendered by the software. Also, WriteableBitmap goes through its own rendering pipeline and therefore cannot take advantage of hardware acceleration.


 


When you Cache an object, you are creating multiple rendering surfaces in the VRAM which are then accelerated using the GPU. Other visible objects in your application that are not cached are rendered as surfaces in software. Your performance will be best if you can minimize the total number of rendering surfaces and get the hardware to do work where it can. Note that BitmapCache is the only supported cache-mode.

Comments (5)

  1. art_scott@msn.com says:

    Thanks, very helpful.

    Do you have any insight into "media" and HW GPU acceleration too?

  2. Jan.Sichula says:

    Hello everyone,

    today I was heavily experimenting with Silverlight 3 video player that was recommend on Silverlight SDK blog for having a SL 3 funcionality. My goal was to produce GPU accelerated player for our high quality (848×480, 16:9, 1500 kbit/s, VBR, VC-1) video publishing needs

    The player is mentioned here:

    http://blogs.msdn.com/silverlight_sdk/archive/2009/05/04/silverlight-video-player-source-code.aspx

    I was able to compile player with VS 2008 and SL 3 Tools for VS 2008. However, after many hours of toil, here are surprising results.

    The two biggest issues that I encountered are as follows.

    1. The accelerated version is slower than non-acceleration. Why and what to do now? I have followed all the advices. Green tint on controls but not on video area seems to indicate that GPU acceleration is on. Also I have the black box with numbers when I use EnableFrameRa-teCounter=true.

    2. The tint supposed to indicate non-accelerated areas is green in this case and not red as documented everywhere else. Why is that?

    I have tested on several machines both low end and high end with both AMD and Nvidia graphics. Results are same everywhere and the slower the machine the more of a slowdown with hardware acceleration.

    Please help, this is an unhappy situation. I am big fan of Silverlight but I have to admit to being disappointed. Can it be that you rushed out SL3 RTW out too quickly? Why not Beta 2, why not RC? Why such artificial dates like July 10 and not a quality driven release?

    Fellow Silverlight programmer,

    Jan Sichula

    (Slovak Republic)

    http://sichula.temelios.sk/ (English website for friends – family photos, videos and new-sletter archive)

  3. SergeyDev says:

    I’ve found this good explanation at last! Thank you.

  4. blu ray ripper says:

    There are cases where I have written that. 😀

  5. cocococo013 says:

    Thank you so much for this post, it is very kind of you!

    Blu-ray Ripper is an excellent Blu-ray disc ripper and Blu-ray movie ripper, that can help you rip movies from Blu-ray disc and convert to all popular video formats stored on your computer. You can also use it to rip Blu-ray into iTunes for your easy management and watching on iPod, iPhone, etc.

    more info:

    http://www.bluray-hd.net/