[PATCH 27/27] glamor: Apply debug labels to our shaders.

Eric Anholt eric at anholt.net
Tue Mar 11 14:30:41 PDT 2014


This will help tools like fips, apitrace, or INTEL_DEBUG=shader_time
provide useful information about the shaders in use.

Signed-off-by: Eric Anholt <eric at anholt.net>
---
 glamor/glamor.c           |  1 +
 glamor/glamor_core.c      | 20 +++++++++++++++++---
 glamor/glamor_fill.c      |  2 +-
 glamor/glamor_gradient.c  |  4 ++--
 glamor/glamor_priv.h      |  4 +++-
 glamor/glamor_render.c    |  2 +-
 glamor/glamor_tile.c      |  2 +-
 glamor/glamor_trapezoid.c |  2 +-
 glamor/glamor_xv.c        |  2 +-
 9 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/glamor/glamor.c b/glamor/glamor.c
index 5338d45..a624a7b 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -372,6 +372,7 @@ glamor_init(ScreenPtr screen, unsigned int flags)
         }
     }
 
+    glamor_priv->has_khr_debug = glamor_gl_has_extension("GL_KHR_debug");
     glamor_priv->has_pack_invert =
         glamor_gl_has_extension("GL_MESA_pack_invert");
     glamor_priv->has_fbo_blit =
diff --git a/glamor/glamor_core.c b/glamor/glamor_core.c
index c0994c1..96723c0 100644
--- a/glamor/glamor_core.c
+++ b/glamor/glamor_core.c
@@ -82,9 +82,10 @@ glamor_compile_glsl_prog(GLenum type, const char *source)
 }
 
 void
-glamor_link_glsl_prog(GLint prog)
+glamor_link_glsl_prog(ScreenPtr screen, GLint prog, const char *format, ...)
 {
     GLint ok;
+    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
 
     glLinkProgram(prog);
     glGetProgramiv(prog, GL_LINK_STATUS, &ok);
@@ -99,6 +100,17 @@ glamor_link_glsl_prog(GLint prog)
         ErrorF("Failed to link: %s\n", info);
         FatalError("GLSL link failure\n");
     }
+
+    if (glamor_priv->has_khr_debug) {
+        char *label;
+        va_list va;
+
+        va_start(va, format);
+        XNFvasprintf(&label, format, va);
+        glObjectLabel(GL_PROGRAM, prog, -1, label);
+        free(label);
+        va_end(va);
+    }
 }
 
 Bool
@@ -255,13 +267,15 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
                          GLAMOR_VERTEX_POS, "v_position");
     glBindAttribLocation(glamor_priv->finish_access_prog[0],
                          GLAMOR_VERTEX_SOURCE, "v_texcoord0");
-    glamor_link_glsl_prog(glamor_priv->finish_access_prog[0]);
+    glamor_link_glsl_prog(screen, glamor_priv->finish_access_prog[0],
+                          "finish access 0");
 
     glBindAttribLocation(glamor_priv->finish_access_prog[1],
                          GLAMOR_VERTEX_POS, "v_position");
     glBindAttribLocation(glamor_priv->finish_access_prog[1],
                          GLAMOR_VERTEX_SOURCE, "v_texcoord0");
-    glamor_link_glsl_prog(glamor_priv->finish_access_prog[1]);
+    glamor_link_glsl_prog(screen, glamor_priv->finish_access_prog[1],
+                          "finish access 1");
 
     glamor_priv->finish_access_revert[0] =
         glGetUniformLocation(glamor_priv->finish_access_prog[0], "revert");
diff --git a/glamor/glamor_fill.c b/glamor/glamor_fill.c
index d91dafb..e58b336 100644
--- a/glamor/glamor_fill.c
+++ b/glamor/glamor_fill.c
@@ -165,7 +165,7 @@ glamor_init_solid_shader(ScreenPtr screen)
 
     glBindAttribLocation(glamor_priv->solid_prog,
                          GLAMOR_VERTEX_POS, "v_position");
-    glamor_link_glsl_prog(glamor_priv->solid_prog);
+    glamor_link_glsl_prog(screen, glamor_priv->solid_prog, "solid");
 
     glamor_priv->solid_color_uniform_location =
         glGetUniformLocation(glamor_priv->solid_prog, "color");
