1 //
2 // Copyright 2016 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 // QueryVk.cpp:
7 // Implements the class methods for QueryVk.
8 //
9
10 #include "libANGLE/renderer/vulkan/QueryVk.h"
11 #include "libANGLE/Context.h"
12 #include "libANGLE/TransformFeedback.h"
13 #include "libANGLE/renderer/vulkan/ContextVk.h"
14 #include "libANGLE/renderer/vulkan/RendererVk.h"
15 #include "libANGLE/renderer/vulkan/TransformFeedbackVk.h"
16
17 #include "common/debug.h"
18
19 namespace rx
20 {
21
22 namespace
23 {
24 struct QueryReleaseHelper
25 {
operator ()rx::__anonfc264e200111::QueryReleaseHelper26 void operator()(vk::QueryHelper &&query) { queryPool->freeQuery(contextVk, &query); }
27
28 ContextVk *contextVk;
29 vk::DynamicQueryPool *queryPool;
30 };
31
IsRenderPassQuery(ContextVk * contextVk,gl::QueryType type)32 bool IsRenderPassQuery(ContextVk *contextVk, gl::QueryType type)
33 {
34 switch (type)
35 {
36 case gl::QueryType::AnySamples:
37 case gl::QueryType::AnySamplesConservative:
38 case gl::QueryType::PrimitivesGenerated:
39 return true;
40 case gl::QueryType::TransformFeedbackPrimitivesWritten:
41 return contextVk->getFeatures().supportsTransformFeedbackExtension.enabled;
42 default:
43 return false;
44 }
45 }
46
IsEmulatedTransformFeedbackQuery(ContextVk * contextVk,gl::QueryType type)47 bool IsEmulatedTransformFeedbackQuery(ContextVk *contextVk, gl::QueryType type)
48 {
49 return type == gl::QueryType::TransformFeedbackPrimitivesWritten &&
50 contextVk->getFeatures().emulateTransformFeedback.enabled;
51 }
52
IsPrimitivesGeneratedQueryShared(ContextVk * contextVk)53 bool IsPrimitivesGeneratedQueryShared(ContextVk *contextVk)
54 {
55 return !contextVk->getFeatures().supportsPipelineStatisticsQuery.enabled;
56 }
57
GetShareQuery(ContextVk * contextVk,gl::QueryType type)58 QueryVk *GetShareQuery(ContextVk *contextVk, gl::QueryType type)
59 {
60 QueryVk *shareQuery = nullptr;
61
62 // If the primitives generated query has its own dedicated Vulkan query, there's no sharing.
63 if (!IsPrimitivesGeneratedQueryShared(contextVk))
64 {
65 return nullptr;
66 }
67
68 switch (type)
69 {
70 case gl::QueryType::PrimitivesGenerated:
71 shareQuery = contextVk->getActiveRenderPassQuery(
72 gl::QueryType::TransformFeedbackPrimitivesWritten);
73 break;
74 case gl::QueryType::TransformFeedbackPrimitivesWritten:
75 shareQuery = contextVk->getActiveRenderPassQuery(gl::QueryType::PrimitivesGenerated);
76 break;
77 default:
78 break;
79 }
80
81 return shareQuery;
82 }
83
84 // When a render pass starts/ends, onRenderPassStart/End is called for all active queries. For
85 // shared queries, the one that is called first would actually manage the query helper begin/end and
86 // allocation, and the one that follows would share it. PrimitivesGenerated and
87 // TransformFeedbackPrimitivesWritten share queries, and the former is processed first.
GetOnRenderPassStartEndShareQuery(ContextVk * contextVk,gl::QueryType type)88 QueryVk *GetOnRenderPassStartEndShareQuery(ContextVk *contextVk, gl::QueryType type)
89 {
90 static_assert(
91 gl::QueryType::PrimitivesGenerated < gl::QueryType::TransformFeedbackPrimitivesWritten,
92 "incorrect assumption about the order in which queries are started in a render pass");
93
94 if (type != gl::QueryType::TransformFeedbackPrimitivesWritten ||
95 !IsPrimitivesGeneratedQueryShared(contextVk))
96 {
97 return nullptr;
98 }
99
100 // For TransformFeedbackPrimitivesWritten, return the already-processed PrimitivesGenerated
101 // share query.
102 return contextVk->getActiveRenderPassQuery(gl::QueryType::PrimitivesGenerated);
103 }
104 } // anonymous namespace
105
QueryVk(gl::QueryType type)106 QueryVk::QueryVk(gl::QueryType type)
107 : QueryImpl(type),
108 mTransformFeedbackPrimitivesDrawn(0),
109 mCachedResult(0),
110 mCachedResultValid(false)
111 {}
112
113 QueryVk::~QueryVk() = default;
114
allocateQuery(ContextVk * contextVk)115 angle::Result QueryVk::allocateQuery(ContextVk *contextVk)
116 {
117 ASSERT(!mQueryHelper.isReferenced());
118 mQueryHelper.setUnreferenced(new vk::RefCounted<vk::QueryHelper>);
119
120 // When used with multiview, render pass queries write as many queries as the number of views.
121 // Render pass queries are always allocated at the beginning of the render pass, so the number
122 // of views is known at this time.
123 uint32_t queryCount = 1;
124 if (IsRenderPassQuery(contextVk, mType))
125 {
126 ASSERT(contextVk->hasStartedRenderPass());
127 queryCount = std::max(contextVk->getCurrentViewCount(), 1u);
128 }
129
130 return contextVk->getQueryPool(mType)->allocateQuery(contextVk, &mQueryHelper.get(),
131 queryCount);
132 }
133
assignSharedQuery(QueryVk * shareQuery)134 void QueryVk::assignSharedQuery(QueryVk *shareQuery)
135 {
136 ASSERT(!mQueryHelper.isReferenced());
137 ASSERT(shareQuery->mQueryHelper.isReferenced());
138 mQueryHelper.copyUnreferenced(shareQuery->mQueryHelper);
139 }
140
releaseQueries(ContextVk * contextVk)141 void QueryVk::releaseQueries(ContextVk *contextVk)
142 {
143 ASSERT(!IsEmulatedTransformFeedbackQuery(contextVk, mType));
144
145 vk::DynamicQueryPool *queryPool = contextVk->getQueryPool(mType);
146
147 // Free the main query
148 if (mQueryHelper.isReferenced())
149 {
150 QueryReleaseHelper releaseHelper = {contextVk, queryPool};
151 mQueryHelper.resetAndRelease(&releaseHelper);
152 }
153 // Free the secondary query used to emulate TimeElapsed
154 queryPool->freeQuery(contextVk, &mQueryHelperTimeElapsedBegin);
155
156 // Free any stashed queries used to support queries that start and stop with the render pass.
157 releaseStashedQueries(contextVk);
158 }
159
releaseStashedQueries(ContextVk * contextVk)160 void QueryVk::releaseStashedQueries(ContextVk *contextVk)
161 {
162 vk::DynamicQueryPool *queryPool = contextVk->getQueryPool(mType);
163
164 for (vk::Shared<vk::QueryHelper> &query : mStashedQueryHelpers)
165 {
166 ASSERT(query.isReferenced());
167
168 QueryReleaseHelper releaseHelper = {contextVk, queryPool};
169 query.resetAndRelease(&releaseHelper);
170 }
171 mStashedQueryHelpers.clear();
172 }
173
onDestroy(const gl::Context * context)174 void QueryVk::onDestroy(const gl::Context *context)
175 {
176 ContextVk *contextVk = vk::GetImpl(context);
177 if (!IsEmulatedTransformFeedbackQuery(contextVk, mType))
178 {
179 releaseQueries(contextVk);
180 }
181 }
182
stashQueryHelper()183 void QueryVk::stashQueryHelper()
184 {
185 ASSERT(mQueryHelper.isReferenced());
186 mStashedQueryHelpers.push_back(std::move(mQueryHelper));
187 ASSERT(!mQueryHelper.isReferenced());
188 }
189
onRenderPassStart(ContextVk * contextVk)190 angle::Result QueryVk::onRenderPassStart(ContextVk *contextVk)
191 {
192 ASSERT(IsRenderPassQuery(contextVk, mType));
193
194 // If there is a query helper already, stash it and allocate a new one for this render pass.
195 if (mQueryHelper.isReferenced())
196 {
197 stashQueryHelper();
198 }
199
200 QueryVk *shareQuery = GetOnRenderPassStartEndShareQuery(contextVk, mType);
201
202 if (shareQuery)
203 {
204 assignSharedQuery(shareQuery);
205
206 // shareQuery has already started the query.
207 return angle::Result::Continue;
208 }
209
210 ANGLE_TRY(allocateQuery(contextVk));
211 return mQueryHelper.get().beginRenderPassQuery(contextVk);
212 }
213
onRenderPassEnd(ContextVk * contextVk)214 void QueryVk::onRenderPassEnd(ContextVk *contextVk)
215 {
216 ASSERT(IsRenderPassQuery(contextVk, mType));
217 ASSERT(mQueryHelper.isReferenced());
218
219 QueryVk *shareQuery = GetOnRenderPassStartEndShareQuery(contextVk, mType);
220
221 // If present, share query has already taken care of ending the query.
222 if (shareQuery == nullptr)
223 {
224 mQueryHelper.get().endRenderPassQuery(contextVk);
225 }
226 }
227
accumulateStashedQueryResult(ContextVk * contextVk,vk::QueryResult * result)228 angle::Result QueryVk::accumulateStashedQueryResult(ContextVk *contextVk, vk::QueryResult *result)
229 {
230 for (vk::Shared<vk::QueryHelper> &query : mStashedQueryHelpers)
231 {
232 vk::QueryResult v(getQueryResultCount(contextVk));
233 ANGLE_TRY(query.get().getUint64Result(contextVk, &v));
234 *result += v;
235 }
236 releaseStashedQueries(contextVk);
237 return angle::Result::Continue;
238 }
239
setupBegin(ContextVk * contextVk)240 angle::Result QueryVk::setupBegin(ContextVk *contextVk)
241 {
242 if (IsRenderPassQuery(contextVk, mType))
243 {
244 // Clean up query helpers from the previous begin/end call on the same query. Only
245 // necessary for in-render-pass queries. The other queries can reuse query helpers as they
246 // are able to reset it ouside the render pass where they are recorded.
247 if (mQueryHelper.isReferenced())
248 {
249 releaseQueries(contextVk);
250 }
251
252 // If either of TransformFeedbackPrimitivesWritten or PrimitivesGenerated queries are
253 // already active when the other one is begun, we have to switch to a new query helper (if
254 // in render pass), and have them share the query helper from here on.
255
256 // If this is a transform feedback query, see if the other transform feedback query is
257 // already active.
258 QueryVk *shareQuery = GetShareQuery(contextVk, mType);
259
260 // If so, make the other query stash its results and continue with a new query helper.
261 if (contextVk->hasStartedRenderPass())
262 {
263 if (shareQuery)
264 {
265 // This serves the following scenario (TF = TransformFeedbackPrimitivesWritten, PG =
266 // PrimitivesGenerated):
267 //
268 // - TF starts <-- QueryHelper1 starts
269 // - Draw
270 // - PG starts <-- QueryHelper1 stashed in TF, TF starts QueryHelper2,
271 // PG shares QueryHelper2
272 // - Draw
273 shareQuery->onRenderPassEnd(contextVk);
274 shareQuery->stashQueryHelper();
275 ANGLE_TRY(shareQuery->allocateQuery(contextVk));
276
277 // Share the query helper with the other transform feedback query. After
278 // |setupBegin()| returns, they query helper is started on behalf of the shared
279 // query.
280 assignSharedQuery(shareQuery);
281 }
282 }
283 else
284 {
285 // Keep the query helper unallocated. When the render pass starts, a new one
286 // will be allocated / shared.
287 return angle::Result::Continue;
288 }
289 }
290
291 // If no query helper, create a new one.
292 if (!mQueryHelper.isReferenced())
293 {
294 ANGLE_TRY(allocateQuery(contextVk));
295 }
296
297 return angle::Result::Continue;
298 }
299
begin(const gl::Context * context)300 angle::Result QueryVk::begin(const gl::Context *context)
301 {
302 ContextVk *contextVk = vk::GetImpl(context);
303
304 mCachedResultValid = false;
305
306 // Transform feedback query is handled by a CPU-calculated value when emulated.
307 if (IsEmulatedTransformFeedbackQuery(contextVk, mType))
308 {
309 ASSERT(!contextVk->getFeatures().supportsTransformFeedbackExtension.enabled);
310 mTransformFeedbackPrimitivesDrawn = 0;
311
312 return angle::Result::Continue;
313 }
314
315 ANGLE_TRY(setupBegin(contextVk));
316
317 switch (mType)
318 {
319 case gl::QueryType::AnySamples:
320 case gl::QueryType::AnySamplesConservative:
321 case gl::QueryType::PrimitivesGenerated:
322 case gl::QueryType::TransformFeedbackPrimitivesWritten:
323 ANGLE_TRY(contextVk->beginRenderPassQuery(this));
324 break;
325 case gl::QueryType::Timestamp:
326 ANGLE_TRY(mQueryHelper.get().beginQuery(contextVk));
327 break;
328 case gl::QueryType::TimeElapsed:
329 // Note: TimeElapsed is implemented by using two Timestamp queries and taking the diff.
330 if (!mQueryHelperTimeElapsedBegin.valid())
331 {
332 // Note that timestamp queries are not allowed with multiview, so query count is
333 // always 1.
334 ANGLE_TRY(contextVk->getQueryPool(mType)->allocateQuery(
335 contextVk, &mQueryHelperTimeElapsedBegin, 1));
336 }
337
338 ANGLE_TRY(mQueryHelperTimeElapsedBegin.flushAndWriteTimestamp(contextVk));
339 break;
340 default:
341 UNREACHABLE();
342 break;
343 }
344
345 return angle::Result::Continue;
346 }
347
end(const gl::Context * context)348 angle::Result QueryVk::end(const gl::Context *context)
349 {
350 ContextVk *contextVk = vk::GetImpl(context);
351
352 // Transform feedback query is handled by a CPU-calculated value when emulated.
353 if (IsEmulatedTransformFeedbackQuery(contextVk, mType))
354 {
355 ASSERT(contextVk->getFeatures().emulateTransformFeedback.enabled);
356 mCachedResult = mTransformFeedbackPrimitivesDrawn;
357
358 // There could be transform feedback in progress, so add the primitives drawn so far
359 // from the current transform feedback object.
360 gl::TransformFeedback *transformFeedback =
361 context->getState().getCurrentTransformFeedback();
362 if (transformFeedback)
363 {
364 mCachedResult += transformFeedback->getPrimitivesDrawn();
365 }
366 mCachedResultValid = true;
367
368 return angle::Result::Continue;
369 }
370
371 switch (mType)
372 {
373 case gl::QueryType::AnySamples:
374 case gl::QueryType::AnySamplesConservative:
375 case gl::QueryType::PrimitivesGenerated:
376 case gl::QueryType::TransformFeedbackPrimitivesWritten:
377 {
378 QueryVk *shareQuery = GetShareQuery(contextVk, mType);
379 ASSERT(shareQuery == nullptr || &mQueryHelper.get() == &shareQuery->mQueryHelper.get());
380
381 ANGLE_TRY(contextVk->endRenderPassQuery(this));
382
383 // If another query shares its query helper with this one, its query has just ended!
384 // Make it stash its query and create a new one so it can continue.
385 if (shareQuery && shareQuery->mQueryHelper.isReferenced())
386 {
387 // This serves the following scenario (TF = TransformFeedbackPrimitivesWritten, PG =
388 // PrimitivesGenerated):
389 //
390 // - TF starts <-- QueryHelper1 starts
391 // - PG starts <-- PG shares QueryHelper1
392 // - Draw
393 // - TF ends <-- Results = QueryHelper1,
394 // QueryHelper1 stashed in PG, PG starts QueryHelper2
395 // - Draw
396 // - PG ends <-- Results = QueryHelper1 + QueryHelper2
397 if (contextVk->hasStartedRenderPass())
398 {
399 ANGLE_TRY(shareQuery->onRenderPassStart(contextVk));
400 }
401 }
402 break;
403 }
404 case gl::QueryType::Timestamp:
405 ANGLE_TRY(mQueryHelper.get().endQuery(contextVk));
406 break;
407 case gl::QueryType::TimeElapsed:
408 ANGLE_TRY(mQueryHelper.get().flushAndWriteTimestamp(contextVk));
409 break;
410 default:
411 UNREACHABLE();
412 break;
413 }
414
415 return angle::Result::Continue;
416 }
417
queryCounter(const gl::Context * context)418 angle::Result QueryVk::queryCounter(const gl::Context *context)
419 {
420 ASSERT(mType == gl::QueryType::Timestamp);
421 ContextVk *contextVk = vk::GetImpl(context);
422
423 mCachedResultValid = false;
424
425 if (!mQueryHelper.isReferenced())
426 {
427 ANGLE_TRY(allocateQuery(contextVk));
428 }
429
430 return mQueryHelper.get().flushAndWriteTimestamp(contextVk);
431 }
432
isUsedInRecordedCommands() const433 bool QueryVk::isUsedInRecordedCommands() const
434 {
435 ASSERT(mQueryHelper.isReferenced());
436
437 if (mQueryHelper.get().usedInRecordedCommands())
438 {
439 return true;
440 }
441
442 for (const vk::Shared<vk::QueryHelper> &query : mStashedQueryHelpers)
443 {
444 if (query.get().usedInRecordedCommands())
445 {
446 return true;
447 }
448 }
449
450 return false;
451 }
452
isCurrentlyInUse(Serial lastCompletedSerial) const453 bool QueryVk::isCurrentlyInUse(Serial lastCompletedSerial) const
454 {
455 ASSERT(mQueryHelper.isReferenced());
456
457 if (mQueryHelper.get().isCurrentlyInUse(lastCompletedSerial))
458 {
459 return true;
460 }
461
462 for (const vk::Shared<vk::QueryHelper> &query : mStashedQueryHelpers)
463 {
464 if (query.get().isCurrentlyInUse(lastCompletedSerial))
465 {
466 return true;
467 }
468 }
469
470 return false;
471 }
472
finishRunningCommands(ContextVk * contextVk)473 angle::Result QueryVk::finishRunningCommands(ContextVk *contextVk)
474 {
475 Serial lastCompletedSerial = contextVk->getLastCompletedQueueSerial();
476
477 if (mQueryHelper.get().usedInRunningCommands(lastCompletedSerial))
478 {
479 ANGLE_TRY(mQueryHelper.get().finishRunningCommands(contextVk));
480 lastCompletedSerial = contextVk->getLastCompletedQueueSerial();
481 }
482
483 for (vk::Shared<vk::QueryHelper> &query : mStashedQueryHelpers)
484 {
485 if (query.get().usedInRunningCommands(lastCompletedSerial))
486 {
487 ANGLE_TRY(query.get().finishRunningCommands(contextVk));
488 lastCompletedSerial = contextVk->getLastCompletedQueueSerial();
489 }
490 }
491 return angle::Result::Continue;
492 }
493
getResult(const gl::Context * context,bool wait)494 angle::Result QueryVk::getResult(const gl::Context *context, bool wait)
495 {
496 ANGLE_TRACE_EVENT0("gpu.angle", "QueryVk::getResult");
497
498 if (mCachedResultValid)
499 {
500 return angle::Result::Continue;
501 }
502
503 ContextVk *contextVk = vk::GetImpl(context);
504 RendererVk *renderer = contextVk->getRenderer();
505
506 // Support the pathological case where begin/end is called on a render pass query but without
507 // any render passes in between. In this case, the query helper is never allocated.
508 if (!mQueryHelper.isReferenced())
509 {
510 ASSERT(IsRenderPassQuery(contextVk, mType));
511 mCachedResult = 0;
512 mCachedResultValid = true;
513 return angle::Result::Continue;
514 }
515
516 // glGetQueryObject* requires an implicit flush of the command buffers to guarantee execution in
517 // finite time.
518 // Note regarding time-elapsed: end should have been called after begin, so flushing when end
519 // has pending work should flush begin too.
520
521 if (isUsedInRecordedCommands())
522 {
523 ANGLE_TRY(contextVk->flushImpl(nullptr));
524
525 ASSERT(!mQueryHelperTimeElapsedBegin.usedInRecordedCommands());
526 ASSERT(!mQueryHelper.get().usedInRecordedCommands());
527 }
528
529 ANGLE_TRY(contextVk->checkCompletedCommands());
530
531 // If the command buffer this query is being written to is still in flight, its reset
532 // command may not have been performed by the GPU yet. To avoid a race condition in this
533 // case, wait for the batch to finish first before querying (or return not-ready if not
534 // waiting).
535 if (isCurrentlyInUse(contextVk->getLastCompletedQueueSerial()))
536 {
537 if (!wait)
538 {
539 return angle::Result::Continue;
540 }
541 ANGLE_PERF_WARNING(contextVk->getDebug(), GL_DEBUG_SEVERITY_HIGH,
542 "GPU stall due to waiting on uncompleted query");
543
544 // Assert that the work has been sent to the GPU
545 ASSERT(!isUsedInRecordedCommands());
546 ANGLE_TRY(finishRunningCommands(contextVk));
547 }
548
549 // If its a render pass query, the current query helper must have commands recorded (i.e. it's
550 // not a newly allocated query with the actual queries all stashed). If this is not respected
551 // and !wait, |mQueryHelper.get().getUint64ResultNonBlocking()| will tell that the result is
552 // readily available, which may not be true. The subsequent calls to |getUint64Result()| on the
553 // stashed queries will incur a wait that is not desired by the application.
554 ASSERT(!IsRenderPassQuery(contextVk, mType) || mQueryHelper.get().hasSubmittedCommands());
555
556 vk::QueryResult result(getQueryResultCount(contextVk));
557
558 if (wait)
559 {
560 ANGLE_TRY(mQueryHelper.get().getUint64Result(contextVk, &result));
561 ANGLE_TRY(accumulateStashedQueryResult(contextVk, &result));
562 }
563 else
564 {
565 bool available = false;
566 ANGLE_TRY(mQueryHelper.get().getUint64ResultNonBlocking(contextVk, &result, &available));
567 if (!available)
568 {
569 // If the results are not ready, do nothing. mCachedResultValid remains false.
570 return angle::Result::Continue;
571 }
572 ANGLE_TRY(accumulateStashedQueryResult(contextVk, &result));
573 }
574
575 double timestampPeriod = renderer->getPhysicalDeviceProperties().limits.timestampPeriod;
576
577 // Fix up the results to what OpenGL expects.
578 switch (mType)
579 {
580 case gl::QueryType::AnySamples:
581 case gl::QueryType::AnySamplesConservative:
582 // OpenGL query result in these cases is binary
583 mCachedResult = !!result.getResult(vk::QueryResult::kDefaultResultIndex);
584 break;
585 case gl::QueryType::Timestamp:
586 mCachedResult = static_cast<uint64_t>(
587 result.getResult(vk::QueryResult::kDefaultResultIndex) * timestampPeriod);
588 break;
589 case gl::QueryType::TimeElapsed:
590 {
591 vk::QueryResult timeElapsedBegin(1);
592
593 // Since the result of the end query of time-elapsed is already available, the
594 // result of begin query must be available too.
595 ANGLE_TRY(mQueryHelperTimeElapsedBegin.getUint64Result(contextVk, &timeElapsedBegin));
596
597 uint64_t delta = result.getResult(vk::QueryResult::kDefaultResultIndex) -
598 timeElapsedBegin.getResult(vk::QueryResult::kDefaultResultIndex);
599 mCachedResult = static_cast<uint64_t>(delta * timestampPeriod);
600 break;
601 }
602 case gl::QueryType::TransformFeedbackPrimitivesWritten:
603 mCachedResult =
604 result.getResult(IsPrimitivesGeneratedQueryShared(contextVk)
605 ? vk::QueryResult::kTransformFeedbackPrimitivesWrittenIndex
606 : vk::QueryResult::kDefaultResultIndex);
607 break;
608 case gl::QueryType::PrimitivesGenerated:
609 mCachedResult = result.getResult(IsPrimitivesGeneratedQueryShared(contextVk)
610 ? vk::QueryResult::kPrimitivesGeneratedIndex
611 : vk::QueryResult::kDefaultResultIndex);
612 break;
613 default:
614 UNREACHABLE();
615 break;
616 }
617
618 mCachedResultValid = true;
619 return angle::Result::Continue;
620 }
getResult(const gl::Context * context,GLint * params)621 angle::Result QueryVk::getResult(const gl::Context *context, GLint *params)
622 {
623 ANGLE_TRY(getResult(context, true));
624 *params = static_cast<GLint>(mCachedResult);
625 return angle::Result::Continue;
626 }
627
getResult(const gl::Context * context,GLuint * params)628 angle::Result QueryVk::getResult(const gl::Context *context, GLuint *params)
629 {
630 ANGLE_TRY(getResult(context, true));
631 *params = static_cast<GLuint>(mCachedResult);
632 return angle::Result::Continue;
633 }
634
getResult(const gl::Context * context,GLint64 * params)635 angle::Result QueryVk::getResult(const gl::Context *context, GLint64 *params)
636 {
637 ANGLE_TRY(getResult(context, true));
638 *params = static_cast<GLint64>(mCachedResult);
639 return angle::Result::Continue;
640 }
641
getResult(const gl::Context * context,GLuint64 * params)642 angle::Result QueryVk::getResult(const gl::Context *context, GLuint64 *params)
643 {
644 ANGLE_TRY(getResult(context, true));
645 *params = mCachedResult;
646 return angle::Result::Continue;
647 }
648
isResultAvailable(const gl::Context * context,bool * available)649 angle::Result QueryVk::isResultAvailable(const gl::Context *context, bool *available)
650 {
651 ANGLE_TRY(getResult(context, false));
652 *available = mCachedResultValid;
653
654 return angle::Result::Continue;
655 }
656
onTransformFeedbackEnd(GLsizeiptr primitivesDrawn)657 void QueryVk::onTransformFeedbackEnd(GLsizeiptr primitivesDrawn)
658 {
659 mTransformFeedbackPrimitivesDrawn += primitivesDrawn;
660 }
661
getQueryResultCount(ContextVk * contextVk) const662 uint32_t QueryVk::getQueryResultCount(ContextVk *contextVk) const
663 {
664 switch (mType)
665 {
666 case gl::QueryType::PrimitivesGenerated:
667 return IsPrimitivesGeneratedQueryShared(contextVk) ? 2 : 1;
668 case gl::QueryType::TransformFeedbackPrimitivesWritten:
669 return 2;
670 default:
671 return 1;
672 }
673 }
674 } // namespace rx
675