Advertisement
elvman

Untitled

Nov 1st, 2018
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. extern CORE_API bool GIsGPUCrashed;
  2. static void TerminateOnDeviceRemoved(HRESULT D3DResult, ID3D11Device* Direct3DDevice)
  3. {
  4.     if (GDynamicRHI)
  5.     {
  6.         GDynamicRHI->CheckGpuHeartbeat();
  7.     }
  8.  
  9.     if (D3DResult == DXGI_ERROR_DEVICE_REMOVED)
  10.     {
  11. #if NV_AFTERMATH
  12.         uint32 Result = 0xffffffff;
  13.         uint32 bDeviceActive = 0;
  14.         if (GDX11NVAfterMathEnabled)
  15.         {
  16.             GFSDK_Aftermath_Device_Status Status;
  17.             auto Res = GFSDK_Aftermath_GetDeviceStatus(&Status);
  18.             Result = uint32(Res);
  19.             if (Res == GFSDK_Aftermath_Result_Success)
  20.             {
  21.                 bDeviceActive = Status == GFSDK_Aftermath_Device_Status_Active ? 1 : 0;
  22.             }
  23.         }
  24.         UE_LOG(LogD3D11RHI, Log, TEXT("[Aftermath] GDynamicRHI=%p, GDX11NVAfterMathEnabled=%d, Result=0x%08X, bDeviceActive=%d"), GDynamicRHI, GDX11NVAfterMathEnabled, Result, bDeviceActive);
  25. #else
  26.         UE_LOG(LogD3D11RHI, Log, TEXT("[Aftermath] NV_AFTERMATH is not set"));
  27. #endif
  28.  
  29.         GIsGPUCrashed = true;      
  30.         if (Direct3DDevice)
  31.         {
  32.             HRESULT hRes = Direct3DDevice->GetDeviceRemovedReason();
  33.  
  34.             const TCHAR* Reason = TEXT("?");
  35.             switch (hRes)
  36.             {
  37.             case DXGI_ERROR_DEVICE_HUNG:            Reason = TEXT("HUNG"); break;
  38.             case DXGI_ERROR_DEVICE_REMOVED:         Reason = TEXT("REMOVED"); break;
  39.             case DXGI_ERROR_DEVICE_RESET:           Reason = TEXT("RESET"); break;
  40.             case DXGI_ERROR_DRIVER_INTERNAL_ERROR:  Reason = TEXT("INTERNAL_ERROR"); break;
  41.             case DXGI_ERROR_INVALID_CALL:           Reason = TEXT("INVALID_CALL"); break;
  42.             case S_OK:                              Reason = TEXT("S_OK"); break;
  43.             }
  44.            
  45.             // We currently don't support removed devices because FTexture2DResource can't recreate its RHI resources from scratch.
  46.             // We would also need to recreate the viewport swap chains from scratch.           
  47.             UE_LOG(LogD3D11RHI, Fatal, TEXT("Unreal Engine is exiting due to D3D device being lost. (Error: 0x%X - '%s')"), hRes, Reason);
  48.         }
  49.         else
  50.         {
  51.             UE_LOG(LogD3D11RHI, Fatal, TEXT("Unreal Engine is exiting due to D3D device being lost. D3D device was not available to assertain DXGI cause."));
  52.         }
  53.  
  54.         // Workaround for the fact that in non-monolithic builds the exe gets into a weird state and exception handling fails.
  55.         // @todo investigate why non-monolithic builds fail to capture the exception when graphics driver crashes.
  56. #if !IS_MONOLITHIC
  57.         FPlatformMisc::RequestExit(true);
  58. #endif
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement