Improve robustness of Context::finish and flush

Trac #16690 Signed-off-by: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@652 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 2b720c92
#define MAJOR_VERSION 0 #define MAJOR_VERSION 0
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 651 #define BUILD_REVISION 652
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -2697,23 +2697,44 @@ void Context::finish() ...@@ -2697,23 +2697,44 @@ void Context::finish()
egl::Display *display = getDisplay(); egl::Display *display = getDisplay();
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
IDirect3DQuery9 *occlusionQuery = NULL; IDirect3DQuery9 *occlusionQuery = NULL;
HRESULT result;
HRESULT result = device->CreateQuery(D3DQUERYTYPE_OCCLUSION, &occlusionQuery); result = device->CreateQuery(D3DQUERYTYPE_OCCLUSION, &occlusionQuery);
if (FAILED(result))
{
ERR("CreateQuery failed hr=%x\n", result);
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
{ {
return error(GL_OUT_OF_MEMORY); return error(GL_OUT_OF_MEMORY);
} }
ASSERT(false);
return;
}
ASSERT(SUCCEEDED(result)); IDirect3DStateBlock9 *savedState = NULL;
result = device->CreateStateBlock(D3DSBT_ALL, &savedState);
if (FAILED(result))
{
ERR("CreateStateBlock failed hr=%x\n", result);
occlusionQuery->Release();
if (occlusionQuery) if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
{ {
IDirect3DStateBlock9 *savedState = NULL; return error(GL_OUT_OF_MEMORY);
device->CreateStateBlock(D3DSBT_ALL, &savedState); }
ASSERT(false);
return;
}
HRESULT result = occlusionQuery->Issue(D3DISSUE_BEGIN); result = occlusionQuery->Issue(D3DISSUE_BEGIN);
ASSERT(SUCCEEDED(result)); if (FAILED(result))
{
ERR("occlusionQuery->Issue(BEGIN) failed hr=%x\n", result);
occlusionQuery->Release();
savedState->Release();
ASSERT(false);
return;
}
// Render something outside the render target // Render something outside the render target
device->SetPixelShader(NULL); device->SetPixelShader(NULL);
...@@ -2724,21 +2745,29 @@ void Context::finish() ...@@ -2724,21 +2745,29 @@ void Context::finish()
device->DrawPrimitiveUP(D3DPT_POINTLIST, 1, data, sizeof(data)); device->DrawPrimitiveUP(D3DPT_POINTLIST, 1, data, sizeof(data));
result = occlusionQuery->Issue(D3DISSUE_END); result = occlusionQuery->Issue(D3DISSUE_END);
ASSERT(SUCCEEDED(result)); if (FAILED(result))
{
ERR("occlusionQuery->Issue(END) failed hr=%x\n", result);
occlusionQuery->Release();
savedState->Apply();
savedState->Release();
ASSERT(false);
return;
}
while (occlusionQuery->GetData(NULL, 0, D3DGETDATA_FLUSH) == S_FALSE) while ((result = occlusionQuery->GetData(NULL, 0, D3DGETDATA_FLUSH)) == S_FALSE)
{ {
// Keep polling, but allow other threads to do something useful first // Keep polling, but allow other threads to do something useful first
Sleep(0); Sleep(0);
} }
occlusionQuery->Release(); occlusionQuery->Release();
if (savedState)
{
savedState->Apply(); savedState->Apply();
savedState->Release(); savedState->Release();
}
if (result == D3DERR_DEVICELOST)
{
error(GL_OUT_OF_MEMORY);
} }
} }
...@@ -2746,20 +2775,28 @@ void Context::flush() ...@@ -2746,20 +2775,28 @@ void Context::flush()
{ {
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
IDirect3DQuery9 *eventQuery = NULL; IDirect3DQuery9 *eventQuery = NULL;
HRESULT result;
HRESULT result = device->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery); result = device->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery);
if (FAILED(result))
{
ERR("CreateQuery failed hr=%x\n", result);
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
{ {
return error(GL_OUT_OF_MEMORY); return error(GL_OUT_OF_MEMORY);
} }
ASSERT(false);
return;
}
ASSERT(SUCCEEDED(result)); result = eventQuery->Issue(D3DISSUE_END);
if (FAILED(result))
if (eventQuery)
{ {
HRESULT result = eventQuery->Issue(D3DISSUE_END); ERR("eventQuery->Issue(END) failed hr=%x\n", result);
ASSERT(SUCCEEDED(result)); ASSERT(false);
eventQuery->Release();
return;
}
result = eventQuery->GetData(NULL, 0, D3DGETDATA_FLUSH); result = eventQuery->GetData(NULL, 0, D3DGETDATA_FLUSH);
eventQuery->Release(); eventQuery->Release();
...@@ -2768,7 +2805,6 @@ void Context::flush() ...@@ -2768,7 +2805,6 @@ void Context::flush()
{ {
error(GL_OUT_OF_MEMORY); error(GL_OUT_OF_MEMORY);
} }
}
} }
void Context::drawClosingLine(unsigned int first, unsigned int last) void Context::drawClosingLine(unsigned int first, unsigned int last)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment