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.
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:
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
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
28 #ifndef __PAN_TEXTURE_H
29 #define __PAN_TEXTURE_H
32 #include "drm-uapi/drm_fourcc.h"
33 #include "util/format/u_format.h"
34 #include "compiler/shader_enums.h"
35 #include "panfrost-job.h"
38 #define PAN_MODIFIER_COUNT 4
39 extern uint64_t pan_best_modifiers
[PAN_MODIFIER_COUNT
];
41 struct panfrost_slice
{
46 /* If there is a header preceding each slice, how big is
47 * that header? Used for AFBC */
50 /* If checksumming is enabled following the slice, what
51 * is its offset/stride? */
52 unsigned checksum_offset
;
53 unsigned checksum_stride
;
54 struct panfrost_bo
*checksum_bo
;
56 /* Has anything been written to this slice? */
62 uint16_t width0
, height0
, depth0
, array_size
;
63 enum pipe_format format
;
64 enum mali_texture_type type
;
65 unsigned first_level
, last_level
;
66 unsigned first_layer
, last_layer
;
68 struct panfrost_bo
*bo
;
69 struct panfrost_slice
*slices
;
70 unsigned cubemap_stride
;
75 panfrost_compute_checksum_size(
76 struct panfrost_slice
*slice
,
83 panfrost_format_supports_afbc(enum pipe_format format
);
86 panfrost_afbc_header_size(unsigned width
, unsigned height
);
89 panfrost_afbc_can_ytr(enum pipe_format format
);
91 /* mali_texture_descriptor */
94 panfrost_estimate_texture_payload_size(
95 unsigned first_level
, unsigned last_level
,
96 unsigned first_layer
, unsigned last_layer
,
98 enum mali_texture_type type
, uint64_t modifier
);
101 panfrost_new_texture(
103 uint16_t width
, uint16_t height
,
104 uint16_t depth
, uint16_t array_size
,
105 enum pipe_format format
,
106 enum mali_texture_type type
,
108 unsigned first_level
, unsigned last_level
,
109 unsigned first_layer
, unsigned last_layer
,
111 unsigned cube_stride
,
114 struct panfrost_slice
*slices
);
117 panfrost_new_texture_bifrost(
118 struct bifrost_texture_descriptor
*descriptor
,
119 uint16_t width
, uint16_t height
,
120 uint16_t depth
, uint16_t array_size
,
121 enum pipe_format format
,
122 enum mali_texture_type type
,
124 unsigned first_level
, unsigned last_level
,
125 unsigned first_layer
, unsigned last_layer
,
127 unsigned cube_stride
,
130 struct panfrost_slice
*slices
,
131 struct panfrost_bo
*payload
);
135 panfrost_get_layer_stride(struct panfrost_slice
*slices
, bool is_3d
, unsigned cube_stride
, unsigned level
);
138 panfrost_texture_offset(struct panfrost_slice
*slices
, bool is_3d
, unsigned cube_stride
, unsigned level
, unsigned face
, unsigned sample
);
142 struct panfrost_format
{
147 extern struct panfrost_format panfrost_pipe_format_table
[PIPE_FORMAT_COUNT
];
150 panfrost_is_z24s8_variant(enum pipe_format fmt
);
153 panfrost_translate_swizzle_4(const unsigned char swizzle
[4]);
156 panfrost_invert_swizzle(const unsigned char *in
, unsigned char *out
);
158 static inline unsigned
159 panfrost_get_default_swizzle(unsigned components
)
161 switch (components
) {
163 return (MALI_CHANNEL_RED
<< 0) | (MALI_CHANNEL_ZERO
<< 3) |
164 (MALI_CHANNEL_ZERO
<< 6) | (MALI_CHANNEL_ONE
<< 9);
166 return (MALI_CHANNEL_RED
<< 0) | (MALI_CHANNEL_GREEN
<< 3) |
167 (MALI_CHANNEL_ZERO
<< 6) | (MALI_CHANNEL_ONE
<< 9);
169 return (MALI_CHANNEL_RED
<< 0) | (MALI_CHANNEL_GREEN
<< 3) |
170 (MALI_CHANNEL_BLUE
<< 6) | (MALI_CHANNEL_ONE
<< 9);
172 return (MALI_CHANNEL_RED
<< 0) | (MALI_CHANNEL_GREEN
<< 3) |
173 (MALI_CHANNEL_BLUE
<< 6) | (MALI_CHANNEL_ALPHA
<< 9);
175 unreachable("Invalid number of components");
179 static inline unsigned
180 panfrost_bifrost_swizzle(unsigned components
)
182 /* Set all components to 0 and force w if needed */
183 return components
< 4 ? 0x10 : 0x00;
187 panfrost_format_to_bifrost_blend(const struct util_format_description
*desc
);
190 struct pan_scoreboard
;
193 panfrost_init_blit_shaders(struct panfrost_device
*dev
);
197 struct pan_pool
*pool
,
198 struct pan_scoreboard
*scoreboard
,
199 mali_ptr blend_shader
,
201 mali_ptr coordinates
, unsigned vertex_count
,
202 struct pan_image
*image
,
205 /* DRM modifier helper */
207 #define drm_is_afbc(mod) \
208 ((mod >> 52) == (DRM_FORMAT_MOD_ARM_TYPE_AFBC | \
209 (DRM_FORMAT_MOD_VENDOR_ARM << 4)))