ilo: update multisample related states for Gen8
[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 static inline int
191 ilo_render_get_draw_commands_len(const struct ilo_render *render,
192 const struct ilo_state_vector *vec)
193 {
194 if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
195 return ilo_render_get_draw_commands_len_gen7(render, vec);
196 else
197 return ilo_render_get_draw_commands_len_gen6(render, vec);
198 }
199
200 void
201 ilo_render_emit_draw_commands_gen6(struct ilo_render *render,
202 const struct ilo_state_vector *vec,
203 struct ilo_render_draw_session *session);
204
205 void
206 ilo_render_emit_draw_commands_gen7(struct ilo_render *render,
207 const struct ilo_state_vector *vec,
208 struct ilo_render_draw_session *session);
209
210 static inline void
211 ilo_render_emit_draw_commands(struct ilo_render *render,
212 const struct ilo_state_vector *vec,
213 struct ilo_render_draw_session *session)
214 {
215 const unsigned batch_used = ilo_builder_batch_used(render->builder);
216
217 if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
218 ilo_render_emit_draw_commands_gen7(render, vec, session);
219 else
220 ilo_render_emit_draw_commands_gen6(render, vec, session);
221
222 assert(ilo_builder_batch_used(render->builder) <= batch_used +
223 ilo_render_get_draw_commands_len(render, vec));
224 }
225
226 int
227 ilo_render_get_rectlist_commands_len_gen6(const struct ilo_render *render,
228 const struct ilo_blitter *blitter);
229
230 static inline int
231 ilo_render_get_rectlist_commands_len(const struct ilo_render *render,
232 const struct ilo_blitter *blitter)
233 {
234 return ilo_render_get_rectlist_commands_len_gen6(render, blitter);
235 }
236
237 void
238 ilo_render_emit_rectlist_commands_gen6(struct ilo_render *r,
239 const struct ilo_blitter *blitter,
240 const struct ilo_render_rectlist_session *session);
241
242 void
243 ilo_render_emit_rectlist_commands_gen7(struct ilo_render *r,
244 const struct ilo_blitter *blitter,
245 const struct ilo_render_rectlist_session *session);
246
247 static inline void
248 ilo_render_emit_rectlist_commands(struct ilo_render *render,
249 const struct ilo_blitter *blitter,
250 const struct ilo_render_rectlist_session *session)
251 {
252 const unsigned batch_used = ilo_builder_batch_used(render->builder);
253
254 if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
255 ilo_render_emit_rectlist_commands_gen7(render, blitter, session);
256 else
257 ilo_render_emit_rectlist_commands_gen6(render, blitter, session);
258
259 assert(ilo_builder_batch_used(render->builder) <= batch_used +
260 ilo_render_get_rectlist_commands_len(render, blitter));
261 }
262
263 int
264 ilo_render_get_launch_grid_commands_len(const struct ilo_render *render,
265 const struct ilo_state_vector *vec);
266
267 void
268 ilo_render_emit_launch_grid_commands(struct ilo_render *render,
269 const struct ilo_state_vector *vec,
270 const struct ilo_render_launch_grid_session *session);
271
272 int
273 ilo_render_get_draw_dynamic_states_len(const struct ilo_render *render,
274 const struct ilo_state_vector *vec);
275
276 void
277 ilo_render_emit_draw_dynamic_states(struct ilo_render *render,
278 const struct ilo_state_vector *vec,
279 struct ilo_render_draw_session *session);
280
281 int
282 ilo_render_get_rectlist_dynamic_states_len(const struct ilo_render *render,
283 const struct ilo_blitter *blitter);
284
285 void
286 ilo_render_emit_rectlist_dynamic_states(struct ilo_render *render,
287 const struct ilo_blitter *blitter,
288 struct ilo_render_rectlist_session *session);
289
290 int
291 ilo_render_get_launch_grid_dynamic_states_len(const struct ilo_render *render,
292 const struct ilo_state_vector *vec);
293
294 void
295 ilo_render_emit_launch_grid_dynamic_states(struct ilo_render *render,
296 const struct ilo_state_vector *vec,
297 struct ilo_render_launch_grid_session *session);
298
299 int
300 ilo_render_get_draw_surface_states_len(const struct ilo_render *render,
301 const struct ilo_state_vector *vec);
302
303 void
304 ilo_render_emit_draw_surface_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_launch_grid_surface_states_len(const struct ilo_render *render,
310 const struct ilo_state_vector *vec);
311
312 void
313 ilo_render_emit_launch_grid_surface_states(struct ilo_render *render,
314 const struct ilo_state_vector *vec,
315 struct ilo_render_launch_grid_session *session);
316
317 void
318 gen6_wa_pre_pipe_control(struct ilo_render *r, uint32_t dw1);
319
320 void
321 gen6_draw_common_select(struct ilo_render *r,
322 const struct ilo_state_vector *ilo,
323 struct ilo_render_draw_session *session);
324
325 void
326 gen6_draw_common_sip(struct ilo_render *r,
327 const struct ilo_state_vector *ilo,
328 struct ilo_render_draw_session *session);
329
330 void
331 gen6_draw_common_base_address(struct ilo_render *r,
332 const struct ilo_state_vector *ilo,
333 struct ilo_render_draw_session *session);
334
335 void
336 gen6_draw_vf(struct ilo_render *r,
337 const struct ilo_state_vector *ilo,
338 struct ilo_render_draw_session *session);
339
340 void
341 gen6_draw_vf_statistics(struct ilo_render *r,
342 const struct ilo_state_vector *ilo,
343 struct ilo_render_draw_session *session);
344
345 void
346 gen6_draw_vs(struct ilo_render *r,
347 const struct ilo_state_vector *ilo,
348 struct ilo_render_draw_session *session);
349
350 void
351 gen6_draw_clip(struct ilo_render *r,
352 const struct ilo_state_vector *ilo,
353 struct ilo_render_draw_session *session);
354
355 void
356 gen6_draw_sf_rect(struct ilo_render *r,
357 const struct ilo_state_vector *ilo,
358 struct ilo_render_draw_session *session);
359
360 void
361 gen6_draw_wm_raster(struct ilo_render *r,
362 const struct ilo_state_vector *ilo,
363 struct ilo_render_draw_session *session);
364
365 #endif /* ILO_RENDER_GEN_H */