Skip to content

Commit 937dd9a

Browse files
committed
Added extra logging for DXGI_DEVICE_REMOVED situations
1 parent 0b82075 commit 937dd9a

File tree

14 files changed

+166
-5
lines changed

14 files changed

+166
-5
lines changed

OptiScaler/Util.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,3 +520,73 @@ bool Util::CheckForRealObject(std::string functionName, IUnknown* pObject, IUnkn
520520

521521
return false;
522522
}
523+
524+
void Util::GetDeviceRemovedReason(ID3D11Device* pDevice)
525+
{
526+
auto reason = pDevice->GetDeviceRemovedReason();
527+
528+
switch (reason)
529+
{
530+
case DXGI_ERROR_DEVICE_HUNG:
531+
LOG_ERROR("Device removed reason: DXGI_ERROR_DEVICE_HUNG");
532+
break;
533+
534+
case DXGI_ERROR_DEVICE_RESET:
535+
LOG_ERROR("Device removed reason: DXGI_ERROR_DEVICE_RESET");
536+
break;
537+
538+
case DXGI_ERROR_DRIVER_INTERNAL_ERROR:
539+
LOG_ERROR("Device removed reason: DXGI_ERROR_DRIVER_INTERNAL_ERROR");
540+
break;
541+
542+
case DXGI_ERROR_INVALID_CALL:
543+
LOG_ERROR("Device removed reason: DXGI_ERROR_INVALID_CALL");
544+
break;
545+
546+
case E_OUTOFMEMORY:
547+
LOG_ERROR("Device removed reason: E_OUTOFMEMORY");
548+
break;
549+
550+
case E_FAIL:
551+
LOG_ERROR("Device removed reason: E_FAIL");
552+
break;
553+
554+
default:
555+
LOG_ERROR("Device removed reason: Unknown ({:X})", reason);
556+
}
557+
}
558+
559+
void Util::GetDeviceRemovedReason(ID3D12Device* pDevice)
560+
{
561+
auto reason = pDevice->GetDeviceRemovedReason();
562+
563+
switch (reason)
564+
{
565+
case DXGI_ERROR_DEVICE_HUNG:
566+
LOG_ERROR("Device removed reason: DXGI_ERROR_DEVICE_HUNG");
567+
break;
568+
569+
case DXGI_ERROR_DEVICE_RESET:
570+
LOG_ERROR("Device removed reason: DXGI_ERROR_DEVICE_RESET");
571+
break;
572+
573+
case DXGI_ERROR_DRIVER_INTERNAL_ERROR:
574+
LOG_ERROR("Device removed reason: DXGI_ERROR_DRIVER_INTERNAL_ERROR");
575+
break;
576+
577+
case DXGI_ERROR_INVALID_CALL:
578+
LOG_ERROR("Device removed reason: DXGI_ERROR_INVALID_CALL");
579+
break;
580+
581+
case E_OUTOFMEMORY:
582+
LOG_ERROR("Device removed reason: E_OUTOFMEMORY");
583+
break;
584+
585+
case E_FAIL:
586+
LOG_ERROR("Device removed reason: E_FAIL");
587+
break;
588+
589+
default:
590+
LOG_ERROR("Device removed reason: Unknown ({:X})", reason);
591+
}
592+
}

OptiScaler/Util.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
#include <filesystem>
55

6-
#include <dxgi.h>
6+
#include <dxgi1_6.h>
7+
#include <d3d11.h>
8+
#include <d3d12.h>
79
#include <xess.h>
810

911
namespace Util
@@ -48,6 +50,8 @@ MonitorInfo GetMonitorInfoForWindow(HWND hwnd);
4850
MonitorInfo GetMonitorInfoForOutput(IDXGIOutput* pOutput);
4951
int GetActiveRefreshRate(HWND hwnd);
5052
bool CheckForRealObject(std::string functionName, IUnknown* pObject, IUnknown** ppRealObject);
53+
void GetDeviceRemovedReason(ID3D11Device* pDevice);
54+
void GetDeviceRemovedReason(ID3D12Device* pDevice);
5155

5256
}; // namespace Util
5357

