xserver: Branch 'master' - 3 commits
Dave Airlie
airlied at kemper.freedesktop.org
Wed Jan 20 12:50:33 PST 2016
glamor/glamor.c | 2
glamor/glamor_gradient.c | 33 ++++++--------
glamor/glamor_picture.c | 27 ++++++-----
glamor/glamor_priv.h | 2
glamor/glamor_vbo.c | 9 +++
glamor/glamor_xv.c | 41 ++++++++++++-----
hw/kdrive/ephyr/ephyr_glamor_glx.c | 86 ++++++++++++++++++++++++++-----------
7 files changed, 136 insertions(+), 64 deletions(-)
New commits:
commit 49aa5e3ea4eecea0562c05a4e52962985a56e510
Author: Keith Packard <keithp at keithp.com>
Date: Wed Sep 10 16:17:52 2014 -0700
glamor: Use vertex array objects
Core contexts require the use of vertex array objects, so switch both glamor
and ephyr/glamor over.
Signed-off-by: Keith Packard <keithp at keithp.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
Signed-off-by: Dave Airlie <airlied at redhat.com>
diff --git a/glamor/glamor.c b/glamor/glamor.c
index 81aba2d..0b5ebef 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -574,6 +574,8 @@ glamor_init(ScreenPtr screen, unsigned int flags)
glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP ||
epoxy_gl_version() >= 30 ||
epoxy_has_gl_extension("GL_NV_pack_subimage");
+ glamor_priv->has_vertex_array_object =
+ epoxy_has_gl_extension("GL_ARB_vertex_array_object");
glamor_setup_debug_output(screen);
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index a190e67..8ed53e7 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -201,6 +201,7 @@ typedef struct glamor_screen_private {
Bool has_unpack_subimage;
Bool has_rw_pbo;
Bool use_quads;
+ Bool has_vertex_array_object;
int max_fbo_size;
struct xorg_list
@@ -247,6 +248,7 @@ typedef struct glamor_screen_private {
char *glyph_defines;
/** Vertex buffer for all GPU rendering. */
+ GLuint vao;
GLuint vbo;
/** Next offset within the VBO that glamor_get_vbo_space() will use. */
int vbo_offset;
diff --git a/glamor/glamor_vbo.c b/glamor/glamor_vbo.c
index ba60ce6..b8db009 100644
--- a/glamor/glamor_vbo.c
+++ b/glamor/glamor_vbo.c
@@ -174,6 +174,11 @@ glamor_init_vbo(ScreenPtr screen)
glamor_make_current(glamor_priv);
glGenBuffers(1, &glamor_priv->vbo);
+ if (glamor_priv->has_vertex_array_object) {
+ glGenVertexArrays(1, &glamor_priv->vao);
+ glBindVertexArray(glamor_priv->vao);
+ } else
+ glamor_priv->vao = 0;
}
void
@@ -183,6 +188,10 @@ glamor_fini_vbo(ScreenPtr screen)
glamor_make_current(glamor_priv);
+ if (glamor_priv->vao != 0) {
+ glDeleteVertexArrays(1, &glamor_priv->vao);
+ glamor_priv->vao = 0;
+ }
if (!glamor_priv->has_map_buffer_range)
free(glamor_priv->vb);
}
diff --git a/hw/kdrive/ephyr/ephyr_glamor_glx.c b/hw/kdrive/ephyr/ephyr_glamor_glx.c
index 582e3af..30c5245 100644
--- a/hw/kdrive/ephyr/ephyr_glamor_glx.c
+++ b/hw/kdrive/ephyr/ephyr_glamor_glx.c
@@ -71,6 +71,8 @@ struct ephyr_glamor {
/* Size of the window that we're rendering to. */
unsigned width, height;
+
+ GLuint vao, vbo;
};
static GLint
@@ -189,47 +191,53 @@ ephyr_glamor_set_texture(struct ephyr_glamor *glamor, uint32_t tex)
glamor->tex = tex;
}
+static void
+ephyr_glamor_set_vertices(struct ephyr_glamor *glamor)
+{
+ glVertexAttribPointer(glamor->texture_shader_position_loc,
+ 2, GL_FLOAT, FALSE, 0, (void *) 0);
+ glVertexAttribPointer(glamor->texture_shader_texcoord_loc,
+ 2, GL_FLOAT, FALSE, 0, (void *) (sizeof (float) * 8));
+
+ glEnableVertexAttribArray(glamor->texture_shader_position_loc);
+ glEnableVertexAttribArray(glamor->texture_shader_texcoord_loc);
+}
+
+static void
+ephyr_glamor_clear_vertices(struct ephyr_glamor *glamor)
+{
+ glDisableVertexAttribArray(glamor->texture_shader_position_loc);
+ glDisableVertexAttribArray(glamor->texture_shader_texcoord_loc);
+}
+
void
ephyr_glamor_damage_redisplay(struct ephyr_glamor *glamor,
struct pixman_region16 *damage)
{
- /* Redraw the whole screen, since glXSwapBuffers leaves the back
- * buffer undefined.
- */
- static const float position[] = {
- -1, -1,
- 1, -1,
- 1, 1,
- -1, 1,
- };
- static const float texcoords[] = {
- 0, 1,
- 1, 1,
- 1, 0,
- 0, 0,
- };
+ GLint old_vao;
glXMakeCurrent(dpy, glamor->glx_win, glamor->ctx);
+ if (glamor->vao) {
+ glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &old_vao);
+ glBindVertexArray(glamor->vao);
+ } else
+ ephyr_glamor_set_vertices(glamor);
+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glUseProgram(glamor->texture_shader);
glViewport(0, 0, glamor->width, glamor->height);
if (!ephyr_glamor_gles2)
glDisable(GL_COLOR_LOGIC_OP);
- glVertexAttribPointer(glamor->texture_shader_position_loc,
- 2, GL_FLOAT, FALSE, 0, position);
- glVertexAttribPointer(glamor->texture_shader_texcoord_loc,
- 2, GL_FLOAT, FALSE, 0, texcoords);
- glEnableVertexAttribArray(glamor->texture_shader_position_loc);
- glEnableVertexAttribArray(glamor->texture_shader_texcoord_loc);
-
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, glamor->tex);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
- glDisableVertexAttribArray(glamor->texture_shader_position_loc);
- glDisableVertexAttribArray(glamor->texture_shader_texcoord_loc);
+ if (glamor->vao)
+ glBindVertexArray(old_vao);
+ else
+ ephyr_glamor_clear_vertices(glamor);
glXSwapBuffers(dpy, glamor->glx_win);
}
@@ -271,6 +279,18 @@ ephyr_glamor_process_event(xcb_generic_event_t *xev)
struct ephyr_glamor *
ephyr_glamor_glx_screen_init(xcb_window_t win)
{
+ static const float position[] = {
+ -1, -1,
+ 1, -1,
+ 1, 1,
+ -1, 1,
+ 0, 1,
+ 1, 1,
+ 1, 0,
+ 0, 0,
+ };
+ GLint old_vao;
+
GLXContext ctx;
struct ephyr_glamor *glamor;
GLXWindow glx_win;
@@ -312,6 +332,24 @@ ephyr_glamor_glx_screen_init(xcb_window_t win)
glamor->glx_win = glx_win;
ephyr_glamor_setup_texturing_shader(glamor);
+ if (epoxy_has_gl_extension("GL_ARB_vertex_array_object")) {
+ glGenVertexArrays(1, &glamor->vao);
+ glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &old_vao);
+ glBindVertexArray(glamor->vao);
+ } else
+ glamor->vao = 0;
+
+ glGenBuffers(1, &glamor->vbo);
+
+ glBindBuffer(GL_ARRAY_BUFFER, glamor->vbo);
+ glBufferData(GL_ARRAY_BUFFER, sizeof (position), position, GL_STATIC_DRAW);
+
+ if (glamor->vao) {
+ ephyr_glamor_set_vertices(glamor);
+ glBindVertexArray(old_vao);
+ } else
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+
return glamor;
}
commit d99204fb5e09ce7be36485d4226f7ad6d6eb24cc
Author: Dave Airlie <airlied at redhat.com>
Date: Tue Jan 19 10:34:14 2016 +1000
glamor/xv: add vbo support (v2.1)
This converts the Xv code to using VBOs instead of
client ptrs. This is necessary to move towards using
the core profile later.
v2: put all boxes into single vbo, use draw arrays
to offset things. (Eric)
v2.1: brown paper bag with releasing vbo.
Reviewed-by: Eric Anholt <eric at anholt.net>
Signed-off-by: Dave Airlie <airlied at redhat.com>
diff --git a/glamor/glamor_xv.c b/glamor/glamor_xv.c
index 85e6528..6e1a588 100644
--- a/glamor/glamor_xv.c
+++ b/glamor/glamor_xv.c
@@ -245,7 +245,6 @@ glamor_xv_render(glamor_port_private *port_priv)
PixmapPtr pixmap = port_priv->pPixmap;
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
glamor_pixmap_private *src_pixmap_priv[3];
- float vertices[32], texcoords[8];
BoxPtr box = REGION_RECTS(&port_priv->clip);
int nBox = REGION_NUM_RECTS(&port_priv->clip);
int dst_x_off, dst_y_off;
@@ -260,6 +259,8 @@ glamor_xv_render(glamor_port_private *port_priv)
float bright, cont, gamma;
int ref = port_priv->transform_index;
GLint uloc, sampler_loc;
+ GLfloat *v;
+ char *vbo_offset;
if (!glamor_priv->xv_prog)
glamor_init_xv_shader(screen);
@@ -335,16 +336,13 @@ glamor_xv_render(glamor_port_private *port_priv)
sampler_loc = glGetUniformLocation(glamor_priv->xv_prog, "v_sampler");
glUniform1i(sampler_loc, 2);
- glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2,
- GL_FLOAT, GL_FALSE,
- 2 * sizeof(float), texcoords);
+ glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
- glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
- GL_FALSE, 2 * sizeof(float), vertices);
-
- glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
glEnable(GL_SCISSOR_TEST);
+
+ v = glamor_get_vbo_space(screen, 16 * sizeof(GLfloat) * nBox, &vbo_offset);
+
for (i = 0; i < nBox; i++) {
float off_x = box[i].x1 - port_priv->drw_x;
float off_y = box[i].y1 - port_priv->drw_y;
@@ -352,6 +350,8 @@ glamor_xv_render(glamor_port_private *port_priv)
float diff_y = (float) port_priv->src_h / (float) port_priv->dst_h;
float srcx, srcy, srcw, srch;
int dstx, dsty, dstw, dsth;
+ GLfloat *vptr = v + (i * 8);
+ GLfloat *tptr = vptr + (8 * nBox);
dstx = box[i].x1 + dst_x_off;
dsty = box[i].y1 + dst_y_off;
@@ -369,7 +369,7 @@ glamor_xv_render(glamor_port_private *port_priv)
dsty,
dstx + dstw,
dsty + dsth * 2,
- vertices);
+ vptr);
glamor_set_normalize_tcoords(src_pixmap_priv[0],
src_xscale[0],
@@ -378,10 +378,29 @@ glamor_xv_render(glamor_port_private *port_priv)
srcy,
srcx + srcw,
srcy + srch * 2,
- texcoords);
+ tptr);
+ }
+
+ glVertexAttribPointer(GLAMOR_VERTEX_POS, 2,
+ GL_FLOAT, GL_FALSE,
+ 2 * sizeof(float), vbo_offset);
+
+ glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2,
+ GL_FLOAT, GL_FALSE,
+ 2 * sizeof(float), vbo_offset + (nBox * 8 * sizeof(GLfloat)));
+
+ glamor_put_vbo_space(screen);
+
+ for (i = 0; i < nBox; i++) {
+ int dstx, dsty, dstw, dsth;
+
+ dstx = box[i].x1 + dst_x_off;
+ dsty = box[i].y1 + dst_y_off;
+ dstw = box[i].x2 - box[i].x1;
+ dsth = box[i].y2 - box[i].y1;
glScissor(dstx, dsty, dstw, dsth);
- glDrawArrays(GL_TRIANGLE_FAN, 0, 3);
+ glDrawArrays(GL_TRIANGLE_FAN, i * 4, 3);
}
glDisable(GL_SCISSOR_TEST);
commit 5582ad1b9b29934498cf3fef305d3a988130cd52
Author: Dave Airlie <airlied at redhat.com>
Date: Mon Jan 11 14:00:04 2016 +1000
glamor: use vbos in gradient/picture code.
This converts two client arrays users to using vbos,
this is necessary to move to using core profile later.
Reviewed-by: Eric Anholt <eric at anholt.net>
Signed-off-by: Dave Airlie <airlied at redhat.com>
diff --git a/glamor/glamor_gradient.c b/glamor/glamor_gradient.c
index 30c29f6..c50542a 100644
--- a/glamor/glamor_gradient.c
+++ b/glamor/glamor_gradient.c
@@ -647,12 +647,12 @@ _glamor_gradient_set_pixmap_destination(ScreenPtr screen,
PicturePtr dst_picture,
GLfloat *xscale, GLfloat *yscale,
int x_source, int y_source,
- float vertices[8],
- float tex_vertices[8],
int tex_normalize)
{
glamor_pixmap_private *pixmap_priv;
PixmapPtr pixmap = NULL;
+ GLfloat *v;
+ char *vbo_offset;
pixmap = glamor_get_drawable_pixmap(dst_picture->pDrawable);
pixmap_priv = glamor_get_pixmap_private(pixmap);
@@ -670,13 +670,15 @@ _glamor_gradient_set_pixmap_destination(ScreenPtr screen,
*xscale, *yscale, x_source, y_source,
dst_picture->pDrawable->width, dst_picture->pDrawable->height);
+ v = glamor_get_vbo_space(screen, 16 * sizeof(GLfloat), &vbo_offset);
+
glamor_set_normalize_vcoords_tri_strip(*xscale, *yscale,
0, 0,
(INT16) (dst_picture->pDrawable->
width),
(INT16) (dst_picture->pDrawable->
height),
- vertices);
+ v);
if (tex_normalize) {
glamor_set_normalize_tcoords_tri_stripe(*xscale, *yscale,
@@ -687,7 +689,7 @@ _glamor_gradient_set_pixmap_destination(ScreenPtr screen,
(INT16) (dst_picture->
pDrawable->height +
y_source),
- tex_vertices);
+ &v[8]);
}
else {
glamor_set_tcoords_tri_strip(x_source, y_source,
@@ -695,28 +697,29 @@ _glamor_gradient_set_pixmap_destination(ScreenPtr screen,
x_source,
(INT16) (dst_picture->pDrawable->height) +
y_source,
- tex_vertices);
+ &v[8]);
}
DEBUGF("vertices --> leftup : %f X %f, rightup: %f X %f,"
"rightbottom: %f X %f, leftbottom : %f X %f\n",
- vertices[0], vertices[1], vertices[2], vertices[3],
- vertices[4], vertices[5], vertices[6], vertices[7]);
+ v[0], v[1], v[2], v[3],
+ v[4], v[5], v[6], v[7]);
DEBUGF("tex_vertices --> leftup : %f X %f, rightup: %f X %f,"
"rightbottom: %f X %f, leftbottom : %f X %f\n",
- tex_vertices[0], tex_vertices[1], tex_vertices[2], tex_vertices[3],
- tex_vertices[4], tex_vertices[5], tex_vertices[6], tex_vertices[7]);
+ v[8], v[9], v[10], v[11],
+ v[12], v[13], v[14], v[15]);
glamor_make_current(glamor_priv);
glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
- GL_FALSE, 0, vertices);
+ GL_FALSE, 0, vbo_offset);
glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT,
- GL_FALSE, 0, tex_vertices);
+ GL_FALSE, 0, vbo_offset + 8 * sizeof(GLfloat));
glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
+ glamor_put_vbo_space(screen);
return 1;
}
@@ -812,13 +815,11 @@ glamor_generate_radial_gradient_picture(ScreenPtr screen,
PixmapPtr pixmap = NULL;
GLint gradient_prog = 0;
int error;
- float tex_vertices[8];
int stops_count = 0;
int count = 0;
GLfloat *stop_colors = NULL;
GLfloat *n_stops = NULL;
GLfloat xscale, yscale;
- float vertices[8];
float transform_mat[3][3];
static const float identity_mat[3][3] = { {1.0, 0.0, 0.0},
{0.0, 1.0, 0.0},
@@ -969,7 +970,7 @@ glamor_generate_radial_gradient_picture(ScreenPtr screen,
if (!_glamor_gradient_set_pixmap_destination
(screen, glamor_priv, dst_picture, &xscale, &yscale, x_source, y_source,
- vertices, tex_vertices, 0))
+ 0))
goto GRADIENT_FAIL;
glamor_set_alu(screen, GXcopy);
@@ -1123,7 +1124,6 @@ glamor_generate_linear_gradient_picture(ScreenPtr screen,
float pt_distance;
float p1_distance;
GLfloat cos_val;
- float tex_vertices[8];
int stops_count = 0;
GLfloat *stop_colors = NULL;
GLfloat *n_stops = NULL;
@@ -1131,7 +1131,6 @@ glamor_generate_linear_gradient_picture(ScreenPtr screen,
float slope;
GLfloat xscale, yscale;
GLfloat pt1[2], pt2[2];
- float vertices[8];
float transform_mat[3][3];
static const float identity_mat[3][3] = { {1.0, 0.0, 0.0},
{0.0, 1.0, 0.0},
@@ -1287,7 +1286,7 @@ glamor_generate_linear_gradient_picture(ScreenPtr screen,
if (!_glamor_gradient_set_pixmap_destination
(screen, glamor_priv, dst_picture, &xscale, &yscale, x_source, y_source,
- vertices, tex_vertices, 1))
+ 1))
goto GRADIENT_FAIL;
glamor_set_alu(screen, GXcopy);
diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index d6f37cf..352858f 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -597,14 +597,6 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
glamor_screen_private *glamor_priv =
glamor_get_screen_private(pixmap->drawable.pScreen);
- static float vertices[8];
-
- static float texcoords_inv[8] = { 0, 0,
- 1, 0,
- 1, 1,
- 0, 1
- };
- float *ptexcoords;
float dst_xscale, dst_yscale;
GLuint tex = 0;
int need_free_bits = 0;
@@ -666,14 +658,22 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
return FALSE;
}
} else {
- ptexcoords = texcoords_inv;
+ static const float texcoords_inv[8] = { 0, 0,
+ 1, 0,
+ 1, 1,
+ 0, 1
+ };
+ GLfloat *v;
+ char *vbo_offset;
+
+ v = glamor_get_vbo_space(screen, 16 * sizeof(GLfloat), &vbo_offset);
pixmap_priv_get_dest_scale(pixmap, pixmap_priv, &dst_xscale, &dst_yscale);
glamor_set_normalize_vcoords(pixmap_priv, dst_xscale,
dst_yscale,
x, y,
x + w, y + h,
- vertices);
+ v);
/* Slow path, we need to flip y or wire alpha to 1. */
glamor_make_current(glamor_priv);
@@ -685,13 +685,16 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
return FALSE;
}
+ memcpy(&v[8], texcoords_inv, 8 * sizeof(GLfloat));
+
glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
- GL_FALSE, 2 * sizeof(float), vertices);
+ GL_FALSE, 2 * sizeof(float), vbo_offset);
glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT,
- GL_FALSE, 2 * sizeof(float), ptexcoords);
+ GL_FALSE, 2 * sizeof(float), vbo_offset + 8 * sizeof(GLfloat));
glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
+ glamor_put_vbo_space(screen);
glamor_set_destination_pixmap_priv_nc(glamor_priv, pixmap, pixmap_priv);
glamor_set_alu(screen, GXcopy);
glActiveTexture(GL_TEXTURE0);
More information about the xorg-commit
mailing list