panfrost: Remove MRT indirection in blend shaders
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 30 Dec 2019 17:13:45 +0000 (12:13 -0500)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 30 Dec 2019 22:11:08 +0000 (17:11 -0500)
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 <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/panfrost/nir/nir_lower_blend.c
src/gallium/drivers/panfrost/nir/nir_lower_blend.h
src/gallium/drivers/panfrost/pan_blend_shaders.c
src/panfrost/midgard/disassemble.c

index 0ffe985250d002c8e34fde7ac40567ee04e3343c..4f3a91945e5f9856b583bb561165206a153dd9ec 100644 (file)
@@ -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
index 846aca27d743f6a4a47971653ae85a240abaecff..d150e99c72f6d191c3df1e084a76f1644124430f 100644 (file)
@@ -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);
index d043d9b84e8acf156ca824e110edd3317d2dee3a..cca2eb567b50ecf499350d6ea9dc54b44e1b0e42 100644 (file)
  */
 
 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);
index d4354388959f58fa2156fb305a04aea7d382b389..1b7d4689ef7f5631d5991f4c9fdf1c5baf808d4c 100644 (file)
@@ -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;
         }