lima: refactor indexed draw indices upload
[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 struct lima_bo *bo;
59 };
60
61 #define LIMA_MAX_VARYING_NUM 13
62
63 struct lima_varying_info {
64 int components;
65 int component_size;
66 int offset;
67 };
68
69 struct lima_vs_shader_state {
70 void *shader;
71 int shader_size;
72 int prefetch;
73
74 /* pipe_constant_buffer.size is aligned with some pad bytes,
75 * so record here for the real start place of gpir lowered
76 * uniforms */
77 int uniform_pending_offset;
78
79 void *constant;
80 int constant_size;
81
82 struct lima_varying_info varying[LIMA_MAX_VARYING_NUM];
83 int varying_stride;
84 int num_outputs;
85 int num_varyings;
86 int gl_pos_idx;
87 int point_size_idx;
88
89 struct lima_bo *bo;
90 };
91
92 struct lima_rasterizer_state {
93 struct pipe_rasterizer_state base;
94 };
95
96 struct lima_blend_state {
97 struct pipe_blend_state base;
98 };
99
100 struct lima_vertex_element_state {
101 struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS];
102 unsigned num_elements;
103 };
104
105 struct lima_context_vertex_buffer {
106 struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
107 unsigned count;
108 uint32_t enabled_mask;
109 };
110
111 struct lima_context_viewport_state {
112 struct pipe_viewport_state transform;
113 float left, right, bottom, top;
114 float near, far;
115 };
116
117 struct lima_context_constant_buffer {
118 const void *buffer;
119 uint32_t size;
120 bool dirty;
121 };
122
123 enum lima_ctx_buff {
124 lima_ctx_buff_sh_gl_pos,
125 lima_ctx_buff_sh_gl_point_size,
126 lima_ctx_buff_gp_varying_info,
127 lima_ctx_buff_gp_attribute_info,
128 lima_ctx_buff_gp_uniform,
129 lima_ctx_buff_gp_vs_cmd,
130 lima_ctx_buff_gp_plbu_cmd,
131 lima_ctx_buff_pp_plb_rsw,
132 lima_ctx_buff_pp_uniform_array,
133 lima_ctx_buff_pp_uniform,
134 lima_ctx_buff_pp_tex_desc,
135 lima_ctx_buff_pp_stack,
136 lima_ctx_buff_num,
137 };
138
139 struct lima_ctx_buff_state {
140 struct pipe_resource *res;
141 unsigned offset;
142 unsigned size;
143 };
144
145 struct lima_texture_stateobj {
146 struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS];
147 unsigned num_textures;
148 struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
149 unsigned num_samplers;
150 };
151
152 struct lima_ctx_plb_pp_stream_key {
153 uint32_t plb_index;
154 uint32_t tiled_w;
155 uint32_t tiled_h;
156 };
157
158 struct lima_ctx_plb_pp_stream {
159 struct lima_ctx_plb_pp_stream_key key;
160 uint32_t refcnt;
161 struct lima_bo *bo;
162 uint32_t offset[4];
163 };
164
165 struct lima_pp_stream_state {
166 struct lima_bo *bo;
167 uint32_t bo_offset;
168 uint32_t offset[8];
169 };
170
171 struct lima_context {
172 struct pipe_context base;
173
174 enum {
175 LIMA_CONTEXT_DIRTY_FRAMEBUFFER = (1 << 0),
176 LIMA_CONTEXT_DIRTY_CLEAR = (1 << 1),
177 LIMA_CONTEXT_DIRTY_SHADER_VERT = (1 << 2),
178 LIMA_CONTEXT_DIRTY_SHADER_FRAG = (1 << 3),
179 LIMA_CONTEXT_DIRTY_VERTEX_ELEM = (1 << 4),
180 LIMA_CONTEXT_DIRTY_VERTEX_BUFF = (1 << 5),
181 LIMA_CONTEXT_DIRTY_VIEWPORT = (1 << 6),
182 LIMA_CONTEXT_DIRTY_SCISSOR = (1 << 7),
183 LIMA_CONTEXT_DIRTY_RASTERIZER = (1 << 8),
184 LIMA_CONTEXT_DIRTY_ZSA = (1 << 9),
185 LIMA_CONTEXT_DIRTY_BLEND_COLOR = (1 << 10),
186 LIMA_CONTEXT_DIRTY_BLEND = (1 << 11),
187 LIMA_CONTEXT_DIRTY_STENCIL_REF = (1 << 12),
188 LIMA_CONTEXT_DIRTY_CONST_BUFF = (1 << 13),
189 LIMA_CONTEXT_DIRTY_TEXTURES = (1 << 14),
190 } dirty;
191
192 struct u_upload_mgr *uploader;
193 struct u_suballocator *suballocator;
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 lima_context_clear clear;
202 struct lima_vs_shader_state *vs;
203 struct lima_fs_shader_state *fs;
204 struct lima_vertex_element_state *vertex_elements;
205 struct lima_context_vertex_buffer vertex_buffers;
206 struct lima_rasterizer_state *rasterizer;
207 struct lima_depth_stencil_alpha_state *zsa;
208 struct pipe_blend_color blend_color;
209 struct lima_blend_state *blend;
210 struct pipe_stencil_ref stencil_ref;
211 struct lima_context_constant_buffer const_buffer[PIPE_SHADER_TYPES];
212 struct lima_texture_stateobj tex_stateobj;
213 struct lima_pp_stream_state pp_stream;
214
215 unsigned min_index;
216 unsigned max_index;
217
218 #define LIMA_CTX_PLB_MIN_NUM 1
219 #define LIMA_CTX_PLB_MAX_NUM 4
220 #define LIMA_CTX_PLB_DEF_NUM 2
221 #define LIMA_CTX_PLB_BLK_SIZE 512
222 unsigned plb_size;
223 unsigned plb_gp_size;
224
225 struct lima_bo *plb[LIMA_CTX_PLB_MAX_NUM];
226 struct lima_bo *gp_tile_heap[LIMA_CTX_PLB_MAX_NUM];
227 #define gp_tile_heap_size 0x100000
228 struct lima_bo *plb_gp_stream;
229 struct lima_bo *sh_varying;
230
231 struct hash_table *plb_pp_stream;
232 uint32_t plb_index;
233
234 struct lima_ctx_buff_state buffer_state[lima_ctx_buff_num];
235
236 struct util_dynarray vs_cmd_array;
237 struct util_dynarray plbu_cmd_array;
238
239 struct lima_submit *gp_submit;
240 struct lima_submit *pp_submit;
241
242 int id;
243
244 struct pipe_debug_callback debug;
245
246 int pp_max_stack_size;
247
248 unsigned index_offset;
249 struct lima_resource *index_res;
250 };
251
252 static inline struct lima_context *
253 lima_context(struct pipe_context *pctx)
254 {
255 return (struct lima_context *)pctx;
256 }
257
258 struct lima_sampler_state {
259 struct pipe_sampler_state base;
260 };
261
262 static inline struct lima_sampler_state *
263 lima_sampler_state(struct pipe_sampler_state *psstate)
264 {
265 return (struct lima_sampler_state *)psstate;
266 }
267
268 struct lima_sampler_view {
269 struct pipe_sampler_view base;
270 };
271
272 static inline struct lima_sampler_view *
273 lima_sampler_view(struct pipe_sampler_view *psview)
274 {
275 return (struct lima_sampler_view *)psview;
276 }
277
278 #define LIMA_CTX_BUFF_SUBMIT_GP (1 << 0)
279 #define LIMA_CTX_BUFF_SUBMIT_PP (1 << 1)
280
281 uint32_t lima_ctx_buff_va(struct lima_context *ctx, enum lima_ctx_buff buff,
282 unsigned submit);
283 void *lima_ctx_buff_map(struct lima_context *ctx, enum lima_ctx_buff buff);
284 void *lima_ctx_buff_alloc(struct lima_context *ctx, enum lima_ctx_buff buff,
285 unsigned size, bool uploader);
286
287 void lima_state_init(struct lima_context *ctx);
288 void lima_state_fini(struct lima_context *ctx);
289 void lima_draw_init(struct lima_context *ctx);
290 void lima_program_init(struct lima_context *ctx);
291 void lima_query_init(struct lima_context *ctx);
292
293 struct pipe_context *
294 lima_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags);
295
296 void lima_flush(struct lima_context *ctx);
297
298 bool lima_need_flush(struct lima_context *ctx, struct lima_bo *bo, bool write);
299 bool lima_is_scanout(struct lima_context *ctx);
300
301 #endif