panfrost: Don't export exception_status
[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 "compiler/shader_enums.h"
34 #include "panfrost-job.h"
35 #include "pan_bo.h"
36
37 struct panfrost_slice {
38 unsigned offset;
39 unsigned stride;
40 unsigned size0;
41
42 /* If there is a header preceding each slice, how big is
43 * that header? Used for AFBC */
44 unsigned header_size;
45
46 /* If checksumming is enabled following the slice, what
47 * is its offset/stride? */
48 unsigned checksum_offset;
49 unsigned checksum_stride;
50 struct panfrost_bo *checksum_bo;
51
52 /* Has anything been written to this slice? */
53 bool initialized;
54 };
55
56 struct pan_image {
57 /* Format and size */
58 uint16_t width0, height0, depth0, array_size;
59 enum pipe_format format;
60 enum mali_texture_type type;
61 unsigned first_level, last_level;
62 unsigned first_layer, last_layer;
63 unsigned nr_samples;
64 struct panfrost_bo *bo;
65 struct panfrost_slice *slices;
66 unsigned cubemap_stride;
67 enum mali_texture_layout layout;
68 };
69
70 unsigned
71 panfrost_compute_checksum_size(
72 struct panfrost_slice *slice,
73 unsigned width,
74 unsigned height);
75
76 /* AFBC */
77
78 bool
79 panfrost_format_supports_afbc(enum pipe_format format);
80
81 unsigned
82 panfrost_afbc_header_size(unsigned width, unsigned height);
83
84 /* mali_texture_descriptor */
85
86 unsigned
87 panfrost_estimate_texture_payload_size(
88 unsigned first_level, unsigned last_level,
89 unsigned first_layer, unsigned last_layer,
90 unsigned nr_samples,
91 enum mali_texture_type type, enum mali_texture_layout layout);
92
93 void
94 panfrost_new_texture(
95 void *out,
96 uint16_t width, uint16_t height,
97 uint16_t depth, uint16_t array_size,
98 enum pipe_format format,
99 enum mali_texture_type type,
100 enum mali_texture_layout layout,
101 unsigned first_level, unsigned last_level,
102 unsigned first_layer, unsigned last_layer,
103 unsigned nr_samples,
104 unsigned cube_stride,
105 unsigned swizzle,
106 mali_ptr base,
107 struct panfrost_slice *slices);
108
109 void
110 panfrost_new_texture_bifrost(
111 struct bifrost_texture_descriptor *descriptor,
112 uint16_t width, uint16_t height,
113 uint16_t depth, uint16_t array_size,
114 enum pipe_format format,
115 enum mali_texture_type type,
116 enum mali_texture_layout layout,
117 unsigned first_level, unsigned last_level,
118 unsigned first_layer, unsigned last_layer,
119 unsigned nr_samples,
120 unsigned cube_stride,
121 unsigned swizzle,
122 mali_ptr base,
123 struct panfrost_slice *slices,
124 struct panfrost_bo *payload);
125
126
127 unsigned
128 panfrost_get_layer_stride(struct panfrost_slice *slices, bool is_3d, unsigned cube_stride, unsigned level);
129
130 unsigned
131 panfrost_texture_offset(struct panfrost_slice *slices, bool is_3d, unsigned cube_stride, unsigned level, unsigned face, unsigned sample);
132
133 /* Formats */
134
135 struct panfrost_format {
136 enum mali_format hw;
137 unsigned bind;
138 };
139
140 extern struct panfrost_format panfrost_pipe_format_table[PIPE_FORMAT_COUNT];
141
142 bool
143 panfrost_is_z24s8_variant(enum pipe_format fmt);
144
145 unsigned
146 panfrost_translate_swizzle_4(const unsigned char swizzle[4]);
147
148 void
149 panfrost_invert_swizzle(const unsigned char *in, unsigned char *out);
150
151 static inline unsigned
152 panfrost_get_default_swizzle(unsigned components)
153 {
154 switch (components) {
155 case 1:
156 return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_ZERO << 3) |
157 (MALI_CHANNEL_ZERO << 6) | (MALI_CHANNEL_ONE << 9);
158 case 2:
159 return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) |
160 (MALI_CHANNEL_ZERO << 6) | (MALI_CHANNEL_ONE << 9);
161 case 3:
162 return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) |
163 (MALI_CHANNEL_BLUE << 6) | (MALI_CHANNEL_ONE << 9);
164 case 4:
165 return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) |
166 (MALI_CHANNEL_BLUE << 6) | (MALI_CHANNEL_ALPHA << 9);
167 default:
168 unreachable("Invalid number of components");
169 }
170 }
171
172 static inline unsigned
173 panfrost_bifrost_swizzle(unsigned components)
174 {
175 /* Set all components to 0 and force w if needed */
176 return components < 4 ? 0x10 : 0x00;
177 }
178
179 enum mali_format
180 panfrost_format_to_bifrost_blend(const struct util_format_description *desc);
181
182 struct pan_pool;
183 struct pan_scoreboard;
184
185 void
186 panfrost_init_blit_shaders(struct panfrost_device *dev);
187
188 void
189 panfrost_load_midg(
190 struct pan_pool *pool,
191 struct pan_scoreboard *scoreboard,
192 mali_ptr blend_shader,
193 mali_ptr fbd,
194 mali_ptr coordinates, unsigned vertex_count,
195 struct pan_image *image,
196 unsigned loc);
197
198 #endif