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>
This commit is contained in:
committed by
Pekka Paalanen
parent
7714c6172d
commit
71078b4044
@@ -159,6 +159,7 @@ struct gl_renderer {
|
|||||||
* List constains cached shaders built from struct gl_shader_requirements
|
* List constains cached shaders built from struct gl_shader_requirements
|
||||||
*/
|
*/
|
||||||
struct wl_list shader_list;
|
struct wl_list shader_list;
|
||||||
|
struct weston_log_scope *shader_scope;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline struct gl_renderer *
|
static inline struct gl_renderer *
|
||||||
@@ -202,4 +203,8 @@ int
|
|||||||
gl_shader_requirements_cmp(const struct gl_shader_requirements *a,
|
gl_shader_requirements_cmp(const struct gl_shader_requirements *a,
|
||||||
const struct gl_shader_requirements *b);
|
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 */
|
#endif /* GL_RENDERER_INTERNAL_H */
|
||||||
|
|||||||
@@ -3340,6 +3340,7 @@ gl_renderer_destroy(struct weston_compositor *ec)
|
|||||||
if (gr->fan_binding)
|
if (gr->fan_binding)
|
||||||
weston_binding_destroy(gr->fan_binding);
|
weston_binding_destroy(gr->fan_binding);
|
||||||
|
|
||||||
|
weston_log_scope_destroy(gr->shader_scope);
|
||||||
free(gr);
|
free(gr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3402,6 +3403,10 @@ gl_renderer_display_create(struct weston_compositor *ec,
|
|||||||
wl_list_init(&gr->shader_list);
|
wl_list_init(&gr->shader_list);
|
||||||
gr->platform = options->egl_platform;
|
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)
|
if (gl_renderer_setup_egl_client_extensions(gr) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
@@ -3490,6 +3495,7 @@ fail_with_error:
|
|||||||
fail_terminate:
|
fail_terminate:
|
||||||
eglTerminate(gr->egl_display);
|
eglTerminate(gr->egl_display);
|
||||||
fail:
|
fail:
|
||||||
|
weston_log_scope_destroy(gr->shader_scope);
|
||||||
free(gr);
|
free(gr);
|
||||||
ec->renderer = NULL;
|
ec->renderer = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include <libweston/libweston.h>
|
#include <libweston/libweston.h>
|
||||||
|
#include <libweston/weston-log.h>
|
||||||
#include <GLES2/gl2.h>
|
#include <GLES2/gl2.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -113,7 +114,7 @@ gl_shader_destroy(struct gl_shader *shader)
|
|||||||
free(shader);
|
free(shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static GLuint
|
||||||
compile_shader(GLenum type, int count, const char **sources)
|
compile_shader(GLenum type, int count, const char **sources)
|
||||||
{
|
{
|
||||||
GLuint s;
|
GLuint s;
|
||||||
@@ -135,6 +136,20 @@ compile_shader(GLenum type, int count, const char **sources)
|
|||||||
return s;
|
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 *
|
static char *
|
||||||
create_shader_config_string(const struct gl_shader_requirements *req)
|
create_shader_config_string(const struct gl_shader_requirements *req)
|
||||||
{
|
{
|
||||||
@@ -155,6 +170,7 @@ struct gl_shader *
|
|||||||
gl_shader_create(struct gl_renderer *gr,
|
gl_shader_create(struct gl_renderer *gr,
|
||||||
const struct gl_shader_requirements *requirements)
|
const struct gl_shader_requirements *requirements)
|
||||||
{
|
{
|
||||||
|
bool verbose = weston_log_scope_is_enabled(gr->shader_scope);
|
||||||
struct gl_shader *shader = NULL;
|
struct gl_shader *shader = NULL;
|
||||||
char msg[512];
|
char msg[512];
|
||||||
GLint status;
|
GLint status;
|
||||||
@@ -170,6 +186,16 @@ gl_shader_create(struct gl_renderer *gr,
|
|||||||
wl_list_init(&shader->link);
|
wl_list_init(&shader->link);
|
||||||
shader->key = *requirements;
|
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;
|
sources[0] = vertex_shader;
|
||||||
shader->vertex_shader = compile_shader(GL_VERTEX_SHADER, 1, sources);
|
shader->vertex_shader = compile_shader(GL_VERTEX_SHADER, 1, sources);
|
||||||
if (shader->vertex_shader == GL_NONE)
|
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));
|
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);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user