SpriteHand
Module Border
  Windows Phone 7 + Silverlight Performance
Module Border
Location: BlogsAndy's Blog    
Posted by: host 3/25/2010 1:48 PM


If you’re creating a graphics intensive application (such as a game) for Windows Phone 7 (WP7) using Silverlight, you’re going to want to maximize performance for both the emulator and your Silverlight code. Let’s look at some ways to maximize both of these.

WP7/Silverlight Graphics Performance

WP7 devices have a separate GPU which is optimized for handling graphics operations such as displaying, scaling, rotating, and 3D. Silverlight on WP7 has the ability to use that GPU, which can greatly increase graphics performance. It does this by allowing a “snapshot” of a visual, called a Bitmap Cache, to be handed over to the GPU for manipulation.

  • Storyboard Animations are Automatically GPU Accelerated.
    If you create a Storyboard animation on SL for WP7, it will automatically use the GPU when it can for displaying, scaling, rotating, and rectangular Clips.  There is nothing you need to do to enable this, it is automatic. This is kind of a “bonus feature” of Silverlight 3 on the Windows Phone (it is not available in desktop Silverlight 3 or Silverlight 4).

  • Procedural Animations need a CacheMode attribute.
    If you are moving elements via code, such as for a game, they will not be automatically GPU accelerated like a Storyboard. You need to add in a CacheMode attribute like so:

    <Canvas x:Name="cnvShip" CacheMode="BitmapCache"

    But make sure you add this only on elements that do not change visually. That is, imagine that you’re taking a snapshot of the element that is cached, and handing that over to the GPU. If anything changes inside that element’s visuals, then the cache will be invalidated and you’ll lose the advantages of caching.

  • Perspective 3D Transforms can be GPU Accelerated.
    If you use a PlaneProjection in a Storyboard, it will use the GPU. You can also apply a CacheMode=”BitmapCache” attribute to a 3D Transform and it will use the GPU. This is another “bonus feature” of Silverlight 3 on the Windows Phone (it is not available in desktop Silverlight 3 but is introduced in Silverlight 4).

  • Examine Graphics Metrics.
    We can get some good graphics metrics from Silverlight on WP7 by adding the following code:

    Application.Current.Host.Settings.EnableFrameRateCounter = true;

    This will show the following metrics at the top of the device window:


    A – Render Thread Framerate
    B – UI Thread Framerate
    C – Amount of Video Memory Used
    D – Total # of Textures Used
    E – Total # of Intermediate Textures Used

    Note that Silverlight on WP7 uses two separate threads, a Render thread for visuals, and a UI thread, to handle input and application logic. Seema Ramchandani gave a great talk detailing these counters at http://live.visitmix.com/MIX10/Sessions/CL60

  • See what’s Using the GPU.
    For performance, we want as many elements to be rendered by the GPU as possible. We can see what is rendered by the GPU by using the following code:

    Application.Current.Host.Settings.EnableCacheVisualization = true;

    When this is set, any elements that are NOT cached will have a colored tint to them. If an element appears its normal color then it IS being cached and handled by the GPU.

  • See What is Being Redrawn.
    For best performance, we want to minimize what is being redrawn on each frame. We can use the following setting in code:

    Application.Current.Host.Settings.EnableRedrawRegions = true;

    … which will show a ghost copy of the visual whenever it is redrawn. If you are seeing  a lot of redraws, and they are large portions of the UI, then maybe you can add some more CacheMode attributes so it is offloaded to the CPU. (Note that when something is handled by the GPU, you will NOT see any redraw regions).

Emulator Performance

Ensure the Emulator can use your Host’s GPU.
The Emulator can take advantage of the GPU on your computer to render graphics, greatly increasing its performance… but only if it meets a couple of requirements.

1.       Make sure your video card supports at least WDDM 1.1 and DirectX 10.

a.       From the Start Menu, select Run and enter dxdiag

b.      Go to the Display tab and ensure that the DDI Version and Driver Model are 10 or better and 1.1 or better, respectively.

c.       To be extra sure the Emulator will like your video card, create an XNA Windows Phone Game. This project template is a bit pickier with GPU support.

                                                               i.       Start up Visual Studio and create a new XNA Game Studio 4.0/Windows Phone Game.

                                                             ii.      Run the project. If you get the following error, then the Emulator will not support your GPU.

Deploy failed with the following error: The current display adapter does not meet the emulator requirements to run XNA Framework applications

… However, all is not lost. It could be that you just need to upgrade your video card drivers. Visit the site for your video card manufacturer and see if they have some newer bits (This one actually worked for me J)

Enable Virtualization in your BIOS

