From 8f4b15636b0c51519d3798dbf77291e5bad7ec3e Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 30 Dec 2019 12:13:45 -0500 Subject: [PATCH] panfrost: Remove MRT indirection in blend shaders Since we have a separate blend shader for each render target, let's simplify this structure and reduce the options memory footprint by 88% or something goofy like that. Should also enable separate blending per render target. Signed-off-by: Alyssa Rosenzweig --- .../drivers/panfrost/nir/nir_lower_blend.c | 8 +-- .../drivers/panfrost/nir/nir_lower_blend.h | 10 ++- .../drivers/panfrost/pan_blend_shaders.c | 64 +++++++++---------- src/panfrost/midgard/disassemble.c | 4 ++ 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/gallium/drivers/panfrost/nir/nir_lower_blend.c b/src/gallium/drivers/panfrost/nir/nir_lower_blend.c index 0ffe985250d..4f3a91945e5 100644 --- a/src/gallium/drivers/panfrost/nir/nir_lower_blend.c +++ b/src/gallium/drivers/panfrost/nir/nir_lower_blend.c @@ -175,7 +175,7 @@ nir_blend( for (unsigned c = 0; c < 4; ++c) { /* Decide properties based on channel */ nir_lower_blend_channel chan = - (c < 3) ? options.rt[0].rgb : options.rt[0].alpha; + (c < 3) ? options.rgb : options.alpha; nir_ssa_def *psrc = nir_channel(b, src, c); nir_ssa_def *pdst = nir_channel(b, dst, c); @@ -197,7 +197,7 @@ nir_blend( /* Then just recombine with an applied colormask */ nir_ssa_def *blended = nir_vec(b, channels, 4); - return nir_color_mask(b, options.rt[0].colormask, blended, dst); + return nir_color_mask(b, options.colormask, blended, dst); } static bool @@ -214,8 +214,8 @@ static bool nir_is_blend_replace(nir_lower_blend_options options) { return - nir_is_blend_channel_replace(options.rt[0].rgb) && - nir_is_blend_channel_replace(options.rt[0].alpha); + nir_is_blend_channel_replace(options.rgb) && + nir_is_blend_channel_replace(options.alpha); } void diff --git a/src/gallium/drivers/panfrost/nir/nir_lower_blend.h b/src/gallium/drivers/panfrost/nir/nir_lower_blend.h index 846aca27d74..d150e99c72f 100644 --- a/src/gallium/drivers/panfrost/nir/nir_lower_blend.h +++ b/src/gallium/drivers/panfrost/nir/nir_lower_blend.h @@ -43,13 +43,11 @@ typedef struct { } nir_lower_blend_channel; typedef struct { - struct { - nir_lower_blend_channel rgb; - nir_lower_blend_channel alpha; + nir_lower_blend_channel rgb; + nir_lower_blend_channel alpha; - /* 4-bit colormask. 0x0 for none, 0xF for RGBA, 0x1 for R */ - unsigned colormask; - } rt[8]; + /* 4-bit colormask. 0x0 for none, 0xF for RGBA, 0x1 for R */ + unsigned colormask; } nir_lower_blend_options; void nir_lower_blend(nir_shader *shader, nir_lower_blend_options options); diff --git a/src/gallium/drivers/panfrost/pan_blend_shaders.c b/src/gallium/drivers/panfrost/pan_blend_shaders.c index d043d9b84e8..cca2eb567b5 100644 --- a/src/gallium/drivers/panfrost/pan_blend_shaders.c +++ b/src/gallium/drivers/panfrost/pan_blend_shaders.c @@ -85,43 +85,41 @@ */ static nir_lower_blend_options -nir_make_options(const struct pipe_blend_state *blend, unsigned nr_cbufs) +nir_make_options(const struct pipe_blend_state *blend, unsigned i) { nir_lower_blend_options options; - for (unsigned i = 0; i < nr_cbufs; ++i) { - /* If blend is disabled, we just use replace mode */ - - nir_lower_blend_channel rgb = { - .func = BLEND_FUNC_ADD, - .src_factor = BLEND_FACTOR_ZERO, - .invert_src_factor = true, - .dst_factor = BLEND_FACTOR_ZERO, - .invert_dst_factor = false - }; - - nir_lower_blend_channel alpha = rgb; - - if (blend->rt[i].blend_enable) { - rgb.func = util_blend_func_to_shader(blend->rt[i].rgb_func); - rgb.src_factor = util_blend_factor_to_shader(blend->rt[i].rgb_src_factor); - rgb.dst_factor = util_blend_factor_to_shader(blend->rt[i].rgb_dst_factor); - rgb.invert_src_factor = util_blend_factor_is_inverted(blend->rt[i].rgb_src_factor); - rgb.invert_dst_factor = util_blend_factor_is_inverted(blend->rt[i].rgb_dst_factor); - - alpha.func = util_blend_func_to_shader(blend->rt[i].alpha_func); - alpha.src_factor = util_blend_factor_to_shader(blend->rt[i].alpha_src_factor); - alpha.dst_factor = util_blend_factor_to_shader(blend->rt[i].alpha_dst_factor); - alpha.invert_src_factor = util_blend_factor_is_inverted(blend->rt[i].alpha_src_factor); - alpha.invert_dst_factor = util_blend_factor_is_inverted(blend->rt[i].alpha_dst_factor); - } - - options.rt[i].rgb = rgb; - options.rt[i].alpha = alpha; - - options.rt[i].colormask = blend->rt[i].colormask; + /* If blend is disabled, we just use replace mode */ + + nir_lower_blend_channel rgb = { + .func = BLEND_FUNC_ADD, + .src_factor = BLEND_FACTOR_ZERO, + .invert_src_factor = true, + .dst_factor = BLEND_FACTOR_ZERO, + .invert_dst_factor = false + }; + + nir_lower_blend_channel alpha = rgb; + + if (blend->rt[i].blend_enable) { + rgb.func = util_blend_func_to_shader(blend->rt[i].rgb_func); + rgb.src_factor = util_blend_factor_to_shader(blend->rt[i].rgb_src_factor); + rgb.dst_factor = util_blend_factor_to_shader(blend->rt[i].rgb_dst_factor); + rgb.invert_src_factor = util_blend_factor_is_inverted(blend->rt[i].rgb_src_factor); + rgb.invert_dst_factor = util_blend_factor_is_inverted(blend->rt[i].rgb_dst_factor); + + alpha.func = util_blend_func_to_shader(blend->rt[i].alpha_func); + alpha.src_factor = util_blend_factor_to_shader(blend->rt[i].alpha_src_factor); + alpha.dst_factor = util_blend_factor_to_shader(blend->rt[i].alpha_dst_factor); + alpha.invert_src_factor = util_blend_factor_is_inverted(blend->rt[i].alpha_src_factor); + alpha.invert_dst_factor = util_blend_factor_is_inverted(blend->rt[i].alpha_dst_factor); } + options.rgb = rgb; + options.alpha = alpha; + + options.colormask = blend->rt[i].colormask; + return options; } @@ -166,7 +164,7 @@ panfrost_compile_blend_shader( nir_store_var(b, c_out, s_src, 0xFF); nir_lower_blend_options options = - nir_make_options(cso, 1); + nir_make_options(cso, rt); NIR_PASS_V(shader, nir_lower_blend, options); NIR_PASS_V(shader, nir_lower_framebuffer, format, screen->gpu_id); diff --git a/src/panfrost/midgard/disassemble.c b/src/panfrost/midgard/disassemble.c index d4354388959..1b7d4689ef7 100644 --- a/src/panfrost/midgard/disassemble.c +++ b/src/panfrost/midgard/disassemble.c @@ -1454,6 +1454,7 @@ disassemble_midgard(uint8_t *code, size_t size, unsigned gpu_id, gl_shader_stage uint32_t *words = (uint32_t *) code; unsigned num_words = size / 4; int tabs = 0; + num_words = MIN2(num_words, 100); bool prefetch_flag = false; @@ -1470,6 +1471,7 @@ disassemble_midgard(uint8_t *code, size_t size, unsigned gpu_id, gl_shader_stage while (i < num_words) { unsigned tag = words[i] & 0xF; unsigned next_tag = (words[i] >> 4) & 0xF; + printf("\t%X -> %X\n", tag, next_tag); unsigned num_quad_words = midgard_word_size[tag]; if (midg_tags[i] && midg_tags[i] != tag) { @@ -1544,12 +1546,14 @@ disassemble_midgard(uint8_t *code, size_t size, unsigned gpu_id, gl_shader_stage /* Break based on instruction prefetch flag */ +#if 0 if (i < num_words && next == 1) { prefetch_flag = true; if (midgard_word_types[words[i] & 0xF] != midgard_word_type_alu) break; } +#endif i += 4 * num_quad_words; } -- 2.30.2