From a29fb64c168b1659d28de495407d594d3200c5fe Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 21 Aug 2020 12:34:24 -0400 Subject: [PATCH] panfrost: Pack vertex properties when compiling They only depend on shader properties so we can do all this work at CSO create time, reducing draw-time overhead. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Tomeu Vizoso Part-of: --- src/gallium/drivers/panfrost/pan_assemble.c | 52 ++++++++++++++++++-- src/gallium/drivers/panfrost/pan_cmdstream.c | 34 ++----------- src/gallium/drivers/panfrost/pan_context.h | 2 + 3 files changed, 53 insertions(+), 35 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_assemble.c b/src/gallium/drivers/panfrost/pan_assemble.c index 05bf5fa948d..f84bf5db9fc 100644 --- a/src/gallium/drivers/panfrost/pan_assemble.c +++ b/src/gallium/drivers/panfrost/pan_assemble.c @@ -38,6 +38,45 @@ #include "tgsi/tgsi_dump.h" +static void +pan_pack_midgard_props(struct panfrost_shader_state *state, + gl_shader_stage stage) +{ + pan_pack(&state->properties, MIDGARD_PROPERTIES, cfg) { + cfg.uniform_buffer_count = state->ubo_count; + cfg.uniform_count = state->uniform_count; + cfg.work_register_count = state->work_reg_count; + cfg.writes_globals = state->writes_global; + cfg.suppress_inf_nan = true; /* XXX */ + } +} + +static void +pan_pack_bifrost_props(struct panfrost_shader_state *state, + gl_shader_stage stage) +{ + switch (stage) { + case MESA_SHADER_VERTEX: + pan_pack(&state->properties, BIFROST_PROPERTIES, cfg) { + cfg.unknown = 0x800000; /* XXX */ + cfg.uniform_buffer_count = state->ubo_count; + } + + pan_pack(&state->preload, PRELOAD_VERTEX, cfg) { + cfg.uniform_count = state->uniform_count; + cfg.vertex_id = true; + cfg.instance_id = true; + } + + break; + case MESA_SHADER_FRAGMENT: + /* TODO */ + break; + default: + unreachable("TODO"); + } +} + static unsigned pan_format_from_nir_base(nir_alu_type base) { @@ -282,6 +321,11 @@ panfrost_shader_compile(struct panfrost_context *ctx, } } + /* Needed for linkage */ + state->attribute_count = attribute_count; + state->varying_count = varying_count; + state->ubo_count = s->info.num_ubos + 1; /* off-by-one for uniforms */ + /* Prepare the descriptors at compile-time */ pan_pack(&state->shader, SHADER, cfg) { cfg.shader = shader; @@ -291,10 +335,10 @@ panfrost_shader_compile(struct panfrost_context *ctx, cfg.sampler_count = cfg.texture_count; } - /* Needed for linkage */ - state->attribute_count = attribute_count; - state->varying_count = varying_count; - state->ubo_count = s->info.num_ubos + 1; /* off-by-one for uniforms */ + if (dev->quirks & IS_BIFROST) + pan_pack_bifrost_props(state, stage); + else + pan_pack_midgard_props(state, stage); /* In both clone and tgsi_to_nir paths, the shader is ralloc'd against * a NULL context */ diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 40df89b0643..2a3cb4dd901 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -316,38 +316,10 @@ panfrost_emit_compute_shader(struct panfrost_context *ctx, memset(meta, 0, sizeof(*meta)); memcpy(&meta->shader, &ss->shader, sizeof(ss->shader)); + memcpy(&meta->midgard_props, &ss->properties, sizeof(ss->properties)); - if (dev->quirks & IS_BIFROST) { - struct mali_bifrost_properties_packed prop; - struct mali_preload_vertex_packed preload; - - pan_pack(&prop, BIFROST_PROPERTIES, cfg) { - cfg.unknown = 0x800000; /* XXX */ - cfg.uniform_buffer_count = ss->ubo_count; - } - - /* TODO: True compute shaders */ - pan_pack(&preload, PRELOAD_VERTEX, cfg) { - cfg.uniform_count = ss->uniform_count; - cfg.vertex_id = true; - cfg.instance_id = true; - } - - memcpy(&meta->bifrost_props, &prop, sizeof(prop)); - memcpy(&meta->bifrost_preload, &preload, sizeof(preload)); - } else { - struct mali_midgard_properties_packed prop; - - pan_pack(&prop, MIDGARD_PROPERTIES, cfg) { - cfg.uniform_buffer_count = ss->ubo_count; - cfg.uniform_count = ss->uniform_count; - cfg.work_register_count = ss->work_reg_count; - cfg.writes_globals = ss->writes_global; - cfg.suppress_inf_nan = true; /* XXX */ - } - - memcpy(&meta->midgard_props, &prop, sizeof(prop)); - } + if (dev->quirks & IS_BIFROST) + memcpy(&meta->bifrost_preload, &ss->preload, sizeof(ss->preload)); } static unsigned diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h index be1745491f5..ef37cb57a32 100644 --- a/src/gallium/drivers/panfrost/pan_context.h +++ b/src/gallium/drivers/panfrost/pan_context.h @@ -184,6 +184,8 @@ struct panfrost_shader_state { /* Compiled, mapped descriptor, ready for the hardware */ bool compiled; struct mali_shader_packed shader; + struct mali_midgard_properties_packed properties; + struct mali_preload_packed preload; /* Non-descript information */ unsigned uniform_count; -- 2.30.2