2 * © Copyright2018-2019 Alyssa Rosenzweig
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #ifndef PAN_RESOURCE_H
27 #define PAN_RESOURCE_H
29 #include <panfrost-job.h>
30 #include "pan_screen.h"
31 #include "pan_allocate.h"
32 #include "pan_texture.h"
33 #include "drm-uapi/drm.h"
34 #include "util/u_range.h"
36 /* Index buffer min/max cache. We need to caclculate the min/max for arbitrary
37 * slices (start, start + count) of the index buffer at drawtime. As this can
38 * be quite expensive, we cache. Conceptually, we just use a hash table mapping
39 * the key (start, count) to the value (min, max). In practice, mesa's hash
40 * table implementation is higher overhead than we would like and makes
41 * handling memory usage a little complicated. So we use this data structure
42 * instead. Searching is O(n) to the size, but the size is capped at the
43 * PANFROST_MINMAX_SIZE constant (so this is a tradeoff between cache hit/miss
44 * ratio and cache search speed). Note that keys are adjacent so we get cache
45 * line alignment benefits. Insertion is O(1) and in-order until the cache
46 * fills up, after that it evicts the oldest cached value in a ring facilitated
50 #define PANFROST_MINMAX_SIZE 64
52 struct panfrost_minmax_cache
{
53 uint64_t keys
[PANFROST_MINMAX_SIZE
];
54 uint64_t values
[PANFROST_MINMAX_SIZE
];
59 struct panfrost_resource
{
60 struct pipe_resource base
;
62 struct pipe_box biggest_rect
;
63 struct pipe_scissor_state extent
;
66 struct panfrost_bo
*bo
;
67 struct renderonly_scanout
*scanout
;
69 struct panfrost_resource
*separate_stencil
;
71 struct util_range valid_buffer_range
;
73 /* Description of the mip levels */
74 struct panfrost_slice slices
[MAX_MIP_LEVELS
];
76 /* Distance from tree to tree */
77 unsigned cubemap_stride
;
79 /* Internal layout (tiled?) */
80 enum mali_texture_layout layout
;
82 /* Is transaciton elimination enabled? */
85 enum pipe_format internal_format
;
87 /* Cached min/max values for index buffers */
88 struct panfrost_minmax_cache
*index_cache
;
91 static inline struct panfrost_resource
*
92 pan_resource(struct pipe_resource
*p
)
94 return (struct panfrost_resource
*)p
;
97 struct panfrost_gtransfer
{
98 struct pipe_transfer base
;
102 static inline struct panfrost_gtransfer
*
103 pan_transfer(struct pipe_transfer
*p
)
105 return (struct panfrost_gtransfer
*)p
;
109 panfrost_get_texture_address(
110 struct panfrost_resource
*rsrc
,
111 unsigned level
, unsigned face
);
113 void panfrost_resource_screen_init(struct panfrost_screen
*screen
);
115 void panfrost_resource_context_init(struct pipe_context
*pctx
);
118 panfrost_resource_hint_layout(
119 struct panfrost_screen
*screen
,
120 struct panfrost_resource
*rsrc
,
121 enum mali_texture_layout layout
,
127 panfrost_blit(struct pipe_context
*pipe
,
128 const struct pipe_blit_info
*info
);
131 panfrost_blit_wallpaper(struct panfrost_context
*ctx
,
132 struct pipe_box
*box
);
135 panfrost_resource_reset_damage(struct panfrost_resource
*pres
);
138 panfrost_resource_set_damage_region(struct pipe_screen
*screen
,
139 struct pipe_resource
*res
,
141 const struct pipe_box
*rects
);
143 #endif /* PAN_RESOURCE_H */