gl::Error Query11::resume() { if (mActiveQuery.query == nullptr) { gl::Error error = flush(false); if (error.isError()) { return error; } D3D11_QUERY_DESC queryDesc; queryDesc.Query = gl_d3d11::ConvertQueryType(getType()); queryDesc.MiscFlags = 0; ID3D11Device *device = mRenderer->getDevice(); HRESULT result = device->CreateQuery(&queryDesc, &mActiveQuery.query); if (FAILED(result)) { return gl::Error(GL_OUT_OF_MEMORY, "Internal query creation failed, result: 0x%X.", result); } // If we are doing time elapsed we also need a query to actually query the timestamp if (getType() == GL_TIME_ELAPSED_EXT) { D3D11_QUERY_DESC desc; desc.Query = D3D11_QUERY_TIMESTAMP; desc.MiscFlags = 0; result = device->CreateQuery(&desc, &mActiveQuery.beginTimestamp); if (FAILED(result)) { return gl::Error(GL_OUT_OF_MEMORY, "Internal query creation failed, result: 0x%X.", result); } result = device->CreateQuery(&desc, &mActiveQuery.endTimestamp); if (FAILED(result)) { return gl::Error(GL_OUT_OF_MEMORY, "Internal query creation failed, result: 0x%X.", result); } } ID3D11DeviceContext *context = mRenderer->getDeviceContext(); context->Begin(mActiveQuery.query); // If we are doing time elapsed, query the begin timestamp if (getType() == GL_TIME_ELAPSED_EXT) { context->End(mActiveQuery.beginTimestamp); } } return gl::Error(GL_NO_ERROR); }
gl::Error Query11::end() { ASSERT(mQuery); ID3D11DeviceContext *context = mRenderer->getDeviceContext(); // If we are doing time elapsed query the end timestamp if (getType() == GL_TIME_ELAPSED_EXT) { context->End(mTimestampEndQuery); } context->End(mQuery); mQueryFinished = false; mResult = GL_FALSE; return gl::Error(GL_NO_ERROR); }
gl::Error Query11::pause() { if (mActiveQuery.query != nullptr) { ID3D11DeviceContext *context = mRenderer->getDeviceContext(); // If we are doing time elapsed query the end timestamp if (getType() == GL_TIME_ELAPSED_EXT) { context->End(mActiveQuery.endTimestamp); } context->End(mActiveQuery.query); mPendingQueries.push_back(mActiveQuery); mActiveQuery = QueryState(); } return flush(false); }
void CRenderCaptureDX::EndRender() { // send commands to the GPU queue g_Windowing.FinishCommandList(); ID3D11DeviceContext* pContext = g_Windowing.GetImmediateContext(); pContext->CopyResource(m_copySurface, m_renderTexture); if (m_query) { pContext->End(m_query); } if (m_flags & CAPTUREFLAG_IMMEDIATELY) SurfaceToBuffer(); else SetState(CAPTURESTATE_NEEDSREADOUT); }
void CRenderCaptureDX::EndRender() { // send commands to the GPU queue auto deviceResources = DX::DeviceResources::Get(); deviceResources->FinishCommandList(); ID3D11DeviceContext* pContext = deviceResources->GetImmediateContext(); pContext->CopyResource(m_copyTex.Get(), m_renderTex.Get()); if (m_query) { pContext->End(m_query); } if (m_flags & CAPTUREFLAG_IMMEDIATELY) SurfaceToBuffer(); else SetState(CAPTURESTATE_NEEDSREADOUT); }