OptiScaler/hooks/FG_Hooks.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,16 @@ HRESULT FGHooks::FGPresent(void* This, UINT SyncInterval, UINT Flags, const DXGI
11141114
result = o_FGSCPresent(This, SyncInterval, Flags);
11151115
else
11161116
result = o_FGSCPresent1(This, SyncInterval, Flags, pPresentParameters);
1117-
LOG_DEBUG("Result: {:X}", result);
1117+
1118+
if (result == S_OK)
1119+
{
1120+
LOG_DEBUG("Result: {:X}", result);
1121+
}
1122+
else
1123+
{
1124+
if (result == DXGI_ERROR_DEVICE_REMOVED && State::Instance().currentD3D12Device != nullptr)
1125+
Util::GetDeviceRemovedReason(State::Instance().currentD3D12Device);
1126+
}
11181127

11191128
Hudfix_Dx12::PresentEnd();
11201129

OptiScaler/shaders/bias/Bias_Dx11.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ bool Bias_Dx11::Dispatch(ID3D11Device* InDevice, ID3D11DeviceContext* InContext,
148148
auto hr = InContext->Map(_constantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
149149
if (FAILED(hr))
150150
{
151+
if (hr == DXGI_ERROR_DEVICE_REMOVED && _device != nullptr)
152+
Util::GetDeviceRemovedReason(_device);
153+
151154
LOG_ERROR("[{0}] Map error {1:x}", _name, hr);
152155
return false;
153156
}

OptiScaler/shaders/bias/Bias_Dx12.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ bool Bias_Dx12::Dispatch(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCm
7676
if (result != S_OK)
7777
{
7878
LOG_ERROR("[{0}] _constantBuffer->Map error {1:x}", _name, (unsigned int) result);
79+
80+
if (result == DXGI_ERROR_DEVICE_REMOVED && _device != nullptr)
81+
Util::GetDeviceRemovedReason(_device);
82+
7983
return false;
8084
}
8185

OptiScaler/shaders/depth_scale/DS_Dx12.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ bool DS_Dx12::Dispatch(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCmdL
7777
if (result != S_OK)
7878
{
7979
LOG_ERROR("[{0}] _constantBuffer->Map error {1:x}", _name, (unsigned int) result);
80+
81+
if (result == DXGI_ERROR_DEVICE_REMOVED && _device != nullptr)
82+
Util::GetDeviceRemovedReason(_device);
83+
8084
return false;
8185
}
8286

OptiScaler/shaders/hud_copy/HudCopy_Dx12.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ bool HudCopy_Dx12::Dispatch(ID3D12Device* InDevice, ID3D12GraphicsCommandList* c
9595
if (result != S_OK)
9696
{
9797
LOG_ERROR("[{0}] _constantBuffer->Map error {1:x}", _name, (unsigned int) result);
98+
99+
if (result == DXGI_ERROR_DEVICE_REMOVED && _device != nullptr)
100+
Util::GetDeviceRemovedReason(_device);
101+
98102
return false;
99103
}
100104

OptiScaler/shaders/hudless_compare/HC_Dx12.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ bool HC_Dx12::Dispatch(IDXGISwapChain3* sc, ID3D12GraphicsCommandList* cmdList,
293293
if (result != S_OK)
294294
{
295295
LOG_ERROR("_constantBuffer->Map error {:X}", (unsigned int) result);
296+
297+
if (result == DXGI_ERROR_DEVICE_REMOVED && _device != nullptr)
298+
Util::GetDeviceRemovedReason(_device);
299+
296300
return false;
297301
}
298302

@@ -370,4 +374,4 @@ HC_Dx12::~HC_Dx12()
370374
_constantBuffer->Release();
371375
_constantBuffer = nullptr;
372376
}
373-
}
377+
}

OptiScaler/shaders/output_scaling/OS_Dx11.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ bool OS_Dx11::Dispatch(ID3D11Device* InDevice, ID3D11DeviceContext* InContext, I
184184
if (FAILED(hr))
185185
{
186186
LOG_ERROR("[{0}] Map error {1:x}", _name, hr);
187+
188+
if (hr == DXGI_ERROR_DEVICE_REMOVED && _device != nullptr)
189+
Util::GetDeviceRemovedReason(_device);
190+
187191
return false;
188192
}
189193

OptiScaler/shaders/output_scaling/OS_Dx12.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,18 @@ bool OS_Dx12::Dispatch(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCmdL
100100
// Copy the updated constant buffer data to the constant buffer resource
101101
UINT8* pCBDataBegin;
102102
CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU
103-
_constantBuffer->Map(0, &readRange, reinterpret_cast<void**>(&pCBDataBegin));
103+
auto result = _constantBuffer->Map(0, &readRange, reinterpret_cast<void**>(&pCBDataBegin));
104+
105+
if (result != S_OK)
106+
{
107+
LOG_ERROR("[{0}] _constantBuffer->Map error {1:x}", _name, (unsigned int) result);
108+
109+
if (result == DXGI_ERROR_DEVICE_REMOVED && _device != nullptr)
110+
Util::GetDeviceRemovedReason(_device);
111+
112+
return false;
113+
}
114+
104115
memcpy(pCBDataBegin, &fsr1Constants, sizeof(fsr1Constants));
105116
_constantBuffer->Unmap(0, nullptr);
106117

@@ -112,7 +123,18 @@ bool OS_Dx12::Dispatch(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCmdL
112123
// Copy the updated constant buffer data to the constant buffer resource
113124
UINT8* pCBDataBegin;
114125
CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU
115-
_constantBuffer->Map(0, &readRange, reinterpret_cast<void**>(&pCBDataBegin));
126+
auto result = _constantBuffer->Map(0, &readRange, reinterpret_cast<void**>(&pCBDataBegin));
127+
128+
if (result != S_OK)
129+
{
130+
LOG_ERROR("[{0}] _constantBuffer->Map error {1:x}", _name, (unsigned int) result);
131+
132+
if (result == DXGI_ERROR_DEVICE_REMOVED && _device != nullptr)
133+
Util::GetDeviceRemovedReason(_device);
134+
135+
return false;
136+
}
137+
116138
memcpy(pCBDataBegin, &constants, sizeof(constants));
117139
_constantBuffer->Unmap(0, nullptr);
118140

0 commit comments

Comments
 (0)