Blender V4.3
gl_query.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "gl_query.hh"
10
11namespace blender::gpu {
12
13#define QUERY_CHUNCK_LEN 256
14
16{
17 glDeleteQueries(query_ids_.size(), query_ids_.data());
18}
19
21{
22 BLI_assert(initialized_ == false);
23 initialized_ = true;
24 type_ = type;
25 gl_type_ = to_gl(type);
26 query_issued_ = 0;
27}
28
29#if 0 /* TODO: to avoid realloc of permanent query pool. */
30void GLQueryPool::reset(GPUQueryType type)
31{
32 initialized_ = false;
33}
34#endif
35
37{
38 /* TODO: add assert about expected usage. */
39 while (query_issued_ >= query_ids_.size()) {
40 int64_t prev_size = query_ids_.size();
41 int64_t chunk_size = prev_size == 0 ? query_ids_.capacity() : QUERY_CHUNCK_LEN;
42 query_ids_.resize(prev_size + chunk_size);
43 glGenQueries(chunk_size, &query_ids_[prev_size]);
44 }
45 glBeginQuery(gl_type_, query_ids_[query_issued_++]);
46}
47
49{
50 /* TODO: add assert about expected usage. */
51 glEndQuery(gl_type_);
52}
53
55{
56 BLI_assert(r_values.size() == query_issued_);
57
58 for (int i = 0; i < query_issued_; i++) {
59 /* NOTE: This is a sync point. */
60 glGetQueryObjectuiv(query_ids_[i], GL_QUERY_RESULT, &r_values[i]);
61 }
62}
63
64} // namespace blender::gpu
#define BLI_assert(a)
Definition BLI_assert.h:50
constexpr int64_t size() const
Definition BLI_span.hh:494
int64_t size() const
void resize(const int64_t new_size)
int64_t capacity() const
void get_occlusion_result(MutableSpan< uint32_t > r_values) override
Definition gl_query.cc:54
void end_query() override
Definition gl_query.cc:48
void begin_query() override
Definition gl_query.cc:36
void init(GPUQueryType type) override
Definition gl_query.cc:20
#define QUERY_CHUNCK_LEN
Definition gl_query.cc:13
static GLenum to_gl(const GPUAttachmentType type)
__int64 int64_t
Definition stdint.h:89