From 834bb5e54cfb20ecba3a55358dc19494e91381e5 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Tue, 26 Jan 2021 17:41:08 +0100 Subject: [PATCH] panfrost: Add a panfrost_compile_shader() helper This deduplicates the if (pan_is_bifrost()) return bifrost_compile_shader_nir(); else return midgard_compile_shader_nir(); pattern. Signed-off-by: Boris Brezillon Reviewed-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/panfrost/pan_assemble.c | 8 +-- .../drivers/panfrost/pan_blend_shaders.c | 8 ++- src/gallium/drivers/panfrost/pan_compute.c | 6 +-- src/gallium/drivers/panfrost/pan_screen.c | 8 +-- src/panfrost/Makefile.sources | 1 + src/panfrost/lib/pan_blit.c | 11 ++-- src/panfrost/lib/pan_shader.h | 54 +++++++++++++++++++ 7 files changed, 67 insertions(+), 29 deletions(-) create mode 100644 src/panfrost/lib/pan_shader.h diff --git a/src/gallium/drivers/panfrost/pan_assemble.c b/src/gallium/drivers/panfrost/pan_assemble.c index f036cecaf9d..b1f74ab8a36 100644 --- a/src/gallium/drivers/panfrost/pan_assemble.c +++ b/src/gallium/drivers/panfrost/pan_assemble.c @@ -28,13 +28,12 @@ #include #include "pan_bo.h" #include "pan_context.h" +#include "pan_shader.h" #include "pan_util.h" #include "panfrost-quirks.h" #include "compiler/nir/nir.h" #include "nir/tgsi_to_nir.h" -#include "midgard/midgard_compile.h" -#include "bifrost/bifrost_compile.h" #include "util/u_dynarray.h" #include "util/u_upload_mgr.h" @@ -274,10 +273,7 @@ panfrost_shader_compile(struct panfrost_context *ctx, panfrost_program *program; - if (pan_is_bifrost(dev)) - program = bifrost_compile_shader_nir(NULL, s, &inputs); - else - program = midgard_compile_shader_nir(NULL, s, &inputs); + program = panfrost_compile_shader(dev, NULL, s, &inputs); /* Prepare the compiled binary for upload */ mali_ptr shader = 0; diff --git a/src/gallium/drivers/panfrost/pan_blend_shaders.c b/src/gallium/drivers/panfrost/pan_blend_shaders.c index fe759f1d0b9..2cb563cd33e 100644 --- a/src/gallium/drivers/panfrost/pan_blend_shaders.c +++ b/src/gallium/drivers/panfrost/pan_blend_shaders.c @@ -25,10 +25,9 @@ #include #include "pan_blend_shaders.h" +#include "pan_shader.h" #include "pan_util.h" #include "panfrost-quirks.h" -#include "midgard/midgard_compile.h" -#include "bifrost/bifrost_compile.h" #include "compiler/nir/nir_builder.h" #include "nir/nir_lower_blend.h" #include "panfrost/util/pan_lower_framebuffer.h" @@ -301,11 +300,10 @@ panfrost_compile_blend_shader(struct panfrost_blend_shader *shader, if (pan_is_bifrost(dev)) { inputs.blend.bifrost_blend_desc = bifrost_get_blend_desc(dev, shader->key.format, shader->key.rt); - program = bifrost_compile_shader_nir(NULL, shader->nir, &inputs); - } else { - program = midgard_compile_shader_nir(NULL, shader->nir, &inputs); } + program = panfrost_compile_shader(dev, NULL, shader->nir, &inputs); + /* Allow us to patch later */ shader->first_tag = program->first_tag; shader->size = program->compiled.size; diff --git a/src/gallium/drivers/panfrost/pan_compute.c b/src/gallium/drivers/panfrost/pan_compute.c index 02b175916f6..1b170153c3e 100644 --- a/src/gallium/drivers/panfrost/pan_compute.c +++ b/src/gallium/drivers/panfrost/pan_compute.c @@ -30,10 +30,9 @@ #include "pan_cmdstream.h" #include "panfrost-quirks.h" #include "pan_bo.h" +#include "pan_shader.h" #include "util/u_memory.h" #include "nir_serialize.h" -#include "midgard/midgard_compile.h" -#include "bifrost/bifrost_compile.h" /* Compute CSOs are tracked like graphics shader CSOs, but are * considerably simpler. We do not implement multiple @@ -65,8 +64,7 @@ panfrost_create_compute_state( blob_reader_init(&reader, hdr->blob, hdr->num_bytes); const struct nir_shader_compiler_options *options = - pan_is_bifrost(dev) ? - &bifrost_nir_options : &midgard_nir_options; + panfrost_get_shader_options(dev); so->cbase.prog = nir_deserialize(NULL, options, &reader); so->cbase.ir_type = PIPE_SHADER_IR_NIR; diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c index d115d4703f7..15ad6d7dabf 100644 --- a/src/gallium/drivers/panfrost/pan_screen.c +++ b/src/gallium/drivers/panfrost/pan_screen.c @@ -44,6 +44,7 @@ #include "drm-uapi/panfrost_drm.h" #include "pan_bo.h" +#include "pan_shader.h" #include "pan_screen.h" #include "pan_resource.h" #include "pan_public.h" @@ -51,8 +52,6 @@ #include "decode.h" #include "pan_context.h" -#include "midgard/midgard_compile.h" -#include "bifrost/bifrost_compile.h" #include "panfrost-quirks.h" static const struct debug_named_value panfrost_debug_options[] = { @@ -764,10 +763,7 @@ panfrost_screen_get_compiler_options(struct pipe_screen *pscreen, enum pipe_shader_ir ir, enum pipe_shader_type shader) { - if (pan_is_bifrost(pan_device(pscreen))) - return &bifrost_nir_options; - else - return &midgard_nir_options; + return panfrost_get_shader_options(pan_device(pscreen)); } struct pipe_screen * diff --git a/src/panfrost/Makefile.sources b/src/panfrost/Makefile.sources index 0697123054c..bfe4b803144 100644 --- a/src/panfrost/Makefile.sources +++ b/src/panfrost/Makefile.sources @@ -38,6 +38,7 @@ lib_FILES := \ lib/pan_pool.h \ lib/pan_props.c \ lib/pan_sampler.c \ + lib/pan_shader.h \ lib/pan_scoreboard.c \ lib/pan_scoreboard.h \ lib/pan_tiler.c \ diff --git a/src/panfrost/lib/pan_blit.c b/src/panfrost/lib/pan_blit.c index 549d601a0a7..af6ff75706d 100644 --- a/src/panfrost/lib/pan_blit.c +++ b/src/panfrost/lib/pan_blit.c @@ -28,11 +28,10 @@ #include #include "pan_encoder.h" #include "pan_pool.h" +#include "pan_shader.h" #include "pan_scoreboard.h" #include "pan_texture.h" #include "panfrost-quirks.h" -#include "../midgard/midgard_compile.h" -#include "../bifrost/bifrost_compile.h" #include "compiler/nir/nir_builder.h" #include "util/u_math.h" @@ -107,12 +106,8 @@ panfrost_build_blit_shader(struct panfrost_device *dev, .gpu_id = dev->gpu_id, }; - panfrost_program *program; - - if (pan_is_bifrost(dev)) - program = bifrost_compile_shader_nir(NULL, shader, &inputs); - else - program = midgard_compile_shader_nir(NULL, shader, &inputs); + panfrost_program *program = + panfrost_compile_shader(dev, NULL, shader, &inputs); ralloc_free(shader); return program; diff --git a/src/panfrost/lib/pan_shader.h b/src/panfrost/lib/pan_shader.h new file mode 100644 index 00000000000..bf22f6e0a95 --- /dev/null +++ b/src/panfrost/lib/pan_shader.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2021 Collabora, Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#ifndef __PAN_SHADER_H__ +#define __PAN_SHADER_H__ + +#include "pan_device.h" +#include "pan_shader.h" + +#include "panfrost/midgard/midgard_compile.h" +#include "panfrost/bifrost/bifrost_compile.h" + +static inline const nir_shader_compiler_options * +panfrost_get_shader_options(const struct panfrost_device *dev) +{ + if (pan_is_bifrost(dev)) + return &bifrost_nir_options; + + return &midgard_nir_options; +} + +static inline panfrost_program * +panfrost_compile_shader(const struct panfrost_device *dev, + void *mem_ctx, nir_shader *nir, + const struct panfrost_compile_inputs *inputs) +{ + if (pan_is_bifrost(dev)) + return bifrost_compile_shader_nir(mem_ctx, nir, inputs); + + return midgard_compile_shader_nir(mem_ctx, nir, inputs); +} + +#endif