1 #include "precompiled.h"
3 // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
8 // Query11.cpp: Defines the rx::Query11 class which implements rx::QueryImpl.
10 #include "libGLESv2/renderer/d3d11/Query11.h"
11 #include "libGLESv2/renderer/d3d11/Renderer11.h"
12 #include "libGLESv2/renderer/d3d11/renderer11_utils.h"
13 #include "libGLESv2/main.h"
18 static bool checkOcclusionQuery(ID3D11DeviceContext *context, ID3D11Query *query, UINT64 *numPixels)
20 HRESULT result = context->GetData(query, numPixels, sizeof(UINT64), 0);
21 return (result == S_OK);
24 static bool checkStreamOutPrimitivesWritten(ID3D11DeviceContext *context, ID3D11Query *query, UINT64 *numPrimitives)
26 D3D11_QUERY_DATA_SO_STATISTICS soStats = { 0 };
27 HRESULT result = context->GetData(query, &soStats, sizeof(D3D11_QUERY_DATA_SO_STATISTICS), 0);
28 *numPrimitives = soStats.NumPrimitivesWritten;
29 return (result == S_OK);
32 Query11::Query11(rx::Renderer11 *renderer, GLenum type) : QueryImpl(type)
47 D3D11_QUERY_DESC queryDesc;
48 queryDesc.Query = gl_d3d11::ConvertQueryType(getType());
49 queryDesc.MiscFlags = 0;
51 if (FAILED(mRenderer->getDevice()->CreateQuery(&queryDesc, &mQuery)))
53 return gl::error(GL_OUT_OF_MEMORY);
57 mRenderer->getDeviceContext()->Begin(mQuery);
63 mRenderer->getDeviceContext()->End(mQuery);
69 GLuint Query11::getResult()
76 // explicitly check for device loss, some drivers seem to return S_FALSE
77 // if the device is lost
78 if (mRenderer->testDeviceLost(true))
80 return gl::error(GL_OUT_OF_MEMORY, 0);
88 GLboolean Query11::isResultAvailable()
98 GLboolean Query11::testQuery()
100 if (mQuery != NULL && mStatus != GL_TRUE)
102 ID3D11DeviceContext *context = mRenderer->getDeviceContext();
104 bool queryFinished = false;
107 case GL_ANY_SAMPLES_PASSED_EXT:
108 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
110 UINT64 numPixels = 0;
111 queryFinished = checkOcclusionQuery(context, mQuery, &numPixels);
114 mResult = (numPixels > 0) ? GL_TRUE : GL_FALSE;
119 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
121 UINT64 numPrimitives = 0;
122 queryFinished = checkStreamOutPrimitivesWritten(context, mQuery, &numPrimitives);
125 mResult = static_cast<GLuint>(numPrimitives);
139 else if (mRenderer->testDeviceLost(true))
141 return gl::error(GL_OUT_OF_MEMORY, GL_TRUE);
147 return GL_TRUE; // prevent blocking when query is null
150 bool Query11::isStarted() const
152 return (mQuery != NULL);