1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef RENDER_PERF__GPU_QUERY_MANAGER_H
17 #define RENDER_PERF__GPU_QUERY_MANAGER_H
18 
19 #include <cstdint>
20 
21 #include <base/containers/string.h>
22 #include <base/containers/string_view.h>
23 #include <base/containers/unique_ptr.h>
24 #include <base/containers/unordered_map.h>
25 #include <render/namespace.h>
26 
27 #include "device/gpu_resource_handle_util.h"
28 
29 RENDER_BEGIN_NAMESPACE()
30 class Device;
31 class GpuQuery;
32 
33 /** GpuQueryManager.
34  * Do not use or call directly. This is managed and handled automatically in the renderer.
35  * Not internally synchronized.
36  */
37 class GpuQueryManager final {
38 public:
39     EngineResourceHandle Create(const BASE_NS::string_view name, BASE_NS::unique_ptr<GpuQuery> gpuQuery);
40 
41     EngineResourceHandle GetGpuHandle(BASE_NS::string_view name) const;
42     GpuQuery* Get(const EngineResourceHandle handle) const;
43 
44 private:
45     BASE_NS::unordered_map<BASE_NS::string, EngineResourceHandle> nameToHandle_;
46     BASE_NS::vector<BASE_NS::unique_ptr<GpuQuery>> resources_;
47 };
48 RENDER_END_NAMESPACE()
49 
50 #endif // CORE__PERF__GPU_QUERY_MANAGER_H
51