2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2020 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2020-09-07 23:52:55 +02:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup gpu
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "gl_query.hh"
|
|
|
|
|
|
|
|
|
|
namespace blender::gpu {
|
|
|
|
|
|
|
|
|
|
#define QUERY_CHUNCK_LEN 256
|
|
|
|
|
|
|
|
|
|
GLQueryPool::~GLQueryPool()
|
|
|
|
|
{
|
|
|
|
|
glDeleteQueries(query_ids_.size(), query_ids_.data());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GLQueryPool::init(GPUQueryType type)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(initialized_ == false);
|
|
|
|
|
initialized_ = true;
|
|
|
|
|
type_ = type;
|
|
|
|
|
gl_type_ = to_gl(type);
|
|
|
|
|
query_issued_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-03 23:08:40 +10:00
|
|
|
#if 0 /* TODO: to avoid realloc of permanent query pool. */
|
2020-09-07 23:52:55 +02:00
|
|
|
void GLQueryPool::reset(GPUQueryType type)
|
|
|
|
|
{
|
|
|
|
|
initialized_ = false;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-11-06 13:18:48 +01:00
|
|
|
void GLQueryPool::begin_query()
|
2020-09-07 23:52:55 +02:00
|
|
|
{
|
2021-07-03 23:08:40 +10:00
|
|
|
/* TODO: add assert about expected usage. */
|
2020-09-07 23:52:55 +02:00
|
|
|
while (query_issued_ >= query_ids_.size()) {
|
|
|
|
|
int64_t prev_size = query_ids_.size();
|
2022-02-12 21:52:24 -08:00
|
|
|
int64_t chunk_size = prev_size == 0 ? query_ids_.capacity() : QUERY_CHUNCK_LEN;
|
|
|
|
|
query_ids_.resize(prev_size + chunk_size);
|
|
|
|
|
glGenQueries(chunk_size, &query_ids_[prev_size]);
|
2020-09-07 23:52:55 +02:00
|
|
|
}
|
|
|
|
|
glBeginQuery(gl_type_, query_ids_[query_issued_++]);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-06 13:18:48 +01:00
|
|
|
void GLQueryPool::end_query()
|
2020-09-07 23:52:55 +02:00
|
|
|
{
|
2021-07-03 23:08:40 +10:00
|
|
|
/* TODO: add assert about expected usage. */
|
2020-09-07 23:52:55 +02:00
|
|
|
glEndQuery(gl_type_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GLQueryPool::get_occlusion_result(MutableSpan<uint32_t> r_values)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(r_values.size() == query_issued_);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < query_issued_; i++) {
|
2021-07-03 23:08:40 +10:00
|
|
|
/* NOTE: This is a sync point. */
|
2020-09-07 23:52:55 +02:00
|
|
|
glGetQueryObjectuiv(query_ids_[i], GL_QUERY_RESULT, &r_values[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace blender::gpu
|