gl-renderer: Add debug scope for shader generator

This helps accounting how many shaders live in the cache, what the
shader source code is, and when shaders are compiled.

Signed-off-by: Harish Krupo <harishkrupo@gmail.com>

v2: Resolved rebase conflicts.
    Put shader_scope in struct gl_renderer, remove struct
    gl_shader_generator.
    Wrote commit message.
    Rebased for "gl-renderer: rewrite fragment shaders" which completely
    changed how shader sources are generated.
    Added cache statistics to debug output on subscribe.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
dev
Harish Krupo 6 years ago committed by Pekka Paalanen
parent 7714c6172d
commit 71078b4044
  1. 5
      libweston/renderer-gl/gl-renderer-internal.h
  2. 6
      libweston/renderer-gl/gl-renderer.c
  3. 70
      libweston/renderer-gl/gl-shaders.c

@ -159,6 +159,7 @@ struct gl_renderer {
* List constains cached shaders built from struct gl_shader_requirements
*/
struct wl_list shader_list;
struct weston_log_scope *shader_scope;
};
static inline struct gl_renderer *
@ -202,4 +203,8 @@ int
gl_shader_requirements_cmp(const struct gl_shader_requirements *a,
const struct gl_shader_requirements *b);
struct weston_log_scope *
gl_shader_scope_create(struct weston_compositor *compositor,
struct gl_renderer *gr);
#endif /* GL_RENDERER_INTERNAL_H */

@ -3340,6 +3340,7 @@ gl_renderer_destroy(struct weston_compositor *ec)
if (gr->fan_binding)
weston_binding_destroy(gr->fan_binding);
weston_log_scope_destroy(gr->shader_scope);
free(gr);
}
@ -3402,6 +3403,10 @@ gl_renderer_display_create(struct weston_compositor *ec,
wl_list_init(&gr->shader_list);
gr->platform = options->egl_platform;
gr->shader_scope = gl_shader_scope_create(ec, gr);
if (!gr->shader_scope)
goto fail;
if (gl_renderer_setup_egl_client_extensions(gr) < 0)
goto fail;
@ -3490,6 +3495,7 @@ fail_with_error:
fail_terminate:
eglTerminate(gr->egl_display);
fail:
weston_log_scope_destroy(gr->shader_scope);
free(gr);
ec->renderer = NULL;
return -1;

@ -34,6 +34,7 @@
#include <assert.h>
#include <libweston/libweston.h>
#include <libweston/weston-log.h>
#include <GLES2/gl2.h>
#include <string.h>
@ -113,7 +114,7 @@ gl_shader_destroy(struct gl_shader *shader)
free(shader);
}
static int
static GLuint
compile_shader(GLenum type, int count, const char **sources)
{
GLuint s;
@ -135,6 +136,20 @@ compile_shader(GLenum type, int count, const char **sources)
return s;
}
static char *
create_shader_description_string(const struct gl_shader_requirements *req)
{
int size;
char *str;
size = asprintf(&str, "%s %cgreen",
gl_shader_texture_variant_to_string(req->variant),
req->green_tint ? '+' : '-');
if (size < 0)
return NULL;
return str;
}
static char *
create_shader_config_string(const struct gl_shader_requirements *req)
{
@ -155,6 +170,7 @@ struct gl_shader *
gl_shader_create(struct gl_renderer *gr,
const struct gl_shader_requirements *requirements)
{
bool verbose = weston_log_scope_is_enabled(gr->shader_scope);
struct gl_shader *shader = NULL;
char msg[512];
GLint status;
@ -170,6 +186,16 @@ gl_shader_create(struct gl_renderer *gr,
wl_list_init(&shader->link);
shader->key = *requirements;
if (verbose) {
char *desc;
desc = create_shader_description_string(requirements);
weston_log_scope_printf(gr->shader_scope,
"Compiling shader program for: %s\n",
desc);
free(desc);
}
sources[0] = vertex_shader;
shader->vertex_shader = compile_shader(GL_VERTEX_SHADER, 1, sources);
if (shader->vertex_shader == GL_NONE)
@ -236,3 +262,45 @@ gl_shader_requirements_cmp(const struct gl_shader_requirements *a,
{
return memcmp(a, b, sizeof(*a));
}
static void
gl_shader_scope_new_subscription(struct weston_log_subscription *subs,
void *data)
{
static const char bar[] = "-----------------------------------------------------------------------------";
struct gl_renderer *gr = data;
struct gl_shader *shader;
int count = 0;
char *desc;
weston_log_subscription_printf(subs,
"Vertex shader body:\n"
"%s\n%s\n"
"Fragment shader body:\n"
"%s\n%s\n%s\n",
bar, vertex_shader,
bar, fragment_shader, bar);
weston_log_subscription_printf(subs, "Cached GLSL programs:\n");
wl_list_for_each(shader, &gr->shader_list, link) {
count++;
desc = create_shader_description_string(&shader->key);
weston_log_subscription_printf(subs,
"%6u: %s\n",
shader->program, desc);
}
weston_log_subscription_printf(subs, "Total: %d programs.\n", count);
}
struct weston_log_scope *
gl_shader_scope_create(struct weston_compositor *compositor,
struct gl_renderer *gr)
{
return weston_compositor_add_log_scope(compositor,
"gl-shader-generator",
"GL renderer shader compilation and cache.\n",
gl_shader_scope_new_subscription,
NULL,
gr);
}

Loading…
Cancel
Save