├── .gitignore ├── D3DDred-WinDbg └── D3DDred.js ├── LICENSE ├── README.md └── SECURITY.md /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /D3DDred-WinDbg/D3DDred.js: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | "use strict"; 5 | 6 | const AutoBreadcrumbsBufferSizeInBytes = 65536; 7 | const AutoBreadcrumbsCommandHistoryOffset = 4096; 8 | const AutoBreadcrumbsCommandHistoryMax = (AutoBreadcrumbsBufferSizeInBytes - AutoBreadcrumbsCommandHistoryOffset) / 4; 9 | 10 | var opStrings = {}; 11 | 12 | function getEnumString(val, enumType) 13 | { 14 | var keys = Object.keys(opStrings); 15 | if (keys.length == 0) 16 | { 17 | // Build the opStrings dictionary 18 | for (var enumerantName of Object.getOwnPropertyNames(enumType.fields)) 19 | { 20 | var enumerant = enumType.fields[enumerantName]; 21 | opStrings[enumerant.value] = enumerantName; 22 | } 23 | } 24 | 25 | var key = val.value; 26 | if (opStrings.hasOwnProperty(key)) 27 | { 28 | return opStrings[key]; 29 | } 30 | 31 | return "Unknown"; 32 | } 33 | 34 | function getContextTable(node) 35 | { 36 | var contextTable = {}; 37 | 38 | // Create a dictionary of breadcrumb contexts keyed by the breadcrumb index 39 | for(var i = 0; i < node.BreadcrumbContextsCount; ++i) 40 | { 41 | contextTable[node.pBreadcrumbContexts[i].BreadcrumbIndex] = i; 42 | } 43 | 44 | return contextTable; 45 | } 46 | 47 | function initializeScript() 48 | { 49 | var symbolSource = ""; 50 | 51 | class BreadcrumbOp 52 | { 53 | constructor(op, context) 54 | { 55 | this.__op = op; 56 | this.__context = context; 57 | } 58 | 59 | toString() 60 | { 61 | var opName = getEnumString(this.__op, host.getModuleType(symbolSource, "D3D12_AUTO_BREADCRUMB_OP")); 62 | return opName + (this.__context ? ", Name: " + host.memory.readWideString(this.__context) : ""); 63 | } 64 | 65 | get Op() { return this.__op;} 66 | get Context() { return this.__context;} 67 | } 68 | 69 | // Produces an array from completed breadcrumb operations 70 | class CompletedOps 71 | { 72 | constructor(node) 73 | { 74 | this.__node = node; 75 | this.__numCompletedOps = node.pLastBreadcrumbValue.dereference(); 76 | this.__numOps = node.BreadcrumbCount; 77 | } 78 | 79 | toString() 80 | { 81 | return "Count: " + this.__numCompletedOps; 82 | } 83 | 84 | *[Symbol.iterator]() 85 | { 86 | if(this.__numOps > AutoBreadcrumbsCommandHistoryMax) 87 | { 88 | host.diagnostics.debugLog("Number of command operations exceeds " + AutoBreadcrumbsCommandHistoryMax + ", the capacity of the AutoBreadcrumb command history") 89 | var totalDroppedCount = this.__numOps - AutoBreadcrumbsCommandHistoryMax; 90 | var completedDroppedCount = max(0, this.__numCompletedOps - totalDroppedCount); 91 | host.diagnostics.debugLog("Total commands dropped: " + totalDroppedCount); 92 | host.diagnostics.debugLog("Completed commands dropped: " + completedDroppedCount); 93 | } 94 | 95 | var contextTable = getContextTable(this.__node); 96 | 97 | // Iterate through each completed op and output the BreadcrumbOp 98 | for(var count = 0; count < this.__numCompletedOps && count < AutoBreadcrumbsCommandHistoryMax; count++) 99 | { 100 | var index = this.__numCompletedOps - count - 1; 101 | var op = host.typeSystem.marshalAs(this.__node.pCommandHistory[index], symbolSource, "D3D12_AUTO_BREADCRUMB_OP"); 102 | 103 | var contextString = null; 104 | if(contextTable.hasOwnProperty(index)) 105 | { 106 | contextString = this.__node.pBreadcrumbContexts[contextTable[index]].pContextString; 107 | } 108 | yield new BreadcrumbOp(op, contextString); 109 | } 110 | } 111 | } 112 | 113 | // Produces an array from not-yet-completed breadcrumb operations 114 | class OutstandingOps 115 | { 116 | constructor(node) 117 | { 118 | this.__node = node; 119 | this.__numCompletedOps = node.pLastBreadcrumbValue.dereference(); 120 | this.__numOps = node.BreadcrumbCount; 121 | } 122 | 123 | toString() 124 | { 125 | return "Count: " + (this.__numOps - this.__numCompletedOps); 126 | } 127 | 128 | *[Symbol.iterator]() 129 | { 130 | var outstanding = this.__numOps - this.__numCompletedOps; 131 | var dropped = outstanding - AutoBreadcrumbsCommandHistoryMax; 132 | var remaining = outstanding - dropped; 133 | if( dropped > 0 ) 134 | { 135 | host.diagnostics.debugLog("Only the last " + remaining + " of " + outstanding + " outstanding operations are available\n"); 136 | } 137 | var start = Math.max(this.__numCompletedOps, this.__numOps - AutoBreadcrumbsCommandHistoryMax); 138 | 139 | var contextTable = getContextTable(this.__node); 140 | 141 | for(var opIndex = start; opIndex < this.__numOps; ++opIndex) 142 | { 143 | var index = opIndex % AutoBreadcrumbsCommandHistoryMax; 144 | var op = host.typeSystem.marshalAs(this.__node.pCommandHistory[index], symbolSource, "D3D12_AUTO_BREADCRUMB_OP"); 145 | 146 | var contextString = null; 147 | if(contextTable.hasOwnProperty(index)) 148 | { 149 | contextString = this.__node.pBreadcrumbContexts[contextTable[index]].pContextString; 150 | } 151 | 152 | yield new BreadcrumbOp(op, contextString); 153 | } 154 | } 155 | } 156 | 157 | class BreadcrumbContexts 158 | { 159 | constructor(node) 160 | { 161 | this.__node = node; 162 | this.__contextCount = node.BreadcrumbContextsCount; 163 | } 164 | 165 | toString() 166 | { 167 | return "Count: " + this.__contextCount; 168 | } 169 | 170 | *[Symbol.iterator]() 171 | { 172 | for(var i = 0; i < this.__contextCount; ++i) 173 | { 174 | yield this.__node.pBreadcrumbContexts[i]; 175 | } 176 | } 177 | } 178 | 179 | // Helper function for choosing wide vs narrow name string (prefer narrow) 180 | function SelectNameHelper(pNameA, pNameW) 181 | { 182 | // If the ascii name pointer is not null then select it 183 | if(pNameA.isNull) 184 | { 185 | return pNameW; 186 | } 187 | else 188 | { 189 | return pNameA; 190 | } 191 | } 192 | 193 | // Visualizer class for D3D12_AUTO_BREADCRUMB_NODE 194 | class AutoBreadcrumbNodeVis 195 | { 196 | toString() 197 | { 198 | var NumCompletedAutoBreadcrumbOps = this.pLastBreadcrumbValue.dereference(); 199 | return "Completed Ops: " + NumCompletedAutoBreadcrumbOps + "/" + this.BreadcrumbCount; 200 | } 201 | get CommandListDebugName() { return SelectNameHelper(this.pCommandListDebugNameA, this.pCommandListDebugNameW);} 202 | get CommandQueueDebugName() { return SelectNameHelper(this.pCommandQueueDebugNameA, this.pCommandQueueDebugNameW);} 203 | get NumCompletedAutoBreadcrumbOps() { return this.pLastBreadcrumbValue.dereference(); } 204 | get NumAutoBreadcrumbOps() { return this.BreadcrumbCount; } 205 | get ReverseCompletedOps() { return new CompletedOps(this); } 206 | get OutstandingOps() { return new OutstandingOps(this); } 207 | } 208 | 209 | // Visualizer class for D3D12_AUTO_BREADCRUMB_NODE1 210 | class AutoBreadcrumbNode1Vis extends AutoBreadcrumbNodeVis 211 | { 212 | } 213 | 214 | // Helper class for creating an array from linked list elements 215 | class LinkedDredNodesToArray 216 | { 217 | constructor(headNode) 218 | { 219 | const CreateArray = host.namespace.Debugger.Utility.Collections.CreateArray; 220 | if(!headNode.isNull) 221 | { 222 | var array = CreateArray(headNode).Flatten(function(node) 223 | { return node.pNext.isNull ? null : CreateArray(node.pNext); }); 224 | this.__nodes = array 225 | } 226 | else 227 | { 228 | this.__nodes = CreateArray(); 229 | } 230 | } 231 | 232 | toString() 233 | { 234 | return "Count: " + this.__nodes.Count(); 235 | } 236 | 237 | *[Symbol.iterator]() 238 | { 239 | for(var node of this.__nodes) 240 | { 241 | yield node; 242 | } 243 | } 244 | } 245 | 246 | // Visualizer class for D3D12_DEVICE_REMOVED_EXTENDED_DATA 247 | class DeviceRemovedExtendedDataVis 248 | { 249 | get AutoBreadcrumbNodes() 250 | { 251 | return new LinkedDredNodesToArray(this.pHeadAutoBreadcrumbNode); 252 | } 253 | } 254 | 255 | // Visualizer class for D3D12_DEVICE_REMOVED_EXTENDED_DATA1 256 | class DeviceRemovedExtendedData1Vis 257 | { 258 | get DeviceRemovedReason() 259 | { 260 | return host.typeSystem.marshalAs(this.DeviceRemovedReason, symbolSource, "HRESULT"); 261 | } 262 | 263 | get AutoBreadcrumbNodes() 264 | { 265 | return new LinkedDredNodesToArray(this.AutoBreadcrumbsOutput.pHeadAutoBreadcrumbNode); 266 | } 267 | 268 | get PageFaultVA() 269 | { 270 | return this.PageFaultOutput.PageFaultVA; 271 | } 272 | 273 | get ExistingAllocations() 274 | { 275 | return new LinkedDredNodesToArray(this.PageFaultOutput.pHeadExistingAllocationNode); 276 | } 277 | 278 | get RecentFreedAllocations() 279 | { 280 | return new LinkedDredNodesToArray(this.PageFaultOutput.pHeadRecentFreedAllocationNode ); 281 | } 282 | } 283 | 284 | // Visualizer class for D3D12_DEVICE_REMOVED_EXTENDED_DATA2 285 | class DeviceRemovedExtendedData2Vis 286 | { 287 | get DeviceRemovedReason() 288 | { 289 | return host.typeSystem.marshalAs(this.DeviceRemovedReason, symbolSource, "HRESULT"); 290 | } 291 | 292 | get AutoBreadcrumbNodes() 293 | { 294 | return new LinkedDredNodesToArray(this.AutoBreadcrumbsOutput.pHeadAutoBreadcrumbNode); 295 | } 296 | 297 | get PageFaultVA() 298 | { 299 | return this.PageFaultOutput.PageFaultVA; 300 | } 301 | 302 | get ExistingAllocations() 303 | { 304 | return new LinkedDredNodesToArray(this.PageFaultOutput.pHeadExistingAllocationNode); 305 | } 306 | 307 | get RecentFreedAllocations() 308 | { 309 | return new LinkedDredNodesToArray(this.PageFaultOutput.pHeadRecentFreedAllocationNode ); 310 | } 311 | } 312 | 313 | // Visualizer class for D3D12_DEVICE_REMOVED_EXTENDED_DATA3 314 | class DeviceRemovedExtendedData3Vis 315 | { 316 | toString() 317 | { 318 | return "DeviceState: " + this.DeviceState.toString(); 319 | } 320 | 321 | get DeviceState() 322 | { 323 | return host.typeSystem.marshalAs(this.DeviceState, symbolSource, "D3D12_DRED_DEVICE_STATE"); 324 | } 325 | 326 | get DeviceRemovedReason() 327 | { 328 | return host.typeSystem.marshalAs(this.DeviceRemovedReason, symbolSource, "HRESULT"); 329 | } 330 | 331 | get AutoBreadcrumbNodes() 332 | { 333 | return new LinkedDredNodesToArray(this.AutoBreadcrumbsOutput.pHeadAutoBreadcrumbNode); 334 | } 335 | 336 | get PageFaultVA() 337 | { 338 | return this.PageFaultOutput.PageFaultVA; 339 | } 340 | 341 | get ExistingAllocations() 342 | { 343 | return new LinkedDredNodesToArray(this.PageFaultOutput.pHeadExistingAllocationNode); 344 | } 345 | 346 | get RecentFreedAllocations() 347 | { 348 | return new LinkedDredNodesToArray(this.PageFaultOutput.pHeadRecentFreedAllocationNode ); 349 | } 350 | } 351 | 352 | // Visualizer class for D3D12_DRED_ALLOCATION_NODE 353 | class DredAllocationNodeVis 354 | { 355 | get ObjectName() 356 | { 357 | return SelectNameHelper(this.ObjectNameA, this.ObjectNameW); 358 | } 359 | 360 | get AllocationType() 361 | { 362 | return host.typeSystem.marshalAs(this.AllocationType, symbolSource, "D3D12_DRED_ALLOCATION_TYPE"); 363 | } 364 | } 365 | 366 | // Visualizer class for D3D12_DRED_ALLOCATION_NODE1 367 | class DredAllocationNode1Vis extends DredAllocationNodeVis 368 | { 369 | } 370 | 371 | // Visualizer class for D3D12_VERSIONED_DEVICE_REMOVED_EXTENDED_DATA 372 | class VersionedDeviceRemovedExtendedDataVis 373 | { 374 | get DREDVersion() { return this["Version"]; } 375 | get Data() 376 | { 377 | switch(this["Version"]) 378 | { 379 | case 1: 380 | return this.Dred_1_0; 381 | break; 382 | 383 | case 2: 384 | return this.Dred_1_1; 385 | break; 386 | 387 | case 3: 388 | return this.Dred_1_2; 389 | break; 390 | 391 | case 4: 392 | return this.Dred_1_3; 393 | break; 394 | 395 | default: 396 | return Error("Invalid or corrupt version data"); 397 | break; 398 | } 399 | } 400 | } 401 | 402 | function __d3d12DeviceRemovedExtendedData() 403 | { 404 | // The D3D12 has been refactored into D3D12.dll and D3D12Core.dll. On systems with this 405 | // refactoring, D3D12DeviceRemovedExtendedData is hosted in D3D12Core.dll. 406 | symbolSource = "d3d12core"; 407 | var x = host.getModuleSymbolAddress(symbolSource, "D3D12DeviceRemovedExtendedData"); 408 | 409 | if (x == null) 410 | { 411 | // Otherwise DRED data is located in d3d12.dll. 412 | symbolSource = "d3d12"; 413 | x = host.getModuleSymbolAddress(symbolSource, "D3D12DeviceRemovedExtendedData"); 414 | } 415 | 416 | // Need to cast the return type to D3D12_VERSIONED_DEVICE_REMOVED_EXTENDED_DATA 417 | // since this information is stripped out of the public PDB 418 | try 419 | { 420 | // First try using the D3D12_VERSIONED_DEVICE_REMOVED_EXTENDED_DATA symbol contained 421 | // in d3d12.pdb. Legacy public d3d12 pdb's do not have this type information at all. 422 | var dred = host.createTypedObject(x, symbolSource, "D3D12_VERSIONED_DEVICE_REMOVED_EXTENDED_DATA"); 423 | return dred.Data; 424 | } 425 | catch(err) 426 | { 427 | // host.namespace.Debugger.Sessions[0].Processes[0].Modules[0].Name 428 | // Iterate through the loaded modules attempt the cast. 429 | // Note: the first loaded module is the application .exe. If the app 430 | // has the DRED symbols loaded then this should go quick. 431 | for(var m of host.currentProcess.Modules) 432 | { 433 | try 434 | { 435 | symbolSource = m.Name; 436 | var dred = host.createTypedObject(x, symbolSource, "D3D12_VERSIONED_DEVICE_REMOVED_EXTENDED_DATA"); 437 | return dred.Data; 438 | } 439 | catch(err) 440 | { 441 | // Skip to the next one 442 | } 443 | } 444 | } 445 | 446 | // None of the symbols contain 447 | host.diagnostics.debugLog("ERROR: D3D12_VERSIONED_DEVICE_REMOVED_EXTENDED_DATA not found in any loaded symbol files.\n") 448 | return null; 449 | } 450 | 451 | return [ new host.typeSignatureRegistration(VersionedDeviceRemovedExtendedDataVis, "D3D12_VERSIONED_DEVICE_REMOVED_EXTENDED_DATA"), 452 | new host.typeSignatureRegistration(DeviceRemovedExtendedDataVis, "D3D12_DEVICE_REMOVED_EXTENDED_DATA"), 453 | new host.typeSignatureRegistration(DeviceRemovedExtendedData1Vis, "D3D12_DEVICE_REMOVED_EXTENDED_DATA1"), 454 | new host.typeSignatureRegistration(DeviceRemovedExtendedData2Vis, "D3D12_DEVICE_REMOVED_EXTENDED_DATA2"), 455 | new host.typeSignatureRegistration(DeviceRemovedExtendedData3Vis, "D3D12_DEVICE_REMOVED_EXTENDED_DATA3"), 456 | new host.typeSignatureRegistration(AutoBreadcrumbNodeVis, "D3D12_AUTO_BREADCRUMB_NODE"), 457 | new host.typeSignatureRegistration(AutoBreadcrumbNode1Vis, "D3D12_AUTO_BREADCRUMB_NODE1"), 458 | new host.typeSignatureRegistration(DredAllocationNodeVis, "D3D12_DRED_ALLOCATION_NODE"), 459 | new host.typeSignatureRegistration(DredAllocationNode1Vis, "D3D12_DRED_ALLOCATION_NODE1"), 460 | new host.functionAlias(__d3d12DeviceRemovedExtendedData, "d3ddred")]; 461 | } 462 | 463 | function uninitializeScript() 464 | { 465 | } 466 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # D3DDred.js 3 | This is a WinDbg Javascript extension that makes it much easier to debug D3D12 DRED (Device Removed Extended Data) state after a device removed event. 4 | 5 | Make sure that you visit the [DirectX Landing Page](https://devblogs.microsoft.com/directx/landing-page/) for more resources for DirectX developers. 6 | 7 | ## Example 8 | This example uses a broken version of the DirectX sample app ModelViewer.exe that causes device removal during the first frame. To debug this, launch ModelViewer using WinDbg and load the D3DDred script any time after the device removal is triggered: 9 | ``` 10 | .scriptload 11 | ``` 12 | 13 | After loading the script, enter the command !d3ddred: 14 | ``` 15 | 0:000> !d3ddred 16 | @$d3ddred() : [object Object] [Type: D3D12_DEVICE_REMOVED_EXTENDED_DATA2] 17 | [] [Type: D3D12_DEVICE_REMOVED_EXTENDED_DATA2] 18 | DeviceRemovedReason : 0x887a0006 (The GPU will not respond to more commands, most likely because of an invalid command passed by the calling applicat [Type: HRESULT] 19 | AutoBreadcrumbNodes : Count: 1 20 | PageFaultVA : 0x286fd0000 21 | ExistingAllocations : Count: 0 22 | RecentFreedAllocations : Count: 1 23 | 24 | ``` 25 | In this example, there is only one AutoBreadcrumbNode object. Clicking on AutoBreadcrumbNodes outputs: 26 | ``` 27 | 0:000> dx -r1 (*((d3d12!D3D12_DEVICE_REMOVED_EXTENDED_DATA2 *)0x7ffa3365ccd8)).AutoBreadcrumbNodes 28 | (*((d3d12!D3D12_DEVICE_REMOVED_EXTENDED_DATA2 *)0x7ffa3365ccd8)).AutoBreadcrumbNodes : Count: 1 29 | [0x0] : 0x23fbd140308 : [object Object] [Type: D3D12_AUTO_BREADCRUMB_NODE1 *] 30 | ``` 31 | Click [0x0]: 32 | ``` 33 | 0:000> dx -r1 ((d3d12!D3D12_AUTO_BREADCRUMB_NODE1 *)0x23fbd140308) : 0x23fbd140308 : [object Object] [Type: D3D12_AUTO_BREADCRUMB_NODE1 *] 34 | [] [Type: D3D12_AUTO_BREADCRUMB_NODE1] 35 | BreadcrumbContexts : [object Object] 36 | CommandListDebugName : 0x0 [Type: wchar_t *] 37 | CommandQueueDebugName : 0x23fbbffb9c0 : "CommandListManager::m_CommandQueue" [Type: wchar_t *] 38 | NumCompletedAutoBreadcrumbOps : 0x3 39 | NumAutoBreadcrumbOps : 0x5 40 | ReverseCompletedOps : [object Object] 41 | OutstandingOps : [object Object] 42 | ``` 43 | This shows that queue “CommandListManager::m_CommandQueue” and command list “ClearBufferCL” contain the likely suspect operation. 44 | 45 | The ReverseCompletedOps value is an array (in reverse order) of command list operations that completed without error. If running on Windows 10 1903 or earlier, clicking on 'ReverseCompletedOps' outputs: 46 | ``` 47 | 0:000> dx -r1 ((ModelViewer!D3D12_AUTO_BREADCRUMB_NODE *)0x23fbd140308)->ReverseCompletedOps : [object Object] 48 | [0x0] : D3D12_AUTO_BREADCRUMB_OP_CLEARUNORDEREDACCESSVIEW (13) [Type: D3D12_AUTO_BREADCRUMB_OP] 49 | ``` 50 | This shows that a command list recording completed only one operation before faulting, which was a ClearUnorderedAccessView command. 51 | 52 | As of DRED v1.2 (available in the Windows 10 20H1 preview release) auto-breadcrumbs includes PIX event and marker strings as 'context' data in the command history. With PIX context support, clicking on 'ReverseCompletedOps will produce a table of operation ID's and context strings (if available): 53 | ``` 54 | 0:000> dx -r1 ((d3d12!D3D12_AUTO_BREADCRUMB_NODE1 *)0x23fbd140308)->ReverseCompletedOps 55 | ((d3d12!D3D12_AUTO_BREADCRUMB_NODE1 *)0x23fbd140308)->ReverseCompletedOps : [object Object] 56 | [0x0] : Op: [object Object], Context: [object Object] 57 | [0x1] : Op: [object Object] 58 | [0x2] : Op: [object Object], Context: [object Object] 59 | ``` 60 | At first glance, this view is less useful. Context data is facilitated by WinDbg 'synthetic objects' and each synthetic object needs to be expanded individually. A better view can be achieved by right-clicking on 'ReverseCompletedOps' and selecting 'Display As Grid'. This will produce a view similar to: 61 | ``` 62 | 0:000> dx -r1 -g ((d3d12!D3D12_AUTO_BREADCRUMB_NODE1 *)0x23fbd140308)->ReverseCompletedOps 63 | ======================================================================================================================= 64 | = = Op = (+) Context = 65 | ======================================================================================================================= 66 | = [0x0] : Op:... - D3D12_AUTO_BREADCRUMB_OP_SETMARKER (0) - 0x23fc7c29840 : "FinishCommandContext" = 67 | = [0x1] : Op:... - D3D12_AUTO_BREADCRUMB_OP_CLEARUNORDEREDACCESSVIEW (13) - = 68 | = [0x2] : Op:... - D3D12_AUTO_BREADCRUMB_OP_SETMARKER (0) - 0x23fbd389890 : "BeginCommandContext" = 69 | ======================================================================================================================= 70 | ``` 71 | 72 | The last column shows that successful ClearUnorderedAccessView occurred between PIXSetMarker("BeginCommandContext") and PIXSetMarker("FinishCommandContext"). 73 | 74 | The OutstandingOps value is an array (in normal forward order) of command list operations that are not guaranteed to have completed without error. 75 | 76 | **DRED 1.1 output:** 77 | ``` 78 | 0:000> dx -r1 ((ModelViewer!D3D12_AUTO_BREADCRUMB_NODE *)0x1e2ed2dcf58)->OutstandingOps : [object Object] 79 | [0x0] : D3D12_AUTO_BREADCRUMB_OP_COPYRESOURCE (9) [Type: D3D12_AUTO_BREADCRUMB_OP] 80 | [0x1] : D3D12_AUTO_BREADCRUMB_OP_RESOURCEBARRIER (15) [Type: D3D12_AUTO_BREADCRUMB_OP] 81 | ``` 82 | 83 | **DRED 1.2 output (using 'Display As Grid'):** 84 | ``` 85 | 0:000> dx -r1 -g ((d3d12!D3D12_AUTO_BREADCRUMB_NODE1 *)0x23fbd140308)->OutstandingOps 86 | ================================================================================== 87 | = = Op = 88 | ================================================================================== 89 | = [0x0] : Op: [object Object] - D3D12_AUTO_BREADCRUMB_OP_COPYRESOURCE (9) = 90 | = [0x1] : Op: [object Object] - D3D12_AUTO_BREADCRUMB_OP_RESOURCEBARRIER (15) = 91 | ================================================================================== 92 | ``` 93 | 94 | In most cases, the first outstanding operation is the strongest suspect. The outstanding CopyResource operation shown here is in fact the culprit. 95 | 96 | Looking back at the initial !d3ddred output, notice that PageFaultVA is not zero. This is an indication that the GPU faulted due to a read or write error (and that the GPU supports reporting of page faults). Beneath PageFaultVA is ExistingAllocations and RecentFreedAllocations. These contain arrays of allocations that match the faulting virtual address. Since ExistingAllocations is 0, it is not interesting in this case. However, RecentFreedAllocations has two entries that match the faulting VA: 97 | ``` 98 | 0:000> dx -r1 (*((d3d12!D3D12_DEVICE_REMOVED_EXTENDED_DATA2 *)0x7ffa3365ccd8)).RecentFreedAllocations 99 | (*((d3d12!D3D12_DEVICE_REMOVED_EXTENDED_DATA2 *)0x7ffa3365ccd8)).RecentFreedAllocations : Count: 1 100 | [0x0] : 0x23fb121e0b0 : [object Object] [Type: D3D12_DRED_ALLOCATION_NODE1 *] 101 | ``` 102 | Allocation 0x0 is an internal heap object, and thus is not very interesting. However, allocation 0x1 reveals: 103 | ``` 104 | 0:000> dx -r1 ((d3d12!D3D12_DRED_ALLOCATION_NODE1 *)0x23fb121e0b0) 105 | ((d3d12!D3D12_DRED_ALLOCATION_NODE1 *)0x23fb121e0b0) : 0x23fb121e0b0 : [object Object] [Type: D3D12_DRED_ALLOCATION_NODE1 *] 106 | [] [Type: D3D12_DRED_ALLOCATION_NODE1] 107 | ObjectName : 0x23fbd475cf0 : "FooBuffer1" [Type: wchar_t *] 108 | AllocationType : D3D12_DRED_ALLOCATION_TYPE_RESOURCE (34) [Type: D3D12_DRED_ALLOCATION_TYPE] 109 | ``` 110 | So, it seems that a buffer named “UAVBuffer01” that was associated with the faulting VA was recently deleted. 111 | The verdict is that the CopyResource operation on CommandList “ClearBufferCL” tried to access buffer “UAVBuffer01” after it had been deleted. 112 | 113 | ## Contributing 114 | 115 | This project welcomes contributions and suggestions. Most contributions require you to agree to a 116 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us 117 | the rights to use your contribution. For details, visit https://cla.microsoft.com. 118 | 119 | When you submit a pull request, a CLA-bot will automatically determine whether you need to provide 120 | a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions 121 | provided by the bot. You will only need to do this once across all repos using our CLA. 122 | 123 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 124 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or 125 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 126 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd). 40 | 41 | 42 | --------------------------------------------------------------------------------