Villacaleb / slimdx

Automatically exported from code.google.com/p/slimdx
MIT License
0 stars 0 forks source link

Debug naming functionality support #760

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be great to have a DebugName property for all objects which can have 
one, implemented via WKPDID_D3DDebugObjectName GUID.

An example implementation is shown below; the similar thing can be done for 
D3D10 (I'm not sure about D3D9) and possibly DXGI.

This property works (i.e. set/get behave consistently) even without debug 
device, the debug name is displayed in PIX captures, and it should be displayed 
in D3D memory leak outputs (did not check).

Index: source/direct3d11/DeviceChild11.cpp
===================================================================
--- source/direct3d11/DeviceChild11.cpp (revision 1792)
+++ source/direct3d11/DeviceChild11.cpp (working copy)
@@ -40,5 +40,32 @@
        InternalPointer->GetDevice( &device );
        return SlimDX::Direct3D11::Device::FromPointer( device );
    }
+
+   System::String^ DeviceChild::DebugName::get()
+   {
+       char name[1024];
+       UINT size = sizeof(name) - 1;
+
+       if (FAILED(InternalPointer->GetPrivateData(WKPDID_D3DDebugObjectName, &size, 
name))) return "";
+
+       name[size] = 0;
+
+       return gcnew System::String(name);
+   }
+   
+   void DeviceChild::DebugName::set(System::String^ value)
+   {
+       if (value->Length > 0)
+       {
+           array<Byte>^ valueBytes = 
System::Text::ASCIIEncoding::ASCII->GetBytes(value);
+           pin_ptr<Byte> pinnedValue = &valueBytes[0];
+
+           InternalPointer->SetPrivateData(WKPDID_D3DDebugObjectName, value->Length, 
pinnedValue);
+       }
+       else
+       {
+           InternalPointer->SetPrivateData(WKPDID_D3DDebugObjectName, 0, NULL);
+       }
+   }
 }
 }
Index: source/direct3d11/DeviceChild11.h
===================================================================
--- source/direct3d11/DeviceChild11.h   (revision 1792)
+++ source/direct3d11/DeviceChild11.h   (working copy)
@@ -52,6 +52,15 @@
            {
                SlimDX::Direct3D11::Device^ get();
            }
+
+           /// <summary>
+           /// Gets or sets the debug object name
+           /// </summary>
+           property System::String^ DebugName
+           {
+               System::String^ get();
+               void set(System::String^ value);
+           }
        };
    }
 };

Original issue reported on code.google.com by arseny.k...@gmail.com on 9 Dec 2010 at 6:11

GoogleCodeExporter commented 9 years ago
Ah yes, I remember wanting to add this functionality when I read about its 
addition in a recent release, but it had completely slipped my mind.

Original comment by Mike.Popoloski on 9 Dec 2010 at 4:22

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r1795.

Original comment by Mike.Popoloski on 11 Dec 2010 at 9:47