1 /*
2 * Copyright (C) 2023 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 #include "gpu_query_gles.h"
17
18 #include <render/namespace.h>
19
20 #include "device/device.h"
21 #include "gles/device_gles.h"
22 #include "gles/gl_functions.h"
23 #include "perf/gpu_query.h"
24
RENDER_BEGIN_NAMESPACE()25 RENDER_BEGIN_NAMESPACE()
26 GpuQueryGLES::GpuQueryGLES(Device& device, const GpuQueryDesc& desc) : desc_(desc)
27 {
28 PLUGIN_ASSERT(static_cast<DeviceGLES&>(device).IsActive());
29 BASE_NS::vector<GLuint> queries(device.GetCommandBufferingCount() + 1);
30 glGenQueries(static_cast<GLsizei>(queries.size()), queries.data());
31 plats_.reserve(queries.size());
32 for (const auto q : queries) {
33 plats_.emplace_back().queryObject = q;
34 }
35 }
36
~GpuQueryGLES()37 GpuQueryGLES::~GpuQueryGLES()
38 {
39 for (const auto& plat : plats_) {
40 glDeleteQueries(1, &plat.queryObject);
41 }
42 }
43
NextQueryIndex()44 void GpuQueryGLES::NextQueryIndex()
45 {
46 queryIndex_ = (queryIndex_ + 1) % ((uint32_t)plats_.size());
47 }
48
GetDesc() const49 const GpuQueryDesc& GpuQueryGLES::GetDesc() const
50 {
51 return desc_;
52 }
53
GetPlatformData() const54 const GpuQueryPlatformData& GpuQueryGLES::GetPlatformData() const
55 {
56 PLUGIN_ASSERT(queryIndex_ < plats_.size());
57 return plats_[queryIndex_];
58 }
59
CreateGpuQueryGLES(Device & device,const GpuQueryDesc & desc)60 BASE_NS::unique_ptr<GpuQuery> CreateGpuQueryGLES(Device& device, const GpuQueryDesc& desc)
61 {
62 return BASE_NS::make_unique<GpuQueryGLES>(device, desc);
63 }
64 RENDER_END_NAMESPACE()
65