583265f4f6011fe8a821e49699a4b471c5516342
[mesa.git] / src / gallium / drivers / ilo / ilo_render_gen.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2012-2013 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28 #ifndef ILO_RENDER_GEN_H
29 #define ILO_RENDER_GEN_H
30
31 #include "ilo_common.h"
32 #include "ilo_builder.h"
33 #include "ilo_state.h"
34 #include "ilo_render.h"
35
36 struct ilo_bo;
37 struct ilo_blitter;
38 struct ilo_render;
39 struct ilo_state_vector;
40
41 /**
42 * Render Engine.
43 */
44 struct ilo_render {
45 const struct ilo_dev_info *dev;
46 struct ilo_builder *builder;
47
48 struct intel_bo *workaround_bo;
49
50 uint32_t sample_pattern_1x;
51 uint32_t sample_pattern_2x;
52 uint32_t sample_pattern_4x;
53 uint32_t sample_pattern_8x[2];
54 uint32_t sample_pattern_16x[4];
55
56 bool hw_ctx_changed;
57
58 /*
59 * Any state that involves resources needs to be re-emitted when the
60 * batch bo changed. This is because we do not pin the resources and
61 * their offsets (or existence) may change between batch buffers.
62 */
63 bool batch_bo_changed;
64 bool state_bo_changed;
65 bool instruction_bo_changed;
66
67 /**
68 * HW states.
69 */
70 struct ilo_render_state {
71 /*
72 * When a WA is needed before some command, we always emit the WA right
73 * before the command. Knowing what have already been done since last
74 * 3DPRIMITIVE allows us to skip some WAs.
75 */
76 uint32_t current_pipe_control_dw1;
77
78 /*
79 * When a WA is needed after some command, we may have the WA follow the
80 * command immediately or defer it. If this is non-zero, a PIPE_CONTROL
81 * will be emitted before 3DPRIMITIVE.
82 */
83 uint32_t deferred_pipe_control_dw1;
84
85 bool primitive_restart;
86 int reduced_prim;
87 int so_max_vertices;
88
89 uint32_t SF_VIEWPORT;
90 uint32_t CLIP_VIEWPORT;
91 uint32_t SF_CLIP_VIEWPORT; /* GEN7+ */
92 uint32_t CC_VIEWPORT;
93
94 uint32_t COLOR_CALC_STATE;
95 uint32_t BLEND_STATE;
96 uint32_t DEPTH_STENCIL_STATE;
97
98 uint32_t SCISSOR_RECT;
99
100 struct {
101 uint32_t BINDING_TABLE_STATE;
102 uint32_t SURFACE_STATE[ILO_MAX_SURFACES];
103 uint32_t SAMPLER_STATE;
104 uint32_t SAMPLER_BORDER_COLOR_STATE[ILO_MAX_SAMPLERS];
105 uint32_t PUSH_CONSTANT_BUFFER;
106 int PUSH_CONSTANT_BUFFER_size;
107 } vs;
108
109 struct {
110 uint32_t BINDING_TABLE_STATE;
111 uint32_t SURFACE_STATE[ILO_MAX_SURFACES];
112 bool active;
113 } gs;
114
115 struct {
116 uint32_t BINDING_TABLE_STATE;
117 uint32_t SURFACE_STATE[ILO_MAX_SURFACES];
118 uint32_t SAMPLER_STATE;
119 uint32_t SAMPLER_BORDER_COLOR_STATE[ILO_MAX_SAMPLERS];
120 uint32_t PUSH_CONSTANT_BUFFER;
121 int PUSH_CONSTANT_BUFFER_size;
122 } wm;
123
124 struct {
125 uint32_t BINDING_TABLE_STATE;
126 uint32_t SURFACE_STATE[ILO_MAX_SURFACES];
127 uint32_t SAMPLER_STATE;
128 uint32_t SAMPLER_BORDER_COLOR_STATE[ILO_MAX_SAMPLERS];
129 uint32_t PUSH_CONSTANT_BUFFER;
130 int PUSH_CONSTANT_BUFFER_size;
131 } cs;
132 } state;
133 };
134
135 struct ilo_render_draw_session {
136 uint32_t pipe_dirty;
137
138 /* commands */
139 int reduced_prim;
140
141 bool prim_changed;
142 bool primitive_restart_changed;
143
144 /* dynamic states */
145 bool viewport_changed;
146 bool scissor_changed;
147
148 bool cc_changed;
149 bool dsa_changed;
150 bool blend_changed;
151
152 bool sampler_vs_changed;
153 bool sampler_gs_changed;
154 bool sampler_fs_changed;
155
156 bool pcb_vs_changed;
157 bool pcb_gs_changed;
158 bool pcb_fs_changed;
159
160 /* surface states */
161 bool binding_table_vs_changed;
162 bool binding_table_gs_changed;
163 bool binding_table_fs_changed;
164 };
165
166 struct ilo_render_rectlist_session {
167 uint32_t vb_start;
168 uint32_t vb_end;
169 };
170
171 struct ilo_render_launch_grid_session {
172 const unsigned *thread_group_offset;
173 const unsigned *thread_group_dim;
174 unsigned thread_group_size;
175 const struct pipe_constant_buffer *input;
176 uint32_t pc;
177
178 uint32_t idrt;
179 int idrt_size;
180 };
181
182 int
183 ilo_render_get_draw_commands_len_gen6(const struct ilo_render *render,
184 const struct ilo_state_vector *vec);
185
186 int
187 ilo_render_get_draw_commands_len_gen7(const struct ilo_render *render,
188 const struct ilo_state_vector *vec);
189
190 int
191 ilo_render_get_draw_commands_len_gen8(const struct ilo_render *render,
192 const struct ilo_state_vector *vec);
193
194 static inline int
195 ilo_render_get_draw_commands_len(const struct ilo_render *render,
196 const struct ilo_state_vector *vec)
197 {
198 if (ilo_dev_gen(render->dev) >= ILO_GEN(8))
199 return ilo_render_get_draw_commands_len_gen8(render, vec);
200 else if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
201 return ilo_render_get_draw_commands_len_gen7(render, vec);
202 else
203 return ilo_render_get_draw_commands_len_gen6(render, vec);
204 }
205
206 void
207 ilo_render_emit_draw_commands_gen6(struct ilo_render *render,
208 const struct ilo_state_vector *vec,
209 struct ilo_render_draw_session *session);
210
211 void
212 ilo_render_emit_draw_commands_gen7(struct ilo_render *render,
213 const struct ilo_state_vector *vec,
214 struct ilo_render_draw_session *session);
215
216 void
217 ilo_render_emit_draw_commands_gen8(struct ilo_render *render,
218 const struct ilo_state_vector *vec,
219 struct ilo_render_draw_session *session);
220
221 static inline void
222 ilo_render_emit_draw_commands(struct ilo_render *render,
223 const struct ilo_state_vector *vec,
224 struct ilo_render_draw_session *session)
225 {
226 const unsigned batch_used = ilo_builder_batch_used(render->builder);
227
228 if (ilo_dev_gen(render->dev) >= ILO_GEN(8))
229 ilo_render_emit_draw_commands_gen8(render, vec, session);
230 else if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
231 ilo_render_emit_draw_commands_gen7(render, vec, session);
232 else
233 ilo_render_emit_draw_commands_gen6(render, vec, session);
234
235 assert(ilo_builder_batch_used(render->builder) <= batch_used +
236 ilo_render_get_draw_commands_len(render, vec));
237 }
238
239 int
240 ilo_render_get_rectlist_commands_len_gen6(const struct ilo_render *render,
241 const struct ilo_blitter *blitter);
242
243 int
244 ilo_render_get_rectlist_commands_len_gen8(const struct ilo_render *render,
245 const struct ilo_blitter *blitter);
246
247 static inline int
248 ilo_render_get_rectlist_commands_len(const struct ilo_render *render,
249 const struct ilo_blitter *blitter)
250 {
251 if (ilo_dev_gen(render->dev) >= ILO_GEN(8))
252 return ilo_render_get_rectlist_commands_len_gen8(render, blitter);
253 else
254 return ilo_render_get_rectlist_commands_len_gen6(render, blitter);
255 }
256
257 void
258 ilo_render_emit_rectlist_commands_gen6(struct ilo_render *r,
259 const struct ilo_blitter *blitter,
260 const struct ilo_render_rectlist_session *session);
261
262 void
263 ilo_render_emit_rectlist_commands_gen7(struct ilo_render *r,
264 const struct ilo_blitter *blitter,
265 const struct ilo_render_rectlist_session *session);
266
267 void
268 ilo_render_emit_rectlist_commands_gen8(struct ilo_render *r,
269 const struct ilo_blitter *blitter,
270 const struct ilo_render_rectlist_session *session);
271
272 static inline void
273 ilo_render_emit_rectlist_commands(struct ilo_render *render,
274 const struct ilo_blitter *blitter,
275 const struct ilo_render_rectlist_session *session)
276 {
277 const unsigned batch_used = ilo_builder_batch_used(render->builder);
278
279 if (ilo_dev_gen(render->dev) >= ILO_GEN(8))
280 ilo_render_emit_rectlist_commands_gen8(render, blitter, session);
281 else if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
282 ilo_render_emit_rectlist_commands_gen7(render, blitter, session);
283 else
284 ilo_render_emit_rectlist_commands_gen6(render, blitter, session);
285
286 assert(ilo_builder_batch_used(render->builder) <= batch_used +
287 ilo_render_get_rectlist_commands_len(render, blitter));
288 }
289
290 int
291 ilo_render_get_launch_grid_commands_len(const struct ilo_render *render,
292 const struct ilo_state_vector *vec);
293
294 void
295 ilo_render_emit_launch_grid_commands(struct ilo_render *render,
296 const struct ilo_state_vector *vec,
297 const struct ilo_render_launch_grid_session *session);
298
299 int
300 ilo_render_get_draw_dynamic_states_len(const struct ilo_render *render,
301 const struct ilo_state_vector *vec);
302
303 void
304 ilo_render_emit_draw_dynamic_states(struct ilo_render *render,
305 const struct ilo_state_vector *vec,
306 struct ilo_render_draw_session *session);
307
308 int
309 ilo_render_get_rectlist_dynamic_states_len(const struct ilo_render *render,
310 const struct ilo_blitter *blitter);
311
312 void
313 ilo_render_emit_rectlist_dynamic_states(struct ilo_render *render,
314 const struct ilo_blitter *blitter,
315 struct ilo_render_rectlist_session *session);
316
317 int
318 ilo_render_get_launch_grid_dynamic_states_len(const struct ilo_render *render,
319 const struct ilo_state_vector *vec);
320
321 void
322 ilo_render_emit_launch_grid_dynamic_states(struct ilo_render *render,
323 const struct ilo_state_vector *vec,
324 struct ilo_render_launch_grid_session *session);
325
326 int
327 ilo_render_get_draw_surface_states_len(const struct ilo_render *render,
328 const struct ilo_state_vector *vec);
329
330 void
331 ilo_render_emit_draw_surface_states(struct ilo_render *render,
332 const struct ilo_state_vector *vec,
333 struct ilo_render_draw_session *session);
334
335 int
336 ilo_render_get_launch_grid_surface_states_len(const struct ilo_render *render,
337 const struct ilo_state_vector *vec);
338
339 void
340 ilo_render_emit_launch_grid_surface_states(struct ilo_render *render,
341 const struct ilo_state_vector *vec,
342 struct ilo_render_launch_grid_session *session);
343
344 void
345 gen6_wa_pre_pipe_control(struct ilo_render *r, uint32_t dw1);
346
347 void
348 gen6_draw_common_select(struct ilo_render *r,
349 const struct ilo_state_vector *ilo,
350 struct ilo_render_draw_session *session);
351
352 void
353 gen6_draw_common_sip(struct ilo_render *r,
354 const struct ilo_state_vector *ilo,
355 struct ilo_render_draw_session *session);
356
357 void
358 gen6_draw_common_base_address(struct ilo_render *r,
359 const struct ilo_state_vector *ilo,
360 struct ilo_render_draw_session *session);
361
362 void
363 gen6_draw_vf(struct ilo_render *r,
364 const struct ilo_state_vector *ilo,
365 struct ilo_render_draw_session *session);
366
367 void
368 gen6_draw_vf_statistics(struct ilo_render *r,
369 const struct ilo_state_vector *ilo,
370 struct ilo_render_draw_session *session);
371
372 void
373 gen6_draw_vs(struct ilo_render *r,
374 const struct ilo_state_vector *ilo,
375 struct ilo_render_draw_session *session);
376
377 void
378 gen6_draw_clip(struct ilo_render *r,
379 const struct ilo_state_vector *ilo,
380 struct ilo_render_draw_session *session);
381
382 void
383 gen6_draw_sf_rect(struct ilo_render *r,
384 const struct ilo_state_vector *ilo,
385 struct ilo_render_draw_session *session);
386
387 void
388 gen6_draw_wm_raster(struct ilo_render *r,
389 const struct ilo_state_vector *ilo,
390 struct ilo_render_draw_session *session);
391
392 void
393 gen7_draw_common_pcb_alloc(struct ilo_render *r,
394 const struct ilo_state_vector *vec,
395 struct ilo_render_draw_session *session);
396
397 void
398 gen7_draw_common_pointers_1(struct ilo_render *r,
399 const struct ilo_state_vector *vec,
400 struct ilo_render_draw_session *session);
401
402 void
403 gen7_draw_common_urb(struct ilo_render *r,
404 const struct ilo_state_vector *vec,
405 struct ilo_render_draw_session *session);
406
407 void
408 gen7_draw_common_pointers_2(struct ilo_render *r,
409 const struct ilo_state_vector *vec,
410 struct ilo_render_draw_session *session);
411
412 void
413 gen7_draw_vs(struct ilo_render *r,
414 const struct ilo_state_vector *vec,
415 struct ilo_render_draw_session *session);
416
417 void
418 gen7_draw_ds(struct ilo_render *r,
419 const struct ilo_state_vector *vec,
420 struct ilo_render_draw_session *session);
421
422 void
423 gen7_draw_te(struct ilo_render *r,
424 const struct ilo_state_vector *vec,
425 struct ilo_render_draw_session *session);
426
427 void
428 gen7_draw_hs(struct ilo_render *r,
429 const struct ilo_state_vector *vec,
430 struct ilo_render_draw_session *session);
431
432 void
433 gen7_draw_gs(struct ilo_render *r,
434 const struct ilo_state_vector *vec,
435 struct ilo_render_draw_session *session);
436
437 void
438 gen7_draw_sol(struct ilo_render *r,
439 const struct ilo_state_vector *vec,
440 struct ilo_render_draw_session *session);
441
442 #endif /* ILO_RENDER_GEN_H */