ilo: give gen6_draw_session a better prefix
[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 packed_sample_position_1x;
51 uint32_t packed_sample_position_4x;
52 uint32_t packed_sample_position_8x[2];
53
54 bool hw_ctx_changed;
55
56 /*
57 * Any state that involves resources needs to be re-emitted when the
58 * batch bo changed. This is because we do not pin the resources and
59 * their offsets (or existence) may change between batch buffers.
60 */
61 bool batch_bo_changed;
62 bool state_bo_changed;
63 bool instruction_bo_changed;
64
65 /**
66 * HW states.
67 */
68 struct ilo_render_state {
69 /*
70 * When a WA is needed before some command, we always emit the WA right
71 * before the command. Knowing what have already been done since last
72 * 3DPRIMITIVE allows us to skip some WAs.
73 */
74 uint32_t current_pipe_control_dw1;
75
76 /*
77 * When a WA is needed after some command, we may have the WA follow the
78 * command immediately or defer it. If this is non-zero, a PIPE_CONTROL
79 * will be emitted before 3DPRIMITIVE.
80 */
81 uint32_t deferred_pipe_control_dw1;
82
83 bool primitive_restart;
84 int reduced_prim;
85 int so_max_vertices;
86
87 uint32_t SF_VIEWPORT;
88 uint32_t CLIP_VIEWPORT;
89 uint32_t SF_CLIP_VIEWPORT; /* GEN7+ */
90 uint32_t CC_VIEWPORT;
91
92 uint32_t COLOR_CALC_STATE;
93 uint32_t BLEND_STATE;
94 uint32_t DEPTH_STENCIL_STATE;
95
96 uint32_t SCISSOR_RECT;
97
98 struct {
99 uint32_t BINDING_TABLE_STATE;
100 int BINDING_TABLE_STATE_size;
101 uint32_t SURFACE_STATE[ILO_MAX_VS_SURFACES];
102 uint32_t SAMPLER_STATE;
103 uint32_t SAMPLER_BORDER_COLOR_STATE[ILO_MAX_SAMPLERS];
104 uint32_t PUSH_CONSTANT_BUFFER;
105 int PUSH_CONSTANT_BUFFER_size;
106 } vs;
107
108 struct {
109 uint32_t BINDING_TABLE_STATE;
110 int BINDING_TABLE_STATE_size;
111 uint32_t SURFACE_STATE[ILO_MAX_GS_SURFACES];
112 bool active;
113 } gs;
114
115 struct {
116 uint32_t BINDING_TABLE_STATE;
117 int BINDING_TABLE_STATE_size;
118 uint32_t SURFACE_STATE[ILO_MAX_WM_SURFACES];
119 uint32_t SAMPLER_STATE;
120 uint32_t SAMPLER_BORDER_COLOR_STATE[ILO_MAX_SAMPLERS];
121 uint32_t PUSH_CONSTANT_BUFFER;
122 int PUSH_CONSTANT_BUFFER_size;
123 } wm;
124 } state;
125 };
126
127 struct ilo_render_draw_session {
128 uint32_t pipe_dirty;
129
130 /* commands */
131 int reduced_prim;
132
133 bool prim_changed;
134 bool primitive_restart_changed;
135
136 /* dynamic states */
137 bool viewport_changed;
138 bool scissor_changed;
139
140 bool cc_changed;
141 bool dsa_changed;
142 bool blend_changed;
143
144 bool sampler_vs_changed;
145 bool sampler_gs_changed;
146 bool sampler_fs_changed;
147
148 bool pcb_vs_changed;
149 bool pcb_gs_changed;
150 bool pcb_fs_changed;
151
152 /* surface states */
153 bool binding_table_vs_changed;
154 bool binding_table_gs_changed;
155 bool binding_table_fs_changed;
156
157 int num_surfaces[PIPE_SHADER_TYPES];
158 };
159
160 int
161 ilo_render_get_draw_commands_len_gen6(const struct ilo_render *render,
162 const struct ilo_state_vector *vec);
163
164 int
165 ilo_render_get_draw_commands_len_gen7(const struct ilo_render *render,
166 const struct ilo_state_vector *vec);
167
168 static inline int
169 ilo_render_get_draw_commands_len(const struct ilo_render *render,
170 const struct ilo_state_vector *vec)
171 {
172 if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
173 return ilo_render_get_draw_commands_len_gen7(render, vec);
174 else
175 return ilo_render_get_draw_commands_len_gen6(render, vec);
176 }
177
178 void
179 ilo_render_emit_draw_commands_gen6(struct ilo_render *render,
180 const struct ilo_state_vector *vec,
181 struct ilo_render_draw_session *session);
182
183 void
184 ilo_render_emit_draw_commands_gen7(struct ilo_render *render,
185 const struct ilo_state_vector *vec,
186 struct ilo_render_draw_session *session);
187
188 static inline void
189 ilo_render_emit_draw_commands(struct ilo_render *render,
190 const struct ilo_state_vector *vec,
191 struct ilo_render_draw_session *session)
192 {
193 const unsigned batch_used = ilo_builder_batch_used(render->builder);
194
195 if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
196 ilo_render_emit_draw_commands_gen7(render, vec, session);
197 else
198 ilo_render_emit_draw_commands_gen6(render, vec, session);
199
200 assert(ilo_builder_batch_used(render->builder) <= batch_used +
201 ilo_render_get_draw_commands_len(render, vec));
202 }
203
204 int
205 ilo_render_get_rectlist_commands_len_gen6(const struct ilo_render *render,
206 const struct ilo_blitter *blitter);
207
208 static inline int
209 ilo_render_get_rectlist_commands_len(const struct ilo_render *render,
210 const struct ilo_blitter *blitter)
211 {
212 return ilo_render_get_rectlist_commands_len_gen6(render, blitter);
213 }
214
215 void
216 ilo_render_emit_rectlist_commands_gen6(struct ilo_render *r,
217 const struct ilo_blitter *blitter);
218
219 void
220 ilo_render_emit_rectlist_commands_gen7(struct ilo_render *r,
221 const struct ilo_blitter *blitter);
222
223 static inline void
224 ilo_render_emit_rectlist_commands(struct ilo_render *render,
225 const struct ilo_blitter *blitter)
226 {
227 const unsigned batch_used = ilo_builder_batch_used(render->builder);
228
229 if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
230 ilo_render_emit_rectlist_commands_gen7(render, blitter);
231 else
232 ilo_render_emit_rectlist_commands_gen6(render, blitter);
233
234 assert(ilo_builder_batch_used(render->builder) <= batch_used +
235 ilo_render_get_rectlist_commands_len(render, blitter));
236 }
237
238 int
239 ilo_render_get_draw_dynamic_states_len(const struct ilo_render *render,
240 const struct ilo_state_vector *vec);
241
242 void
243 ilo_render_emit_draw_dynamic_states(struct ilo_render *render,
244 const struct ilo_state_vector *vec,
245 struct ilo_render_draw_session *session);
246
247 int
248 ilo_render_get_rectlist_dynamic_states_len(const struct ilo_render *render,
249 const struct ilo_blitter *blitter);
250
251 void
252 ilo_render_emit_rectlist_dynamic_states(struct ilo_render *render,
253 const struct ilo_blitter *blitter);
254
255 int
256 ilo_render_get_draw_surface_states_len(const struct ilo_render *render,
257 const struct ilo_state_vector *vec);
258
259 void
260 ilo_render_emit_draw_surface_states(struct ilo_render *render,
261 const struct ilo_state_vector *vec,
262 struct ilo_render_draw_session *session);
263
264 void
265 gen6_wa_pre_pipe_control(struct ilo_render *r, uint32_t dw1);
266
267 void
268 gen6_draw_common_select(struct ilo_render *r,
269 const struct ilo_state_vector *ilo,
270 struct ilo_render_draw_session *session);
271
272 void
273 gen6_draw_common_sip(struct ilo_render *r,
274 const struct ilo_state_vector *ilo,
275 struct ilo_render_draw_session *session);
276
277 void
278 gen6_draw_common_base_address(struct ilo_render *r,
279 const struct ilo_state_vector *ilo,
280 struct ilo_render_draw_session *session);
281
282 void
283 gen6_draw_vf(struct ilo_render *r,
284 const struct ilo_state_vector *ilo,
285 struct ilo_render_draw_session *session);
286
287 void
288 gen6_draw_vf_statistics(struct ilo_render *r,
289 const struct ilo_state_vector *ilo,
290 struct ilo_render_draw_session *session);
291
292 void
293 gen6_draw_vs(struct ilo_render *r,
294 const struct ilo_state_vector *ilo,
295 struct ilo_render_draw_session *session);
296
297 void
298 gen6_draw_clip(struct ilo_render *r,
299 const struct ilo_state_vector *ilo,
300 struct ilo_render_draw_session *session);
301
302 void
303 gen6_draw_sf_rect(struct ilo_render *r,
304 const struct ilo_state_vector *ilo,
305 struct ilo_render_draw_session *session);
306
307 void
308 gen6_draw_wm_raster(struct ilo_render *r,
309 const struct ilo_state_vector *ilo,
310 struct ilo_render_draw_session *session);
311
312 #endif /* ILO_RENDER_GEN_H */