Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // QueryGL.cpp: Implements the class methods for QueryGL. |
| 8 | |
| 9 | #include "libANGLE/renderer/gl/QueryGL.h" |
| 10 | |
| 11 | #include "common/debug.h" |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 12 | #include "libANGLE/renderer/gl/FunctionsGL.h" |
| 13 | #include "libANGLE/renderer/gl/StateManagerGL.h" |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 14 | #include "libANGLE/renderer/gl/renderergl_utils.h" |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 15 | |
| 16 | namespace |
| 17 | { |
| 18 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame^] | 19 | GLuint64 MergeQueryResults(gl::QueryType type, GLuint64 currentResult, GLuint64 newResult) |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 20 | { |
| 21 | switch (type) |
| 22 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame^] | 23 | case gl::QueryType::AnySamples: |
| 24 | case gl::QueryType::AnySamplesConservative: |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 25 | return (currentResult == GL_TRUE || newResult == GL_TRUE) ? GL_TRUE : GL_FALSE; |
| 26 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame^] | 27 | case gl::QueryType::TransformFeedbackPrimitivesWritten: |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 28 | return currentResult + newResult; |
| 29 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame^] | 30 | case gl::QueryType::TimeElapsed: |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 31 | return currentResult + newResult; |
| 32 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame^] | 33 | case gl::QueryType::Timestamp: |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 34 | return newResult; |
| 35 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame^] | 36 | case gl::QueryType::PrimitivesGenerated: |
Jiawei Shao | d2fa07e | 2018-03-15 09:20:25 +0800 | [diff] [blame] | 37 | return currentResult + newResult; |
| 38 | |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 39 | default: |
| 40 | UNREACHABLE(); |
| 41 | return 0; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | } // anonymous namespace |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 46 | |
| 47 | namespace rx |
| 48 | { |
| 49 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame^] | 50 | QueryGL::QueryGL(gl::QueryType type) : QueryImpl(type) |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 51 | { |
| 52 | } |
| 53 | |
| 54 | QueryGL::~QueryGL() |
| 55 | { |
| 56 | } |
| 57 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame^] | 58 | StandardQueryGL::StandardQueryGL(gl::QueryType type, |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 59 | const FunctionsGL *functions, |
| 60 | StateManagerGL *stateManager) |
| 61 | : QueryGL(type), |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 62 | mType(type), |
| 63 | mFunctions(functions), |
| 64 | mStateManager(stateManager), |
| 65 | mActiveQuery(0), |
| 66 | mPendingQueries(), |
| 67 | mResultSum(0) |
| 68 | { |
| 69 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 70 | |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 71 | StandardQueryGL::~StandardQueryGL() |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 72 | { |
Geoff Lang | bcb4c68 | 2018-02-05 14:56:54 -0500 | [diff] [blame] | 73 | if (mActiveQuery != 0) |
| 74 | { |
| 75 | mStateManager->endQuery(mType, this, mActiveQuery); |
| 76 | mFunctions->deleteQueries(1, &mActiveQuery); |
| 77 | mActiveQuery = 0; |
| 78 | } |
| 79 | |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 80 | while (!mPendingQueries.empty()) |
| 81 | { |
Geoff Lang | bcb4c68 | 2018-02-05 14:56:54 -0500 | [diff] [blame] | 82 | GLuint id = mPendingQueries.front(); |
| 83 | mFunctions->deleteQueries(1, &id); |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 84 | mPendingQueries.pop_front(); |
| 85 | } |
| 86 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 87 | |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 88 | gl::Error StandardQueryGL::begin() |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 89 | { |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 90 | mResultSum = 0; |
Ian Ewell | 292f005 | 2016-02-04 10:37:32 -0500 | [diff] [blame] | 91 | return resume(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 92 | } |
| 93 | |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 94 | gl::Error StandardQueryGL::end() |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 95 | { |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 96 | return pause(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 97 | } |
| 98 | |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 99 | gl::Error StandardQueryGL::queryCounter() |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 100 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame^] | 101 | ASSERT(mType == gl::QueryType::Timestamp); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 102 | |
| 103 | // Directly create a query for the timestamp and add it to the pending query queue, as timestamp |
| 104 | // queries do not have the traditional begin/end block and never need to be paused/resumed |
| 105 | GLuint query; |
| 106 | mFunctions->genQueries(1, &query); |
| 107 | mFunctions->queryCounter(query, GL_TIMESTAMP); |
| 108 | mPendingQueries.push_back(query); |
| 109 | |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 110 | return gl::NoError(); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | template <typename T> |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 114 | gl::Error StandardQueryGL::getResultBase(T *params) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 115 | { |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 116 | ASSERT(mActiveQuery == 0); |
| 117 | |
| 118 | gl::Error error = flush(true); |
| 119 | if (error.isError()) |
| 120 | { |
| 121 | return error; |
| 122 | } |
| 123 | |
| 124 | ASSERT(mPendingQueries.empty()); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 125 | *params = static_cast<T>(mResultSum); |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 126 | |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 127 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 128 | } |
| 129 | |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 130 | gl::Error StandardQueryGL::getResult(GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 131 | { |
| 132 | return getResultBase(params); |
| 133 | } |
| 134 | |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 135 | gl::Error StandardQueryGL::getResult(GLuint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 136 | { |
| 137 | return getResultBase(params); |
| 138 | } |
| 139 | |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 140 | gl::Error StandardQueryGL::getResult(GLint64 *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 141 | { |
| 142 | return getResultBase(params); |
| 143 | } |
| 144 | |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 145 | gl::Error StandardQueryGL::getResult(GLuint64 *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 146 | { |
| 147 | return getResultBase(params); |
| 148 | } |
| 149 | |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 150 | gl::Error StandardQueryGL::isResultAvailable(bool *available) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 151 | { |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 152 | ASSERT(mActiveQuery == 0); |
| 153 | |
| 154 | gl::Error error = flush(false); |
| 155 | if (error.isError()) |
| 156 | { |
| 157 | return error; |
| 158 | } |
| 159 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 160 | *available = mPendingQueries.empty(); |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 161 | return gl::NoError(); |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 162 | } |
| 163 | |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 164 | gl::Error StandardQueryGL::pause() |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 165 | { |
| 166 | if (mActiveQuery != 0) |
| 167 | { |
Geoff Lang | bcb4c68 | 2018-02-05 14:56:54 -0500 | [diff] [blame] | 168 | mStateManager->endQuery(mType, this, mActiveQuery); |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 169 | |
| 170 | mPendingQueries.push_back(mActiveQuery); |
| 171 | mActiveQuery = 0; |
| 172 | } |
| 173 | |
| 174 | // Flush to make sure the pending queries don't add up too much. |
| 175 | gl::Error error = flush(false); |
| 176 | if (error.isError()) |
| 177 | { |
| 178 | return error; |
| 179 | } |
| 180 | |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 181 | return gl::NoError(); |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 182 | } |
| 183 | |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 184 | gl::Error StandardQueryGL::resume() |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 185 | { |
| 186 | if (mActiveQuery == 0) |
| 187 | { |
| 188 | // Flush to make sure the pending queries don't add up too much. |
| 189 | gl::Error error = flush(false); |
| 190 | if (error.isError()) |
| 191 | { |
| 192 | return error; |
| 193 | } |
| 194 | |
| 195 | mFunctions->genQueries(1, &mActiveQuery); |
Geoff Lang | bcb4c68 | 2018-02-05 14:56:54 -0500 | [diff] [blame] | 196 | mStateManager->beginQuery(mType, this, mActiveQuery); |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 197 | } |
| 198 | |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 199 | return gl::NoError(); |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 200 | } |
| 201 | |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 202 | gl::Error StandardQueryGL::flush(bool force) |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 203 | { |
| 204 | while (!mPendingQueries.empty()) |
| 205 | { |
| 206 | GLuint id = mPendingQueries.front(); |
| 207 | if (!force) |
| 208 | { |
| 209 | GLuint resultAvailable = 0; |
| 210 | mFunctions->getQueryObjectuiv(id, GL_QUERY_RESULT_AVAILABLE, &resultAvailable); |
| 211 | if (resultAvailable == GL_FALSE) |
| 212 | { |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 213 | return gl::NoError(); |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 217 | // Even though getQueryObjectui64v was introduced for timer queries, there is nothing in the |
| 218 | // standard that says that it doesn't work for any other queries. It also passes on all the |
| 219 | // trybots, so we use it if it is available |
| 220 | if (mFunctions->getQueryObjectui64v != nullptr) |
| 221 | { |
| 222 | GLuint64 result = 0; |
| 223 | mFunctions->getQueryObjectui64v(id, GL_QUERY_RESULT, &result); |
| 224 | mResultSum = MergeQueryResults(mType, mResultSum, result); |
| 225 | } |
| 226 | else |
| 227 | { |
| 228 | GLuint result = 0; |
| 229 | mFunctions->getQueryObjectuiv(id, GL_QUERY_RESULT, &result); |
| 230 | mResultSum = MergeQueryResults(mType, mResultSum, static_cast<GLuint64>(result)); |
| 231 | } |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 232 | |
Geoff Lang | bcb4c68 | 2018-02-05 14:56:54 -0500 | [diff] [blame] | 233 | mFunctions->deleteQueries(1, &id); |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 234 | |
| 235 | mPendingQueries.pop_front(); |
| 236 | } |
| 237 | |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 238 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 239 | } |
| 240 | |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 241 | class SyncProviderGL |
| 242 | { |
| 243 | public: |
| 244 | virtual ~SyncProviderGL() {} |
| 245 | virtual gl::Error flush(bool force, bool *finished) = 0; |
| 246 | }; |
| 247 | |
| 248 | class SyncProviderGLSync : public SyncProviderGL |
| 249 | { |
| 250 | public: |
| 251 | SyncProviderGLSync(const FunctionsGL *functions) : mFunctions(functions), mSync(nullptr) |
| 252 | { |
| 253 | mSync = mFunctions->fenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); |
| 254 | } |
| 255 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 256 | ~SyncProviderGLSync() override { mFunctions->deleteSync(mSync); } |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 257 | |
| 258 | gl::Error flush(bool force, bool *finished) override |
| 259 | { |
| 260 | if (force) |
| 261 | { |
| 262 | mFunctions->clientWaitSync(mSync, 0, 0); |
| 263 | *finished = true; |
| 264 | } |
| 265 | else |
| 266 | { |
| 267 | GLint value = 0; |
| 268 | mFunctions->getSynciv(mSync, GL_SYNC_STATUS, 1, nullptr, &value); |
| 269 | *finished = (value == GL_SIGNALED); |
| 270 | } |
| 271 | |
| 272 | return gl::NoError(); |
| 273 | } |
| 274 | |
| 275 | private: |
| 276 | const FunctionsGL *mFunctions; |
| 277 | GLsync mSync; |
| 278 | }; |
| 279 | |
| 280 | class SyncProviderGLQuery : public SyncProviderGL |
| 281 | { |
| 282 | public: |
| 283 | SyncProviderGLQuery(const FunctionsGL *functions, |
| 284 | StateManagerGL *stateManager, |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame^] | 285 | gl::QueryType type) |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 286 | : mFunctions(functions), mQuery(0) |
| 287 | { |
| 288 | mFunctions->genQueries(1, &mQuery); |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame^] | 289 | ANGLE_SWALLOW_ERR(stateManager->pauseQuery(type)); |
| 290 | mFunctions->beginQuery(ToGLenum(type), mQuery); |
| 291 | mFunctions->endQuery(ToGLenum(type)); |
| 292 | ANGLE_SWALLOW_ERR(stateManager->resumeQuery(type)); |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 293 | } |
| 294 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 295 | ~SyncProviderGLQuery() override { mFunctions->deleteQueries(1, &mQuery); } |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 296 | |
| 297 | gl::Error flush(bool force, bool *finished) override |
| 298 | { |
| 299 | if (force) |
| 300 | { |
| 301 | GLint result = 0; |
| 302 | mFunctions->getQueryObjectiv(mQuery, GL_QUERY_RESULT, &result); |
| 303 | *finished = true; |
| 304 | } |
| 305 | else |
| 306 | { |
| 307 | GLint available = 0; |
| 308 | mFunctions->getQueryObjectiv(mQuery, GL_QUERY_RESULT_AVAILABLE, &available); |
| 309 | *finished = (available == GL_TRUE); |
| 310 | } |
| 311 | |
| 312 | return gl::NoError(); |
| 313 | } |
| 314 | |
| 315 | private: |
| 316 | const FunctionsGL *mFunctions; |
| 317 | GLuint mQuery; |
| 318 | }; |
| 319 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame^] | 320 | SyncQueryGL::SyncQueryGL(gl::QueryType type, |
| 321 | const FunctionsGL *functions, |
| 322 | StateManagerGL *stateManager) |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 323 | : QueryGL(type), |
| 324 | mFunctions(functions), |
| 325 | mStateManager(stateManager), |
| 326 | mSyncProvider(nullptr), |
| 327 | mFinished(false) |
| 328 | { |
| 329 | ASSERT(IsSupported(mFunctions)); |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame^] | 330 | ASSERT(type == gl::QueryType::CommandsCompleted); |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | SyncQueryGL::~SyncQueryGL() |
| 334 | { |
| 335 | } |
| 336 | |
| 337 | bool SyncQueryGL::IsSupported(const FunctionsGL *functions) |
| 338 | { |
| 339 | return nativegl::SupportsFenceSync(functions) || nativegl::SupportsOcclusionQueries(functions); |
| 340 | } |
| 341 | |
| 342 | gl::Error SyncQueryGL::begin() |
| 343 | { |
| 344 | return gl::NoError(); |
| 345 | } |
| 346 | |
| 347 | gl::Error SyncQueryGL::end() |
| 348 | { |
| 349 | if (nativegl::SupportsFenceSync(mFunctions)) |
| 350 | { |
| 351 | mSyncProvider.reset(new SyncProviderGLSync(mFunctions)); |
| 352 | } |
| 353 | else if (nativegl::SupportsOcclusionQueries(mFunctions)) |
| 354 | { |
| 355 | mSyncProvider.reset( |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame^] | 356 | new SyncProviderGLQuery(mFunctions, mStateManager, gl::QueryType::AnySamples)); |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 357 | } |
| 358 | else |
| 359 | { |
| 360 | ASSERT(false); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 361 | return gl::InternalError() << "No native support for sync queries."; |
Geoff Lang | a20fc00 | 2016-08-08 15:19:56 -0400 | [diff] [blame] | 362 | } |
| 363 | return gl::NoError(); |
| 364 | } |
| 365 | |
| 366 | gl::Error SyncQueryGL::queryCounter() |
| 367 | { |
| 368 | UNREACHABLE(); |
| 369 | return gl::NoError(); |
| 370 | } |
| 371 | |
| 372 | gl::Error SyncQueryGL::getResult(GLint *params) |
| 373 | { |
| 374 | return getResultBase(params); |
| 375 | } |
| 376 | |
| 377 | gl::Error SyncQueryGL::getResult(GLuint *params) |
| 378 | { |
| 379 | return getResultBase(params); |
| 380 | } |
| 381 | |
| 382 | gl::Error SyncQueryGL::getResult(GLint64 *params) |
| 383 | { |
| 384 | return getResultBase(params); |
| 385 | } |
| 386 | |
| 387 | gl::Error SyncQueryGL::getResult(GLuint64 *params) |
| 388 | { |
| 389 | return getResultBase(params); |
| 390 | } |
| 391 | |
| 392 | gl::Error SyncQueryGL::isResultAvailable(bool *available) |
| 393 | { |
| 394 | ANGLE_TRY(flush(false)); |
| 395 | *available = mFinished; |
| 396 | return gl::NoError(); |
| 397 | } |
| 398 | |
| 399 | gl::Error SyncQueryGL::pause() |
| 400 | { |
| 401 | return gl::NoError(); |
| 402 | } |
| 403 | |
| 404 | gl::Error SyncQueryGL::resume() |
| 405 | { |
| 406 | return gl::NoError(); |
| 407 | } |
| 408 | |
| 409 | gl::Error SyncQueryGL::flush(bool force) |
| 410 | { |
| 411 | if (mSyncProvider == nullptr) |
| 412 | { |
| 413 | ASSERT(mFinished); |
| 414 | return gl::NoError(); |
| 415 | } |
| 416 | |
| 417 | ANGLE_TRY(mSyncProvider->flush(force, &mFinished)); |
| 418 | if (mFinished) |
| 419 | { |
| 420 | mSyncProvider.reset(); |
| 421 | } |
| 422 | |
| 423 | return gl::NoError(); |
| 424 | } |
| 425 | |
| 426 | template <typename T> |
| 427 | gl::Error SyncQueryGL::getResultBase(T *params) |
| 428 | { |
| 429 | ANGLE_TRY(flush(true)); |
| 430 | *params = static_cast<T>(mFinished ? GL_TRUE : GL_FALSE); |
| 431 | return gl::NoError(); |
| 432 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 433 | } |