When Silverlight3 was released, my friends and I were excited by the new GPU hardware acceleration, so we started a reckless overnight test, but the result was really disappointing. Yes, no matter how you modify your code, you can't feel a noticeable performance boost. The next day, the word GPU gradually away from my mind. Until a few days ago, after interacting with a friend, I was again asked to test the idea of GPU hardware acceleration in SILVERLIGHT4. It is an accident do not know, a measure startled. In the recent days of Silverlight, I believe this article and test results will become the most powerful in the development of Silverlight in the spring brother! Yes, Faith is eternal life!
Now that you want to use GPU hardware acceleration, we first need to know its definition principle and function, you can refer to MSDN's related introduction, below is my core content of streamlining:
GPU hardware acceleration is the behavior of caching a visual element or visual tree of an element as a bitmap surface using a composite cache. This can lead to significant performance improvements for some scenarios. With cache compositing, you can cache a visual element as a bitmap after it is first rendered. After an object or object tree is cached as a bitmap, when the application refreshes, it no longer passes the render phase, but only renders the cached bitmap. This kind of cached bitmap exchange can take advantage of the hardware acceleration provided in the user's GPU, which greatly improves the performance of some scenarios.
Next, to start the GPU hardware acceleration in Silverlight, you must first set the parameters:
1 Add the parameter <param name= "Enablegpuacceleration" value= "true" in the Silverlight Page object/>
2 set Cachemode values for Uelement objects that need to be accelerated using GPU, such as:
Xaml:
<MediaElement>
<MediaElement.CacheMode>
<BitmapCache RenderAtScale="4"/>
</ MediaElement.CacheMode>
</MediaElement>
or C #:
MediaElement mediaElement = new MediaElement () {CacheMode = new BitmapCache() { RenderAtScale = 4 } };
Where the Renderatscale in the Bitmapcache cache indicates the scale used to render the object as a cached bitmap. If you specify it as a negative number, an error is raised. The default value is 1. Note: The smaller the Renderatscale CPU consumption, the less memory footprint, that is, the better performance! In addition, the bitmap renders in a fuzzy state when the Renderatscale is between 0 and 1. Perhaps a friend will ask: game development we can set it to 0.8 or so, not only blur the edge and lose too much pixel, but also improve performance, of course, this has yet to be further tested.
Finally, we have to understand the scope of GPU hardware acceleration. For the current SILVERLIGHT4 version, we can accelerate GPU hardware for transform, RectangleGeometry, Opacity, Visibility, projection, Deepzoom and other objects. The objects derived from transform include: RotateTransform, ScaleTransform, SkewTransform, TranslateTransform, MatrixTransform, TransformGroup, and projection (three-dimensional perspective)-derived objects contain planeprojection and matrix3dprojection.
It is worth mentioning that Silverlight's GPU hardware acceleration support for projection and Deepzoom was added in version 4, from which I We can predict the future development trend of Siverlight: web3d hardware acceleration will be the perfect support in the Silverlight successor version!
These are the theoretical highlights of the GPU hardware acceleration in Silverlight, followed by my demo and evaluation of the GPU hardware acceleration feature in the test Silverligh4, which I believe is the beginning of the most exciting moment in this article:
Demo Online Demo Address: http://silverfuture.cn/Demos/demo1.html
Here is my test environment and results---------------------------------------
Machine configuration: