freedreno: cleanup slice alignment/setup
authorRob Clark <robclark@freedesktop.org>
Thu, 4 Dec 2014 21:56:33 +0000 (16:56 -0500)
committerRob Clark <robclark@freedesktop.org>
Tue, 9 Dec 2014 23:01:21 +0000 (18:01 -0500)
Collapse things back into a setup_slices() which takes the desired
alignment as a param.  This gets things ready for a4xx which has some
slightly different requirements.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
src/gallium/drivers/freedreno/freedreno_resource.c

index 6b31d263290f3443c4594a466dcd5a6dccc797ce..461e378c89e4b16077321ad42b38a4d8b26d9bdd 100644 (file)
@@ -188,7 +188,7 @@ static const struct u_resource_vtbl fd_resource_vtbl = {
 };
 
 static uint32_t
-setup_slices(struct fd_resource *rsc)
+setup_slices(struct fd_resource *rsc, uint32_t alignment)
 {
        struct pipe_resource *prsc = &rsc->base.b;
        uint32_t level, size = 0;
@@ -201,7 +201,7 @@ setup_slices(struct fd_resource *rsc)
 
                slice->pitch = align(width, 32);
                slice->offset = size;
-               slice->size0 = slice->pitch * height * rsc->cpp;
+               slice->size0 = align(slice->pitch * height * rsc->cpp, alignment);
 
                size += slice->size0 * depth * prsc->array_size;
 
@@ -213,33 +213,20 @@ setup_slices(struct fd_resource *rsc)
        return size;
 }
 
-/* 2d array and 3d textures seem to want their layers aligned to
- * page boundaries
- */
 static uint32_t
-setup_slices_array(struct fd_resource *rsc)
+slice_alignment(struct pipe_screen *pscreen, const struct pipe_resource *tmpl)
 {
-       struct pipe_resource *prsc = &rsc->base.b;
-       uint32_t level, size = 0;
-       uint32_t width = prsc->width0;
-       uint32_t height = prsc->height0;
-       uint32_t depth = prsc->depth0;
-
-       for (level = 0; level <= prsc->last_level; level++) {
-               struct fd_resource_slice *slice = fd_resource_slice(rsc, level);
-
-               slice->pitch = align(width, 32);
-               slice->offset = size;
-               slice->size0 = align(slice->pitch * height * rsc->cpp, 4096);
-
-               size += slice->size0 * depth * prsc->array_size;
-
-               width = u_minify(width, 1);
-               height = u_minify(height, 1);
-               depth = u_minify(depth, 1);
+       /* on a3xx, 2d array and 3d textures seem to want their
+        * layers aligned to page boundaries:
+        */
+       switch (tmpl->target) {
+       case PIPE_TEXTURE_3D:
+       case PIPE_TEXTURE_1D_ARRAY:
+       case PIPE_TEXTURE_2D_ARRAY:
+               return 4096;
+       default:
+               return 1;
        }
-
-       return size;
 }
 
 /**
@@ -273,16 +260,7 @@ fd_resource_create(struct pipe_screen *pscreen,
 
        assert(rsc->cpp);
 
-       switch (tmpl->target) {
-       case PIPE_TEXTURE_3D:
-       case PIPE_TEXTURE_1D_ARRAY:
-       case PIPE_TEXTURE_2D_ARRAY:
-               size = setup_slices_array(rsc);
-               break;
-       default:
-               size = setup_slices(rsc);
-               break;
-       }
+       size = setup_slices(rsc, slice_alignment(pscreen, tmpl));
 
        realloc_bo(rsc, size);
        if (!rsc->bo)