[gtk/backports-for-4-2: 7/7] gsk: Respect max element vertices limitation




commit 5699e5ba711f52f418ce8fd6c60422cbf40746a0
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jun 18 06:50:59 2021 -0700

    gsk: Respect max element vertices limitation
    
    We are pretty good at batching commands now, and we can easily
    produce batches that exceed the maximum number of elements per
    draw call that the hw can handle. Query that number, and respect
    it when merging batches.
    
    This fixes the rendering of the overview map in GtkSourceView.

 gsk/ngl/gsknglcommandqueue.c        | 6 +++++-
 gsk/ngl/gsknglcommandqueueprivate.h | 6 ++++++
 2 files changed, 11 insertions(+), 1 deletion(-)
---
diff --git a/gsk/ngl/gsknglcommandqueue.c b/gsk/ngl/gsknglcommandqueue.c
index 73f21b6e6d..8e610d60df 100644
--- a/gsk/ngl/gsknglcommandqueue.c
+++ b/gsk/ngl/gsknglcommandqueue.c
@@ -444,9 +444,12 @@ gsk_ngl_command_queue_new (GdkGLContext       *context,
   else
     self->uniforms = gsk_ngl_uniform_state_new ();
 
-  /* Determine max texture size immediately and restore context */
+  /* Determine max texture size and other limitations immediately
+   * and restore context
+   */
   gdk_gl_context_make_current (context);
   glGetIntegerv (GL_MAX_TEXTURE_SIZE, &self->max_texture_size);
+  glGetIntegerv (GL_MAX_ELEMENTS_VERTICES, &self->max_elements_vertices);
 
   return g_steal_pointer (&self);
 }
@@ -617,6 +620,7 @@ gsk_ngl_command_queue_end_draw (GskNglCommandQueue *self)
       last_batch->any.viewport.height == batch->any.viewport.height &&
       last_batch->draw.framebuffer == batch->draw.framebuffer &&
       last_batch->draw.vbo_offset + last_batch->draw.vbo_count == batch->draw.vbo_offset &&
+      last_batch->draw.vbo_count + batch->draw.vbo_count <= self->max_elements_vertices &&
       snapshots_equal (self, last_batch, batch))
     {
       last_batch->draw.vbo_count += batch->draw.vbo_count;
diff --git a/gsk/ngl/gsknglcommandqueueprivate.h b/gsk/ngl/gsknglcommandqueueprivate.h
index bcd7c8312d..4356179436 100644
--- a/gsk/ngl/gsknglcommandqueueprivate.h
+++ b/gsk/ngl/gsknglcommandqueueprivate.h
@@ -231,6 +231,12 @@ struct _GskNglCommandQueue
    */
   int max_texture_size;
 
+  /* Discovered max element count. We must not create batches that contain
+   * more vertices than this number.
+   */
+
+  int max_elements_vertices;
+
   /* The index of the last batch in @batches, which may not be the element
    * at the end of the array, as batches can be reordered. This is used to
    * update the "next" index when adding a new batch.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]