1 /*
2 * Copyright (C) 2021 Collabora, Ltd.
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 #ifndef __PAN_BLITTER_H
26 #define __PAN_BLITTER_H
27
28 #include "util/format/u_format.h"
29 #include "pan_desc.h"
30 #include "pan_pool.h"
31 #include "pan_texture.h"
32 #include "pan_util.h"
33
34 struct pan_blend_shader_cache;
35 struct pan_fb_info;
36 struct pan_jc;
37 struct pan_pool;
38
39 struct pan_blitter_cache {
40 unsigned gpu_id;
41 struct {
42 struct pan_pool *pool;
43 struct hash_table *blit;
44 struct hash_table *blend;
45 pthread_mutex_t lock;
46 } shaders;
47 struct {
48 struct pan_pool *pool;
49 struct hash_table *rsds;
50 pthread_mutex_t lock;
51 } rsds;
52 struct pan_blend_shader_cache *blend_shader_cache;
53 };
54
55 struct pan_blit_info {
56 struct {
57 struct {
58 const struct pan_image *image;
59 enum pipe_format format;
60 } planes[MAX_IMAGE_PLANES];
61 unsigned level;
62 struct {
63 int32_t x, y, z;
64 unsigned layer;
65 } start, end;
66 } src, dst;
67 struct {
68 bool enable;
69 uint16_t minx, miny, maxx, maxy;
70 } scissor;
71 bool nearest;
72 };
73
74 struct pan_blit_context {
75 mali_ptr rsd, vpd;
76 mali_ptr textures;
77 mali_ptr samplers;
78 mali_ptr position;
79 struct {
80 enum mali_texture_dimension dim;
81 struct {
82 float x, y;
83 } start, end;
84 union {
85 unsigned layer_offset;
86 float z_offset;
87 };
88 } src;
89 struct {
90 int32_t layer_offset;
91 int32_t cur_layer;
92 int32_t last_layer;
93 } dst;
94 float z_scale;
95 };
96
97 static inline bool
pan_blit_next_surface(struct pan_blit_context * ctx)98 pan_blit_next_surface(struct pan_blit_context *ctx)
99 {
100 if (ctx->dst.last_layer < ctx->dst.layer_offset) {
101 if (ctx->dst.cur_layer <= ctx->dst.last_layer)
102 return false;
103
104 ctx->dst.cur_layer--;
105 } else {
106 if (ctx->dst.cur_layer >= ctx->dst.last_layer)
107 return false;
108
109 ctx->dst.cur_layer++;
110 }
111
112 return true;
113 }
114
115 #ifdef PAN_ARCH
116 void GENX(pan_blitter_cache_init)(struct pan_blitter_cache *cache,
117 unsigned gpu_id,
118 struct pan_blend_shader_cache *blend_shader_cache,
119 struct pan_pool *bin_pool,
120 struct pan_pool *desc_pool);
121
122 void GENX(pan_blitter_cache_cleanup)(struct pan_blitter_cache *cache);
123
124 unsigned GENX(pan_preload_fb)(struct pan_blitter_cache *cache,
125 struct pan_pool *desc_pool, struct pan_jc *jc,
126 struct pan_fb_info *fb, mali_ptr tsd,
127 mali_ptr tiler, struct panfrost_ptr *jobs);
128
129 void GENX(pan_blit_ctx_init)(struct pan_blitter_cache *cache,
130 const struct pan_blit_info *info,
131 struct pan_pool *blit_pool,
132 struct pan_blit_context *ctx);
133
134 struct panfrost_ptr GENX(pan_blit)(struct pan_blit_context *ctx,
135 struct pan_pool *pool, struct pan_jc *jc,
136 mali_ptr tsd, mali_ptr tiler);
137 #endif
138
139 #endif
140