This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/gpu/opengl/gl_query.cc
Jesse Yurkovich 7413c2feed Cleanup: Optimize gl query code path
Currently whenever gl queries are performed for the viewport, a large
1024 byte array is allocated to store the query results (256 of them).

Unfortunately, if any gizmo using a `draw_select` callback is active
(e.g. the transform gizmos), these queries (and allocations) will occur
during every mouse move event.

Change the vector to allow for up to 16 query results before making an
allocation. This provides enough space for every built-in gizmo except
Scale Cage (which needs 27 queries). It also removes unnecessary
allocations from two other related vectors used during query processing.

Differential Revision: https://developer.blender.org/D13784
2022-02-12 21:52:24 -08:00

64 lines
1.4 KiB
C++

/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2020 Blender Foundation. All rights reserved. */
/** \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;
}
#if 0 /* TODO: to avoid realloc of permanent query pool. */
void GLQueryPool::reset(GPUQueryType type)
{
initialized_ = false;
}
#endif
void GLQueryPool::begin_query()
{
/* TODO: add assert about expected usage. */
while (query_issued_ >= query_ids_.size()) {
int64_t prev_size = query_ids_.size();
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]);
}
glBeginQuery(gl_type_, query_ids_[query_issued_++]);
}
void GLQueryPool::end_query()
{
/* TODO: add assert about expected usage. */
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++) {
/* NOTE: This is a sync point. */
glGetQueryObjectuiv(query_ids_[i], GL_QUERY_RESULT, &r_values[i]);
}
}
} // namespace blender::gpu