• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.h:
7 //    Defines the class interface for QueryVk, implementing QueryImpl.
8 //
9 
10 #ifndef LIBANGLE_RENDERER_VULKAN_QUERYVK_H_
11 #define LIBANGLE_RENDERER_VULKAN_QUERYVK_H_
12 
13 #include "libANGLE/renderer/QueryImpl.h"
14 #include "libANGLE/renderer/vulkan/vk_helpers.h"
15 
16 namespace rx
17 {
18 class TransformFeedbackVk;
19 
20 class QueryVk : public QueryImpl
21 {
22   public:
23     QueryVk(gl::QueryType type);
24     ~QueryVk() override;
25 
26     void onDestroy(const gl::Context *context) override;
27 
28     angle::Result begin(const gl::Context *context) override;
29     angle::Result end(const gl::Context *context) override;
30     angle::Result queryCounter(const gl::Context *context) override;
31     angle::Result getResult(const gl::Context *context, GLint *params) override;
32     angle::Result getResult(const gl::Context *context, GLuint *params) override;
33     angle::Result getResult(const gl::Context *context, GLint64 *params) override;
34     angle::Result getResult(const gl::Context *context, GLuint64 *params) override;
35     angle::Result isResultAvailable(const gl::Context *context, bool *available) override;
36 
37     void onTransformFeedbackEnd(GLsizeiptr primitivesDrawn);
getQueryHelper()38     vk::QueryHelper *getQueryHelper()
39     {
40         ASSERT(mQueryHelper.isReferenced());
41         return &mQueryHelper.get();
42     }
43 
44     // Called by ContextVk on render pass start / end for render pass queries.  These will
45     // stash and create new queries as needed.
46     angle::Result onRenderPassStart(ContextVk *contextVk);
47     void onRenderPassEnd(ContextVk *contextVk);
48 
49   private:
50     angle::Result getResult(const gl::Context *context, bool wait);
51 
52     bool isUsedInRecordedCommands() const;
53     bool isCurrentlyInUse(Serial lastCompletedSerial) const;
54     angle::Result finishRunningCommands(ContextVk *contextVk);
55     void stashQueryHelper();
56     uint32_t getQueryResultCount(ContextVk *contextVk) const;
57     angle::Result accumulateStashedQueryResult(ContextVk *contextVk, vk::QueryResult *result);
58 
59     // Manage query allocations
60     angle::Result allocateQuery(ContextVk *contextVk);
61     void assignSharedQuery(QueryVk *shareQuery);
62     void releaseQueries(ContextVk *contextVk);
63     void releaseStashedQueries(ContextVk *contextVk);
64 
65     // Prepare for begin by handling peculiarities such as the two transform feedback queries
66     // sharing QueryHelpers.
67     angle::Result setupBegin(ContextVk *contextVk);
68 
69     // Used for all queries, except TimeElapsed (begin) or those that are emulated.  For transform
70     // feedback queries, these can be shared if the two queries are simultaneously active.
71     vk::Shared<vk::QueryHelper> mQueryHelper;
72     // Used for queries that may end up with multiple outstanding query helper objects as they end
73     // and begin again with render passes.
74     std::vector<vk::Shared<vk::QueryHelper>> mStashedQueryHelpers;
75     // An additional query used for TimeElapsed (begin), as it is implemented using Timestamp.
76     vk::QueryHelper mQueryHelperTimeElapsedBegin;
77     // Used with TransformFeedbackPrimitivesWritten when transform feedback is emulated.
78     size_t mTransformFeedbackPrimitivesDrawn;
79 
80     uint64_t mCachedResult;
81     bool mCachedResultValid;
82 };
83 
84 }  // namespace rx
85 
86 #endif  // LIBANGLE_RENDERER_VULKAN_QUERYVK_H_
87