Jump to content

  • Log In with Google      Sign In   
  • Create Account

Shawn Hargreaves' Blog

Customizing Visual Studio GPU profiling

  Posted by , 14 April 2014 - - - - - - · 842 views

The GPU profiling feature discussed in my previous post includes a not-very-obvious customization mechanism:
  • Graphics / Start Diagnostics, use Print Screen to capture frames, then return to Visual Studio
  • Open up the folder that contains the resulting .vsglog capture file (eg. right-click on GraphicsExperiment1.vsglog and select Open Containing Folder)
  • In this folder you will see a file named something like GraphicsExperiment1.vsglog.GraphicsFrameAnalysisParameters.xml
  • Edit this XML to configure GPU performance analysis settings
  • Now when you select the Frame Analysis tab and click on the Click here label, these new settings will be used
Yes yes, I know – we simply didn’t have time to make a better UI for these options :-) Although most people will be fine with the defaults, we figured it was still worth exposing this XML file for more advanced users to tweak things to their preference.
Interesting settings to adjust:
<ExperimentRepeatCount> (default 5). This controls how many times each measurement is repeated, which is done to measure standard deviation and be able to tell which measurements result from noise other than the actual thing we are trying to measure. Turn it down to 1, and analysis will run much faster but you will no longer be able to tell if some results are due to random noise. Increase it, and you will get more accurate results even if the underlying data is noisy, but you might have to wait a while (perhaps leave such an analysis running while you go to lunch).
<Variant ID=”X”>. These elements control which experiments (changing viewport size, MSAA, filtering, reduced texture dimensions, etc.) are carried out. Deleting ones you don’t need will speed up the analysis. If you only care about the baseline time per draw call, delete all but variant #0 for the fastest possible analysis (#0 is the baseline, which cannot be turned off).
<Variants HardwareCounterMode=”Default”>. This controls whether we will collect and display any hardware-specific counter values reported by the D3D driver (as exposed via the ID3D11Device::CreateCounter API and D3D11_COUNTER_DEVICE_DEPENDENT_0). The resulting data can be valuable for understanding GPU performance, but unfortunately not all drivers properly support this functionality, so by default we collect counters only on specific devices where we recognize the driver and know it will do the right thing. Hardware counters will be collected automatically on new Windows Phone 8.1 devices, but not on desktop PCs where we have no way to be sure what the driver will do if we call that API! If you are feeling brave, change the “Default” setting to “ForceEnable” and see what happens. On my dev PC the result is:

The analysis tool returned an error.
Code
0x8031801E


