broadcom/vc5: Set up per-MRT clear colors.
authorEric Anholt <eric@anholt.net>
Thu, 5 Oct 2017 22:40:18 +0000 (15:40 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 10 Oct 2017 18:42:06 +0000 (11:42 -0700)
Fixes fbo-mrt-alphatest.

src/gallium/drivers/vc5/vc5_context.h
src/gallium/drivers/vc5/vc5_draw.c
src/gallium/drivers/vc5/vc5_rcl.c

index 96b21b8fa09815c0f93d4d13ead62d0eb4fb32c4..d4f9e1eac6b70cf11fd8bbcf7ad569552964b8aa 100644 (file)
@@ -247,7 +247,7 @@ struct vc5_job {
          * (either clears or draws).
          */
         uint32_t resolve;
-        uint32_t clear_color[2];
+        uint32_t clear_color[4][4];
         float clear_z;
         uint8_t clear_s;
 
index c4e9973f949a8ee28675bb4edf1a6abb7eae758d..fe5a2c2129386056733f054ba31e049a323fbcc2 100644 (file)
@@ -516,17 +516,6 @@ vc5_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
                 vc5_flush(pctx);
 }
 
-static uint32_t
-pack_rgba(enum pipe_format format, const float *rgba)
-{
-        union util_color uc;
-        util_pack_color(rgba, format, &uc);
-        if (util_format_get_blocksize(format) == 2)
-                return uc.us;
-        else
-                return uc.ui[0];
-}
-
 static void
 vc5_clear(struct pipe_context *pctx, unsigned buffers,
           const union pipe_color_union *color, double depth, unsigned stencil)
@@ -543,32 +532,22 @@ vc5_clear(struct pipe_context *pctx, unsigned buffers,
                 job = vc5_get_job_for_fbo(vc5);
         }
 
-        if (buffers & PIPE_CLEAR_COLOR0) {
+        for (int i = 0; i < VC5_MAX_DRAW_BUFFERS; i++) {
+                uint32_t bit = PIPE_CLEAR_COLOR0 << i;
+                if (!(buffers & bit))
+                        continue;
+
+                struct pipe_surface *cbuf = vc5->framebuffer.cbufs[i];
                 struct vc5_resource *rsc =
-                        vc5_resource(vc5->framebuffer.cbufs[0]->texture);
-                uint32_t clear_color;
-
-#if 0
-                if (vc5_rt_format_is_565(vc5->framebuffer.cbufs[0]->format)) {
-                        /* In 565 mode, the hardware will be packing our color
-                         * for us.
-                         */
-                        clear_color = pack_rgba(PIPE_FORMAT_R8G8B8A8_UNORM,
-                                                color->f);
-                } else {
-                        /* Otherwise, we need to do this packing because we
-                         * support multiple swizzlings of RGBA8888.
-                         */
-                        clear_color =
-                                pack_rgba(vc5->framebuffer.cbufs[0]->format,
-                                          color->f);
-                }
-#endif
-                clear_color = pack_rgba(vc5->framebuffer.cbufs[0]->format,
-                                        color->f);
+                        vc5_resource(cbuf->texture);
+
+                union util_color uc;
+                util_pack_color(color->f, cbuf->format, &uc);
+
+                memcpy(job->clear_color[i], uc.ui,
+                       util_format_get_blocksize(cbuf->format));
 
-                job->clear_color[0] = job->clear_color[1] = clear_color;
-                rsc->initialized_buffers |= (buffers & PIPE_CLEAR_COLOR0);
+                rsc->initialized_buffers |= bit;
         }
 
         unsigned zsclear = buffers & PIPE_CLEAR_DEPTHSTENCIL;
index ebc77dcce06051b346f1c0a19fc34f126b291d52..83b383acd1a82c990341838253f4a123019bc277 100644 (file)
@@ -147,6 +147,13 @@ vc5_emit_rcl(struct vc5_job *job)
                         if (job->resolve & PIPE_CLEAR_COLOR0 << i)
                                 rsc->writes++;
                 }
+
+                cl_emit(&job->rcl, TILE_RENDERING_MODE_CONFIGURATION_CLEAR_COLORS_PART1,
+                        clear) {
+                        clear.clear_color_low_32_bits = job->clear_color[i][0];
+                        clear.clear_color_next_24_bits = job->clear_color[i][1] & 0xffffff;
+                        clear.render_target_number = i;
+                };
         }
 
         /* TODO: Don't bother emitting if we don't load/clear Z/S. */
@@ -174,11 +181,6 @@ vc5_emit_rcl(struct vc5_job *job)
                         rsc->writes++;
         }
 
-        cl_emit(&job->rcl, TILE_RENDERING_MODE_CONFIGURATION_CLEAR_COLORS_PART1,
-                clear) {
-                clear.clear_color_low_32_bits = job->clear_color[0];
-        };
-
         /* Ends rendering mode config. */
         cl_emit(&job->rcl, TILE_RENDERING_MODE_CONFIGURATION_Z_STENCIL_CLEAR_VALUES,
                 clear) {