[Mesa-dev] [PATCH] panfrost: Use standard ALIGN_POT/INFINITY macros

Alyssa Rosenzweig alyssa.rosenzweig at collabora.com
Fri Jul 5 15:26:50 UTC 2019


We had vendored duplicates from pre-Mesa days; clean that up.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
---
 src/gallium/drivers/panfrost/pan_afbc.c     |  6 +++---
 src/gallium/drivers/panfrost/pan_allocate.c |  4 ++--
 src/gallium/drivers/panfrost/pan_allocate.h |  6 ------
 src/gallium/drivers/panfrost/pan_context.c  | 12 ++++++------
 src/gallium/drivers/panfrost/pan_resource.c | 16 ++++++++--------
 5 files changed, 19 insertions(+), 25 deletions(-)

diff --git a/src/gallium/drivers/panfrost/pan_afbc.c b/src/gallium/drivers/panfrost/pan_afbc.c
index d812639d8ca..298c04be1c4 100644
--- a/src/gallium/drivers/panfrost/pan_afbc.c
+++ b/src/gallium/drivers/panfrost/pan_afbc.c
@@ -105,8 +105,8 @@ unsigned
 panfrost_afbc_header_size(unsigned width, unsigned height)
 {
         /* Align to tile */
-        unsigned aligned_width  = ALIGN(width,  AFBC_TILE_WIDTH);
-        unsigned aligned_height = ALIGN(height, AFBC_TILE_HEIGHT);
+        unsigned aligned_width  = ALIGN_POT(width,  AFBC_TILE_WIDTH);
+        unsigned aligned_height = ALIGN_POT(height, AFBC_TILE_HEIGHT);
 
         /* Compute size in tiles, rather than pixels */
         unsigned tile_count_x = aligned_width  / AFBC_TILE_WIDTH;
@@ -117,6 +117,6 @@ panfrost_afbc_header_size(unsigned width, unsigned height)
         unsigned header_bytes = tile_count * AFBC_HEADER_BYTES_PER_TILE;
 
         /* Align and go */
-        return ALIGN(header_bytes, AFBC_CACHE_ALIGN);
+        return ALIGN_POT(header_bytes, AFBC_CACHE_ALIGN);
 
 }
