panfrost: Emit texture descriptor on bifrost
[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 #include "panfrost-job.h"
34
35 struct panfrost_slice {
36 unsigned offset;
37 unsigned stride;
38 unsigned size0;
39
40 /* If there is a header preceding each slice, how big is
41 * that header? Used for AFBC */
42 unsigned header_size;
43
44 /* If checksumming is enabled following the slice, what
45 * is its offset/stride? */
46 unsigned checksum_offset;
47 unsigned checksum_stride;
48
49 /* Has anything been written to this slice? */
50 bool initialized;
51 };
52
53 unsigned
54 panfrost_compute_checksum_size(
55 struct panfrost_slice *slice,
56 unsigned width,
57 unsigned height);
58
59 /* AFBC */
60
61 bool
62 panfrost_format_supports_afbc(enum pipe_format format);
63
64 unsigned
65 panfrost_afbc_header_size(unsigned width, unsigned height);
66
67 /* mali_texture_descriptor */
68
69 unsigned
70 panfrost_estimate_texture_size(
71 unsigned first_level, unsigned last_level,
72 unsigned first_layer, unsigned last_layer,
73 enum mali_texture_type type, enum mali_texture_layout layout);
74
75 void
76 panfrost_new_texture(
77 void *out,
78 uint16_t width, uint16_t height,
79 uint16_t depth, uint16_t array_size,
80 enum pipe_format format,
81 enum mali_texture_type type,
82 enum mali_texture_layout layout,
83 unsigned first_level, unsigned last_level,
84 unsigned first_layer, unsigned last_layer,
85 unsigned cube_stride,
86 unsigned swizzle,
87 mali_ptr base,
88 struct panfrost_slice *slices);
89
90 void
91 panfrost_new_texture_bifrost(
92 struct bifrost_texture_descriptor *descriptor,
93 uint16_t width, uint16_t height,
94 uint16_t depth, uint16_t array_size,
95 enum pipe_format format,
96 enum mali_texture_type type,
97 enum mali_texture_layout layout,
98 unsigned first_level, unsigned last_level,
99 unsigned first_layer, unsigned last_layer,
100 unsigned cube_stride,
101 unsigned swizzle,
102 mali_ptr base,
103 struct panfrost_slice *slices);
104
105
106 unsigned
107 panfrost_get_layer_stride(struct panfrost_slice *slices, bool is_3d, unsigned cube_stride, unsigned level);
108
109 unsigned
110 panfrost_texture_offset(struct panfrost_slice *slices, bool is_3d, unsigned cube_stride, unsigned level, unsigned face);
111
112 /* Formats */
113
114 enum mali_format
115 panfrost_find_format(const struct util_format_description *desc);
116
117 bool
118 panfrost_is_z24s8_variant(enum pipe_format fmt);
119
120 unsigned
121 panfrost_translate_swizzle_4(const unsigned char swizzle[4]);
122
123 void
124 panfrost_invert_swizzle(const unsigned char *in, unsigned char *out);
125
126 static inline unsigned
127 panfrost_get_default_swizzle(unsigned components)
128 {
129 switch (components) {
130 case 1:
131 return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_ZERO << 3) |
132 (MALI_CHANNEL_ZERO << 6) | (MALI_CHANNEL_ONE << 9);
133 case 2:
134 return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) |
135 (MALI_CHANNEL_ZERO << 6) | (MALI_CHANNEL_ONE << 9);
136 case 3:
137 return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) |
138 (MALI_CHANNEL_BLUE << 6) | (MALI_CHANNEL_ONE << 9);
139 case 4:
140 return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) |
141 (MALI_CHANNEL_BLUE << 6) | (MALI_CHANNEL_ALPHA << 9);
142 default:
143 unreachable("Invalid number of components");
144 }
145 }
146
147 #endif