xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/freedreno/a2xx/fd2_resource.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2018 Jonathan Marek <[email protected]>
3  * SPDX-License-Identifier: MIT
4  *
5  * Authors:
6  *    Jonathan Marek <[email protected]>
7  */
8 
9 #include "fd2_resource.h"
10 
11 uint32_t
fd2_setup_slices(struct fd_resource * rsc)12 fd2_setup_slices(struct fd_resource *rsc)
13 {
14    struct pipe_resource *prsc = &rsc->b.b;
15    enum pipe_format format = prsc->format;
16    uint32_t height0 = util_format_get_nblocksy(format, prsc->height0);
17    uint32_t level, size = 0;
18 
19    /* 32 pixel alignment */
20    fdl_set_pitchalign(&rsc->layout, fdl_cpp_shift(&rsc->layout) + 5);
21 
22    for (level = 0; level <= prsc->last_level; level++) {
23       struct fdl_slice *slice = fd_resource_slice(rsc, level);
24       uint32_t pitch = fdl2_pitch(&rsc->layout, level);
25       uint32_t nblocksy = align(u_minify(height0, level), 32);
26 
27       /* mipmaps have power of two sizes in memory */
28       if (level)
29          nblocksy = util_next_power_of_two(nblocksy);
30 
31       slice->offset = size;
32       slice->size0 = align(pitch * nblocksy, 4096);
33 
34       size += slice->size0 * u_minify(prsc->depth0, level) * prsc->array_size;
35    }
36 
37    return size;
38 }
39 
40 unsigned
fd2_tile_mode(const struct pipe_resource * tmpl)41 fd2_tile_mode(const struct pipe_resource *tmpl)
42 {
43    /* disable tiling for cube maps, freedreno uses a 2D array for the staging
44     * texture, (a2xx supports 2D arrays but it is not implemented)
45     */
46    if (tmpl->target == PIPE_TEXTURE_CUBE)
47       return 0;
48    /* we can enable tiling for any resource we can render to */
49    return (tmpl->bind & PIPE_BIND_RENDER_TARGET) ? 1 : 0;
50 }
51