none
Questions regarding BitmapCache and GPU acceleration

    Question

    1.  Does enabling BitmapCache on an element cause all child elements to use BitmapCaching?  If I enable it on a canvas, for instance, do all child Image elements of the canvas inherit this property?
    2. How do I assign the CacheMode property of an element to be BitmapCache using C# code rather than xaml?  I'm confused since BitmapCache is its own type.
    3. I'm rendering Image elements onto a canvas which animate by using a sprite sheet bitmap as source and call SetClip to change frames .  Performance actually worsens when I enable BitmapCaching in the parent canvas (I've enabled GPUAcceleration, and the cache visualization option implies they are indeed cached, since their color is unchanged).  What gives?
    4. Is there a difference between using a TranslateTransform and  calling SetValue() for LeftProperty/TopProperty?  I see no performance difference between the two.
    Friday, March 27, 2009 5:04 PM

Answers

    1.  Does enabling BitmapCache on an element cause all child elements to use BitmapCaching?  If I enable it on a canvas, for instance, do all child Image elements of the canvas inherit this property?

      Yes. So you need to be careful with where you put the BitmapCache setting. If you put it on an element that contains more dynamic elements such as storyboard elements and such, then you won't see much perf improvement.

    2. How do I assign the CacheMode property of an element to be BitmapCache using C# code rather than xaml?  I'm confused since BitmapCache is its own type.

      element.CacheMode = new System.Windows.Media.BitmapCache();

    3. I'm rendering Image elements onto a canvas which animate by using a sprite sheet bitmap as source and call SetClip to change frames .  Performance actually worsens when I enable BitmapCaching in the parent canvas (I've enabled GPUAcceleration, and the cache visualization option implies they are indeed cached, since their color is unchanged).  What gives?

      It sounds like you want the CacheMode set just on the Image element that you are Clipping, not the Parent Canvas. But if you post your XAML it could be verified.

    4. Is there a difference between using a TranslateTransform and  calling SetValue() for LeftProperty/TopProperty?  I see no performance difference between the two.

      Nope, same perf.

     

    Friday, March 27, 2009 5:35 PM

All replies

    1.  Does enabling BitmapCache on an element cause all child elements to use BitmapCaching?  If I enable it on a canvas, for instance, do all child Image elements of the canvas inherit this property?

      Yes. So you need to be careful with where you put the BitmapCache setting. If you put it on an element that contains more dynamic elements such as storyboard elements and such, then you won't see much perf improvement.

    2. How do I assign the CacheMode property of an element to be BitmapCache using C# code rather than xaml?  I'm confused since BitmapCache is its own type.

      element.CacheMode = new System.Windows.Media.BitmapCache();

    3. I'm rendering Image elements onto a canvas which animate by using a sprite sheet bitmap as source and call SetClip to change frames .  Performance actually worsens when I enable BitmapCaching in the parent canvas (I've enabled GPUAcceleration, and the cache visualization option implies they are indeed cached, since their color is unchanged).  What gives?

      It sounds like you want the CacheMode set just on the Image element that you are Clipping, not the Parent Canvas. But if you post your XAML it could be verified.

    4. Is there a difference between using a TranslateTransform and  calling SetValue() for LeftProperty/TopProperty?  I see no performance difference between the two.

      Nope, same perf.

     

    Friday, March 27, 2009 5:35 PM
  • All very helpful answers.  Thanks again!

    I mentioned this in the sprite engine thread but I might as well say it here as well: I followed your suggestion about giving Image elements BitmapCaching rather than the Canvas itself (actually that's where I was going with my 2nd question, but regardless.. :P).  Turns out that really did the trick - doubled my performance.  Interestingly, if I enable bitmap caching for both the Canvas and the Image elements, I get no improvement, it has to only be the Image elements.  I wonder why this is.

    Friday, March 27, 2009 8:09 PM