DX11: Allow lost device for few frames.

This commit is contained in:
Branimir Karadžić 2014-09-30 21:16:24 -07:00
parent 3a67a73b3c
commit 61ed393f6c
5 changed files with 41 additions and 6 deletions

View file

@ -282,6 +282,9 @@ typedef enum bgfx_fatal
BGFX_FATAL_INVALID_SHADER,
BGFX_FATAL_UNABLE_TO_INITIALIZE,
BGFX_FATAL_UNABLE_TO_CREATE_TEXTURE,
BGFX_FATAL_DEVICE_LOST,
BGFX_FATAL_COUNT
} bgfx_fatal_t;

View file

@ -32,6 +32,9 @@ namespace bgfx
InvalidShader,
UnableToInitialize,
UnableToCreateTexture,
DeviceLost,
Count
};
};

View file

@ -1349,7 +1349,7 @@ again:
{
RendererType::Enum first = RendererType::Direct3D9;
RendererType::Enum second = RendererType::Direct3D11;
if (0x601 == getWindowsVersion() )
if (0x601 <= getWindowsVersion() )
{
first = RendererType::Direct3D11;
second = RendererType::Direct3D9;
@ -2722,6 +2722,7 @@ again:
#include <bgfx.c99.h>
#include <bgfxplatform.c99.h>
BX_STATIC_ASSERT(bgfx::Fatal::Count == bgfx::Fatal::Enum(BGFX_FATAL_COUNT) );
BX_STATIC_ASSERT(bgfx::RendererType::Count == bgfx::RendererType::Enum(BGFX_RENDERER_TYPE_COUNT) );
BX_STATIC_ASSERT(bgfx::Attrib::Count == bgfx::Attrib::Enum(BGFX_ATTRIB_COUNT) );
BX_STATIC_ASSERT(bgfx::AttribType::Count == bgfx::AttribType::Enum(BGFX_ATTRIB_TYPE_COUNT) );

View file

@ -539,7 +539,8 @@ RENDERDOC_IMPORT
struct RendererContextD3D11 : public RendererContextI
{
RendererContextD3D11()
: m_captureTexture(NULL)
: m_lost(0)
, m_captureTexture(NULL)
, m_captureResolve(NULL)
, m_wireframe(false)
, m_flags(BGFX_RESET_NONE)
@ -1158,16 +1159,42 @@ RENDERDOC_IMPORT
capturePostReset();
}
static bool isLost(HRESULT _hr)
{
return DXGI_ERROR_DEVICE_REMOVED == _hr
|| DXGI_ERROR_DEVICE_HUNG == _hr
|| DXGI_ERROR_DEVICE_RESET == _hr
|| DXGI_ERROR_DRIVER_INTERNAL_ERROR == _hr
|| DXGI_ERROR_NOT_CURRENTLY_AVAILABLE == _hr
;
}
void flip() BX_OVERRIDE
{
if (NULL != m_swapChain)
{
HRESULT hr = 0;
uint32_t syncInterval = !!(m_flags & BGFX_RESET_VSYNC);
for (uint32_t ii = 1, num = m_numWindows; ii < num; ++ii)
for (uint32_t ii = 1, num = m_numWindows && SUCCEEDED(hr); ii < num; ++ii)
{
DX_CHECK(m_frameBuffers[m_windows[ii].idx].m_swapChain->Present(syncInterval, 0) );
hr = m_frameBuffers[m_windows[ii].idx].m_swapChain->Present(syncInterval, 0);
}
if (SUCCEEDED(hr) )
{
hr = m_swapChain->Present(syncInterval, 0);
}
if (FAILED(hr)
&& isLost(hr) )
{
++m_lost;
BGFX_FATAL(10 > m_lost, bgfx::Fatal::DeviceLost, "Device is lost. FAILED 0x%08x", hr);
}
else
{
m_lost = 0;
}
DX_CHECK(m_swapChain->Present(syncInterval, 0) );
}
}
@ -1978,6 +2005,7 @@ RENDERDOC_IMPORT
IDXGIFactory* m_factory;
IDXGISwapChain* m_swapChain;
uint16_t m_lost;
uint16_t m_numWindows;
FrameBufferHandle m_windows[BGFX_CONFIG_MAX_FRAME_BUFFERS];

View file

@ -1042,7 +1042,7 @@ namespace bgfx
postReset();
}
bool isLost(HRESULT _hr) const
static bool isLost(HRESULT _hr)
{
return D3DERR_DEVICELOST == _hr
|| D3DERR_DRIVERINTERNALERROR == _hr