From f4ab72d8e8a320df3e2f3cb10f7e4cb60396404d Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Sat, 30 Jan 2021 12:20:23 -0800 Subject: [PATCH] freedreno/ir3: Reshuffle ir3_shader_create() This had only a single caller, so no need to be exported. With that done, fold the ir3_shader creation (ie. the cheap part) into ir3_shader_state_create(), and rename what is left. This is prep to moving initial variant creation to a work queue. It does slightly change the error handling, in that we don't cleanup the shader hwcso. We wouldn't be able to do this anyways with async compile. But it ends up using the same error handling paths that we'd hit if we got a compile failure for a draw-time variant. Signed-off-by: Rob Clark Part-of: --- .../drivers/freedreno/ir3/ir3_gallium.c | 66 +++++++++++-------- .../drivers/freedreno/ir3/ir3_gallium.h | 5 -- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/src/gallium/drivers/freedreno/ir3/ir3_gallium.c b/src/gallium/drivers/freedreno/ir3/ir3_gallium.c index 7b041530458..ef76628c821 100644 --- a/src/gallium/drivers/freedreno/ir3/ir3_gallium.c +++ b/src/gallium/drivers/freedreno/ir3/ir3_gallium.c @@ -168,28 +168,13 @@ copy_stream_out(struct ir3_stream_output_info *i, } } -struct ir3_shader * -ir3_shader_create(struct ir3_compiler *compiler, - const struct pipe_shader_state *cso, - struct pipe_debug_callback *debug, - struct pipe_screen *screen) +static void +create_initial_variants(struct ir3_shader_state *hwcso, + struct pipe_debug_callback *debug) { - nir_shader *nir; - if (cso->type == PIPE_SHADER_IR_NIR) { - /* we take ownership of the reference: */ - nir = cso->ir.nir; - } else { - debug_assert(cso->type == PIPE_SHADER_IR_TGSI); - if (ir3_shader_debug & IR3_DBG_DISASM) { - tgsi_dump(cso->tokens, 0); - } - nir = tgsi_to_nir(cso->tokens, screen, false); - } - - struct ir3_stream_output_info stream_output = {}; - copy_stream_out(&stream_output, &cso->stream_output); - - struct ir3_shader *shader = ir3_shader_from_nir(compiler, nir, 0, &stream_output); + struct ir3_shader *shader = hwcso->shader; + struct ir3_compiler *compiler = shader->compiler; + nir_shader *nir = shader->nir; /* Compile standard variants immediately to try to avoid draw-time stalls * to run the compiler. @@ -228,7 +213,7 @@ ir3_shader_create(struct ir3_compiler *compiler, key.safe_constlen = false; struct ir3_shader_variant *v = ir3_shader_variant(shader, key, false, debug); if (!v) - return NULL; + return; if (v->constlen > compiler->max_const_safe) { key.safe_constlen = true; @@ -240,7 +225,7 @@ ir3_shader_create(struct ir3_compiler *compiler, key.safe_constlen = false; v = ir3_shader_variant(shader, key, true, debug); if (!v) - return NULL; + return; if (v->constlen > compiler->max_const_safe) { key.safe_constlen = true; @@ -249,8 +234,6 @@ ir3_shader_create(struct ir3_compiler *compiler, } shader->initial_variants_done = true; - - return shader; } /* a bit annoying that compute-shader and normal shader state objects @@ -319,7 +302,38 @@ ir3_shader_state_create(struct pipe_context *pctx, const struct pipe_shader_stat struct ir3_compiler *compiler = ctx->screen->compiler; struct ir3_shader_state *hwcso = calloc(1, sizeof(*hwcso)); - hwcso->shader = ir3_shader_create(compiler, cso, &ctx->debug, pctx->screen); + /* + * Convert to nir (if necessary): + */ + + nir_shader *nir; + if (cso->type == PIPE_SHADER_IR_NIR) { + /* we take ownership of the reference: */ + nir = cso->ir.nir; + } else { + debug_assert(cso->type == PIPE_SHADER_IR_TGSI); + if (ir3_shader_debug & IR3_DBG_DISASM) { + tgsi_dump(cso->tokens, 0); + } + nir = tgsi_to_nir(cso->tokens, pctx->screen, false); + } + + /* + * Create ir3_shader: + * + * This part is cheap, it doesn't compile initial variants + */ + + struct ir3_stream_output_info stream_output = {}; + copy_stream_out(&stream_output, &cso->stream_output); + + hwcso->shader = ir3_shader_from_nir(compiler, nir, 0, &stream_output); + + /* + * Create initial variants to avoid draw-time stalls: + */ + + create_initial_variants(hwcso, &ctx->debug); return hwcso; } diff --git a/src/gallium/drivers/freedreno/ir3/ir3_gallium.h b/src/gallium/drivers/freedreno/ir3/ir3_gallium.h index d52c84f4ddb..8523895e684 100644 --- a/src/gallium/drivers/freedreno/ir3/ir3_gallium.h +++ b/src/gallium/drivers/freedreno/ir3/ir3_gallium.h @@ -31,11 +31,6 @@ #include "pipe/p_screen.h" #include "ir3/ir3_shader.h" -struct ir3_shader * ir3_shader_create(struct ir3_compiler *compiler, - const struct pipe_shader_state *cso, - struct pipe_debug_callback *debug, - struct pipe_screen *screen); - /** * The ir3 hwcso type, use ir3_get_shader() to dereference the * underlying ir3_shader