1/*
2 * Copyright (C) 2018 Rob Clark <robclark@freedesktop.org>
3 * Copyright © 2018 Google, Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 * Authors:
25 *    Rob Clark <robclark@freedesktop.org>
26 */
27
28#include <stdio.h>
29
30#include "freedreno_layout.h"
31
32void
33fdl_layout_buffer(struct fdl_layout *layout, uint32_t size)
34{
35   layout->width0 = size;
36   layout->height0 = 1;
37   layout->depth0 = 1;
38   layout->cpp = 1;
39   layout->cpp_shift = 0;
40   layout->size = size;
41   layout->format = PIPE_FORMAT_R8_UINT;
42   layout->nr_samples = 1;
43}
44
45const char *
46fdl_tile_mode_desc(const struct fdl_layout *layout, int level)
47{
48   if (fdl_ubwc_enabled(layout, level))
49      return "UBWC";
50   else if (fdl_tile_mode(layout, level) == 0) /* TILE6_LINEAR and friends */
51      return "linear";
52   else
53      return "tiled";
54}
55
56void
57fdl_dump_layout(struct fdl_layout *layout)
58{
59   for (uint32_t level = 0;
60        level < ARRAY_SIZE(layout->slices) && layout->slices[level].size0;
61        level++) {
62      struct fdl_slice *slice = &layout->slices[level];
63      struct fdl_slice *ubwc_slice = &layout->ubwc_slices[level];
64
65      fprintf(
66         stderr,
67         "%s: %ux%ux%u@%ux%u:\t%2u: stride=%4u, size=%6u,%6u, "
68         "aligned_height=%3u, offset=0x%x,0x%x, layersz %5u,%5u %s\n",
69         util_format_name(layout->format), u_minify(layout->width0, level),
70         u_minify(layout->height0, level), u_minify(layout->depth0, level),
71         layout->cpp, layout->nr_samples, level, fdl_pitch(layout, level),
72         slice->size0, ubwc_slice->size0,
73         slice->size0 / fdl_pitch(layout, level), slice->offset,
74         ubwc_slice->offset, layout->layer_size, layout->ubwc_layer_size,
75         fdl_tile_mode_desc(layout, level));
76   }
77}
78