Module: Mesa Branch: master Commit: 6fdd1d30f6684a716b70bff5948137e6e54adf6e URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=6fdd1d30f6684a716b70bff5948137e6e54adf6e
Author: Rob Clark <[email protected]> Date: Sat Jan 30 10:55:41 2021 -0800 freedreno/ir3: Add ir3_shader_state Initially just a wrapper for ir3_shader, but this is where we'll hook in the bookkeeping for async compile. Signed-off-by: Rob Clark <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8795> --- src/gallium/drivers/freedreno/a3xx/fd3_draw.c | 2 +- src/gallium/drivers/freedreno/a3xx/fd3_emit.h | 4 +-- src/gallium/drivers/freedreno/a4xx/fd4_emit.h | 4 +-- src/gallium/drivers/freedreno/a5xx/fd5_compute.c | 2 +- src/gallium/drivers/freedreno/a5xx/fd5_emit.h | 4 +-- src/gallium/drivers/freedreno/a6xx/fd6_compute.c | 2 +- src/gallium/drivers/freedreno/a6xx/fd6_draw.c | 6 ++-- src/gallium/drivers/freedreno/ir3/ir3_cache.c | 15 ++++---- src/gallium/drivers/freedreno/ir3/ir3_cache.h | 2 +- src/gallium/drivers/freedreno/ir3/ir3_gallium.c | 45 +++++++++++++++++++++--- src/gallium/drivers/freedreno/ir3/ir3_gallium.h | 10 ++++++ 11 files changed, 71 insertions(+), 25 deletions(-) diff --git a/src/gallium/drivers/freedreno/a3xx/fd3_draw.c b/src/gallium/drivers/freedreno/a3xx/fd3_draw.c index c2c486993ef..2045b553202 100644 --- a/src/gallium/drivers/freedreno/a3xx/fd3_draw.c +++ b/src/gallium/drivers/freedreno/a3xx/fd3_draw.c @@ -143,7 +143,7 @@ fd3_draw_vbo(struct fd_context *ctx, const struct pipe_draw_info *info, .sprite_coord_mode = ctx->rasterizer->sprite_coord_mode, }; - if (fd3_needs_manual_clipping(ctx->prog.vs, ctx->rasterizer)) + if (fd3_needs_manual_clipping(ir3_get_shader(ctx->prog.vs), ctx->rasterizer)) emit.key.ucp_enables = ctx->rasterizer->clip_plane_enable; fixup_shader_state(ctx, &emit.key); diff --git a/src/gallium/drivers/freedreno/a3xx/fd3_emit.h b/src/gallium/drivers/freedreno/a3xx/fd3_emit.h index 93e41e3d9de..9b423fb88d6 100644 --- a/src/gallium/drivers/freedreno/a3xx/fd3_emit.h +++ b/src/gallium/drivers/freedreno/a3xx/fd3_emit.h @@ -64,7 +64,7 @@ static inline const struct ir3_shader_variant * fd3_emit_get_vp(struct fd3_emit *emit) { if (!emit->vs) { - struct ir3_shader *shader = emit->prog->vs; + struct ir3_shader *shader = ir3_get_shader(emit->prog->vs); emit->vs = ir3_shader_variant(shader, emit->key, emit->binning_pass, emit->debug); } @@ -80,7 +80,7 @@ fd3_emit_get_fp(struct fd3_emit *emit) static const struct ir3_shader_variant binning_fs = {}; emit->fs = &binning_fs; } else { - struct ir3_shader *shader = emit->prog->fs; + struct ir3_shader *shader = ir3_get_shader(emit->prog->fs); emit->fs = ir3_shader_variant(shader, emit->key, false, emit->debug); } diff --git a/src/gallium/drivers/freedreno/a4xx/fd4_emit.h b/src/gallium/drivers/freedreno/a4xx/fd4_emit.h index 502f7b592fa..d140c6cd116 100644 --- a/src/gallium/drivers/freedreno/a4xx/fd4_emit.h +++ b/src/gallium/drivers/freedreno/a4xx/fd4_emit.h @@ -72,7 +72,7 @@ static inline const struct ir3_shader_variant * fd4_emit_get_vp(struct fd4_emit *emit) { if (!emit->vs) { - struct ir3_shader *shader = emit->prog->vs; + struct ir3_shader *shader = ir3_get_shader(emit->prog->vs); emit->vs = ir3_shader_variant(shader, emit->key, emit->binning_pass, emit->debug); } @@ -88,7 +88,7 @@ fd4_emit_get_fp(struct fd4_emit *emit) static const struct ir3_shader_variant binning_fs = {}; emit->fs = &binning_fs; } else { - struct ir3_shader *shader = emit->prog->fs; + struct ir3_shader *shader = ir3_get_shader(emit->prog->fs); emit->fs = ir3_shader_variant(shader, emit->key, false, emit->debug); } diff --git a/src/gallium/drivers/freedreno/a5xx/fd5_compute.c b/src/gallium/drivers/freedreno/a5xx/fd5_compute.c index 3cf0efbf3e1..d8d973cac47 100644 --- a/src/gallium/drivers/freedreno/a5xx/fd5_compute.c +++ b/src/gallium/drivers/freedreno/a5xx/fd5_compute.c @@ -122,7 +122,7 @@ fd5_launch_grid(struct fd_context *ctx, const struct pipe_grid_info *info) struct fd_ringbuffer *ring = ctx->batch->draw; unsigned nglobal = 0; - v = ir3_shader_variant(ctx->compute, key, false, &ctx->debug); + v = ir3_shader_variant(ir3_get_shader(ctx->compute), key, false, &ctx->debug); if (!v) return; diff --git a/src/gallium/drivers/freedreno/a5xx/fd5_emit.h b/src/gallium/drivers/freedreno/a5xx/fd5_emit.h index d76fc2967c6..4d06b41aa1d 100644 --- a/src/gallium/drivers/freedreno/a5xx/fd5_emit.h +++ b/src/gallium/drivers/freedreno/a5xx/fd5_emit.h @@ -80,7 +80,7 @@ static inline const struct ir3_shader_variant * fd5_emit_get_vp(struct fd5_emit *emit) { if (!emit->vs) { - struct ir3_shader *shader = emit->prog->vs; + struct ir3_shader *shader = ir3_get_shader(emit->prog->vs); emit->vs = ir3_shader_variant(shader, emit->key, emit->binning_pass, emit->debug); } @@ -96,7 +96,7 @@ fd5_emit_get_fp(struct fd5_emit *emit) static const struct ir3_shader_variant binning_fs = {}; emit->fs = &binning_fs; } else { - struct ir3_shader *shader = emit->prog->fs; + struct ir3_shader *shader = ir3_get_shader(emit->prog->fs); emit->fs = ir3_shader_variant(shader, emit->key, false, emit->debug); } diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_compute.c b/src/gallium/drivers/freedreno/a6xx/fd6_compute.c index 94f4245849e..25fdb8aca3e 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_compute.c +++ b/src/gallium/drivers/freedreno/a6xx/fd6_compute.c @@ -106,7 +106,7 @@ fd6_launch_grid(struct fd_context *ctx, const struct pipe_grid_info *info) struct fd_ringbuffer *ring = ctx->batch->draw; unsigned nglobal = 0; - v = ir3_shader_variant(ctx->compute, key, false, &ctx->debug); + v = ir3_shader_variant(ir3_get_shader(ctx->compute), key, false, &ctx->debug); if (!v) return; diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_draw.c b/src/gallium/drivers/freedreno/a6xx/fd6_draw.c index 728dcdc66ba..9aa2df455c3 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_draw.c +++ b/src/gallium/drivers/freedreno/a6xx/fd6_draw.c @@ -171,7 +171,7 @@ fd6_draw_vbo(struct fd_context *ctx, const struct pipe_draw_info *info, unsigned index_offset) { struct fd6_context *fd6_ctx = fd6_context(ctx); - struct ir3_shader *gs = ctx->prog.gs; + struct shader_info *gs_info = ir3_get_shader_info(ctx->prog.gs); struct fd6_emit emit = { .ctx = ctx, .vtx = &ctx->vtx, @@ -195,7 +195,7 @@ fd6_draw_vbo(struct fd_context *ctx, const struct pipe_draw_info *info, .fsaturate_s = fd6_ctx->fsaturate_s, .fsaturate_t = fd6_ctx->fsaturate_t, .fsaturate_r = fd6_ctx->fsaturate_r, - .layer_zero = !gs || !(gs->nir->info.outputs_written & VARYING_BIT_LAYER), + .layer_zero = !gs_info || !(gs_info->outputs_written & VARYING_BIT_LAYER), .vsamples = ctx->tex[PIPE_SHADER_VERTEX].samples, .fsamples = ctx->tex[PIPE_SHADER_FRAGMENT].samples, .sample_shading = (ctx->min_samples > 1), @@ -218,7 +218,7 @@ fd6_draw_vbo(struct fd_context *ctx, const struct pipe_draw_info *info, if (!(ctx->prog.hs && ctx->prog.ds)) return false; - shader_info *ds_info = &emit.key.ds->nir->info; + struct shader_info *ds_info = ir3_get_shader_info(emit.key.ds); emit.key.key.tessellation = ir3_tess_mode(ds_info->tess.primitive_mode); } diff --git a/src/gallium/drivers/freedreno/ir3/ir3_cache.c b/src/gallium/drivers/freedreno/ir3/ir3_cache.c index 606e610be79..e5ff5a29656 100644 --- a/src/gallium/drivers/freedreno/ir3/ir3_cache.c +++ b/src/gallium/drivers/freedreno/ir3/ir3_cache.c @@ -97,11 +97,11 @@ ir3_cache_lookup(struct ir3_cache *cache, const struct ir3_cache_key *key, debug_assert(key->ds); struct ir3_shader *shaders[MESA_SHADER_STAGES] = { - [MESA_SHADER_VERTEX] = key->vs, - [MESA_SHADER_TESS_CTRL] = key->hs, - [MESA_SHADER_TESS_EVAL] = key->ds, - [MESA_SHADER_GEOMETRY] = key->gs, - [MESA_SHADER_FRAGMENT] = key->fs, + [MESA_SHADER_VERTEX] = ir3_get_shader(key->vs), + [MESA_SHADER_TESS_CTRL] = ir3_get_shader(key->hs), + [MESA_SHADER_TESS_EVAL] = ir3_get_shader(key->ds), + [MESA_SHADER_GEOMETRY] = ir3_get_shader(key->gs), + [MESA_SHADER_FRAGMENT] = ir3_get_shader(key->fs), }; struct ir3_shader_variant *variants[MESA_SHADER_STAGES]; @@ -119,7 +119,8 @@ ir3_cache_lookup(struct ir3_cache *cache, const struct ir3_cache_key *key, } } - uint32_t safe_constlens = ir3_trim_constlen(variants, key->vs->compiler); + struct ir3_compiler *compiler = shaders[MESA_SHADER_VERTEX]->compiler; + uint32_t safe_constlens = ir3_trim_constlen(variants, compiler); shader_key.safe_constlen = true; for (gl_shader_stage stage = MESA_SHADER_VERTEX; @@ -136,7 +137,7 @@ ir3_cache_lookup(struct ir3_cache *cache, const struct ir3_cache_key *key, if (ir3_has_binning_vs(&key->key)) { shader_key.safe_constlen = !!(safe_constlens & (1 << MESA_SHADER_VERTEX)); - bs = ir3_shader_variant(key->vs, key->key, true, debug); + bs = ir3_shader_variant(shaders[MESA_SHADER_VERTEX], key->key, true, debug); if (!bs) return NULL; } else { diff --git a/src/gallium/drivers/freedreno/ir3/ir3_cache.h b/src/gallium/drivers/freedreno/ir3/ir3_cache.h index d4332eeb38a..71708ad9ffc 100644 --- a/src/gallium/drivers/freedreno/ir3/ir3_cache.h +++ b/src/gallium/drivers/freedreno/ir3/ir3_cache.h @@ -37,7 +37,7 @@ /* key into program state cache */ struct ir3_cache_key { - struct ir3_shader *vs, *hs, *ds, *gs, *fs; // 5 pointers + struct ir3_shader_state *vs, *hs, *ds, *gs, *fs; // 5 pointers struct ir3_shader_key key; // 7 dwords }; diff --git a/src/gallium/drivers/freedreno/ir3/ir3_gallium.c b/src/gallium/drivers/freedreno/ir3/ir3_gallium.c index 34e1a8ce22a..266aaf894e6 100644 --- a/src/gallium/drivers/freedreno/ir3/ir3_gallium.c +++ b/src/gallium/drivers/freedreno/ir3/ir3_gallium.c @@ -43,6 +43,16 @@ #include "ir3/ir3_compiler.h" #include "ir3/ir3_nir.h" +/** + * The hardware cso for shader state + * + * Initially just a container for the ir3_shader, but this is where we'll + * plumb in async compile. + */ +struct ir3_shader_state { + struct ir3_shader *shader; +}; + static void dump_shader_info(struct ir3_shader_variant *v, struct pipe_debug_callback *debug) { @@ -246,7 +256,7 @@ ir3_shader_create(struct ir3_compiler *compiler, /* a bit annoying that compute-shader and normal shader state objects * aren't a bit more aligned. */ -static struct ir3_shader * +static struct ir3_shader_state * ir3_shader_create_compute(struct ir3_compiler *compiler, const struct pipe_compute_state *cso, struct pipe_debug_callback *debug, @@ -275,7 +285,10 @@ ir3_shader_create_compute(struct ir3_compiler *compiler, shader->initial_variants_done = true; - return shader; + struct ir3_shader_state *hwcso = calloc(1, sizeof(*hwcso)); + hwcso->shader = shader; + + return hwcso; } void * @@ -304,13 +317,18 @@ ir3_shader_state_create(struct pipe_context *pctx, const struct pipe_shader_stat { struct fd_context *ctx = fd_context(pctx); struct ir3_compiler *compiler = ctx->screen->compiler; - return ir3_shader_create(compiler, cso, &ctx->debug, pctx->screen); + struct ir3_shader_state *hwcso = calloc(1, sizeof(*hwcso)); + + hwcso->shader = ir3_shader_create(compiler, cso, &ctx->debug, pctx->screen); + + return hwcso; } void -ir3_shader_state_delete(struct pipe_context *pctx, void *hwcso) +ir3_shader_state_delete(struct pipe_context *pctx, void *_hwcso) { - struct ir3_shader *so = hwcso; + struct ir3_shader_state *hwcso = _hwcso; + struct ir3_shader *so = hwcso->shader; /* free the uploaded shaders, since this is handled outside of the * shared ir3 code (ie. not used by turnip): @@ -326,6 +344,23 @@ ir3_shader_state_delete(struct pipe_context *pctx, void *hwcso) } ir3_shader_destroy(so); + free(hwcso); +} + +struct ir3_shader * +ir3_get_shader(struct ir3_shader_state *hwcso) +{ + if (!hwcso) + return NULL; + return hwcso->shader; +} + +struct shader_info * +ir3_get_shader_info(struct ir3_shader_state *hwcso) +{ + if (!hwcso) + return NULL; + return &hwcso->shader->nir->info; } static void diff --git a/src/gallium/drivers/freedreno/ir3/ir3_gallium.h b/src/gallium/drivers/freedreno/ir3/ir3_gallium.h index bc11bb43386..3fef6249ffa 100644 --- a/src/gallium/drivers/freedreno/ir3/ir3_gallium.h +++ b/src/gallium/drivers/freedreno/ir3/ir3_gallium.h @@ -35,6 +35,13 @@ 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 + */ +struct ir3_shader_state; + struct ir3_shader_variant * ir3_shader_variant(struct ir3_shader *shader, struct ir3_shader_key key, bool binning_pass, struct pipe_debug_callback *debug); @@ -44,6 +51,9 @@ void * ir3_shader_compute_state_create(struct pipe_context *pctx, void * ir3_shader_state_create(struct pipe_context *pctx, const struct pipe_shader_state *cso); void ir3_shader_state_delete(struct pipe_context *pctx, void *hwcso); +struct ir3_shader * ir3_get_shader(struct ir3_shader_state *hwcso); +struct shader_info * ir3_get_shader_info(struct ir3_shader_state *hwcso); + void ir3_prog_init(struct pipe_context *pctx); void ir3_screen_init(struct pipe_screen *pscreen); _______________________________________________ mesa-commit mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-commit
