VideoBackends/D3D11: Include HRESULT in error messages

This commit is contained in:
Pokechu22
2021-12-12 12:50:13 -08:00
parent 140c8217f6
commit 23cdb5c576
9 changed files with 73 additions and 38 deletions

View File

@ -7,12 +7,12 @@
#include <d3d11_1.h>
#include <d3dcompiler.h>
#include <dxgi1_5.h>
#include <fmt/format.h>
#include <vector>
#include <wrl/client.h>
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Common/MsgHandler.h"
#include "Common/HRWrap.h"
namespace DX11
{
@ -41,4 +41,32 @@ bool SupportsLogicOp(u32 adapter_index);
} // namespace D3D
// Wrapper for HRESULT to be used with fmt. Note that we can't create a fmt::formatter directly
// for HRESULT as HRESULT is simply a typedef on long and not a distinct type.
// Unlike the version in Common, this variant also knows to call GetDeviceRemovedReason if needed.
struct DX11HRWrap
{
constexpr explicit DX11HRWrap(HRESULT hr) : m_hr(hr) {}
const HRESULT m_hr;
};
} // namespace DX11
template <>
struct fmt::formatter<DX11::DX11HRWrap>
{
constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const DX11::DX11HRWrap& hr, FormatContext& ctx)
{
if (hr.m_hr == DXGI_ERROR_DEVICE_REMOVED && DX11::D3D::device != nullptr)
{
return fmt::format_to(ctx.out(), "{}\nDevice removal reason: {}", Common::HRWrap(hr.m_hr),
Common::HRWrap(DX11::D3D::device->GetDeviceRemovedReason()));
}
else
{
return fmt::format_to(ctx.out(), "{}", Common::HRWrap(hr.m_hr));
}
}
};