diff --git a/glamor/glamor_gradient.c b/glamor/glamor_gradient.c
index 6a7b528..baa4a03 100644
--- a/glamor/glamor_gradient.c
+++ b/glamor/glamor_gradient.c
@@ -377,7 +377,7 @@ _glamor_create_radial_gradient_program(ScreenPtr screen, int stops_count,
     glBindAttribLocation(gradient_prog, GLAMOR_VERTEX_POS, "v_position");
     glBindAttribLocation(gradient_prog, GLAMOR_VERTEX_SOURCE, "v_texcoord");
 
-    glamor_link_glsl_prog(gradient_prog);
+    glamor_link_glsl_prog(screen, gradient_prog, "radial gradient");
 
     glUseProgram(0);
 
@@ -590,7 +590,7 @@ _glamor_create_linear_gradient_program(ScreenPtr screen, int stops_count,
     glBindAttribLocation(gradient_prog, GLAMOR_VERTEX_POS, "v_position");
     glBindAttribLocation(gradient_prog, GLAMOR_VERTEX_SOURCE, "v_texcoord");
 
-    glamor_link_glsl_prog(gradient_prog);
+    glamor_link_glsl_prog(screen, gradient_prog, "linear gradient");
 
     glUseProgram(0);
 
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 918f45c..91b3af8 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -214,6 +214,7 @@ typedef struct glamor_screen_private {
     int has_pack_invert;
     int has_fbo_blit;
     int has_buffer_storage;
+    int has_khr_debug;
     int max_fbo_size;
 
     struct xorg_list
@@ -594,7 +595,8 @@ Bool glamor_stipple(PixmapPtr pixmap, PixmapPtr stipple,
                     unsigned long fg_pixel, unsigned long bg_pixel,
                     int stipple_x, int stipple_y);
 GLint glamor_compile_glsl_prog(GLenum type, const char *source);
-void glamor_link_glsl_prog(GLint prog);
+void glamor_link_glsl_prog(ScreenPtr screen, GLint prog,
+                           const char *format, ...) _X_ATTRIBUTE_PRINTF(3,4);
 void glamor_get_color_4f_from_pixel(PixmapPtr pixmap,
                                     unsigned long fg_pixel, GLfloat *color);
 
diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c
index 93d9ead..121ae77 100644
--- a/glamor/glamor_render.c
+++ b/glamor/glamor_render.c
@@ -332,7 +332,7 @@ glamor_create_composite_shader(ScreenPtr screen, struct shader_key *key,
     glBindAttribLocation(prog, GLAMOR_VERTEX_SOURCE, "v_texcoord0");
     glBindAttribLocation(prog, GLAMOR_VERTEX_MASK, "v_texcoord1");
 
-    glamor_link_glsl_prog(prog);
+    glamor_link_glsl_prog(screen, prog, "composite");
 
     shader->prog = prog;
 
diff --git a/glamor/glamor_tile.c b/glamor/glamor_tile.c
index 7288af3..ba7f11f 100644
--- a/glamor/glamor_tile.c
+++ b/glamor/glamor_tile.c
@@ -73,7 +73,7 @@ glamor_init_tile_shader(ScreenPtr screen)
                          GLAMOR_VERTEX_POS, "v_position");
     glBindAttribLocation(glamor_priv->tile_prog,
                          GLAMOR_VERTEX_SOURCE, "v_texcoord0");
-    glamor_link_glsl_prog(glamor_priv->tile_prog);
+    glamor_link_glsl_prog(screen, glamor_priv->tile_prog, "tile");
 
     sampler_uniform_location =
         glGetUniformLocation(glamor_priv->tile_prog, "sampler");
diff --git a/glamor/glamor_trapezoid.c b/glamor/glamor_trapezoid.c
index 0064f2a..9c39740 100644
--- a/glamor/glamor_trapezoid.c
+++ b/glamor/glamor_trapezoid.c
@@ -1357,7 +1357,7 @@ glamor_init_trapezoid_shader(ScreenPtr screen)
     glBindAttribLocation(glamor_priv->trapezoid_prog,
                          GLAMOR_VERTEX_RIGHT_PARAM, "v_right_param");
 
-    glamor_link_glsl_prog(glamor_priv->trapezoid_prog);
+    glamor_link_glsl_prog(screen, glamor_priv->trapezoid_prog, "trapezoid");
 
     glUseProgram(0);
 
diff --git a/glamor/glamor_xv.c b/glamor/glamor_xv.c
index fb90457..c0219b0 100644
--- a/glamor/glamor_xv.c
+++ b/glamor/glamor_xv.c
@@ -109,7 +109,7 @@ glamor_init_xv_shader(ScreenPtr screen)
                          GLAMOR_VERTEX_POS, "v_position");
     glBindAttribLocation(glamor_priv->xv_prog,
                          GLAMOR_VERTEX_SOURCE, "v_texcoord0");
-    glamor_link_glsl_prog(glamor_priv->xv_prog);
+    glamor_link_glsl_prog(screen, glamor_priv->xv_prog, "xv");
 
     glamor_put_context(glamor_priv);
 }
-- 
1.9.0



More information about the xorg-devel mailing list