From: Christian Gmeiner Date: Tue, 14 Mar 2017 18:57:15 +0000 (+0100) Subject: etnaviv: add basic shader variant support X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=65e9bd2703f2fce29321f3512d4a2673df2556d3;p=mesa.git etnaviv: add basic shader variant support This commit adds some basic infrastructure to handle shader variants. We are still creating exactly one shader variant for each shader. Signed-off-by: Christian Gmeiner Reviewed-by: Lucas Stach --- diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler.h b/src/gallium/drivers/etnaviv/etnaviv_compiler.h index 2a3b4f4f4ee..8de01264a9b 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_compiler.h +++ b/src/gallium/drivers/etnaviv/etnaviv_compiler.h @@ -92,6 +92,9 @@ struct etna_shader_variant { /* unknown input property (XX_INPUT_COUNT, field UNK8) */ uint32_t input_count_unk8; + + /* shader variants form a linked list */ + struct etna_shader_variant *next; }; struct etna_varying { diff --git a/src/gallium/drivers/etnaviv/etnaviv_shader.c b/src/gallium/drivers/etnaviv/etnaviv_shader.c index 35084e54848..0ef611fdff9 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_shader.c +++ b/src/gallium/drivers/etnaviv/etnaviv_shader.c @@ -31,6 +31,7 @@ #include "etnaviv_debug.h" #include "etnaviv_util.h" +#include "tgsi/tgsi_parse.h" #include "util/u_math.h" #include "util/u_memory.h" @@ -266,25 +267,65 @@ etna_shader_update_vertex(struct etna_context *ctx) ctx->vertex_elements); } +static struct etna_shader_variant * +create_variant(struct etna_shader *shader) +{ + struct etna_shader_variant *v; + + v = etna_compile_shader(shader->specs, shader->tokens); + if (!v) { + debug_error("compile failed!"); + return NULL; + } + + v->id = ++shader->variant_count; + + return v; +} + static void * etna_create_shader_state(struct pipe_context *pctx, const struct pipe_shader_state *pss) { struct etna_context *ctx = etna_context(pctx); - struct etna_shader_variant *shader = etna_compile_shader(&ctx->specs, pss->tokens); + struct etna_shader *shader = CALLOC_STRUCT(etna_shader); + + if (!shader) + return NULL; static uint32_t id; shader->id = id++; + shader->specs = &ctx->specs; + shader->tokens = tgsi_dup_tokens(pss->tokens); - dump_shader_info(shader, &ctx->debug); + /* compile new variant */ + struct etna_shader_variant *v; - return shader; + v = create_variant(shader); + if (v) { + v->next = shader->variants; + shader->variants = v; + dump_shader_info(v, &ctx->debug); + } + + return v; } static void etna_delete_shader_state(struct pipe_context *pctx, void *ss) { - etna_destroy_shader(ss); + struct etna_shader *shader = ss; + struct etna_shader_variant *v, *t; + + v = shader->variants; + while (v) { + t = v; + v = v->next; + etna_destroy_shader(t); + } + + FREE(shader->tokens); + FREE(shader); } static void diff --git a/src/gallium/drivers/etnaviv/etnaviv_shader.h b/src/gallium/drivers/etnaviv/etnaviv_shader.h index 1dbd2006579..c613c17df0a 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_shader.h +++ b/src/gallium/drivers/etnaviv/etnaviv_shader.h @@ -30,6 +30,18 @@ #include "pipe/p_state.h" struct etna_context; +struct etna_shader_variant; + +struct etna_shader { + /* shader id (for debug): */ + uint32_t id; + uint32_t variant_count; + + struct tgsi_token *tokens; + struct etna_specs *specs; + + struct etna_shader_variant *variants; +}; bool etna_shader_link(struct etna_context *ctx);