[Mesa-dev] [PATCH 10/42] panfrost/midgard: Route blend load intrinsic

Alyssa Rosenzweig alyssa.rosenzweig at collabora.com
Mon Jul 8 14:08:23 UTC 2019


Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
---
 .../panfrost/midgard/midgard_compile.c        | 17 +++-------
 .../panfrost/midgard/nir_lower_framebuffer.c  | 33 +++++++++++++++++--
 2 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/src/gallium/drivers/panfrost/midgard/midgard_compile.c b/src/gallium/drivers/panfrost/midgard/midgard_compile.c
index 0f51104a19d..292c6dc363d 100644
--- a/src/gallium/drivers/panfrost/midgard/midgard_compile.c
+++ b/src/gallium/drivers/panfrost/midgard/midgard_compile.c
@@ -1380,18 +1380,11 @@ emit_intrinsic(compiler_context *ctx, nir_intrinsic_instr *instr)
                 break;
        }
 
-        case nir_intrinsic_load_output:
-                assert(nir_src_is_const(instr->src[0]));
+        /* Reads off the tilebuffer during blending, tasty */
+        case nir_intrinsic_load_raw_output_pan:
                 reg = nir_dest_index(ctx, &instr->dest);
-
-                if (ctx->is_blend) {
-                        /* TODO: MRT */
-                        emit_fb_read_blend_scalar(ctx, reg);
-                } else {
-                        DBG("Unknown output load\n");
-                        assert(0);
-                }
-
+                assert(ctx->is_blend);
+                emit_fb_read_blend_scalar(ctx, reg);
                 break;
 
         case nir_intrinsic_load_blend_const_color_rgba: {
@@ -1460,7 +1453,7 @@ emit_intrinsic(compiler_context *ctx, nir_intrinsic_instr *instr)
                 break;
 
         /* Special case of store_output for lowered blend shaders */
-        case nir_intrinsic_store_blended_output:
+        case nir_intrinsic_store_raw_output_pan:
                 assert (ctx->stage == MESA_SHADER_FRAGMENT);
                 reg = nir_src_index(ctx, &instr->src[0]);
 
diff --git a/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c b/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c
index 580df9d7442..08ef290a20b 100644
--- a/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c
+++ b/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c
@@ -54,6 +54,12 @@ nir_float_to_native(nir_builder *b, nir_ssa_def *c_float)
    return converted;
 }
 
+static nir_ssa_def *
+nir_native_to_float(nir_builder *b, nir_ssa_def *c_native)
+{
+   return c_native;
+}
+
 void
 nir_lower_framebuffer(nir_shader *shader)
 {
@@ -95,7 +101,7 @@ nir_lower_framebuffer(nir_shader *shader)
 
                /* Rewrite to use a native store by creating a new intrinsic */
                nir_intrinsic_instr *new =
-                  nir_intrinsic_instr_create(shader, nir_intrinsic_store_blended_output);
+                  nir_intrinsic_instr_create(shader, nir_intrinsic_store_raw_output_pan);
                new->src[0] = nir_src_for_ssa(converted);
 
                /* TODO: What about non-RGBA? Is that different? */
@@ -106,7 +112,30 @@ nir_lower_framebuffer(nir_shader *shader)
                /* (And finally removing the old) */
                nir_instr_remove(instr);
             } else {
-               /* TODO loads */
+               /* For loads, add conversion after */
+               b.cursor = nir_after_instr(instr);
+
+               /* Rewrite to use a native load by creating a new intrinsic */
+
+               nir_intrinsic_instr *new =
+                  nir_intrinsic_instr_create(shader, nir_intrinsic_load_raw_output_pan);
+
+               new->num_components = 4;
+
+               unsigned bitsize = 32;
+               nir_ssa_dest_init(&new->instr, &new->dest, 4, bitsize, NULL);
+               nir_builder_instr_insert(&b, &new->instr);
+
+               /* Convert the raw value */
+               nir_ssa_def *raw = &new->dest.ssa;
+               nir_ssa_def *converted = nir_native_to_float(&b, raw);
+
+               /* Rewrite to use the converted value */
+               nir_src rewritten = nir_src_for_ssa(converted);
+               nir_ssa_def_rewrite_uses_after(&intr->dest.ssa, rewritten, instr);
+
+               /* Finally, remove the old load */
+               nir_instr_remove(instr);
             }
          }
       }
-- 
2.20.1



More information about the mesa-dev mailing list