lima: remove definition of lima_is_scanout
[mesa.git] / src / gallium / drivers / lima / lima_context.h
1 /*
2 * Copyright (c) 2017-2019 Lima Project
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, sub license,
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
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the 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 NON-INFRINGEMENT. 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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
25 #ifndef H_LIMA_CONTEXT
26 #define H_LIMA_CONTEXT
27
28 #include "util/slab.h"
29 #include "util/u_dynarray.h"
30
31 #include "pipe/p_context.h"
32 #include "pipe/p_state.h"
33
34 struct lima_context_framebuffer {
35 struct pipe_framebuffer_state base;
36 int tiled_w, tiled_h;
37 int shift_w, shift_h;
38 int block_w, block_h;
39 int shift_min;
40 };
41
42 struct lima_context_clear {
43 unsigned buffers;
44 uint32_t color_8pc;
45 uint32_t depth;
46 uint32_t stencil;
47 uint64_t color_16pc;
48 };
49
50 struct lima_depth_stencil_alpha_state {
51 struct pipe_depth_stencil_alpha_state base;
52 };
53
54 struct lima_fs_shader_state {
55 void *shader;
56 int shader_size;
57 int stack_size;
58 bool uses_discard;
59 struct lima_bo *bo;
60 };
61
62 #define LIMA_MAX_VARYING_NUM 13
63
64 struct lima_varying_info {
65 int components;
66 int component_size;
67 int offset;
68 };
69
70 struct lima_vs_shader_state {
71 void *shader;
72 int shader_size;
73 int prefetch;
74
75 /* pipe_constant_buffer.size is aligned with some pad bytes,
76 * so record here for the real start place of gpir lowered
77 * uniforms */
78 int uniform_pending_offset;
79
80 void *constant;
81 int constant_size;
82
83 struct lima_varying_info varying[LIMA_MAX_VARYING_NUM];
84 int varying_stride;
85 int num_outputs;
86 int num_varyings;
87 int gl_pos_idx;
88 int point_size_idx;
89
90 struct lima_bo *bo;
91 };
92
93 struct lima_rasterizer_state {
94 struct pipe_rasterizer_state base;
95 };
96
97 struct lima_blend_state {
98 struct pipe_blend_state base;
99 };
100
101 struct lima_vertex_element_state {
102 struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS];
103 unsigned num_elements;
104 };
105
106 struct lima_context_vertex_buffer {
107 struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
108 unsigned count;
109 uint32_t enabled_mask;
110 };
111
112 struct lima_context_viewport_state {
113 struct pipe_viewport_state transform;
114 float left, right, bottom, top;
115 float near, far;
116 };
117
118 struct lima_context_constant_buffer {
119 const void *buffer;
120 uint32_t size;
121 bool dirty;
122 };
123
124 enum lima_ctx_buff {
125 lima_ctx_buff_gp_varying_info,
126 lima_ctx_buff_gp_attribute_info,
127 lima_ctx_buff_gp_uniform,
128 lima_ctx_buff_gp_vs_cmd,
129 lima_ctx_buff_gp_plbu_cmd,
130 lima_ctx_buff_pp_plb_rsw,
131 lima_ctx_buff_pp_uniform_array,
132 lima_ctx_buff_pp_uniform,
133 lima_ctx_buff_pp_tex_desc,
134 lima_ctx_buff_pp_stack,
135 lima_ctx_buff_num,
136 };
137
138 struct lima_ctx_buff_state {
139 struct pipe_resource *res;
140 unsigned offset;
141 unsigned size;
142 };
143
144 struct lima_texture_stateobj {
145 struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS];
146 unsigned num_textures;
147 struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
148 unsigned num_samplers;
149 };
150
151 struct lima_ctx_plb_pp_stream_key {
152 uint32_t plb_index;
153 uint32_t tiled_w;
154 uint32_t tiled_h;
155 };
156
157 struct lima_ctx_plb_pp_stream {
158 struct lima_ctx_plb_pp_stream_key key;
159 uint32_t refcnt;
160 struct lima_bo *bo;
161 uint32_t offset[4];
162 };
163
164 struct lima_pp_stream_state {
165 struct lima_bo *bo;
166 uint32_t bo_offset;
167 uint32_t offset[8];
168 };
169
170 struct lima_context {
171 struct pipe_context base;
172
173 enum {
174 LIMA_CONTEXT_DIRTY_FRAMEBUFFER = (1 << 0),
175 LIMA_CONTEXT_DIRTY_CLEAR = (1 << 1),
176 LIMA_CONTEXT_DIRTY_SHADER_VERT = (1 << 2),
177 LIMA_CONTEXT_DIRTY_SHADER_FRAG = (1 << 3),
178 LIMA_CONTEXT_DIRTY_VERTEX_ELEM = (1 << 4),
179 LIMA_CONTEXT_DIRTY_VERTEX_BUFF = (1 << 5),
180 LIMA_CONTEXT_DIRTY_VIEWPORT = (1 << 6),
181 LIMA_CONTEXT_DIRTY_SCISSOR = (1 << 7),
182 LIMA_CONTEXT_DIRTY_RASTERIZER = (1 << 8),
183 LIMA_CONTEXT_DIRTY_ZSA = (1 << 9),
184 LIMA_CONTEXT_DIRTY_BLEND_COLOR = (1 << 10),
185 LIMA_CONTEXT_DIRTY_BLEND = (1 << 11),
186 LIMA_CONTEXT_DIRTY_STENCIL_REF = (1 << 12),
187 LIMA_CONTEXT_DIRTY_CONST_BUFF = (1 << 13),
188 LIMA_CONTEXT_DIRTY_TEXTURES = (1 << 14),
189 } dirty;
190
191 unsigned resolve;
192
193 struct u_upload_mgr *uploader;
194 struct blitter_context *blitter;
195
196 struct slab_child_pool transfer_pool;
197
198 struct lima_context_framebuffer framebuffer;
199 struct lima_context_viewport_state viewport;
200 struct pipe_scissor_state scissor;
201 struct pipe_scissor_state damage_rect;
202 struct lima_context_clear clear;
203 struct lima_vs_shader_state *vs;
204 struct lima_fs_shader_state *fs;
205 struct lima_vertex_element_state *vertex_elements;
206 struct lima_context_vertex_buffer vertex_buffers;
207 struct lima_rasterizer_state *rasterizer;
208 struct lima_depth_stencil_alpha_state *zsa;
209 struct pipe_blend_color blend_color;
210 struct lima_blend_state *blend;
211 struct pipe_stencil_ref stencil_ref;
212 struct lima_context_constant_buffer const_buffer[PIPE_SHADER_TYPES];
213 struct lima_texture_stateobj tex_stateobj;
214 struct lima_pp_stream_state pp_stream;
215
216 unsigned min_index;
217 unsigned max_index;
218
219 #define LIMA_CTX_PLB_MIN_NUM 1
220 #define LIMA_CTX_PLB_MAX_NUM 4
221 #define LIMA_CTX_PLB_DEF_NUM 2
222 #define LIMA_CTX_PLB_BLK_SIZE 512
223 unsigned plb_size;
224 unsigned plb_gp_size;
225
226 struct lima_bo *plb[LIMA_CTX_PLB_MAX_NUM];
227 struct lima_bo *gp_tile_heap[LIMA_CTX_PLB_MAX_NUM];
228 uint32_t gp_tile_heap_size;
229 struct lima_bo *plb_gp_stream;
230 struct lima_bo *gp_output;
231 uint32_t gp_output_varyings_offt;
232 uint32_t gp_output_point_size_offt;
233
234 struct hash_table *plb_pp_stream;
235 uint32_t plb_index;
236
237 struct lima_ctx_buff_state buffer_state[lima_ctx_buff_num];
238
239 struct util_dynarray vs_cmd_array;
240 struct util_dynarray plbu_cmd_array;
241
242 struct lima_submit *gp_submit;
243 struct lima_submit *pp_submit;
244
245 int id;
246
247 struct pipe_debug_callback debug;
248
249 int pp_max_stack_size;
250
251 unsigned index_offset;
252 struct lima_resource *index_res;
253 };
254
255 static inline struct lima_context *
256 lima_context(struct pipe_context *pctx)
257 {
258 return (struct lima_context *)pctx;
259 }
260
261 struct lima_sampler_state {
262 struct pipe_sampler_state base;
263 };
264
265 static inline struct lima_sampler_state *
266 lima_sampler_state(struct pipe_sampler_state *psstate)
267 {
268 return (struct lima_sampler_state *)psstate;
269 }
270
271 struct lima_sampler_view {
272 struct pipe_sampler_view base;
273 };
274
275 static inline struct lima_sampler_view *
276 lima_sampler_view(struct pipe_sampler_view *psview)
277 {
278 return (struct lima_sampler_view *)psview;
279 }
280
281 #define LIMA_CTX_BUFF_SUBMIT_GP (1 << 0)
282 #define LIMA_CTX_BUFF_SUBMIT_PP (1 << 1)
283
284 uint32_t lima_ctx_buff_va(struct lima_context *ctx, enum lima_ctx_buff buff,
285 unsigned submit);
286 void *lima_ctx_buff_map(struct lima_context *ctx, enum lima_ctx_buff buff);
287 void *lima_ctx_buff_alloc(struct lima_context *ctx, enum lima_ctx_buff buff,
288 unsigned size);
289
290 void lima_state_init(struct lima_context *ctx);
291 void lima_state_fini(struct lima_context *ctx);
292 void lima_draw_init(struct lima_context *ctx);
293 void lima_program_init(struct lima_context *ctx);
294 void lima_query_init(struct lima_context *ctx);
295
296 struct pipe_context *
297 lima_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags);
298
299 void lima_flush(struct lima_context *ctx);
300
301 bool lima_need_flush(struct lima_context *ctx, struct lima_bo *bo, bool write);
302
303 #endif