[Mesa-dev] [PATCH 27/42] panfrost: Pipe framebuffer format around

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


Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
---
 src/gallium/drivers/panfrost/midgard/nir_lower_blend.h    | 3 ++-
 .../drivers/panfrost/midgard/nir_lower_framebuffer.c      | 3 +--
 src/gallium/drivers/panfrost/pan_blend_shaders.c          | 8 ++++++--
 src/gallium/drivers/panfrost/pan_blend_shaders.h          | 6 +++++-
 src/gallium/drivers/panfrost/pan_context.c                | 8 +++++++-
 5 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/panfrost/midgard/nir_lower_blend.h b/src/gallium/drivers/panfrost/midgard/nir_lower_blend.h
index 2805ca25d97..7a2df6e5e29 100644
--- a/src/gallium/drivers/panfrost/midgard/nir_lower_blend.h
+++ b/src/gallium/drivers/panfrost/midgard/nir_lower_blend.h
@@ -26,6 +26,7 @@
 #define NIR_BLEND_H
 
 #include "compiler/nir/nir.h"
+#include "pipe/p_format.h"
 
 /* These structs encapsulates the blend state such that it can be lowered
  * cleanly
@@ -54,6 +55,6 @@ typedef struct {
 void nir_lower_blend(nir_shader *shader, nir_lower_blend_options options);
 
 void
-nir_lower_framebuffer(nir_shader *shader);
+nir_lower_framebuffer(nir_shader *shader, enum pipe_format format);
 
 #endif
diff --git a/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c b/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c
index f5182ca7394..85bb6488e69 100644
--- a/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c
+++ b/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c
@@ -99,12 +99,11 @@ nir_native_to_float(nir_builder *b,
 }
 
 void
-nir_lower_framebuffer(nir_shader *shader)
+nir_lower_framebuffer(nir_shader *shader, enum pipe_format format)
 {
    /* Blend shaders are represented as special fragment shaders */
    assert(shader->info.stage == MESA_SHADER_FRAGMENT);
 
-   enum pipe_format format = PIPE_FORMAT_R8G8B8A8_UNORM;
    const struct util_format_description *format_desc =
       util_format_description(format);
 
diff --git a/src/gallium/drivers/panfrost/pan_blend_shaders.c b/src/gallium/drivers/panfrost/pan_blend_shaders.c
index 640ddc86847..91c8fb89688 100644
--- a/src/gallium/drivers/panfrost/pan_blend_shaders.c
+++ b/src/gallium/drivers/panfrost/pan_blend_shaders.c
@@ -115,7 +115,11 @@ nir_make_options(const struct pipe_blend_state *blend, unsigned nr_cbufs)
 }
 
 void
-panfrost_make_blend_shader(struct panfrost_context *ctx, struct panfrost_blend_state *cso, const struct pipe_blend_color *blend_color)
+panfrost_make_blend_shader(
+                struct panfrost_context *ctx,
+                struct panfrost_blend_state *cso,
+                const struct pipe_blend_color *blend_color,
+                enum pipe_format format)
 {
         /* Build the shader */
 
@@ -149,7 +153,7 @@ panfrost_make_blend_shader(struct panfrost_context *ctx, struct panfrost_blend_s
                 nir_make_options(&cso->base, 1);
         NIR_PASS_V(shader, nir_lower_blend, options);
 
-        NIR_PASS_V(shader, nir_lower_framebuffer);
+        NIR_PASS_V(shader, nir_lower_framebuffer, format);
 
         /* Compile the built shader */
 
diff --git a/src/gallium/drivers/panfrost/pan_blend_shaders.h b/src/gallium/drivers/panfrost/pan_blend_shaders.h
index 1a914772673..23acd39581a 100644
--- a/src/gallium/drivers/panfrost/pan_blend_shaders.h
+++ b/src/gallium/drivers/panfrost/pan_blend_shaders.h
@@ -31,6 +31,10 @@
 #include "pan_context.h"
 
 void
-panfrost_make_blend_shader(struct panfrost_context *ctx, struct panfrost_blend_state *cso, const struct pipe_blend_color *blend_color);
+panfrost_make_blend_shader(
+                struct panfrost_context *ctx,
+                struct panfrost_blend_state *cso,
+                const struct pipe_blend_color *blend_color,
+                enum pipe_format format);
 
 #endif
diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c
index 82cd2ea6a48..be5d0a14cf5 100644
--- a/src/gallium/drivers/panfrost/pan_context.c
+++ b/src/gallium/drivers/panfrost/pan_context.c
@@ -2381,9 +2381,15 @@ panfrost_create_blend_state(struct pipe_context *pipe,
         if (panfrost_make_fixed_blend_mode(&blend->rt[0], so, blend->rt[0].colormask, &ctx->blend_color))
                 return so;
 
+        /* TODO: Key against framebuffer. TODO: MRT explicitly */
+        if (!ctx->pipe_framebuffer.nr_cbufs)
+                return so;
+
+        enum pipe_format format = ctx->pipe_framebuffer.cbufs[0]->format;
+
         /* If we can't, compile a blend shader instead */
 
-        panfrost_make_blend_shader(ctx, so, &ctx->blend_color);
+        panfrost_make_blend_shader(ctx, so, &ctx->blend_color, format);
 
         return so;
 }
-- 
2.20.1



More information about the mesa-dev mailing list