Partager via


Silverlight Hardware Acceleration

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Caching visual elements as bitmaps allows you to take advantage of hardware acceleration. 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.

Shows how caching can improve performance.

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

NoteNote:

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.

Diagram showing hardware accleration process.

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.

NoteNote:

Hardware acceleration is only enabled on Windows Vista, Windows 7, and Windows XP. On Windows XP, NVidia, ATI, Intel cards with a driver date post November 2004 is required for hardware acceleration.

Version Notes

Note that Silverlight 3 applications cannot hardware accelerate perspective transforms (3-D effects) or Deep Zoom. See 3-D Effects (Perspective Transforms), and Deep Zoom for more information.