diff --git a/src/gallium/drivers/panfrost/pan_allocate.c b/src/gallium/drivers/panfrost/pan_allocate.c
index 37a6785e7df..dff8373cbd5 100644
--- a/src/gallium/drivers/panfrost/pan_allocate.c
+++ b/src/gallium/drivers/panfrost/pan_allocate.c
@@ -38,7 +38,7 @@
 struct panfrost_transfer
 panfrost_allocate_chunk(struct panfrost_context *ctx, size_t size, unsigned heap_id)
 {
-        size = ALIGN(size, ALIGNMENT);
+        size = ALIGN_POT(size, ALIGNMENT);
 
         struct pipe_context *gallium = (struct pipe_context *) ctx;
         struct panfrost_screen *screen = pan_screen(gallium->screen);
@@ -63,7 +63,7 @@ struct panfrost_transfer
 panfrost_allocate_transient(struct panfrost_context *ctx, size_t sz)
 {
         /* Pad the size */
-        sz = ALIGN(sz, ALIGNMENT);
+        sz = ALIGN_POT(sz, ALIGNMENT);
 
         /* Check if there is room in the current entry */
         struct panfrost_transient_pool *pool = &ctx->transient_pools[ctx->cmdstream_i];
diff --git a/src/gallium/drivers/panfrost/pan_allocate.h b/src/gallium/drivers/panfrost/pan_allocate.h
index 20ba204dee8..45c86b7cb7b 100644
--- a/src/gallium/drivers/panfrost/pan_allocate.h
+++ b/src/gallium/drivers/panfrost/pan_allocate.h
@@ -127,10 +127,4 @@ panfrost_reserve(struct panfrost_memory *mem, size_t sz)
 struct panfrost_transfer
 panfrost_allocate_chunk(struct panfrost_context *ctx, size_t size, unsigned heap_id);
 
-#include <math.h>
-#define inff INFINITY
-
-#define R(...) #__VA_ARGS__
-#define ALIGN(x, y) (((x) + ((y) - 1)) & ~((y) - 1))
-
 #endif /* __PAN_ALLOCATE_H__ */
diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c
index b9fb187be44..90ea38645dc 100644
--- a/src/gallium/drivers/panfrost/pan_context.c
+++ b/src/gallium/drivers/panfrost/pan_context.c
@@ -536,7 +536,7 @@ panfrost_emit_varyings(
         slot->stride = stride;
         slot->size = stride * count;
 
-        ctx->varying_height += ALIGN(slot->size, 64);
+        ctx->varying_height += ALIGN_POT(slot->size, 64);
         assert(ctx->varying_height < ctx->varying_mem.bo->size);
 
         return varying_address;
@@ -1292,7 +1292,7 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data)
                         mali_ptr gpu = panfrost_map_constant_buffer_gpu(ctx, buf, ubo);
 
                         unsigned bytes_per_field = 16;
-                        unsigned aligned = ALIGN(sz, bytes_per_field);
+                        unsigned aligned = ALIGN_POT(sz, bytes_per_field);
                         unsigned fields = aligned / bytes_per_field;
 
                         ubos[ubo].size = MALI_POSITIVE(fields);
@@ -1318,10 +1318,10 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data)
                  * should work, but in practice causes issues when we're not
                  * explicitly trying to scissor */
 
-                .clip_minx = -inff,
-                .clip_miny = -inff,
-                .clip_maxx = inff,
-                .clip_maxy = inff,
+                .clip_minx = -INFINITY,
+                .clip_miny = -INFINITY,
+                .clip_maxx = INFINITY,
+                .clip_maxy = INFINITY,
 
                 .clip_minz = 0.0,
                 .clip_maxz = 1.0,
diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c
index b651fcffb11..4acbae25d4a 100644
--- a/src/gallium/drivers/panfrost/pan_resource.c
+++ b/src/gallium/drivers/panfrost/pan_resource.c
@@ -229,8 +229,8 @@ panfrost_compute_checksum_sizes(
                 unsigned width,
                 unsigned height)
 {
-        unsigned aligned_width = ALIGN(width, CHECKSUM_TILE_WIDTH);
-        unsigned aligned_height = ALIGN(height, CHECKSUM_TILE_HEIGHT);
+        unsigned aligned_width = ALIGN_POT(width, CHECKSUM_TILE_WIDTH);
+        unsigned aligned_height = ALIGN_POT(height, CHECKSUM_TILE_HEIGHT);
 
         unsigned tile_count_x = aligned_width / CHECKSUM_TILE_WIDTH;
         unsigned tile_count_y = aligned_height / CHECKSUM_TILE_HEIGHT;
@@ -282,8 +282,8 @@ panfrost_setup_slices(struct panfrost_resource *pres, size_t *bo_size)
                 unsigned effective_depth = depth;
 
                 if (should_align) {
-                        effective_width = ALIGN(effective_width, 16);
-                        effective_height = ALIGN(effective_height, 16);
+                        effective_width = ALIGN_POT(effective_width, 16);
+                        effective_height = ALIGN_POT(effective_height, 16);
 
                         /* We don't need to align depth */
                 }
@@ -295,7 +295,7 @@ panfrost_setup_slices(struct panfrost_resource *pres, size_t *bo_size)
 
                 /* ..but cache-line align it for performance */
                 if (can_align_stride && pres->layout == PAN_LINEAR)
-                        stride = ALIGN(stride, 64);
+                        stride = ALIGN_POT(stride, 64);
 
                 slice->stride = stride;
 
@@ -337,14 +337,14 @@ panfrost_setup_slices(struct panfrost_resource *pres, size_t *bo_size)
         if (res->target != PIPE_TEXTURE_3D) {
                 /* Arrays and cubemaps have the entire miptree duplicated */
 
-                pres->cubemap_stride = ALIGN(offset, 64);
-                *bo_size = ALIGN(pres->cubemap_stride * res->array_size, 4096);
+                pres->cubemap_stride = ALIGN_POT(offset, 64);
+                *bo_size = ALIGN_POT(pres->cubemap_stride * res->array_size, 4096);
         } else {
                 /* 3D strides across the 2D layers */
                 assert(res->array_size == 1);
 
                 pres->cubemap_stride = size_2d;
-                *bo_size = ALIGN(offset, 4096);
+                *bo_size = ALIGN_POT(offset, 4096);
         }
 }
 
-- 
2.20.1



More information about the mesa-dev mailing list