panfrost: Pipe framebuffer format around
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 2 Jul 2019 13:34:52 +0000 (06:34 -0700)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 10 Jul 2019 13:12:05 +0000 (06:12 -0700)
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/panfrost/midgard/nir_lower_blend.h
src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c
src/gallium/drivers/panfrost/pan_blend_shaders.c
src/gallium/drivers/panfrost/pan_blend_shaders.h
src/gallium/drivers/panfrost/pan_context.c

index 2805ca25d974ce9d19bff1584959d8a8d0866284..7a2df6e5e297b146ae721750dfe19e24b27a57c7 100644 (file)
@@ -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
index f5182ca73945735fee5263eaff388de2338b5832..85bb6488e69359153e13638574475c944c12afa1 100644 (file)
@@ -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);
 
index 640ddc868476f396097717105994e8b7b5ed8108..91c8fb89688d423624d73038770bc3d878b0a156 100644 (file)
@@ -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 */
 
index 1a914772673942ee4a61e2fbccc5a24f07d9b08a..23acd39581aecd307c91391a10e42e6606cca647 100644 (file)
 #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
index 82cd2ea6a48666835a7a1968f119104756c2d49a..be5d0a14cf5a74aaa88b8d0d8b72924178fec2b4 100644 (file)
@@ -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;
 }