<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>WPF3D Team Blog : Performance</title><link>http://blogs.msdn.com/wpf3d/archive/tags/Performance/default.aspx</link><description>Tags: Performance</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>What's New in Graphics for 4.0 Beta 2</title><link>http://blogs.msdn.com/wpf3d/archive/2009/10/20/what-s-new-in-graphics-for-4-0-beta-2.aspx</link><pubDate>Wed, 21 Oct 2009 01:26:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9910288</guid><dc:creator>wpf3d</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/wpf3d/comments/9910288.aspx</comments><wfw:commentRss>http://blogs.msdn.com/wpf3d/commentrss.aspx?PostID=9910288</wfw:commentRss><description>&lt;p&gt;Last beta &lt;a href="http://blogs.msdn.com/wpf3d/archive/2009/06/24/what-s-new-in-graphics-for-4-0-beta-1.aspx"&gt;I mentioned&lt;/a&gt; we were saving the best for Beta 2 so thank you for waiting :)&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;New Features&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The PixelShader class now accepts Pixel Shader 3.0 shaders when your hardware supports them. &lt;strong&gt;Important&lt;/strong&gt;: There is no software rendering for PS 3.0. For example, you won't see PS 3.0 Effects over Remote Desktop, when printing, in RenderTargetBitmap, etc...&lt;/li&gt;    &lt;li&gt;You can now tell us to cache the render output of an element tree in memory using what we've been calling the &amp;quot;cached composition&amp;quot; feature. The APIs for this feature are &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.cachemode(VS.100).aspx"&gt;UIElement.CacheMode&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.bitmapcachebrush(VS.100).aspx"&gt;BitmapCacheBrush&lt;/a&gt;. Think of this as hardware RenderTargetBitmap but without the BitmapSource APIs. Cached composition is more efficient than VisualBrush and allows you to specify a scale to render at if you know you'll be zooming. We'll have to write about this more later. &lt;/li&gt;    &lt;li&gt;Brand new text rendering and layout. One of the biggest complaints about WPF has been small text &amp;quot;clarity&amp;quot; so we added &amp;quot;Display&amp;quot; mode text rendering which snaps to the pixel grid and looks just like the GDI rendering the rest of Windows uses. Rendering of East Asian fonts that have embedded bitmaps has also improved. &lt;a href="http://blogs.msdn.com/text/archive/2009/08/24/wpf-4-0-text-stack-improvements.aspx"&gt;All of the details&lt;/a&gt; are over at the WPF Text blog. You should be able to notice a big difference over Beta 1 in Visual Studio 2010.&lt;/li&gt;    &lt;li&gt;My team didn't do this, but it helps us out quite a bit. WPF layout can position elements on sub-pixel boundaries which causes blurry bitmaps or seams. There have been specific workarounds for these things but no general fix. Now you can set &lt;a href="http://blogs.msdn.com/text/archive/2009/08/27/layout-rounding.aspx"&gt;layout rounding&lt;/a&gt; on the element tree root and walk away.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Some Notable Bug Fixes&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;We've fixed most of our D3D9D.dll issues. If you're on XP SP3 &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=b66e14b8-8505-4b17-bf80-edb2df5abad4&amp;amp;displaylang=en#issues"&gt;you'll still hit a problem&lt;/a&gt; that's out of our control. To workaround that or any other issue, you can copy d3d9d.dll to the exe folder, rename it to d3d9.dll, and check the &amp;quot;break on error&amp;quot; box in the control panel as usual but &lt;strong&gt;do not&lt;/strong&gt; enable d3d9d.dll globally. Or you can use the checked D3D9.dll as mentioned in the release notes I just linked to. &lt;/li&gt;    &lt;li&gt;Fixed all known D3DImage device lost and timing bugs. If you find more, let us know ASAP. &lt;/li&gt;    &lt;li&gt;ColorContext should finally work in all scenarios! It can still throw exceptions when the embedded ColorContext is bad. I believe we shipped Beta 2 with some backwards compat exception issues that have been fixed for final release. &lt;/li&gt;    &lt;li&gt;WriteableBitmap was not respecting dirty rect size. If your dirty region is small compared to the size of the entire WriteableBitmap, you will see CPU improvement.&lt;/li&gt;    &lt;li&gt;&lt;em&gt;Minor&lt;/em&gt; 3D performance improvements. We reduced the amount of DrawPrimitive() calls for large indexed meshes and slightly improved CPU usage for large Model3D counts.&lt;/li&gt;    &lt;li&gt;We reduced the amount of GC.Collect(2) calls caused by bitmap allocations &lt;/li&gt;    &lt;li&gt;The render thread no longer dies when you create &amp;quot;32 / number of monitors&amp;quot; WPF AppDomains.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;A Notable Bug&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Remember how &lt;a href="http://blogs.msdn.com/wpf3d/archive/2009/06/24/what-s-new-in-graphics-for-4-0-beta-1.aspx"&gt;I said&lt;/a&gt; we disabled hardware rendering if you didn't have PS 2.0? Well, that wasn't true. We thought we did but there was a bug and it's in Beta 2 as well. It'll be true for the final release.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;It's also worth mentioning that &lt;a href="http://blogs.msdn.com/jgoldb/archive/2009/10/19/what-s-new-in-net-framework-4-client-profile-beta-2.aspx"&gt;.NET Framework 4.0 setup size has shrunk dramatically&lt;/a&gt;. The full x86 installer is down to ~38MB and the new &amp;quot;client&amp;quot; installer down to ~31MB. Full 3.5 SP1 is 231MB!&lt;/p&gt;  &lt;p&gt;-- Jordan&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9910288" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/wpf3d/archive/tags/3D/default.aspx">3D</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/4.0+Beta+2/default.aspx">4.0 Beta 2</category></item><item><title>Transparent DiffuseMaterials and Depth Sorting</title><link>http://blogs.msdn.com/wpf3d/archive/2009/06/18/transparent-diffusematerials-and-depth-sorting.aspx</link><pubDate>Fri, 19 Jun 2009 04:28:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9778262</guid><dc:creator>wpf3d</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/wpf3d/comments/9778262.aspx</comments><wfw:commentRss>http://blogs.msdn.com/wpf3d/commentrss.aspx?PostID=9778262</wfw:commentRss><description>&lt;p&gt;I &lt;a href="http://blogs.msdn.com/wpf3d/archive/2007/03/08/material-behavior.aspx"&gt;hinted at this a long time ago&lt;/a&gt; and then forgot to follow up, whoops! &lt;/p&gt;  &lt;p&gt;As the old post says, DiffuseMaterial writes to the depth buffer. This means if you draw one diffuse model and then draw another diffuse model behind it, the card knows not to draw the second one on top of the first because the first is closer. The depth buffer only knows about position and has no concept of transparency so if the first model is transparent, you won’t see the second model behind it because the depth buffer rejected it as being behind the first.&lt;/p&gt;  &lt;p&gt;What does this mean? This means you have to sort your transparent DiffuseMaterials from back to front. If your scene is dynamic, you’ll have to do this any time the relationship between the transparent models and the camera changes. Peter gives an example of how to do this &lt;a href="http://blogs.msdn.com/pantal/archive/2007/07/23/sorting-for-wpf-3d-transparency.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;-- Jordan&lt;/p&gt;  &lt;p&gt;P.S. If you have a lot of overlapping models (a.k.a overdraw) you can sort your opaque models from front to back. This will prevent all of the obstructed models from being rasterized and will improve performance if rasterization is the bottleneck. If you have both opaque and transparent models, first draw the opaque ones then the transparent ones.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9778262" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/wpf3d/archive/tags/Materials/default.aspx">Materials</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/3D/default.aspx">3D</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/Performance/default.aspx">Performance</category></item><item><title>3.5 SP1 Software 3D Leak Fix Available</title><link>http://blogs.msdn.com/wpf3d/archive/2009/06/08/3-5-sp1-software-3d-leak-fix-available.aspx</link><pubDate>Tue, 09 Jun 2009 01:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9710503</guid><dc:creator>wpf3d</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/wpf3d/comments/9710503.aspx</comments><wfw:commentRss>http://blogs.msdn.com/wpf3d/commentrss.aspx?PostID=9710503</wfw:commentRss><description>&lt;p&gt;In 3.5 SP1 it was really easy to leak memory when doing software 3D rendering involving a VisualBrush or DrawingBrush. We got this complaint many times online and in person. Unfortunately, there is no work around. It’s described in “Issue 2” from &lt;a href="http://support.microsoft.com/kb/967634/"&gt;this new Knowledge Base article&lt;/a&gt;. The fix should also be in 4.0 Beta 1. &lt;/p&gt;  &lt;p&gt;-- Jordan&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9710503" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/wpf3d/archive/tags/3D/default.aspx">3D</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/3.5+SP1/default.aspx">3.5 SP1</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/4.0+Beta+1/default.aspx">4.0 Beta 1</category></item><item><title>3D Hit Testing</title><link>http://blogs.msdn.com/wpf3d/archive/2009/05/18/3d-hit-testing.aspx</link><pubDate>Tue, 19 May 2009 04:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9626597</guid><dc:creator>wpf3d</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/wpf3d/comments/9626597.aspx</comments><wfw:commentRss>http://blogs.msdn.com/wpf3d/commentrss.aspx?PostID=9626597</wfw:commentRss><description>&lt;p&gt;How to do 3D hit testing has come up a bit recently in the forums but essentially it isn’t any different than 2D hit testing which is described on MSDN &lt;a href="http://msdn.microsoft.com/en-us/library/ms752097.aspx"&gt;here&lt;/a&gt;. You can either start with a 2D point on the Viewport3D or a 3D point on a Visual3D. &lt;/p&gt;  &lt;p&gt;Starting at the Viewport3D level is straightforward. Suppose you have a mouse down handler and you want it to hit test into 3D:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;MouseHitTest(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;MouseButtonEventArgs &lt;/span&gt;args)
{
    &lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;mousePos = args.GetPosition(viewport3d);
    &lt;span style="color: #2b91af"&gt;PointHitTestParameters &lt;/span&gt;hitParams = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PointHitTestParameters&lt;/span&gt;(mousePos);
    &lt;span style="color: #2b91af"&gt;VisualTreeHelper&lt;/span&gt;.HitTest(viewport3d, &lt;span style="color: blue"&gt;null&lt;/span&gt;, ResultCallback, hitParams);
}&lt;/pre&gt;

