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: // Fence11.cpp: Defines the rx::Fence11 class which implements rx::FenceImpl. michael@0: michael@0: #include "libGLESv2/renderer/Fence11.h" michael@0: #include "libGLESv2/main.h" michael@0: #include "libGLESv2/renderer/Renderer11.h" michael@0: michael@0: namespace rx michael@0: { michael@0: michael@0: Fence11::Fence11(rx::Renderer11 *renderer) michael@0: { michael@0: mRenderer = renderer; michael@0: mQuery = NULL; michael@0: } michael@0: michael@0: Fence11::~Fence11() michael@0: { michael@0: if (mQuery) michael@0: { michael@0: mQuery->Release(); michael@0: mQuery = NULL; michael@0: } michael@0: } michael@0: michael@0: GLboolean Fence11::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 Fence11::setFence(GLenum condition) michael@0: { michael@0: if (!mQuery) michael@0: { michael@0: D3D11_QUERY_DESC queryDesc; michael@0: queryDesc.Query = D3D11_QUERY_EVENT; michael@0: queryDesc.MiscFlags = 0; michael@0: michael@0: if (FAILED(mRenderer->getDevice()->CreateQuery(&queryDesc, &mQuery))) michael@0: { michael@0: return gl::error(GL_OUT_OF_MEMORY); michael@0: } michael@0: } michael@0: michael@0: mRenderer->getDeviceContext()->End(mQuery); michael@0: michael@0: setCondition(condition); michael@0: setStatus(GL_FALSE); michael@0: } michael@0: michael@0: GLboolean Fence11::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 = mRenderer->getDeviceContext()->GetData(mQuery, NULL, 0, 0); michael@0: michael@0: if (mRenderer->isDeviceLost()) michael@0: { 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 Fence11::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 Fence11::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 = mRenderer->getDeviceContext()->GetData(mQuery, NULL, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH); michael@0: michael@0: if (mRenderer->isDeviceLost()) michael@0: { michael@0: params[0] = GL_TRUE; 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: }