Support for Virtualization at the CPU level is provided on newer processors. This can significantly increase the speed of emulators, allowing them to talk more directly to the CPU, instead of a software layer. Because this is a CPU-level function, you need to go into your computer’s BIOS to enable it (it will normally be OFF by default, so you will need to switch it on).

1.       Reboot your computer and look for the magic BIOS key. It could be Ins, Del, a Function Key, it all depends on the BIOS version.

2.       Once inside the BIOS, look for a category named “Virtualization” or something to that effect. Switch all of those options on.

Summary

I’m sure there are some things here I missed or just didn’t know about, so please give me your comments. Here are a few links to other resources on the topics above:

Silverlight Performance on Windows Phone – Seema Ramchandani

WP7 Developer FAQ

Silverlight 3: GPU Acceleration + Bitmap Caching – My Blog

Permalink |  Trackback

Comments (3)   Add Comment
Re: Windows Phone 7 + Silverlight Performance    By Anonymous on 3/27/2010 1:12 AM
Great article. There were a couple things I didn't know about here.

Noticed you were missing one thing that I came across. Have you looked into the CompositeTransform recommendation from Microsoft? They mention to use that if you are doing multiple transformations. Mentioned in the performance section:

http://msdn.microsoft.com/en-us/library/ff426930%28VS.96%29.aspx

CompositeTransforms were added in Silverlight 4..and this is one of those things that WP7 is Silverlight 3+a little Silverlight 4.

-- Bart Czernicki

Re: Windows Phone 7 + Silverlight Performance    By Anonymous on 3/27/2010 10:16 AM
Thanks Bart. That's a great tip. I also was noticing that Blend 4 Beta is nice enough to use a CompositeTransform for you in a WP7 project.

-Andy

Re: Windows Phone 7 + Silverlight Performance    By Anonymous on 1/8/2012 10:59 PM
Hi,
Application.Current.Host.Settings.EnableCacheVisualization = true;

When this is set, any elements that are NOT cached will have a colored tint to them. If an element appears its normal color then it IS being cached and handled by the GPU.

-->
Not correct,
on wp7, cached = tinted





Title:
Comment:
Add Comment   Cancel 
Module Border Module Border
Module Border
  Subscribe
Module Border
RSS   Twitter
Module Border Module Border
Module Border
  Diversions
Module Border


PHYSAMAJIG
This Windows app was created using Physics Helper XAML, and the Farseer Physics Engine.
DOWNLOAD

MORE INFO



TALKING RAGDOLL
This Windows Phone app was created using Silverlight, the  Physics Helper Library,  and the Farseer Physics Engine. It gets interesting when you import your friends photos and have your way with them!

MORE INFO



BOSS LAUNCH
This physics game won first place in the Server Quest Contest. Created using Silverlight , the Physics Helper Library,  and the Farseer Physics Engine.
PLAY IT

MORE INFO



DESTROY ALL INVADERS
A scrolling shooter game where the objective is to destroy the invading UFO's flying over a neighborhood of your choosing. Imagery provided by Microsoft Virtual Earth. Created using Silverlight.
PLAY IT

INFO AND CODE



PHYSICS HELPER DEMOS
These demos were created for the Physics Helper Library, which makes it easy to create physics games and simulations using Expression Blend, Silverlight, and the Farseer Physics Engine.
PLAY IT

INFO AND CODE



HOOK SHOT
This little basketball game took first place in the TeamZoneSports Silverlight Contest. Created using Silverlight and the Farseer Physics engine.
PLAY IT

MORE INFO



SORT THE FOOBARS
A game where you need to sort the good foobars from the bad ones. Created using Silverlight and the Farseer Physics engine.
PLAY IT

MORE INFO



POLYGON PHYSICS DEMO
A demo showing polygon physics where the user draws physics objects with the mouse. Created using Silverlight and the Farseer Physics engine.
PLAY IT

MORE INFO



SILVERLIGHT ROCKS!
Destroy the asteroids before they destroy your ship! Created using Silverlight.
PLAY IT

INFO AND CODE



FISH GAME
A simple game of harpoon-the-fish. Written using the AJAX Sprite Toolkit.
PLAY IT

INFO AND CODE

Module Border Module Border
Module Border
  Search_Blog
Module Border
Module Border Module Border
Module Border
  Blog_Archive
Module Border
Module Border Module Border
Copyright (c) 2014 andy.beaulieu.com - Login
toms outlet cheap toms jordan pas cher Timberland Boots mulberry outlet portafoglio prada hollister soldes hogan scarpe mbt hogan jordan pas cher louboutin soldes jordan Homme louboutin pas cher Gucci Borse louboutin pas cher jordan pas cher lancel pas cher cheap ray ban sunglasses ray ban outlet toms outlet toms outlet scarpe mbt occhiali da sole a basso costo Louboutin Chaussures basket louboutin hollister pas cher jordan shoes sale