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,48 +2697,77 @@ void Context::finish() ...@@ -2697,48 +2697,77 @@ 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))
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
{ {
return error(GL_OUT_OF_MEMORY); ERR("CreateQuery failed hr=%x\n", result);
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
{
return error(GL_OUT_OF_MEMORY);
}
ASSERT(false);
return;
} }
ASSERT(SUCCEEDED(result)); IDirect3DStateBlock9 *savedState = NULL;
result = device->CreateStateBlock(D3DSBT_ALL, &savedState);
if (occlusionQuery) if (FAILED(result))
{ {
IDirect3DStateBlock9 *savedState = NULL; ERR("CreateStateBlock failed hr=%x\n", result);
device->CreateStateBlock(D3DSBT_ALL, &savedState); occlusionQuery->Release();
HRESULT result = occlusionQuery->Issue(D3DISSUE_BEGIN);
ASSERT(SUCCEEDED(result));
// Render something outside the render target
device->SetPixelShader(NULL);
device->SetVertexShader(NULL);
device->SetFVF(D3DFVF_XYZRHW);
float data[4] = {-1.0f, -1.0f, -1.0f, 1.0f};
display->startScene();
device->DrawPrimitiveUP(D3DPT_POINTLIST, 1, data, sizeof(data));
result = occlusionQuery->Issue(D3DISSUE_END);
ASSERT(SUCCEEDED(result));
while (occlusionQuery->GetData(NULL, 0, D3DGETDATA_FLUSH) == S_FALSE) if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
{ {
// Keep polling, but allow other threads to do something useful first return error(GL_OUT_OF_MEMORY);
Sleep(0);
} }
ASSERT(false);
return;
}
result = occlusionQuery->Issue(D3DISSUE_BEGIN);
if (FAILED(result))
{
ERR("occlusionQuery->Issue(BEGIN) failed hr=%x\n", result);
occlusionQuery->Release(); occlusionQuery->Release();
savedState->Release();
ASSERT(false);
return;
}
if (savedState) // Render something outside the render target
{ device->SetPixelShader(NULL);
savedState->Apply(); device->SetVertexShader(NULL);
savedState->Release(); device->SetFVF(D3DFVF_XYZRHW);
} float data[4] = {-1.0f, -1.0f, -1.0f, 1.0f};
display->startScene();
device->DrawPrimitiveUP(D3DPT_POINTLIST, 1, data, sizeof(data));
result = occlusionQuery->Issue(D3DISSUE_END);
if (FAILED(result))
{
ERR("occlusionQuery->Issue(END) failed hr=%x\n", result);
occlusionQuery->Release();
savedState->Apply();
savedState->Release();
ASSERT(false);
return;
}
while ((result = occlusionQuery->GetData(NULL, 0, D3DGETDATA_FLUSH)) == S_FALSE)
{
// Keep polling, but allow other threads to do something useful first
Sleep(0);
}
occlusionQuery->Release();
savedState->Apply();
savedState->Release();
if (result == D3DERR_DEVICELOST)
{
error(GL_OUT_OF_MEMORY);
} }
} }
...@@ -2746,28 +2775,35 @@ void Context::flush() ...@@ -2746,28 +2775,35 @@ 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))
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
{ {
return error(GL_OUT_OF_MEMORY); ERR("CreateQuery failed hr=%x\n", result);
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
{
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);
result = eventQuery->GetData(NULL, 0, D3DGETDATA_FLUSH);
eventQuery->Release(); eventQuery->Release();
return;
}
if (result == D3DERR_DEVICELOST) result = eventQuery->GetData(NULL, 0, D3DGETDATA_FLUSH);
{ eventQuery->Release();
error(GL_OUT_OF_MEMORY);
} if (result == D3DERR_DEVICELOST)
{
error(GL_OUT_OF_MEMORY);
} }
} }
......
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