etnaviv: add helper to work out RS alignment
authorLucas Stach <l.stach@pengutronix.de>
Tue, 4 Jul 2017 14:19:51 +0000 (16:19 +0200)
committerLucas Stach <l.stach@pengutronix.de>
Wed, 19 Jul 2017 14:26:49 +0000 (16:26 +0200)
The minimum RS alignment calculation is needed in various places.
Extract a helper to avoid open-coding the calcuation at every site.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
src/gallium/drivers/etnaviv/etnaviv_resource.c
src/gallium/drivers/etnaviv/etnaviv_translate.h

index 8d96baf2a04087838dda9f1e2231c7bf9a4821ca..1cd906d4afa5dd08232bc007d065f7a7ff79cc36 100644 (file)
@@ -180,11 +180,8 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned layout,
                         &paddingY, &halign);
    assert(paddingX && paddingY);
 
-   if (templat->target != PIPE_BUFFER) {
-      unsigned min_paddingY = 4 * screen->specs.pixel_pipes;
-      if (paddingY < min_paddingY)
-         paddingY = min_paddingY;
-   }
+   if (templat->target != PIPE_BUFFER)
+      etna_adjust_rs_align(screen->specs.pixel_pipes, NULL, &paddingY);
 
    struct etna_resource *rsc = CALLOC_STRUCT(etna_resource);
 
@@ -368,11 +365,10 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
 
    /* We will be using the RS to copy with this resource, so we must
     * ensure that it is appropriately aligned for the RS requirements. */
-   unsigned paddingX = ETNA_RS_WIDTH_MASK + 1;
-   unsigned paddingY = (ETNA_RS_HEIGHT_MASK + 1) * screen->specs.pixel_pipes;
+   level->padded_width = level->width;
+   level->padded_height = level->height;
+   etna_adjust_rs_align(&level->padded_width, &level->padded_height);
 
-   level->padded_width = align(level->width, paddingX);
-   level->padded_height = align(level->height, paddingY);
    level->layer_stride = level->stride * util_format_get_nblocksy(prsc->format,
                                                                   level->padded_height);
 
index cbbfdf23d93dfa8928eba27bd821d35170163f2a..0761251a3694792063c45e07bdbaccbec690d7a7 100644 (file)
@@ -37,6 +37,7 @@
 #include "hw/state_3d.xml.h"
 
 #include "util/u_format.h"
+#include "util/u_math.h"
 
 #include <stdio.h>
 
@@ -405,6 +406,18 @@ etna_layout_multiple(unsigned layout, unsigned pixel_pipes, bool rs_align,
    }
 }
 
+static inline void etna_adjust_rs_align(unsigned num_pixelpipes,
+                                        unsigned *paddingX, unsigned *paddingY)
+{
+   unsigned alignX = ETNA_RS_WIDTH_MASK + 1;
+   unsigned alignY = (ETNA_RS_HEIGHT_MASK + 1) * num_pixelpipes;
+
+   if (paddingX)
+      *paddingX = align(*paddingX, alignX);
+   if (paddingY)
+      *paddingY = align(*paddingY, alignY);
+}
+
 static inline uint32_t
 translate_clear_depth_stencil(enum pipe_format format, float depth,
                               unsigned stencil)