so I guess my driver does not properly support ID3D11Device::CreateCounter :-(http://blogs.msdn.com/aggbug.aspx?PostID=10517210

Source


Customizing Visual Studio GPU profiling

  Posted by , 14 April 2014 - - - - - - · 55 views

The GPU profiling feature discussed in my previous post includes a not-very-obvious customization mechanism:

  • Graphics / Start Diagnostics, use Print Screen to capture frames, then return to Visual Studio
  • Open up the folder that contains the resulting .vsglog capture file (eg. right-click on GraphicsExperiment1.vsglog and select Open Containing Folder)
  • In this folder you will see a file named something like GraphicsExperiment1.vsglog.GraphicsFrameAnalysisParameters.xml
  • Edit this XML to configure GPU performance analysis settings
  • Now when you select the Frame Analysis tab and click on the Click here label, these new settings will be used
Yes yes, I know &ndash; we simply didn&rsquo;t have time to make a better UI for these options Posted Image Although most people will be fine with the defaults, we figured it was still worth exposing this XML file for more advanced users to tweak things to their preference.
Interesting settings to adjust:
&lt;ExperimentRepeatCount&gt; (default 5). This controls how many times each measurement is repeated, which is done to measure standard deviation and be able to tell which measurements result from noise other than the actual thing we are trying to measure. Turn it down to 1, and analysis will run much faster but you will no longer be able to tell if some results are due to random noise. Increase it, and you will get more accurate results even if the underlying data is noisy, but you might have to wait a while (perhaps leave such an analysis running while you go to lunch).
&lt;Variant ID=&rdquo;X&rdquo;&gt;. These elements control which experiments (changing viewport size, MSAA, filtering, reduced texture dimensions, etc.) are carried out. Deleting ones you don&rsquo;t need will speed up the analysis. If you only care about the baseline time per draw call, delete all but variant #0 for the fastest possible analysis (#0 is the baseline, which cannot be turned off).
&lt;Variants HardwareCounterMode=&rdquo;Default&rdquo;&gt;. This controls whether we will collect and display any hardware-specific counter values reported by the D3D driver (as exposed via the ID3D11Device::CreateCounter API and D3D11_COUNTER_DEVICE_DEPENDENT_0). The resulting data can be valuable for understanding GPU performance, but unfortunately not all drivers properly support this functionality, so by default we collect counters only on specific devices where we recognize the driver and know it will do the right thing. Hardware counters will be collected automatically on new Windows Phone 8.1 devices, but not on desktop PCs where we have no way to be sure what the driver will do if we call that API! If you are feeling brave, change the &ldquo;Default&rdquo; setting to &ldquo;ForceEnable&rdquo; and see what happens. On my dev PC the result is:

The analysis tool returned an error.
Code
0x8031801E

so I guess my driver does not properly support ID3D11Device::CreateCounter Posted Image


<a href="https://blogs.msdn.microsoft.com/shawnhar/2014/04/14/customizing-visual-studio-gpu-profiling/" class='bbc_url' rel='nofollow external'>Source</a>




GPU profiling in Visual Studio 2013 Update 2

  Posted by , 05 April 2014 - - - - - - · 1,703 views

The graphics debugging tool formerly known as PIX has been integrated into Visual Studio for a while now, and gets better in every release. But unlike Xbox PIX, the Windows incarnation of this technology has until now been only for debugging and not profiling. It provided lots of information about what happened, but none at all about how long things took.
For Windows Phone 8.1, my team (hi Adrian!) added the ability to measure and analyze GPU performance. I'm particularly proud of the fact that, thanks to our efforts to make the Windows and Phone graphics stacks as similar as possible, we were able to build this new feature focusing mostly on Phone, yet the resulting code works exactly the same on full Windows. Visual Studio is even able to reuse a single version of our GPU performance analysis DLL across both Windows 8.1 and Phone 8.1.
Rong's talk at the Build conference shows this in action, and you can download Visual Studio 2013 Update 2 RC to try it out for yourself.


Here's how it works. I opened the default D3D project template, which gives me an oh-so-exciting spinning cube plus a framerate counter in the bottom right corner:

Posted Image
To use the graphics diagnostics feature, open the Debug menu, click Graphics, and then Start Diagnostics:

Posted Image
This will run the app with D3D tracing enabled. Press the Print Screen (PrtSc) key one or more times to capture the frames you want to analyze. When you quit the app, Visual Studio will open its graphics debugger. This will look familiar if you have used PIX before, but the UI is considerably improved in this release, plus it now supports Phone as well as Windows:

Posted Image
So far so good, but where is this new profiling feature? Select the Frame Analysis tab, and click where it says Click here:

Posted Image

Our new analysis engine will whir and click for a while (the more complicated your rendering, the longer this will take). When everything has been measured it shows a report describing the GPU performance of every draw call in the frame:

Posted Image
This simple app only contains two draw calls. Event #117 (DrawIndexed) is the cube, while #137 (DrawIndexedInstanced) is the framerate counter. There would obviously be a lot more data if you analyzed something more complicated, in which case the ID3DUserDefinedAnnotation API can be used to organize and label different sections of your rendering.
The blue bars near the top (labeled Time) show how long each draw call took for the GPU to execute. Clearly our cube is much more expensive than the framerate text (although both are ridiculously quick -- this template isn't exactly stressing my GPU :-) The column titled Baseline shows the numeric duration of each draw, and the other columns show a series of experiments where we changed various things about the rendering and measured how much difference each one made to the GPU. For instance this data tells us that:
  • Shrinking the output viewport to 1x1 reduced GPU time to just 2% of the original. This means we are heavily fill rate limited, so a possible optimization would be to reduce the backbuffer resolution.
  • Turning on 2x or 4x MSAA slowed things down, but only by ~10% -- worth considering whether we can afford that slight perf hit in exchange for the quality improvement?
  • Reducing the backbuffer from 32 to 16 bit format gave only a small improvement.
  • Automatically adding mipmaps to all the textures, or shrinking all the textures to half size, did not significantly affect performance, so we know this app is not bottlenecked by texture fetch bandwidth.

There are a couple of different forms of color highlighting going on in this report:
  • The background of the first draw call is light red to show it was one of the more expensive draws in the frame, and therefore the part worth concentrating on.
  • The most statistically significant differences produced by the various rendering experiments are highlighted in green (for improvements) or red (for changes that hurt performance). Numbers that are not highlighted indicate that, although we did measure a change of performance, this may just be random measurement noise rather than a truly significant change.

Move the mouse over any of these numbers to a view a hover tip showing more data about that particular measurement.
"Sounds great! So what types of device can I use this stuff on?"
  • The debugging part of this tool works on all Windows 8.1 and Phone 8.1 devices.
  • Performance analysis requires the graphics driver to support timestamp queries, which was not part of Windows Phone 8. This will work on Windows, and on newer 8.1 phones once those are available, but it will not work on existing phones (even when they are upgraded to the 8.1 OS, their older drivers will be missing the necessary query ability)
  • New 8.1 phones will also report GPU counter values directly from the driver, which gives much richer information about what is going on inside the GPU.

Source


GPU profiling in Visual Studio 2013 Update 2

  Posted by , 05 April 2014 - - - - - - · 49 views

<p>The graphics debugging tool formerly known as PIX has been integrated into Visual Studio for a while now, and gets better in every release.&nbsp; But unlike Xbox PIX, the Windows incarnation of this technology has until now been only for debugging and not profiling.&nbsp; It provided lots of information about what happened, but none at all about how long things took.
<p>For Windows Phone 8.1, my team (<em>hi Adrian!</em>) added the ability to measure and analyze GPU performance.&nbsp; I&rsquo;m particularly proud of the fact that, thanks to our efforts to make the <a href="http://blogs.msdn.com/b/shawnhar/archive/2014/04/03/windows-phone-8-1.aspx" target="_blank">Windows and Phone graphics stacks as similar as possible</a>, we were able to build this new feature focusing mostly on Phone, yet the resulting code works exactly the same on full Windows.&nbsp; Visual Studio is even able to reuse a single version of our GPU performance analysis DLL across both Windows 8.1 and Phone 8.1.</p>
<p><a href="http://channel9.msdn.com/Events/Build/2014/3-594" target="_blank">Rong&rsquo;s talk at the Build conference</a> shows this in action, and you can download <a href="http://blogs.msdn.com/b/somasegar/archive/2014/04/02/visual-studio-2013-update-2-rc-universal-projects-for-windows-and-windows-phone.aspx" target="_blank">Visual Studio 2013 Update 2 RC</a> to try it out for yourself.</p>
<p>&nbsp;</p>
<p>Here&rsquo;s how it works.&nbsp; I opened the default D3D project template, which gives me an oh-so-exciting spinning cube plus a framerate counter in the bottom right corner:</p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/70/20/metablogapi/3005.image_5682C323.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/3005.image_5F00_5682C323.png"><img style="border: 0px currentcolor; display: inline; background-image: none;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/70/20/metablogapi/5700.image_thumb_6C57FBA7.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/5700.image_5F00_thumb_5F00_6C57FBA7.png" alt="image" width="320" height="180" border="0"></a></p>
<p>&nbsp;</p>
<p>To use the graphics diagnostics feature, open the <em>Debug </em>menu, click <em>Graphics</em>, and then <em>Start Diagnostics</em>:</p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/70/20/metablogapi/2335.image5_34428F9F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/2335.image5_5F00_34428F9F.png"><img style="border: 0px currentcolor; display: inline; background-image: none;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/70/20/metablogapi/0272.image5_thumb_3AF59922.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/0272.image5_5F00_thumb_5F00_3AF59922.png" alt="image" width="697" height="253" border="0"></a></p>
<p>&nbsp;</p>
<p>This will run the app with D3D tracing enabled.&nbsp; Press the <em>Print Screen </em>(PrtSc) key one or more times to capture the frames you want to analyze.&nbsp; When you quit the app, Visual Studio will open its graphics debugger.&nbsp; This will look familiar if you have used PIX before, but the UI is considerably improved in this release, plus it now supports Phone as well as Windows:</p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/70/20/metablogapi/8524.image_1ADA8C65.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/8524.image_5F00_1ADA8C65.png"><img style="margin: 0px; border: 0px currentcolor; display: inline; background-image: none;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/70/20/metablogapi/0184.image_thumb_569A2518.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/0184.image_5F00_thumb_5F00_569A2518.png" alt="image" width="640" height="453" border="0"></a></p>
<p>&nbsp;</p>
<p>So far so good, but where is this new profiling feature?&nbsp;&nbsp; Select the <em>Frame Analysis </em>tab, and click where it says <em>Click here</em>:</p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/70/20/metablogapi/7041.image_4F7AE8A0.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/7041.image_5F00_4F7AE8A0.png"><img style="margin: 0px; border: 0px currentcolor; display: inline; background-image: none;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/70/20/metablogapi/3731.image_thumb_16640B9E.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/3731.image_5F00_thumb_5F00_16640B9E.png" alt="image" width="514" height="345" border="0"></a></p>
<p>&nbsp;</p>
<p>Our new analysis engine will whir and click for a while (the more complicated your rendering, the longer this will take).&nbsp; When everything has been measured it shows a report describing the GPU performance of every draw call in the frame:</p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/70/20/metablogapi/0677.image_7648FEE0.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/0677.image_5F00_7648FEE0.png"><img style="border: 0px currentcolor; display: inline; background-image: none;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/70/20/metablogapi/7043.image_thumb_562DF223.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/7043.image_5F00_thumb_5F00_562DF223.png" alt="image" width="1169" height="611" border="0"></a></p>
<p>&nbsp;</p>
<p>This simple app only contains two draw calls.&nbsp; Event #117 (DrawIndexed) is the cube, while #137 (DrawIndexedInstanced) is the framerate counter.&nbsp; There would obviously be a lot more data if you analyzed something more complicated, in which case the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh446881%28v=vs.85%29.aspx" target="_blank">ID3DUserDefinedAnnotation</a> API can be used to organize and label different sections of your rendering.</p>
<p>The blue bars near the top (labeled <em>Time</em>) show how long each draw call took for the GPU to execute.&nbsp; Clearly our cube is much more expensive than the framerate text&nbsp; (although both are ridiculously quick &ndash; this template isn&rsquo;t exactly stressing my GPU <img src="https://blogs.msdn.microsoft.com/shawnhar/wp-includes/images/smilies/icon_smile.gif" alt=":-)" class="wp-smiley" />&nbsp;&nbsp; The column titled <em>Baseline </em>shows the numeric duration of each draw, and the other columns show a series of experiments where we changed various things about the rendering and measured how much difference each one made to the GPU.&nbsp; For instance this data tells us that:</p>
<ol>
<li>Shrinking the output viewport to 1×1 reduced GPU time to just 2% of the original.&nbsp; This means we are heavily fill rate limited, so a possible optimization would be to reduce the backbuffer resolution.</li>
<li>Turning on 2x or 4x MSAA slowed things down, but only by ~10% &ndash; worth considering whether we can afford that slight perf hit in exchange for the quality improvement?</li>
<li>Reducing the backbuffer from 32 to 16 bit format gave only a small improvement.</li>
<li>Automatically adding mipmaps to all the textures, or shrinking all the textures to half size, did not significantly affect performance, so we know this app is not bottlenecked by texture fetch bandwidth.</li>
</ol>
<p>There are a couple of different forms of color highlighting going on in this report:</p>
<ol>
<li>The background of the first draw call is light red to show it was one of the more expensive draws in the frame, and therefore the part worth concentrating on.</li>
<li>The most statistically significant differences produced by the various rendering experiments are highlighted in green (for improvements) or red (for changes that hurt performance).&nbsp; Numbers that are not highlighted indicate that, although we did measure a change of performance, this may just be random measurement noise rather than a truly significant change.</li>
</ol>
<p>Move the mouse over any of these numbers to a view a hover tip showing more data about that particular measurement.</p>
<p>&nbsp;</p>
<p><em>&ldquo;Sounds great!&nbsp; So what types of device can I use this stuff on?&rdquo;</em></p>
<ol>
<li>The debugging part of this tool works on all Windows 8.1 and Phone 8.1 devices.</li>
<li>Performance analysis requires the graphics driver to support timestamp queries, which was not part of Windows Phone 8.&nbsp; This will work on Windows, and on newer 8.1 phones once those are available, but it will not work on existing phones&nbsp; (even when they are upgraded to the 8.1 OS, their older drivers will be missing the necessary query ability)</li>
<li>New 8.1 phones will also report GPU counter values directly from the driver, which gives much richer information about what is going on inside the GPU.</li>
</ol>


<a href="https://blogs.msdn.microsoft.com/shawnhar/2014/04/05/gpu-profiling-in-visual-studio-2013-update-2/" class='bbc_url' rel='nofollow external'>Source</a>




Windows Phone 8.1

  Posted by , 03 April 2014 - - - - - - · 667 views

Hey up, long time no blog…

At the Build conference this week we announced what I’ve been working on for the last while: Windows Phone 8.1. It’s full of cool new stuff, but my contribution was deep in the entrails of the operating system, converging the graphics stack between Phone and desktop Windows and making sure this shared code runs well in limited memory on mobile GPU hardware. I haven’t been blogging much because, while I found this kind of work to be important and a lot of fun, there just isn’t much that’s interesting to discuss in public along the lines of “yay, one more place where Phone used to differ from Windows is now the same” or “huzzah, one more driver bug fixed!” :-)

You can pretty much sum up the end result as graphics on Phone 8.1 now being the same as Windows. For instance:
  • Phone now supports D2D
  • Phone now supports DWrite
  • Phone now supports WIC (Windows Imaging Codec)
  • Phone now includes the HLSL shader compiler
  • Corner cases where Phone D3D did not support all the same features as Windows (for instance not all of the same swapchain options were available) are now much more similar
  • The Visual Studio Graphics Diagnostics feature (aka PIX) now works on Phone
  • You can now have a single Visual Studio project that targets both Windows and Phone

The Phone 8.1 SDK and emulator is available for download, and see Dan’s Build talk for more details and demos.

We also updated DirectXTK to include Phone 8.1 projects, which makes WICTextureLoader and SaveWICTextureToFile available on Phone.
Source


Windows Phone 8.1

  Posted by , 03 April 2014 - - - - - - · 36 views

<p><em>Hey up, long time no blog&hellip;</em>
<p>At the <a href="http://www.buildwindows.com/" target="_blank">Build conference</a> this week we announced what I&rsquo;ve been working on for the last while: Windows Phone 8.1.&nbsp; It&rsquo;s full of <a href="http://www.technologyreview.com/news/526101/say-hello-to-microsofts-answer-to-siri" target="_blank">cool new stuff</a>, but my contribution was deep in the entrails of the operating system, converging the graphics stack between Phone and desktop Windows and making sure this shared code runs well in limited memory on mobile GPU hardware.&nbsp; I haven&rsquo;t been blogging much because, while I found this kind of work to be important and a lot of fun, there just isn&rsquo;t much that&rsquo;s interesting to discuss in public along the lines of &ldquo;<em>yay, one more place where Phone used to differ from Windows is now the same</em>&rdquo; or &ldquo;<em>huzzah, one more driver bug fixed!</em>&rdquo; <img src="https://blogs.msdn.microsoft.com/shawnhar/wp-includes/images/smilies/icon_smile.gif" alt=":-)" class="wp-smiley" /></p>
<p>You can pretty much sum up the end result as graphics on Phone 8.1 now being the same as Windows. For instance:</p>
<ul>
<li>Phone now supports D2D</li>
<li>Phone now supports DWrite</li>
<li>Phone now supports WIC&nbsp; (Windows Imaging Codec)</li>
<li>Phone now includes the HLSL shader compiler</li>
<li>Corner cases where Phone D3D did not support all the same features as Windows (for instance not all of the same swapchain options were available) are now much more similar</li>
<li>The Visual Studio Graphics Diagnostics feature (aka PIX) now works on Phone</li>
<li>You can now have a single Visual Studio project that targets both Windows and Phone</li>
</ul>
<p>The <a href="https://dev.windowsphone.com/en-us/downloadsdk" target="_blank">Phone 8.1 SDK and emulator </a>is available for download, and see <a href="http://channel9.msdn.com/Events/Build/2014/3-510" target="_blank">Dan&rsquo;s Build talk</a> for more details and demos.</p>
<p>We also updated <a href="https://directxtk.codeplex.com/" target="_blank">DirectXTK</a> to include Phone 8.1 projects, which makes WICTextureLoader and SaveWICTextureToFile available on Phone.</p></p>


<a href="https://blogs.msdn.microsoft.com/shawnhar/2014/04/03/windows-phone-8-1/" class='bbc_url' rel='nofollow external'>Source</a>







April 2014 »

S M T W T F S
  12345
6789101112
13141516171819
20212223242526
27282930