[Mesa-dev] [PATCH 1/2] st/mesa: add a debug option to compile shaders at link time
Marek Olšák
maraeo at gmail.com
Tue Apr 14 05:36:27 PDT 2015
Ping. This is required for shader-db.
Marek
On Sat, Apr 11, 2015 at 1:49 AM, Marek Olšák <maraeo at gmail.com> wrote:
> From: Marek Olšák <marek.olsak at amd.com>
>
> v2: fix crashes
> ---
> src/mesa/state_tracker/st_cb_program.c | 4 +++
> src/mesa/state_tracker/st_debug.c | 1 +
> src/mesa/state_tracker/st_debug.h | 1 +
> src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 3 +-
> src/mesa/state_tracker/st_program.c | 47 ++++++++++++++++++++++++++++--
> src/mesa/state_tracker/st_program.h | 3 ++
> 6 files changed, 55 insertions(+), 4 deletions(-)
>
> diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c
> index aa301d8..c382d7d 100644
> --- a/src/mesa/state_tracker/st_cb_program.c
> +++ b/src/mesa/state_tracker/st_cb_program.c
> @@ -41,6 +41,7 @@
> #include "draw/draw_context.h"
>
> #include "st_context.h"
> +#include "st_debug.h"
> #include "st_program.h"
> #include "st_mesa_to_tgsi.h"
> #include "st_cb_program.h"
> @@ -214,6 +215,9 @@ st_program_string_notify( struct gl_context *ctx,
> st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
> }
>
> + if (ST_DEBUG & DEBUG_PRECOMPILE)
> + st_precompile_shader_variant(st, prog);
> +
> /* XXX check if program is legal, within limits */
> return GL_TRUE;
> }
> diff --git a/src/mesa/state_tracker/st_debug.c b/src/mesa/state_tracker/st_debug.c
> index de3e3a9..50891c1 100644
> --- a/src/mesa/state_tracker/st_debug.c
> +++ b/src/mesa/state_tracker/st_debug.c
> @@ -56,6 +56,7 @@ static const struct debug_named_value st_debug_flags[] = {
> { "draw", DEBUG_DRAW, NULL },
> { "buffer", DEBUG_BUFFER, NULL },
> { "wf", DEBUG_WIREFRAME, NULL },
> + { "precompile", DEBUG_PRECOMPILE, NULL },
> DEBUG_NAMED_VALUE_END
> };
>
> diff --git a/src/mesa/state_tracker/st_debug.h b/src/mesa/state_tracker/st_debug.h
> index cc81978..288eccf 100644
> --- a/src/mesa/state_tracker/st_debug.h
> +++ b/src/mesa/state_tracker/st_debug.h
> @@ -47,6 +47,7 @@ st_print_current(void);
> #define DEBUG_DRAW 0x100
> #define DEBUG_BUFFER 0x200
> #define DEBUG_WIREFRAME 0x400
> +#define DEBUG_PRECOMPILE 0x800
>
> #ifdef DEBUG
> extern int ST_DEBUG;
> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> index d12eb07..5fa7a41 100644
> --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> @@ -5367,7 +5367,8 @@ st_translate_program(
> * program constant) has to happen before creating this linkage.
> */
> for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
> - if (program->shader_program->_LinkedShaders[i] == NULL)
> + if (program->shader_program->_LinkedShaders[i] == NULL ||
> + program->shader_program->_LinkedShaders[i]->Program == NULL)
> continue;
>
> _mesa_associate_uniform_storage(ctx, program->shader_program,
> diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
> index 4cfd817..f4f907c 100644
> --- a/src/mesa/state_tracker/st_program.c
> +++ b/src/mesa/state_tracker/st_program.c
> @@ -185,9 +185,6 @@ st_prepare_vertex_program(struct gl_context *ctx,
> if (stvp->Base.IsPositionInvariant)
> _mesa_insert_mvp_code(ctx, &stvp->Base);
>
> - if (!stvp->glsl_to_tgsi)
> - assert(stvp->Base.Base.NumInstructions > 1);
> -
> /*
> * Determine number of inputs, the mappings between VERT_ATTRIB_x
> * and TGSI generic input indexes, plus input attrib semantic info.
> @@ -1318,3 +1315,47 @@ st_print_current_vertex_program(void)
> }
> }
> }
> +
> +
> +/**
> + * Compile one shader variant.
> + */
> +void
> +st_precompile_shader_variant(struct st_context *st,
> + struct gl_program *prog)
> +{
> + switch (prog->Target) {
> + case GL_VERTEX_PROGRAM_ARB: {
> + struct st_vertex_program *p = (struct st_vertex_program *)prog;
> + struct st_vp_variant_key key;
> +
> + memset(&key, 0, sizeof(key));
> + key.st = st;
> + st_get_vp_variant(st, p, &key);
> + break;
> + }
> +
> + case GL_GEOMETRY_PROGRAM_NV: {
> + struct st_geometry_program *p = (struct st_geometry_program *)prog;
> + struct st_gp_variant_key key;
> +
> + memset(&key, 0, sizeof(key));
> + key.st = st;
> + st_get_gp_variant(st, p, &key);
> + break;
> + }
> +
> + case GL_FRAGMENT_PROGRAM_ARB: {
> + struct st_fragment_program *p = (struct st_fragment_program *)prog;
> + struct st_fp_variant_key key;
> +
> + memset(&key, 0, sizeof(key));
> + key.st = st;
> + st_get_fp_variant(st, p, &key);
> + break;
> + }
> +
> + default:
> + assert(0);
> + }
> +}
> diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
> index 451d7bb..b2c86fa 100644
> --- a/src/mesa/state_tracker/st_program.h
> +++ b/src/mesa/state_tracker/st_program.h
> @@ -329,6 +329,9 @@ st_destroy_program_variants(struct st_context *st);
> extern void
> st_print_current_vertex_program(void);
>
> +extern void
> +st_precompile_shader_variant(struct st_context *st,
> + struct gl_program *prog);
>
> #ifdef __cplusplus
> }
> --
> 2.1.0
>
More information about the mesa-dev
mailing list