&lt;p&gt;Visual3D is slightly trickier because a point is no longer sufficient in 3D space. You also need to specify a direction. An origin point plus a direction is known as a &lt;em&gt;ray&lt;/em&gt;. It will look something like this:&lt;/p&gt;

&lt;pre class="code"&gt;    &lt;span style="color: #2b91af"&gt;RayHitTestParameters &lt;/span&gt;hitParams = 
        &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;RayHitTestParameters&lt;/span&gt;(
            &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point3D&lt;/span&gt;(0, 0, 0),
            &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3D&lt;/span&gt;(1, 0, 0)
            );
    &lt;span style="color: #2b91af"&gt;VisualTreeHelper&lt;/span&gt;.HitTest(visual3d, &lt;span style="color: blue"&gt;null&lt;/span&gt;, ResultCallback, hitParams);&lt;/pre&gt;

&lt;p&gt;The only difference is the HitTestParameters.&lt;/p&gt;

&lt;p&gt;The second argument to HitTest is a filter which allows you to control which parts of the tree get tested. Skipping part of the tree is a perf win of course, but generally you’ll want to hit test everything and this is covered well in the MSDN article so I won’t do it here.&lt;/p&gt;

&lt;p&gt;The third argument, the result callback, is where the action happens. We’ve hit something and we’ve decided to tell you about it. It could be 3D or it could be 2D. It’s up to you to decide what you’re looking for and when/if you want to stop. &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HitTestResultBehavior &lt;/span&gt;ResultCallback(&lt;span style="color: #2b91af"&gt;HitTestResult &lt;/span&gt;result)
{
    &lt;span style="color: green"&gt;// Did we hit 3D?
    &lt;/span&gt;&lt;span style="color: #2b91af"&gt;RayHitTestResult &lt;/span&gt;rayResult = result &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;RayHitTestResult&lt;/span&gt;; 
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(rayResult != &lt;span style="color: blue"&gt;null&lt;/span&gt;) 
    { 
        &lt;span style="color: green"&gt;// Did we hit a MeshGeometry3D?
        &lt;/span&gt;&lt;span style="color: #2b91af"&gt;RayMeshGeometry3DHitTestResult &lt;/span&gt;rayMeshResult = 
            rayResult &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;RayMeshGeometry3DHitTestResult&lt;/span&gt;;
                                                                                          
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(rayMeshResult != &lt;span style="color: blue"&gt;null&lt;/span&gt;) 
        { 
            &lt;span style="color: green"&gt;// Yes we did!
        &lt;/span&gt;} 
    } 
    
    &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HitTestResultBehavior&lt;/span&gt;.Continue; 
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;RayMeshGeometry3DHitTestResult has MeshHit, PointHit, and DistanceToRayOrigin properties which tell you pretty much everything you want to know. It also has the triangle indices and weights (a.k.a. &lt;em&gt;barycentric coordinates&lt;/em&gt;) so you can do things like figure out the texture coordinate of the point hit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance Tip&lt;/strong&gt;: As you mouse over 3D we do hit testing behind your back because there could be interactive 2D on the 3D or a 2D layer underneath the 3D (empty Viewport3D space is considered transparent for hit testing purposes). If you know you don’t need either of those, disable hit testing on the Viewport3D by setting its IsHitTestVisible property to false. This is an old tip but a good one :)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sneaky Performance Tip&lt;/strong&gt;: Can’t disable hit testing and it’s still eating up a bunch of CPU? Override HitTestCore() and, while the mouse is moving, only &lt;em&gt;really&lt;/em&gt; issue the hit test every two or three (or more!) requests. This will introduce lag of course but that may be acceptable to your application.&lt;/p&gt;

