Implement glFinish using event queries.

ANGLEBUG=232 TRAC #18650 Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@807 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 96a4a6ce
#define MAJOR_VERSION 0
#define MINOR_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 806
#define BUILD_REVISION 807
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
......
......@@ -2785,12 +2785,13 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *
}
}
void Context::finish()
// Implements glFlush when block is false, glFinish when block is true
void Context::sync(bool block)
{
IDirect3DQuery9 *occlusionQuery = NULL;
IDirect3DQuery9 *eventQuery = NULL;
HRESULT result;
result = mDevice->CreateQuery(D3DQUERYTYPE_OCCLUSION, &occlusionQuery);
result = mDevice->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery);
if (FAILED(result))
{
ERR("CreateQuery failed hr=%x\n", result);
......@@ -2802,93 +2803,27 @@ void Context::finish()
return;
}
IDirect3DStateBlock9 *savedState = NULL;
result = mDevice->CreateStateBlock(D3DSBT_ALL, &savedState);
if (FAILED(result))
{
ERR("CreateStateBlock failed hr=%x\n", result);
occlusionQuery->Release();
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
{
return error(GL_OUT_OF_MEMORY);
}
ASSERT(false);
return;
}
result = occlusionQuery->Issue(D3DISSUE_BEGIN);
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
mDevice->SetPixelShader(NULL);
mDevice->SetVertexShader(NULL);
mDevice->SetFVF(D3DFVF_XYZRHW);
float data[4] = {-1.0f, -1.0f, -1.0f, 1.0f};
mDisplay->startScene();
mDevice->DrawPrimitiveUP(D3DPT_POINTLIST, 1, data, sizeof(data));
result = occlusionQuery->Issue(D3DISSUE_END);
result = eventQuery->Issue(D3DISSUE_END);
if (FAILED(result))
{
ERR("occlusionQuery->Issue(END) failed hr=%x\n", result);
occlusionQuery->Release();
savedState->Apply();
savedState->Release();
ERR("eventQuery->Issue(END) failed hr=%x\n", result);
ASSERT(false);
eventQuery->Release();
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)
do
{
error(GL_OUT_OF_MEMORY);
}
}
result = eventQuery->GetData(NULL, 0, D3DGETDATA_FLUSH);
void Context::flush()
{
IDirect3DQuery9 *eventQuery = NULL;
HRESULT result;
result = mDevice->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery);
if (FAILED(result))
{
ERR("CreateQuery failed hr=%x\n", result);
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
if(block && result == S_FALSE)
{
return error(GL_OUT_OF_MEMORY);
// Keep polling, but allow other threads to do something useful first
Sleep(0);
}
ASSERT(false);
return;
}
result = eventQuery->Issue(D3DISSUE_END);
if (FAILED(result))
{
ERR("eventQuery->Issue(END) failed hr=%x\n", result);
ASSERT(false);
eventQuery->Release();
return;
}
while(block && result == S_FALSE);
result = eventQuery->GetData(NULL, 0, D3DGETDATA_FLUSH);
eventQuery->Release();
if (result == D3DERR_DEVICELOST)
......
......@@ -421,8 +421,7 @@ class Context
void clear(GLbitfield mask);
void drawArrays(GLenum mode, GLint first, GLsizei count);
void drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices);
void finish();
void flush();
void sync(bool block); // flush/finish
// Draw the last segment of a line loop
void drawClosingLine(unsigned int first, unsigned int last);
......
......@@ -1951,7 +1951,7 @@ void __stdcall glFinish(void)
if (context)
{
context->finish();
context->sync(true);
}
}
catch(std::bad_alloc&)
......@@ -1970,7 +1970,7 @@ void __stdcall glFlush(void)
if (context)
{
context->flush();
context->sync(false);
}
}
catch(std::bad_alloc&)
......
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