From 1e4c49e0b5db350528e9fbc730803338ad4995fb Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 21 Aug 2020 14:16:18 -0400 Subject: panfrost: Upload shader descriptors at CSO create Now that we've fixed all the implicit state dependencies, these don't change after the variant is created. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Tomeu Vizoso Part-of: --- src/gallium/drivers/panfrost/pan_assemble.c | 22 ++++++++++++++++++++++ src/gallium/drivers/panfrost/pan_context.c | 5 +++++ src/gallium/drivers/panfrost/pan_context.h | 9 +++++++++ 3 files changed, 36 insertions(+) diff --git a/src/gallium/drivers/panfrost/pan_assemble.c b/src/gallium/drivers/panfrost/pan_assemble.c index 21c1810de75..236acd77046 100644 --- a/src/gallium/drivers/panfrost/pan_assemble.c +++ b/src/gallium/drivers/panfrost/pan_assemble.c @@ -35,6 +35,7 @@ #include "midgard/midgard_compile.h" #include "bifrost/bifrost_compile.h" #include "util/u_dynarray.h" +#include "util/u_upload_mgr.h" #include "tgsi/tgsi_dump.h" @@ -98,6 +99,24 @@ pan_pack_bifrost_props(struct panfrost_shader_state *state, } } +static void +pan_upload_shader_descriptor(struct panfrost_context *ctx, + struct panfrost_shader_state *state) +{ + const struct panfrost_device *dev = pan_device(ctx->base.screen); + struct mali_shader_meta meta; + + memset(&meta, 0, sizeof(meta)); + memcpy(&meta.shader, &state->shader, sizeof(state->shader)); + memcpy(&meta.midgard_props, &state->properties, sizeof(state->properties)); + + if (dev->quirks & IS_BIFROST) + memcpy(&meta.bifrost_preload, &state->preload, sizeof(state->preload)); + + u_upload_data(ctx->state_uploader, 0, sizeof(meta), sizeof(meta), + &meta, &state->upload.offset, &state->upload.rsrc); +} + static unsigned pan_format_from_nir_base(nir_alu_type base) { @@ -361,6 +380,9 @@ panfrost_shader_compile(struct panfrost_context *ctx, else pan_pack_midgard_props(state, stage); + if (stage != MESA_SHADER_FRAGMENT) + pan_upload_shader_descriptor(ctx, state); + /* In both clone and tgsi_to_nir paths, the shader is ralloc'd against * a NULL context */ ralloc_free(s); diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index 3002e551f6b..bcf0d199bd4 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -486,10 +486,15 @@ panfrost_delete_shader_state( for (unsigned i = 0; i < cso->variant_count; ++i) { struct panfrost_shader_state *shader_state = &cso->variants[i]; panfrost_bo_unreference(shader_state->bo); + + if (shader_state->upload.rsrc) + pipe_resource_reference(&shader_state->upload.rsrc, NULL); + shader_state->bo = NULL; } free(cso->variants); + free(so); } diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h index d490f4aca56..b7314c59e5f 100644 --- a/src/gallium/drivers/panfrost/pan_context.h +++ b/src/gallium/drivers/panfrost/pan_context.h @@ -188,6 +188,15 @@ struct panfrost_rasterizer { struct panfrost_shader_state { /* Compiled, mapped descriptor, ready for the hardware */ bool compiled; + + /* Uploaded shader descriptor (TODO: maybe stuff the packed unuploaded + * bits in a union to save some memory?) */ + + struct { + struct pipe_resource *rsrc; + uint32_t offset; + } upload; + struct mali_shader_packed shader; struct mali_midgard_properties_packed properties; struct mali_preload_packed preload; -- cgit v1.2.3