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