D3D: Added GetDebugObjectName and parameter checking in SetDebugObjectName

This commit is contained in:
mr.greywater 2015-02-09 13:14:45 +01:00
parent 3d3a68a2f0
commit b5ffba3291
1 changed files with 20 additions and 1 deletions

View File

@ -70,10 +70,29 @@ void SetDebugObjectName(T resource, const char* name)
static_assert(std::is_convertible<T, ID3D11DeviceChild*>::value, static_assert(std::is_convertible<T, ID3D11DeviceChild*>::value,
"resource must be convertible to ID3D11DeviceChild*"); "resource must be convertible to ID3D11DeviceChild*");
#if defined(_DEBUG) || defined(DEBUGFAST) #if defined(_DEBUG) || defined(DEBUGFAST)
resource->SetPrivateData(WKPDID_D3DDebugObjectName, (UINT)strlen(name), name); if (resource)
resource->SetPrivateData(WKPDID_D3DDebugObjectName, (UINT)(name ? strlen(name) : 0), name);
#endif #endif
} }
template <typename T>
std::string GetDebugObjectName(T resource)
{
static_assert(std::is_convertible<T, ID3D11DeviceChild*>::value,
"resource must be convertible to ID3D11DeviceChild*");
std::string name;
#if defined(_DEBUG) || defined(DEBUGFAST)
if (resource)
{
UINT size = 0;
resource->GetPrivateData(WKPDID_D3DDebugObjectName, &size, nullptr); //get required size
name.resize(size);
resource->GetPrivateData(WKPDID_D3DDebugObjectName, &size, const_cast<char*>(name.data()));
}
#endif
return name;
}
} // namespace D3D } // namespace D3D
typedef HRESULT (WINAPI* CREATEDXGIFACTORY)(REFIID, void**); typedef HRESULT (WINAPI* CREATEDXGIFACTORY)(REFIID, void**);