xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/freedreno/a4xx/fd4_resource.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2012 Rob Clark <[email protected]>
3  * SPDX-License-Identifier: MIT
4  *
5  * Authors:
6  *    Rob Clark <[email protected]>
7  *    Jonathan Marek <[email protected]>
8  */
9 
10 #include "fd4_resource.h"
11 
12 uint32_t
fd4_setup_slices(struct fd_resource * rsc)13 fd4_setup_slices(struct fd_resource *rsc)
14 {
15    struct pipe_resource *prsc = &rsc->b.b;
16    enum pipe_format format = prsc->format;
17    uint32_t level, size = 0;
18    uint32_t width = prsc->width0;
19    uint32_t height = prsc->height0;
20    uint32_t depth = prsc->depth0;
21    /* in layer_first layout, the level (slice) contains just one
22     * layer (since in fact the layer contains the slices)
23     */
24    uint32_t layers_in_level, alignment;
25 
26    if (prsc->target == PIPE_TEXTURE_3D) {
27       rsc->layout.layer_first = false;
28       layers_in_level = prsc->array_size;
29       alignment = 4096;
30    } else {
31       rsc->layout.layer_first = true;
32       layers_in_level = 1;
33       alignment = 1;
34    }
35 
36    /* 32 pixel alignment */
37    fdl_set_pitchalign(&rsc->layout, fdl_cpp_shift(&rsc->layout) + 5);
38 
39    for (level = 0; level <= prsc->last_level; level++) {
40       struct fdl_slice *slice = fd_resource_slice(rsc, level);
41       uint32_t pitch = fdl_pitch(&rsc->layout, level);
42       uint32_t nblocksy = util_format_get_nblocksy(format, height);
43 
44       slice->offset = size;
45 
46       /* 3d textures can have different layer sizes for high levels, but the
47        * hw auto-sizer is buggy (or at least different than what this code
48        * does), so as soon as the layer size range gets into range, we stop
49        * reducing it.
50        */
51       if (prsc->target == PIPE_TEXTURE_3D &&
52           (level > 1 && fd_resource_slice(rsc, level - 1)->size0 <= 0xf000))
53          slice->size0 = fd_resource_slice(rsc, level - 1)->size0;
54       else
55          slice->size0 = align(nblocksy * pitch, alignment);
56 
57       size += slice->size0 * depth * layers_in_level;
58 
59       width = u_minify(width, 1);
60       height = u_minify(height, 1);
61       depth = u_minify(depth, 1);
62    }
63 
64    return size;
65 }
66