{"id":3065,"date":"2017-11-29T23:38:56","date_gmt":"2017-11-29T23:38:56","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/pix\/?page_id=3065"},"modified":"2017-11-29T23:38:56","modified_gmt":"2017-11-29T23:38:56","slug":"tdr-debugging","status":"publish","type":"page","link":"https:\/\/devblogs.microsoft.com\/pix\/tdr-debugging\/","title":{"rendered":"TDR Debugging"},"content":{"rendered":"<p>Timeout detection and recovery (TDRs) and device removals occur as a result of a fault in the driver, Direct3D runtime, or hardware. A TDR or device removal causes a reset of the GPU adapter, at which point all device resources are lost. This is typically caused by invalid commands issued due to a bug in the application.<\/p>\n<p>TDRs can be captured, analyzed, and debugged using PIX GPU captures. Note that in order to take a GPU capture for debugging a TDR, you must be able to reproduce the TDR while a GPU capture is in progress. If the TDR is caused by a race condition or other rare, hard to repro problem, it may not be possible to capture it using PIX.<\/p>\n<p>Due to incompatibilities with current drivers, before using PIX to debug a TDR we recommend opening <em>Settings<\/em> and:<\/p>\n<ul>\n<li>Unchecking <em>Enable GPU Plugins<\/em><\/li>\n<li>Checking <em>Disable PIX HUD in applications running under GPU capture<\/em><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>Taking a GPU Capture of a TDR<\/h2>\n<p>In order to debug or analyze a TDR, a GPU capture must be taken of the frame or workload that produces the TDR. In order to capture a TDR it is recommended to use programmatic capture via the IDXGraphicsAnalysis interface. Programmatic capture allows an application to control when to begin and end GPU capture itself, which is typically the easiest way to capture the specific workload known to cause the TDR. For more information about programmatic capture, see <a href=\"https:\/\/blogs.msdn.microsoft.com\/pix\/programmatic-capture\/\">here<\/a>.<\/p>\n<p>PIX GPU captures are robust against application-caused TDRs and crashes. If an application terminates unexpectedly during capture, PIX will produce a valid GPU capture containing every API call made prior to termination. A capture of an application that suffered a TDR during GPU capture can be identified by the \u201cDevice Removal (TDR) at capture\u201d message in the Warnings pane when opening the file.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2017\/11\/tdr1.png\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2017\/11\/tdr1.png\" alt=\"\" class=\"alignnone size-full wp-image-3075\" width=\"576\" height=\"283\" srcset=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2017\/11\/tdr1.png 576w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2017\/11\/tdr1-300x147.png 300w\" sizes=\"(max-width: 576px) 100vw, 576px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>Debugging a TDR<\/h2>\n<p>&nbsp;<\/p>\n<h4>Using PIX Remotely<\/h4>\n<p>It is strongly recommended to use PIX remoting to debug TDRs. PIX remoting allows the analysis engine to run on a different computer than the one running the PIX user interface. As debugging a TDR typically causes the analysis engine to TDR the machine it\u2019s running on, attempting to debug TDRs locally may cause instability of the PIX user interface. More information about PIX remoting can be found <a href=\"https:\/\/blogs.msdn.microsoft.com\/pix\/remoting\/\">here<\/a>.<\/p>\n<p>If you attempt to start analysis on a capture containing a TDR without using PIX remoting, PIX will emit the following warning:<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2017\/11\/tdr2.png\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2017\/11\/tdr2.png\" alt=\"\" class=\"alignnone size-full wp-image-3085\" width=\"499\" height=\"251\" srcset=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2017\/11\/tdr2.png 499w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2017\/11\/tdr2-300x151.png 300w\" sizes=\"(max-width: 499px) 100vw, 499px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h4>Setting the \u2018TdrLimit\u2019 Registry Keys<\/h4>\n<p>By default, Windows will block applications that cause excessive TDRs from accessing the graphics hardware. This is intended as protection against denial-of-service attacks but can result in PIX itself being blocked from accessing graphics hardware. If this occurs, PIX analysis will fail.<\/p>\n<p>To debug TDRs using PIX, the \u2018TdrLimit\u2019 debugging registry keys must be set in order to disable the Windows TDR denial-of-service protections. The two registry keys that must be set are:<\/p>\n<pre>    [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\GraphicsDrivers]\n    \"TdrLimitCount\"=dword:00000020\n    \"TdrLimitTime\"=dword:00000005<\/pre>\n<p>These registry keys require a reboot to take effect. Because these registry keys are intended for debugging only, they should not be set outside of testing and debugging scenarios (to unset, delete the TdrLimitCount and TdrLimitTime values using regedit). More information about these registry keys can be found at <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-hardware\/drivers\/display\/tdr-registry-keys\">TDR Registry Keys<\/a>.<\/p>\n<p>PIX will detect an attempt to perform analysis on a machine which does not have these registry keys set, and display the following dialog:<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2017\/11\/tdr3.png\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2017\/11\/tdr3.png\" alt=\"\" class=\"alignnone size-full wp-image-3095\" width=\"507\" height=\"315\" srcset=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2017\/11\/tdr3.png 507w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2017\/11\/tdr3-300x186.png 300w\" sizes=\"(max-width: 507px) 100vw, 507px\" \/><\/a><\/p>\n<p>Selecting \u2018Yes\u2019 will cause PIX to set the required registry keys on the analysis device automatically, and prompt for a reboot to allow them to take effect. Setting these registry keys requires administrative privileges, so a UAC prompt may appear to request elevation for PIX.<\/p>\n<p>&nbsp;<\/p>\n<h4>TDR Analysis<\/h4>\n<p>Once PIX is running remotely and the correct TdrLimit registry keys are set, PIX can be used to debug and inspect the capture file as usual. A new feature is available in Dr. PIX to aid in finding the GPU operation that triggered the TDR.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2017\/11\/tdr4.png\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2017\/11\/tdr4.png\" alt=\"\" class=\"alignnone size-full wp-image-3105\" width=\"576\" height=\"365\" srcset=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2017\/11\/tdr4.png 576w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2017\/11\/tdr4-300x190.png 300w\" sizes=\"(max-width: 576px) 100vw, 576px\" \/><\/a><\/p>\n<p>The \u2018TDR Analysis\u2019 experiment executes each GPU operation (such as draws and dispatches) in isolation and reports back the event that was determined to have triggered the TDR or device removal. Clicking the link in the \u2018Event\u2019 column will navigate to the relevant entry in the Event List.<\/p>\n<p>Once the GPU operation is identified the other views in PIX can be used to debug it. In particular Shader Edit and Continue can be used to quickly iterate on shaders to narrow down the cause of the TDR.<\/p>\n<p>Note that not all views will be available when a TDR is present. For example if executing a pixel shader on a draw call causes a TDR, PIX will be unable to display the rendering output in the Pipeline view for that draw call. However most views in PIX will generally continue to function when debugging a TDR. Collection of timing data and performance counters is not supported for captures that contain TDRs.<\/p>\n<p>&nbsp;<\/p>\n<h4>Using the Debug Layer and GPU Validation<\/h4>\n<p>The <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/mt490476.aspx\">D3D12 Debug Layer<\/a> is a powerful tool for determining the root cause of a TDR. When analyzing a capture PIX can automatically enable the debug layer and, optionally, run additional GPU Validation. Running the debug layer or GPU validation from within PIX is useful if, for example, the performance overhead of the debug layer is too great to enable it in the application itself. Many forms of invalid behavior (including those which can cause TDRs) are caught by the debug layer and GPU validation.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2017\/11\/tdr5.png\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2017\/11\/tdr5.png\" alt=\"\" class=\"alignnone size-full wp-image-3115\" width=\"584\" height=\"128\" srcset=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2017\/11\/tdr5.png 584w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2017\/11\/tdr5-300x66.png 300w\" sizes=\"(max-width: 584px) 100vw, 584px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Timeout detection and recovery (TDRs) and device removals occur as a result of a fault in the driver, Direct3D runtime, or hardware. A TDR or device removal causes a reset of the GPU adapter, at which point all device resources are lost. This is typically caused by invalid commands issued due to a bug in [&hellip;]<\/p>\n","protected":false},"author":1719,"featured_media":4769,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"footnotes":""},"class_list":["post-3065","page","type-page","status-publish","has-post-thumbnail","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/pages\/3065","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/users\/1719"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/comments?post=3065"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/pages\/3065\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/media\/4769"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/media?parent=3065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}