xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/metal/mtl_occlusion_query_pool.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright (c) 2020 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 // mtl_occlusion_query_pool: A pool for allocating visibility query within
7 // one render pass.
8 //
9 
10 #ifndef LIBANGLE_RENDERER_METAL_MTL_OCCLUSION_QUERY_POOL_H_
11 #define LIBANGLE_RENDERER_METAL_MTL_OCCLUSION_QUERY_POOL_H_
12 
13 #include <vector>
14 
15 #include "libANGLE/Context.h"
16 #include "libANGLE/renderer/metal/mtl_common.h"
17 #include "libANGLE/renderer/metal/mtl_resources.h"
18 
19 namespace rx
20 {
21 
22 class ContextMtl;
23 class QueryMtl;
24 
25 namespace mtl
26 {
27 
28 class OcclusionQueryPool
29 {
30   public:
31     OcclusionQueryPool();
32     ~OcclusionQueryPool();
33 
34     void destroy(ContextMtl *contextMtl);
35 
36     // Allocate an offset in visibility buffer for a query in a render pass.
37     // - clearOldValue = true, if the old value of query will be cleared before combining in the
38     // visibility resolve pass. This flag is only allowed to be false for the first allocation of
39     // the render pass or the query that already has an allocated offset.
40     // Note: a query might have more than one allocated offset. They will be combined in the final
41     // step.
42     angle::Result allocateQueryOffset(ContextMtl *contextMtl, QueryMtl *query, bool clearOldValue);
43     // Deallocate all offsets used for a query.
44     void deallocateQueryOffset(ContextMtl *contextMtl, QueryMtl *query);
45     // Retrieve a buffer that will contain the visibility results of all allocated queries for
46     // a render pass
getRenderPassVisibilityPoolBuffer()47     const BufferRef &getRenderPassVisibilityPoolBuffer() const { return mRenderPassResultsPool; }
getNumRenderPassAllocatedQueries()48     size_t getNumRenderPassAllocatedQueries() const { return mAllocatedQueries.size(); }
49     // This function is called at the end of render pass
50     void resolveVisibilityResults(ContextMtl *contextMtl);
51     // Clear visibility pool buffer to drop previous results
52     void prepareRenderPassVisibilityPoolBuffer(ContextMtl *contextMtl);
53 
54   private:
55     // Buffer to hold the visibility results for current render pass
56     BufferRef mRenderPassResultsPool;
57 
58     // List of allocated queries per render pass
59     std::vector<QueryMtl *> mAllocatedQueries;
60 
61     bool mResetFirstQuery = false;
62     bool mUsed            = false;
63 };
64 
65 }  // namespace mtl
66 }  // namespace rx
67 
68 #endif /* LIBANGLE_RENDERER_METAL_MTL_OCCLUSION_QUERY_POOL_H_ */
69