Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/panfrost/lib/pan_texture.h
4560 views
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 "drm-uapi/drm_fourcc.h"
33
#include "util/format/u_format.h"
34
#include "compiler/shader_enums.h"
35
#include "midgard_pack.h"
36
#include "pan_bo.h"
37
#include "pan_device.h"
38
#include "pan_util.h"
39
#include "pan_format.h"
40
41
#define PAN_MODIFIER_COUNT 4
42
extern uint64_t pan_best_modifiers[PAN_MODIFIER_COUNT];
43
44
struct pan_image_slice_layout {
45
unsigned offset;
46
unsigned line_stride;
47
unsigned row_stride;
48
unsigned surface_stride;
49
50
struct {
51
/* Size of the AFBC header preceding each slice */
52
unsigned header_size;
53
54
/* Size of the AFBC body */
55
unsigned body_size;
56
57
/* Stride between two rows of AFBC headers */
58
unsigned row_stride;
59
60
/* Stride between AFBC headers of two consecutive surfaces.
61
* For 3D textures, this must be set to header size since
62
* AFBC headers are allocated together, for 2D arrays this
63
* should be set to size0, since AFBC headers are placed at
64
* the beginning of each layer
65
*/
66
unsigned surface_stride;
67
} afbc;
68
69
/* If checksumming is enabled following the slice, what
70
* is its offset/stride? */
71
struct {
72
unsigned offset;
73
unsigned stride;
74
unsigned size;
75
} crc;
76
77
unsigned size;
78
};
79
80
enum pan_image_crc_mode {
81
PAN_IMAGE_CRC_NONE,
82
PAN_IMAGE_CRC_INBAND,
83
PAN_IMAGE_CRC_OOB,
84
};
85
86
#ifndef PAN_PACK_H
87
/* Avoid the GenXML dependence */
88
89
enum mali_texture_dimension {
90
MALI_TEXTURE_DIMENSION_CUBE = 0,
91
MALI_TEXTURE_DIMENSION_1D = 1,
92
MALI_TEXTURE_DIMENSION_2D = 2,
93
MALI_TEXTURE_DIMENSION_3D = 3,
94
};
95
#endif
96
97
struct pan_image_layout {
98
uint64_t modifier;
99
enum pipe_format format;
100
unsigned width, height, depth;
101
unsigned nr_samples;
102
enum mali_texture_dimension dim;
103
unsigned nr_slices;
104
struct pan_image_slice_layout slices[MAX_MIP_LEVELS];
105
unsigned array_size;
106
unsigned array_stride;
107
unsigned data_size;
108
109
enum pan_image_crc_mode crc_mode;
110
/* crc_size != 0 only if crc_mode == OOB otherwise CRC words are
111
* counted in data_size */
112
unsigned crc_size;
113
};
114
115
struct pan_image_mem {
116
struct panfrost_bo *bo;
117
unsigned offset;
118
};
119
120
struct pan_image {
121
struct pan_image_mem data;
122
struct pan_image_mem crc;
123
struct pan_image_layout layout;
124
};
125
126
struct pan_image_view {
127
/* Format, dimension and sample count of the view might differ from
128
* those of the image (2D view of a 3D image surface for instance).
129
*/
130
enum pipe_format format;
131
enum mali_texture_dimension dim;
132
unsigned first_level, last_level;
133
unsigned first_layer, last_layer;
134
unsigned char swizzle[4];
135
const struct pan_image *image;
136
137
/* If EXT_multisampled_render_to_texture is used, this may be
138
* greater than image->layout.nr_samples. */
139
unsigned nr_samples;
140
141
/* Only valid if dim == 1D, needed to implement buffer views */
142
struct {
143
unsigned offset;
144
unsigned size;
145
} buf;
146
};
147
148
unsigned
149
panfrost_compute_checksum_size(
150
struct pan_image_slice_layout *slice,
151
unsigned width,
152
unsigned height);
153
154
/* AFBC */
155
156
bool
157
panfrost_format_supports_afbc(const struct panfrost_device *dev,
158
enum pipe_format format);
159
160
#define AFBC_HEADER_BYTES_PER_TILE 16
161
162
unsigned
163
panfrost_afbc_header_size(unsigned width, unsigned height);
164
165
bool
166
panfrost_afbc_can_ytr(enum pipe_format format);
167
168
unsigned
169
panfrost_block_dim(uint64_t modifier, bool width, unsigned plane);
170
171
unsigned
172
panfrost_estimate_texture_payload_size(const struct panfrost_device *dev,
173
const struct pan_image_view *iview);
174
175
void
176
panfrost_new_texture(const struct panfrost_device *dev,
177
const struct pan_image_view *iview,
178
void *out,
179
const struct panfrost_ptr *payload);
180
181
unsigned
182
panfrost_get_layer_stride(const struct pan_image_layout *layout,
183
unsigned level);
184
185
unsigned
186
panfrost_texture_offset(const struct pan_image_layout *layout,
187
unsigned level, unsigned array_idx,
188
unsigned surface_idx);
189
190
struct pan_pool;
191
struct pan_scoreboard;
192
193
/* DRM modifier helper */
194
195
#define drm_is_afbc(mod) \
196
((mod >> 52) == (DRM_FORMAT_MOD_ARM_TYPE_AFBC | \
197
(DRM_FORMAT_MOD_VENDOR_ARM << 4)))
198
199
/* Map modifiers to mali_texture_layout for packing in a texture descriptor */
200
201
static inline enum mali_texture_layout
202
panfrost_modifier_to_layout(uint64_t modifier)
203
{
204
if (drm_is_afbc(modifier))
205
return MALI_TEXTURE_LAYOUT_AFBC;
206
else if (modifier == DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED)
207
return MALI_TEXTURE_LAYOUT_TILED;
208
else if (modifier == DRM_FORMAT_MOD_LINEAR)
209
return MALI_TEXTURE_LAYOUT_LINEAR;
210
else
211
unreachable("Invalid modifer");
212
}
213
214
struct pan_image_explicit_layout {
215
unsigned offset;
216
unsigned line_stride;
217
};
218
219
bool
220
pan_image_layout_init(const struct panfrost_device *dev,
221
struct pan_image_layout *layout,
222
uint64_t modifier,
223
enum pipe_format format,
224
enum mali_texture_dimension dim,
225
unsigned width, unsigned height, unsigned depth,
226
unsigned array_size, unsigned nr_samples,
227
unsigned nr_slices,
228
enum pan_image_crc_mode crc_mode,
229
const struct pan_image_explicit_layout *explicit_layout);
230
231
struct pan_surface {
232
union {
233
mali_ptr data;
234
struct {
235
mali_ptr header;
236
mali_ptr body;
237
} afbc;
238
};
239
};
240
241
void
242
pan_iview_get_surface(const struct pan_image_view *iview,
243
unsigned level, unsigned layer, unsigned sample,
244
struct pan_surface *surf);
245
246
#endif
247
248