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