[Bf-blender-cvs] [7413c2feede] master: Cleanup: Optimize gl query code path

Jesse Yurkovich noreply at git.blender.org
Sun Feb 13 07:06:19 CET 2022


Commit: 7413c2feede68c45f13fa37ebdcbf325d8f32c10
Author: Jesse Yurkovich
Date:   Sat Feb 12 21:52:24 2022 -0800
Branches: master
https://developer.blender.org/rB7413c2feede68c45f13fa37ebdcbf325d8f32c10

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

===================================================================

M	source/blender/gpu/intern/gpu_query.hh
M	source/blender/gpu/intern/gpu_select_sample_query.cc
M	source/blender/gpu/opengl/gl_query.cc
M	source/blender/gpu/opengl/gl_query.hh

===================================================================

diff --git a/source/blender/gpu/intern/gpu_query.hh b/source/blender/gpu/intern/gpu_query.hh
index e563d208c06..da264c4a98d 100644
--- a/source/blender/gpu/intern/gpu_query.hh
+++ b/source/blender/gpu/intern/gpu_query.hh
@@ -11,6 +11,8 @@
 
 namespace blender::gpu {
 
+#define QUERY_MIN_LEN 16
+
 typedef enum GPUQueryType {
   GPU_QUERY_OCCLUSION = 0,
 } GPUQueryType;
diff --git a/source/blender/gpu/intern/gpu_select_sample_query.cc b/source/blender/gpu/intern/gpu_select_sample_query.cc
index ab890b08935..26c9ed79d6c 100644
--- a/source/blender/gpu/intern/gpu_select_sample_query.cc
+++ b/source/blender/gpu/intern/gpu_select_sample_query.cc
@@ -37,7 +37,7 @@ struct GPUSelectQueryState {
   /** GPU queries abstraction. Contains an array of queries. */
   QueryPool *queries;
   /** Array holding the id corresponding id to each query. */
-  Vector<uint> *ids;
+  Vector<uint, QUERY_MIN_LEN> *ids;
   /** Cache on initialization. */
   GPUSelectResult *buffer;
   /** The capacity of the `buffer` array. */
@@ -71,7 +71,7 @@ void gpu_select_query_begin(GPUSelectResult *buffer,
   g_query_state.index = 0;
   g_query_state.oldhits = oldhits;
 
-  g_query_state.ids = new Vector<uint>();
+  g_query_state.ids = new Vector<uint, QUERY_MIN_LEN>();
   g_query_state.queries = GPUBackend::get()->querypool_alloc();
   g_query_state.queries->init(GPU_QUERY_OCCLUSION);
 
@@ -149,7 +149,7 @@ uint gpu_select_query_end()
   }
 
   Span<uint> ids = *g_query_state.ids;
-  Vector<uint32_t> result(ids.size());
+  Vector<uint32_t, QUERY_MIN_LEN> result(ids.size());
   g_query_state.queries->get_occlusion_result(result);
 
   for (int i = 0; i < result.size(); i++) {
diff --git a/source/blender/gpu/opengl/gl_query.cc b/source/blender/gpu/opengl/gl_query.cc
index 3195ec95ed2..0081efbf1e7 100644
--- a/source/blender/gpu/opengl/gl_query.cc
+++ b/source/blender/gpu/opengl/gl_query.cc
@@ -37,8 +37,9 @@ void GLQueryPool::begin_query()
   /* TODO: add assert about expected usage. */
   while (query_issued_ >= query_ids_.size()) {
     int64_t prev_size = query_ids_.size();
-    query_ids_.resize(prev_size + QUERY_CHUNCK_LEN);
-    glGenQueries(QUERY_CHUNCK_LEN, &query_ids_[prev_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_++]);
 }
diff --git a/source/blender/gpu/opengl/gl_query.hh b/source/blender/gpu/opengl/gl_query.hh
index 0dc4a6b8d51..e15a2584e07 100644
--- a/source/blender/gpu/opengl/gl_query.hh
+++ b/source/blender/gpu/opengl/gl_query.hh
@@ -18,7 +18,7 @@ namespace blender::gpu {
 class GLQueryPool : public QueryPool {
  private:
   /** Contains queries object handles. */
-  Vector<GLuint> query_ids_;
+  Vector<GLuint, QUERY_MIN_LEN> query_ids_;
   /** Type of this query pool. */
   GPUQueryType type_;
   /** Associated GL type. */



More information about the Bf-blender-cvs mailing list