Blender  V2.93
gl_query.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2020, Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "gl_query.hh"
25 
26 namespace blender::gpu {
27 
28 #define QUERY_CHUNCK_LEN 256
29 
31 {
32  glDeleteQueries(query_ids_.size(), query_ids_.data());
33 }
34 
36 {
37  BLI_assert(initialized_ == false);
38  initialized_ = true;
39  type_ = type;
40  gl_type_ = to_gl(type);
41  query_issued_ = 0;
42 }
43 
44 #if 0 /* TODO to avoid realloc of permanent query pool. */
46 {
47  initialized_ = false;
48 }
49 #endif
50 
52 {
53  /* TODO add assert about expected usage. */
54  while (query_issued_ >= query_ids_.size()) {
55  int64_t prev_size = query_ids_.size();
56  query_ids_.resize(prev_size + QUERY_CHUNCK_LEN);
57  glGenQueries(QUERY_CHUNCK_LEN, &query_ids_[prev_size]);
58  }
59  glBeginQuery(gl_type_, query_ids_[query_issued_++]);
60 }
61 
63 {
64  /* TODO add assert about expected usage. */
65  glEndQuery(gl_type_);
66 }
67 
69 {
70  BLI_assert(r_values.size() == query_issued_);
71 
72  for (int i = 0; i < query_issued_; i++) {
73  /* Note: This is a sync point. */
74  glGetQueryObjectuiv(query_ids_[i], GL_QUERY_RESULT, &r_values[i]);
75  }
76 }
77 
78 } // namespace blender::gpu
#define BLI_assert(a)
Definition: BLI_assert.h:58
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
void reset()
clear internal cached data and reset random seed
constexpr int64_t size() const
Definition: BLI_span.hh:524
int64_t size() const
Definition: BLI_vector.hh:662
void resize(const int64_t new_size)
Definition: BLI_vector.hh:368
void get_occlusion_result(MutableSpan< uint32_t > r_values) override
Definition: gl_query.cc:68
void end_query(void) override
Definition: gl_query.cc:62
void init(GPUQueryType type) override
Definition: gl_query.cc:35
void begin_query(void) override
Definition: gl_query.cc:51
#define QUERY_CHUNCK_LEN
Definition: gl_query.cc:28
static GLenum to_gl(const GPUAttachmentType type)
__int64 int64_t
Definition: stdint.h:92