• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 Rob Clark <robclark@freedesktop.org>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  * Authors:
24  *    Rob Clark <robclark@freedesktop.org>
25  */
26 
27 #include "fd5_resource.h"
28 
29 static void
setup_lrz(struct fd_resource * rsc)30 setup_lrz(struct fd_resource *rsc)
31 {
32 	struct fd_screen *screen = fd_screen(rsc->base.screen);
33 	const uint32_t flags = DRM_FREEDRENO_GEM_CACHE_WCOMBINE |
34 			DRM_FREEDRENO_GEM_TYPE_KMEM; /* TODO */
35 	unsigned lrz_pitch  = align(DIV_ROUND_UP(rsc->base.width0, 8), 64);
36 	unsigned lrz_height = DIV_ROUND_UP(rsc->base.height0, 8);
37 
38 	/* LRZ buffer is super-sampled: */
39 	switch (rsc->base.nr_samples) {
40 	case 4:
41 		lrz_pitch *= 2;
42 		/* fallthrough */
43 	case 2:
44 		lrz_height *= 2;
45 	}
46 
47 	unsigned size = lrz_pitch * lrz_height * 2;
48 
49 	size += 0x1000; /* for GRAS_LRZ_FAST_CLEAR_BUFFER */
50 
51 	rsc->lrz_height = lrz_height;
52 	rsc->lrz_width = lrz_pitch;
53 	rsc->lrz_pitch = lrz_pitch;
54 	rsc->lrz = fd_bo_new(screen->dev, size, flags, "lrz");
55 }
56 
57 uint32_t
fd5_setup_slices(struct fd_resource * rsc)58 fd5_setup_slices(struct fd_resource *rsc)
59 {
60 	struct pipe_resource *prsc = &rsc->base;
61 
62 	if ((fd_mesa_debug & FD_DBG_LRZ) && has_depth(rsc->base.format))
63 		setup_lrz(rsc);
64 
65 	fdl5_layout(&rsc->layout, prsc->format, fd_resource_nr_samples(prsc),
66 			prsc->width0, prsc->height0, prsc->depth0,
67 			prsc->last_level + 1, prsc->array_size,
68 			prsc->target == PIPE_TEXTURE_3D);
69 
70 	return rsc->layout.size;
71 }
72