&lt;p&gt;-- Jordan&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9626597" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/wpf3d/archive/tags/3D/default.aspx">3D</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/Hit+Testing/default.aspx">Hit Testing</category></item><item><title>Bootcamp Lecture</title><link>http://blogs.msdn.com/wpf3d/archive/2007/03/29/bootcamp-lecture.aspx</link><pubDate>Thu, 29 Mar 2007 21:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1989951</guid><dc:creator>wpf3d</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/wpf3d/comments/1989951.aspx</comments><wfw:commentRss>http://blogs.msdn.com/wpf3d/commentrss.aspx?PostID=1989951</wfw:commentRss><description>&lt;P&gt;We gave a lecture on 3D yesterday at a "WPF Bootcamp" event and I've attached the slides. Here's the outline:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Intro to WPF3D with a simple example&lt;/LI&gt;
&lt;LI&gt;Interactive 2D on 3D&lt;/LI&gt;
&lt;LI&gt;Performance tips (based on &lt;A href="http://blogs.msdn.com/wpfsdk/archive/2007/01/15/maximizing-wpf-3d-performance-on-tier-2-hardware.aspx" mce_href="http://blogs.msdn.com/wpfsdk/archive/2007/01/15/maximizing-wpf-3d-performance-on-tier-2-hardware.aspx"&gt;this paper&lt;/A&gt;)&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;-- Jordan&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1989951" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/wpf3d/attachment/1989951.ashx" length="783591" type="application/vnd.openxmlformats-officedocument.pres" /><category domain="http://blogs.msdn.com/wpf3d/archive/tags/3D/default.aspx">3D</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/Lectures/default.aspx">Lectures</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/Basics/default.aspx">Basics</category></item><item><title>WPF3D Perf Guide for Tier 2 Hardware</title><link>http://blogs.msdn.com/wpf3d/archive/2007/01/16/wpf3d-perf-guide-for-tier-2-hardware.aspx</link><pubDate>Wed, 17 Jan 2007 02:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1480802</guid><dc:creator>wpf3d</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/wpf3d/comments/1480802.aspx</comments><wfw:commentRss>http://blogs.msdn.com/wpf3d/commentrss.aspx?PostID=1480802</wfw:commentRss><description>&lt;P&gt;David Teitlebaum has put together &lt;A href="http://blogs.msdn.com/wpfsdk/archive/2007/01/15/maximizing-wpf-3d-performance-on-tier-2-hardware.aspx" mce_href="http://blogs.msdn.com/wpfsdk/archive/2007/01/15/maximizing-wpf-3d-performance-on-tier-2-hardware.aspx"&gt;a set of perf guidelines&lt;/A&gt; which should help you get the most out of WPF3D on Tier 2 devices. &lt;/P&gt;
&lt;P&gt;&amp;lt;Disclaimer&amp;gt; Before you go off and implement all of the tips be sure to profile your application to find out where the true&amp;nbsp;bottlenecks are in order to get the most improvement for the least amount of effort. Furthermore, these are just guidelines that are generally true but in reality they may differ depending on the underlying hardware &amp;lt;/Disclaimer&amp;gt; :)&lt;/P&gt;
&lt;P&gt;In the future, we hope to expand upon some of the tips here on the blog.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-- Jordan&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1480802" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/wpf3d/archive/tags/3D/default.aspx">3D</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/wpf3d/archive/tags/Performance/default.aspx">Performance</category></item></channel></rss>