panfrost: Implement index buffer cache
[mesa.git] / src / gallium / drivers / panfrost / pan_resource.h
1 /*
2 * © Copyright2018-2019 Alyssa Rosenzweig
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * SOFTWARE.
22 *
23 */
24
25
26 #ifndef PAN_RESOURCE_H
27 #define PAN_RESOURCE_H
28
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"
35
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
47 * by index.
48 */
49
50 #define PANFROST_MINMAX_SIZE 64
51
52 struct panfrost_minmax_cache {
53 uint64_t keys[PANFROST_MINMAX_SIZE];
54 uint64_t values[PANFROST_MINMAX_SIZE];
55 unsigned size;
56 unsigned index;
57 };
58
59 struct panfrost_resource {
60 struct pipe_resource base;
61 struct {
62 struct pipe_box biggest_rect;
63 struct pipe_scissor_state extent;
64 } damage;
65
66 struct panfrost_bo *bo;
67 struct renderonly_scanout *scanout;
68
69 struct panfrost_resource *separate_stencil;
70
71 struct util_range valid_buffer_range;
72
73 /* Description of the mip levels */
74 struct panfrost_slice slices[MAX_MIP_LEVELS];
75
76 /* Distance from tree to tree */
77 unsigned cubemap_stride;
78
79 /* Internal layout (tiled?) */
80 enum mali_texture_layout layout;
81
82 /* Is transaciton elimination enabled? */
83 bool checksummed;
84
85 enum pipe_format internal_format;
86
87 /* Cached min/max values for index buffers */
88 struct panfrost_minmax_cache *index_cache;
89 };
90
91 static inline struct panfrost_resource *
92 pan_resource(struct pipe_resource *p)
93 {
94 return (struct panfrost_resource *)p;
95 }
96
97 struct panfrost_gtransfer {
98 struct pipe_transfer base;
99 void *map;
100 };
101
102 static inline struct panfrost_gtransfer *
103 pan_transfer(struct pipe_transfer *p)
104 {
105 return (struct panfrost_gtransfer *)p;
106 }
107
108 mali_ptr
109 panfrost_get_texture_address(
110 struct panfrost_resource *rsrc,
111 unsigned level, unsigned face);
112
113 void panfrost_resource_screen_init(struct panfrost_screen *screen);
114
115 void panfrost_resource_context_init(struct pipe_context *pctx);
116
117 void
118 panfrost_resource_hint_layout(
119 struct panfrost_screen *screen,
120 struct panfrost_resource *rsrc,
121 enum mali_texture_layout layout,
122 signed weight);
123
124 /* Blitting */
125
126 void
127 panfrost_blit(struct pipe_context *pipe,
128 const struct pipe_blit_info *info);
129
130 void
131 panfrost_blit_wallpaper(struct panfrost_context *ctx,
132 struct pipe_box *box);
133
134 void
135 panfrost_resource_reset_damage(struct panfrost_resource *pres);
136
137 void
138 panfrost_resource_set_damage_region(struct pipe_screen *screen,
139 struct pipe_resource *res,
140 unsigned int nrects,
141 const struct pipe_box *rects);
142
143 #endif /* PAN_RESOURCE_H */