[DX11 Debug] Checks whether the D3D object is disposed: reportliveobjects () usage

Source: Internet
Author: User

Reference article "DirectX Leak debugging": http://masterkenth.com/blog/2014/03/07/directx-leak-debugging/


DX11 has a number of improvements in debug, one of which is the ability to output an D3D object that is not released, but by default it is output like this:

D3d11 Warning:process is terminating. Using simple reporting. Reportliveobjects () at runtime for standard reporting. [State_creation WARNING #0: UNKNOWN] D3d11 warning:live Producer at 0x00361180, Refcount:3. [State_creation WARNING #0: Unknown]d3d11 warning:live Object A T 0x00362010, refcount:0. [State_creation WARNING #0: Unknown]d3d11 warning:live Object at 0x003713f8, refcount:0. [S] Tate_creation WARNING #0: Unknown]d3d11 warning:live Object at 0x0037755c, refcount:0. [State_creation WARNING #0: unkn  Own]d3d11 Warning:live object at 0X003776FC, refcount:0. [State_creation WARNING #0: Unknown]d3d11 warning:live Object At 0x00377894, refcount:0. [State_creation WARNING #0: UNKNOWN] D3d11 Warning:live object at 0x00377b34, refcount:0. [State_creation WARNING #0: Unknown]d3d11 warning:live object at 0X00377CC4, refcount:0. [State_creation WARNING #0: Unknown]d3d11 warning:live Object at 0x00378290, refcount:0. [STA Te_creation WARNING #0: Unknown]d3dWarning:live object at 0x003787f4, refcount:0. [State_creation WARNING #0: Unknown]d3d11 warning:live object at 0x0 037a884, refcount:0. [State_creation WARNING #0: Unknown]d3d11 warning:live Object at 0x0037aa44, refcount:0. [STATE_ CREATION WARNING #0: Unknown]d3d11 warning:live Object at 0x0037c7ac, refcount:0. [State_creation WARNING #0: unknown]d 3d11 Warning:live object at 0x0037b784, refcount:0. [State_creation WARNING #0: Unknown]d3d11 warning:live object at 0 X0037cc14, refcount:0. [State_creation WARNING #0: Unknown]d3d11 warning:live Object at 0x0037f29c, refcount:1. [STAT E_creation WARNING #0: Unknown]d3d11 warning:live Object at 0x0037de1c, refcount:0. [State_creation WARNING #0: UNKNOWN  ]d3d11 Warning:live object at 0X0037FE3C, refcount:1. [State_creation WARNING #0: Unknown]d3d11 warning:live object at 0X04191A14, refcount:0. [State_creation WARNING #0: UNKNOWN] D3d11 warning:live Object at 0x041e0364, refcount:0. [State_creation WARNING #0: Unknown]d3d11 warning:live object:19 [state_creation WARNING #0: Unknown]dxgi warning:li ve Producer at 0x00340978, Refcount:4. [State_creation WARNING #0:]dxgi warning:live Object at 0x00353640, Refcount:2 . [State_creation WARNING #0:] DXGI warning:live object:1 [state_creation WARNING #0:]

The above-mentioned warnings are of no help to us and do not output anything like that. So D3D provides a reportliveobjects () method that allows developers to query the status of the current D3D objects directly

One

Before using this method, we need to do some preparation-define the D3D device as the debug mode. The flag parameter is set to D3d11_create_device_debugwhen the DEVICE is created. And the DX SDK comes with the example in sample is the same practice

#if defined (DEBUG) | | Defined (_DEBUG) createdeviceflags |= d3d11_create_device_debug; #endifD3D11CreateDeviceAndSwapChain (NULL, Mdrivertype, NULL, Createdeviceflags, Featurelevels, Numfeaturelevels,d3d11_sdk_version, &desc, &mSwapChain, &mdevice, &mfeaturelevel, &mdevicecontext);

Two

Next we can call the Reportliveobjects () method at any time. It is generally used before device->release () to check whether other objects have been properly disposed. The demonstration is as follows:

#if defined (DEBUG) | | Defined (_DEBUG) Id3d11debug *d3ddebug; HRESULT hr = Mdevice->queryinterface (__uuidof (Id3d11debug), reinterpret_cast<void**> (&d3dDebug)); SUCCEEDED (HR)) {hr = D3ddebug->reportlivedeviceobjects (d3d11_rldo_detail);} if (d3ddebug! = nullptr) d3ddebug->release (); #endifif (Mdevice! = nullptr) mdevice->release ();

Three

The parameter of Reportliveobjects () is an enum, with 3:

D3d11_rldo_summary

Show General overview

D3d11_rldo_detail

Show more information

D3d11_rldo_ignore_internal

MSDN explanation is useless, just give DX internal use (then what do you define this to do!). )

