Follow Me on Instagram Subscribe via RSS Feed

Enabling GPU Acceleration on PivotViewer

December 12, 2011

This is going to be a quick post on using the PivotViewer (both the v1 and the SL5 version).  Every once and a while you realize that you do something out of habit and forget to mention it to anyone, and that was the case here.

I was doing some research into another PivotViewer request when I came across some code inside of the SL5 PivotViewer.  I noticed that when you set a new ItemsSource, it does a check to see if GPU acceleration is enabled or not.  The best I can tell is it will continue on if it isn’t, but a warning message is logged internally to the PivotViewer.

PivotViewer is a graphically intense control.  It only makes sense that it would utilize the GPU whenever necessary so why  not let it?  I have been enabling the GPU acceleration on all of my production PivotViewer applications for some time now.  However, until I came across that line of code, it never really occurred to me to share that little piece of information.

You can find specifics about enabling GPU acceleration in the MSDN documentation.  Although, we will take a look at how to do it here.  Enabling GPU acceleration is as simple as adding a <param> tag to your Silverlight <object> tag in your HTML.  The param that you are adding looks like :

<param name="enableGPUAcceleration" value="true" />

He is what your Silverlight object should look like now:

<object data="data:application/x-silverlight-2," 
            type="application/x-silverlight-2" 
            width="100%" height="100%">
    <param name="source" value="ClientBin/myproj.xap"/>
    <param name="enableGPUAcceleration" value="true" />
    <param name="onError" value="onSilverlightError" />
    <!-- rest of default object -->
</object>

And that’s it.  Now that wasn’t too hard, was it? So now we know how to enable GPU acceleration, but is PivotViewer really using it?  I wondered that same thing myself.  So I decided to test it out to see what was going on.  The Silverlight object has another nifty (yep, I said nifty) little <param> that allows you to see what objects are taking advantage of GPU acceleration within your application.  Now this is not something, for reasons that will be obvious shortly, you will want to leave on in a production environment.  However, it can be very useful in testing. 

The enableCacheVisualization parameter allows you to see what Silverlight controls are taking advantage of the GPU acceleration.  If a control is using it, then the image remains unchanged.  Elements that are not using it are tented red.  As you might guess, it doesn’t take very long to determine which controls are taking advantage of GPU acceleration.  Let’s add the following <param> to our <object> as :

    <param name="EnableCacheVisualization" value="true" />

Now when you run your PivotViewer application, you should get something that looks like this:

image

Our new testing <param> shows us that PivotViewer is GPU acceleration for the trading cards.  Again, this makes sense that PivotViewer would take advantage of it, it’s just not something that everyone takes a moment to consider.

So there you have my PivotViewer tip for today.  As our collections continue to get larger and more complicated, this will hopefully come in handy.  If you have not grabbed the Silverlight 5 RTW stop what you are doing (after you finish this post of course) and go grab it on the Silverlight download page.

Also, I am doing a 12 Days of Silverlight series over the next 2 weeks to talk about some of my favorite features in the new version.  And yes, PivotViewer will make the list.

Comments (5)

Trackback URL | Comments RSS Feed

  1. Chris Arnold says:

    Hi Tony,

    So, are there *any* circumstances in which you wouldn’t enable GPU acceleration and, if not, why is this not the default?

    Cheers,

    Chris

  2. Tony Champion says:

    Good question and one I had to ask the experts on. As always, the Silverlight team comes thru…

    The product team has said, they’ve found stability and performance could be worse on certain types of devices when GPU acceleration is enabled compared to software rendering. The devices affected are usually low-end or older GPUs that are capable of SL GPU acceleration. They have seen problems on these devices both first hand and reported by customers. For example, Intel integrated (gma500, gma91x),. older Nvidia Geforces, etc.

  3. Len Chase says:

    Hi:
    I created your basic pivotviewer 5 example it worked great. Then I tried to move it to a Business Application. it works sort of!
    The items show up behind the pivotviewer it’s self, so I see them thru the control as it is partially transparent.
    Any Idea on what I might have done wrong?
    Thanks
    Len

  4. Tony Champion says:

    That’s a bit unexpected. My first thought is that you don’t have your templates set up quite right. Are you using multiple templates? If so, are they all working correctly? The PV transitions between one template to the next. So if one template is empty or transparent, then you would get your semi transparent look you are getting (making it look like it is behind the PV).

  5. Len Chase says:

    Tony:
    Only one template a slightly modified version of your basic sample. could it have anything to do with using a view? I will double check the xaml.
    Also do you happen to know if the filtered collection or the filter values are accessible?
    Thanks for your feedback.
    Len

Leave a Reply