panfrost: Move format translation to root
[mesa.git] / src / panfrost / encoder / pan_texture.h
1 /*
2 * Copyright (C) 2008 VMware, Inc.
3 * Copyright (C) 2014 Broadcom
4 * Copyright (C) 2018-2019 Alyssa Rosenzweig
5 * Copyright (C) 2019-2020 Collabora, Ltd.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 *
26 */
27
28 #ifndef __PAN_TEXTURE_H
29 #define __PAN_TEXTURE_H
30
31 #include <stdbool.h>
32 #include "util/format/u_format.h"
33
34 struct panfrost_slice {
35 unsigned offset;
36 unsigned stride;
37 unsigned size0;
38
39 /* If there is a header preceding each slice, how big is
40 * that header? Used for AFBC */
41 unsigned header_size;
42
43 /* If checksumming is enabled following the slice, what
44 * is its offset/stride? */
45 unsigned checksum_offset;
46 unsigned checksum_stride;
47
48 /* Has anything been written to this slice? */
49 bool initialized;
50 };
51
52 unsigned
53 panfrost_compute_checksum_size(
54 struct panfrost_slice *slice,
55 unsigned width,
56 unsigned height);
57
58 /* AFBC */
59
60 bool
61 panfrost_format_supports_afbc(enum pipe_format format);
62
63 unsigned
64 panfrost_afbc_header_size(unsigned width, unsigned height);
65
66 /* Formats */
67
68 enum mali_format
69 panfrost_find_format(const struct util_format_description *desc);
70
71 bool
72 panfrost_is_z24s8_variant(enum pipe_format fmt);
73
74 unsigned
75 panfrost_translate_swizzle_4(const unsigned char swizzle[4]);
76
77 void
78 panfrost_invert_swizzle(const unsigned char *in, unsigned char *out);
79
80 static inline unsigned
81 panfrost_get_default_swizzle(unsigned components)
82 {
83 switch (components) {
84 case 1:
85 return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_ZERO << 3) |
86 (MALI_CHANNEL_ZERO << 6) | (MALI_CHANNEL_ONE << 9);
87 case 2:
88 return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) |
89 (MALI_CHANNEL_ZERO << 6) | (MALI_CHANNEL_ONE << 9);
90 case 3:
91 return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) |
92 (MALI_CHANNEL_BLUE << 6) | (MALI_CHANNEL_ONE << 9);
93 case 4:
94 return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) |
95 (MALI_CHANNEL_BLUE << 6) | (MALI_CHANNEL_ALPHA << 9);
96 default:
97 unreachable("Invalid number of components");
98 }
99 }
100
101 #endif