michael@0: #include "precompiled.h" michael@0: // michael@0: // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: // Fence9.cpp: Defines the rx::Fence9 class. michael@0: michael@0: #include "libGLESv2/renderer/Fence9.h" michael@0: #include "libGLESv2/main.h" michael@0: #include "libGLESv2/renderer/renderer9_utils.h" michael@0: #include "libGLESv2/renderer/Renderer9.h" michael@0: michael@0: namespace rx michael@0: { michael@0: michael@0: Fence9::Fence9(rx::Renderer9 *renderer) michael@0: { michael@0: mRenderer = renderer; michael@0: mQuery = NULL; michael@0: } michael@0: michael@0: Fence9::~Fence9() michael@0: { michael@0: if (mQuery) michael@0: { michael@0: mRenderer->freeEventQuery(mQuery); michael@0: mQuery = NULL; michael@0: } michael@0: } michael@0: michael@0: GLboolean Fence9::isFence() michael@0: { michael@0: // GL_NV_fence spec: michael@0: // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an existing fence. michael@0: return mQuery != NULL; michael@0: } michael@0: michael@0: void Fence9::setFence(GLenum condition) michael@0: { michael@0: if (!mQuery) michael@0: { michael@0: mQuery = mRenderer->allocateEventQuery(); michael@0: if (!mQuery) michael@0: { michael@0: return gl::error(GL_OUT_OF_MEMORY); michael@0: } michael@0: } michael@0: michael@0: HRESULT result = mQuery->Issue(D3DISSUE_END); michael@0: ASSERT(SUCCEEDED(result)); michael@0: michael@0: setCondition(condition); michael@0: setStatus(GL_FALSE); michael@0: } michael@0: michael@0: GLboolean Fence9::testFence() michael@0: { michael@0: if (mQuery == NULL) michael@0: { michael@0: return gl::error(GL_INVALID_OPERATION, GL_TRUE); michael@0: } michael@0: michael@0: HRESULT result = mQuery->GetData(NULL, 0, D3DGETDATA_FLUSH); michael@0: michael@0: if (d3d9::isDeviceLostError(result)) michael@0: { michael@0: mRenderer->notifyDeviceLost(); michael@0: return gl::error(GL_OUT_OF_MEMORY, GL_TRUE); michael@0: } michael@0: michael@0: ASSERT(result == S_OK || result == S_FALSE); michael@0: setStatus(result == S_OK); michael@0: return getStatus(); michael@0: } michael@0: michael@0: void Fence9::finishFence() michael@0: { michael@0: if (mQuery == NULL) michael@0: { michael@0: return gl::error(GL_INVALID_OPERATION); michael@0: } michael@0: michael@0: while (!testFence()) michael@0: { michael@0: Sleep(0); michael@0: } michael@0: } michael@0: michael@0: void Fence9::getFenceiv(GLenum pname, GLint *params) michael@0: { michael@0: if (mQuery == NULL) michael@0: { michael@0: return gl::error(GL_INVALID_OPERATION); michael@0: } michael@0: michael@0: switch (pname) michael@0: { michael@0: case GL_FENCE_STATUS_NV: michael@0: { michael@0: // GL_NV_fence spec: michael@0: // Once the status of a fence has been finished (via FinishFenceNV) or tested and the returned status is TRUE (via either TestFenceNV michael@0: // or GetFenceivNV querying the FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence. michael@0: if (getStatus()) michael@0: { michael@0: params[0] = GL_TRUE; michael@0: return; michael@0: } michael@0: michael@0: HRESULT result = mQuery->GetData(NULL, 0, 0); michael@0: michael@0: if (d3d9::isDeviceLostError(result)) michael@0: { michael@0: params[0] = GL_TRUE; michael@0: mRenderer->notifyDeviceLost(); michael@0: return gl::error(GL_OUT_OF_MEMORY); michael@0: } michael@0: michael@0: ASSERT(result == S_OK || result == S_FALSE); michael@0: setStatus(result == S_OK); michael@0: params[0] = getStatus(); michael@0: michael@0: break; michael@0: } michael@0: case GL_FENCE_CONDITION_NV: michael@0: params[0] = getCondition(); michael@0: break; michael@0: default: michael@0: return gl::error(GL_INVALID_ENUM); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: }