xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/freedreno/a5xx/fd5_resource.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2018 Rob Clark <[email protected]>
3  * SPDX-License-Identifier: MIT
4  *
5  * Authors:
6  *    Rob Clark <[email protected]>
7  */
8 
9 #include "fd5_resource.h"
10 
11 static void
setup_lrz(struct fd_resource * rsc)12 setup_lrz(struct fd_resource *rsc)
13 {
14    struct fd_screen *screen = fd_screen(rsc->b.b.screen);
15    unsigned lrz_pitch = align(DIV_ROUND_UP(rsc->b.b.width0, 8), 64);
16    unsigned lrz_height = DIV_ROUND_UP(rsc->b.b.height0, 8);
17 
18    /* LRZ buffer is super-sampled: */
19    switch (rsc->b.b.nr_samples) {
20    case 4:
21       lrz_pitch *= 2;
22       FALLTHROUGH;
23    case 2:
24       lrz_height *= 2;
25    }
26 
27    unsigned size = lrz_pitch * lrz_height * 2;
28 
29    size += 0x1000; /* for GRAS_LRZ_FAST_CLEAR_BUFFER */
30 
31    rsc->lrz_height = lrz_height;
32    rsc->lrz_width = lrz_pitch;
33    rsc->lrz_pitch = lrz_pitch;
34    rsc->lrz = fd_bo_new(screen->dev, size, FD_BO_NOMAP, "lrz");
35 }
36 
37 uint32_t
fd5_setup_slices(struct fd_resource * rsc)38 fd5_setup_slices(struct fd_resource *rsc)
39 {
40    struct pipe_resource *prsc = &rsc->b.b;
41 
42    if (FD_DBG(LRZ) && has_depth(prsc->format) && !is_z32(prsc->format))
43       setup_lrz(rsc);
44 
45    fdl5_layout(&rsc->layout, prsc->format, fd_resource_nr_samples(prsc),
46                prsc->width0, prsc->height0, prsc->depth0, prsc->last_level + 1,
47                prsc->array_size, prsc->target == PIPE_TEXTURE_3D);
48 
49    return rsc->layout.size;
50 }
51