#include "DxgiInfoManager.h" #include "Window.h" #include "Graphics.h" #include #include #pragma comment(lib, "dxguid.lib") #define GFX_THROW_NOINFO(hrcall) if( FAILED( hr = (hrcall) ) ) throw Graphics::HrException( __LINE__,__FILE__,hr ) DxgiInfoManager::DxgiInfoManager() { // define function signature of DXGIGetDebugInterface typedef HRESULT (WINAPI* DXGIGetDebugInterface)(REFIID,void **); // load the dll that contains the function DXGIGetDebugInterface const auto hModDxgiDebug = LoadLibraryEx( "dxgidebug.dll",nullptr,LOAD_LIBRARY_SEARCH_SYSTEM32 ); if( hModDxgiDebug == nullptr ) { throw CHWND_LAST_EXCEPT(); } // get address of DXGIGetDebugInterface in dll const auto DxgiGetDebugInterface = reinterpret_cast( reinterpret_cast(GetProcAddress( hModDxgiDebug,"DXGIGetDebugInterface" )) ); if( DxgiGetDebugInterface == nullptr ) { throw CHWND_LAST_EXCEPT(); } HRESULT hr; GFX_THROW_NOINFO( DxgiGetDebugInterface( __uuidof(IDXGIInfoQueue),reinterpret_cast(&pDxgiInfoQueue) ) ); } DxgiInfoManager::~DxgiInfoManager() { if( pDxgiInfoQueue != nullptr ) { pDxgiInfoQueue->Release(); } } void DxgiInfoManager::Set() noexcept { // set the index (next) so that the next all to GetMessages() // will only get errors generated after this call next = pDxgiInfoQueue->GetNumStoredMessages( DXGI_DEBUG_ALL ); } std::vector DxgiInfoManager::GetMessages() const { std::vector messages; const auto end = pDxgiInfoQueue->GetNumStoredMessages( DXGI_DEBUG_ALL ); for( auto i = next; i < end; i++ ) { HRESULT hr; SIZE_T messageLength; // get the size of message i in bytes GFX_THROW_NOINFO( pDxgiInfoQueue->GetMessage( DXGI_DEBUG_ALL,i,nullptr,&messageLength ) ); // allocate memory for message auto bytes = std::make_unique( messageLength ); auto pMessage = reinterpret_cast(bytes.get()); // get the message and push its description into the vector GFX_THROW_NOINFO( pDxgiInfoQueue->GetMessage( DXGI_DEBUG_ALL,i,pMessage,&messageLength ) ); messages.emplace_back( pMessage->pDescription ); } return messages; }