[PATCH 09/20] glamor: Add glamor_program PolyPoint implementation

Keith Packard keithp at keithp.com
Tue Mar 18 22:09:43 PDT 2014


This accelerates poly point when possible by off-loading all geometry
computation to the GPU.

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 glamor/glamor_polyops.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++---
 glamor/glamor_priv.h    |  3 ++
 2 files changed, 91 insertions(+), 4 deletions(-)

diff --git a/glamor/glamor_polyops.c b/glamor/glamor_polyops.c
index 1484d80..852e832 100644
--- a/glamor/glamor_polyops.c
+++ b/glamor/glamor_polyops.c
@@ -27,17 +27,101 @@
  */
 
 #include "glamor_priv.h"
+#include "glamor_transform.h"
+
+static const glamor_facet glamor_facet_point = {
+    .name = "poly_point",
+    .vs_vars = "attribute vec2 primitive;\n",
+    .vs_exec = GLAMOR_POS(gl_Position, primitive),
+};
 
 static Bool
-_glamor_poly_point(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
+_glamor_poly_point(DrawablePtr drawable, GCPtr gc, int mode, int npt,
                    DDXPointPtr ppt, Bool fallback)
 {
-    if (!fallback && glamor_ddx_fallback_check_gc(pGC)
-        && glamor_ddx_fallback_check_pixmap(pDrawable))
+    ScreenPtr screen = drawable->pScreen;
+    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
+    PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
+    glamor_program *prog = &glamor_priv->point_prog;
+    glamor_pixmap_private *pixmap_priv;
+    int off_x, off_y;
+    GLshort *vbo_ppt;
+    char *vbo_offset;
+    int box_x, box_y;
+
+    if (!fallback && glamor_ddx_fallback_check_gc(gc)
+        && glamor_ddx_fallback_check_pixmap(drawable))
         return FALSE;
 
-    miPolyPoint(pDrawable, pGC, mode, npt, ppt);
+    pixmap_priv = glamor_get_pixmap_private(pixmap);
+    if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
+        goto bail;
+
+    glamor_get_context(glamor_priv);
+
+    if (prog->failed)
+        goto bail_ctx;
+
+    if (!prog->prog) {
+        if (!glamor_build_program(screen, prog,
+                                  &glamor_facet_point,
+                                  &glamor_fill_solid))
+            goto bail_ctx;
+    }
+
+    if (!glamor_use_program(pixmap, gc, prog, NULL))
+        goto bail_ctx;
+
+    vbo_ppt = glamor_get_vbo_space(screen, npt * (2 * sizeof (INT16)), &vbo_offset);
+    glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
+    glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_SHORT, GL_FALSE, 0, vbo_offset);
+    if (mode == CoordModePrevious) {
+        int n = npt;
+        INT16 x = 0, y = 0;
+        while (n--) {
+            vbo_ppt[0] = (x += ppt->x);
+            vbo_ppt[1] = (y += ppt->y);
+            vbo_ppt += 2;
+            ppt++;
+        }
+    } else
+        memcpy(vbo_ppt, ppt, npt * (2 * sizeof (INT16)));
+    glamor_put_vbo_space(screen);
+
+    glEnable(GL_SCISSOR_TEST);
+
+    glamor_pixmap_loop(pixmap_priv, box_x, box_y) {
+        int nbox = RegionNumRects(gc->pCompositeClip);
+        BoxPtr box = RegionRects(gc->pCompositeClip);
+
+        glamor_set_destination_drawable(drawable, box_x, box_y, TRUE, TRUE, prog->matrix_uniform, &off_x, &off_y);
+
+        while (nbox--) {
+            glScissor(box->x1 + off_x,
+                      box->y1 + off_y,
+                      box->x2 - box->x1,
+                      box->y2 - box->y1);
+            box++;
+            glDrawArrays(GL_POINTS, 0, npt);
+        }
+    }
+
+    glDisable(GL_SCISSOR_TEST);
+    glDisable(GL_COLOR_LOGIC_OP);
+    glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
+
+    glamor_put_context(glamor_priv);
+
+    glamor_priv->state = RENDER_STATE;
+    glamor_priv->render_idle_cnt = 0;
+
+    return TRUE;
 
+bail_ctx:
+    glDisable(GL_COLOR_LOGIC_OP);
+    glamor_put_context(glamor_priv);
+bail:
+    miPolyPoint(drawable, gc, mode, npt, ppt);
     return TRUE;
 }
 
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 1f6df3d..e4be4f3 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -219,6 +219,9 @@ typedef struct glamor_screen_private {
     GLint solid_prog;
     GLint solid_color_uniform_location;
 
+    /* glamor point shader */
+    glamor_program point_prog;
+
     /* vertext/elment_index buffer object for render */
     GLuint vbo, ebo;
     /** Next offset within the VBO that glamor_get_vbo_space() will use. */
-- 
1.9.0



More information about the xorg-devel mailing list