What is the difference between d3d11_rldo_summary and D3d11_rldo_detail, ignoring the third one? Let's take a look at the output of 2.

d3d11_rldo_summary:

D3d11 warning:using id3d11debug::reportlivedeviceobjects with D3d11_rldo_detail would help drill into object lifetimes. Objects with Refcount=0 and intref=0 'll be eventually destroyed through typical Immediate Context usage. However, if the application requires these objects to being destroyed sooner, clearstate followed by Flush on the Immediate C Ontext'll realize their Destruction. [State_creation WARNING #422: live_object_summary] D3d11 warning:live Id3d11device at 0x0036110c, Refcount:5 [state_creation WARNING #441: Live_device]
D3d11_rldo_detail:

D3d11 warning:live Id3d11device at 0x004ed84c, Refcount:5 [state_creation WARNING #441: Live_device]d3d11 warning:live Id3d11context at 0x004ee5c8, refcount:0, intref:1 [state_creation WARNING #2097226: Live_context]d3d11 warning:live I D3ddevicecontextstate at 0x005013d8, refcount:0, intref:1 [state_creation WARNING #3145742: live_devicecontextstate]d3 D11 warning:live id3d11blendstate at 0x0050753c, refcount:0, intref:1 [state_creation WARNING #435: live_blendstate]d3 D11 warning:live id3d11depthstencilstate at 0X005076DC, refcount:0, intref:1 [state_creation WARNING #436: LIVE_DEPTHS  Tencilstate]d3d11 warning:live id3d11rasterizerstate at 0x0050784c, refcount:0, intref:1 [STATE_CREATION WARNING #437: Live_rasterizerstate]d3d11 warning:live Id3d11sampler at 0X00507AEC, refcount:0, intref:1 [STATE_CREATION WARNING #43 4:live_sampler]d3d11 warning:live id3d11query at 0x00507ca4, refcount:0, intref:1 [state_creation WARNING #438: LIVE_ Query]d3d11 warning:live Idxgiswapchain at 0x00508270, refcount:0 [state_creation WARNING #442: Live_swapchain]d3d11 warning:live ID3D11Texture 0x005087d4, refcount:0, intref:1 [state_creation WARNING #425: Live_texture2d]d3d11 warning:live id3d11rasterize Rstate at 0x0050a89c, refcount:0, intref:0 [state_creation WARNING #437: Live_rasterizerstate]d3d11 warning:live ID3D1 1RenderTargetView at 0x0050aa34, refcount:0, intref:0 [state_creation WARNING #428: Live_rendertargetview]d3d11 WARNING : Live id3d11vertexshader at 0x0050c79c, refcount:0, intref:0 [state_creation WARNING #430: Live_vertexshader]d3d11 WAR Ning:live id3d11inputlayout at 0x0050b774, refcount:0, intref:0 [state_creation WARNING #433: Live_inputlayout]d3d11 W  Arning:live Id3d11pixelshader at 0X0050CC04, refcount:0, intref:0 [state_creation WARNING #432: Live_pixelshader]d3d11 Warning:live Id3d11vertexshader at 0x0050d0cc, Refcount:1, intref:0 [state_creation WARNING #430: live_vertexshader]d 3d11 warning:live ID3D11InputLayout at 0x0050deac, refcount:0, intref:0 [state_creation WARNING #433: Live_inputlayout]d3d11 warning:live ID3 D11pixelshader at 0x00517844, Refcount:1, intref:0 [state_creation WARNING #432: Live_pixelshader]d3d11 warning:live I D3d11buffer at 0x009066d4, refcount:0, intref:0 [state_creation WARNING #423: Live_buffer]d3d11 warning:live ID3D11Tex Ture2d at 0x00979754, refcount:0, intref:1 [state_creation WARNING #425: live_texture2d]
It's obvious!

Four

Intref is an object reference inside D3D, RefCount is a D3D object not released in our program, such as our id3d11context,refcount is 0, but Intref is 1, because we created a context in the program, So there's a reference inside the D3D, and we just need to be aware that the object RefCount not 0 is OK.

So the above line of information tells us that there is also a id3d11device,id3d11vertexshader and Id3d11pixelshader object that is not released, and that the VS and PS objects can be freed, but because Reportliveobjects () The method is called by device, so we can't release the device until then, but without a problem, we can safely release Id3d11debug and Id3d11device when we make sure the refcount of the other objects is 0.

[DX11 Debug] Checks whether the D3D object is disposed: reportliveobjects () usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.