Silverlight Tip of the Day #104 – How to Enable GPU Acceleration

This item was filled under [ 新闻News ]

With the release of Silverlight 3 Beta 1 GPU (Graphics Processing Unit) acceleration (or hardware acceleration) is now available. The GPU is a processor attached to your graphics card that is generally used for calculating floating point operations. In addition, it contains a number of graphics primitives that when used will save you a lot of CPU time.

By default this option is disabled and to use it you must enable it both on your Silverlight control/plug-in as well as any of the controls you want to leverage it.

To enable it on your Silverlight control open your web page that hosts the Silverlight control.

For HTML modify the Silverlight control to include the following param:

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

For ASPX add the following attribute:

<asp:Silverlight ID=”Silverlight1″ EnableGPUAcceleration=”true” runat=”server” Source=”~/ClientBin/MyApp.xap” MinimumVersion=”3.0.40307.0″ Width=”100%” Height=”100%” />

Now, to apply it to a control you will need to add CacheMode=”BitmapCache” to the control. The following example shows you how to add it to an Image control:

<Image CacheMode=”BitmapCache” Source=”MyImage.png”></Image>

Currently BitmapCache is the only option. What this does is it causes visual elements (and all their children) to be cached as bitmaps after they have already been rendered. Once cached, your application can bypass the expensive rendering phase for the cached elements and just display them.

If you want to test out what is being cached in your application add the following attribute to your Silverlight control:

<asp:Silverlight EnableCacheVisualization=”true” ID=”Silverlight1″EnableGPUAcceleration=”true” runat=”server” Source=”~/ClientBin/MyAPp.xap”MinimumVersion=”3.0.40307.0″ Width=”100%” Height=”100%” />

Uncached objects will appear tinted where as cached objects will not be tinted.

This feature is supported on:

  1. Windows: Both full screen and non-full screen
  2. Mac: Full screen only.

This feature should be used when the following are occurring to your control:

  1. Transformations (translating, rotating, stretching, etc.).
  2. Clipping.
  3. Blending.

 

Thank you, 
–Mike Snow 

喜欢这篇文章的人还喜欢。。。

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Comment

Anti-spam text: (Required) *
To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text. Click to hear an audio file of the anti-spam word