i965: Split brw_blorp.c/h into multiple files
[mesa.git] / src / mesa / drivers / dri / i965 / blorp_priv.h
1 /*
2 * Copyright © 2012 Intel Corporation
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, sublicense,
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 next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * 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 NONINFRINGEMENT. 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 DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #pragma once
25
26 #include <stdint.h>
27
28 #include "blorp.h"
29 #include "brw_reg.h"
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /**
36 * Binding table indices used by BLORP.
37 */
38 enum {
39 BRW_BLORP_RENDERBUFFER_BINDING_TABLE_INDEX,
40 BRW_BLORP_TEXTURE_BINDING_TABLE_INDEX,
41 BRW_BLORP_NUM_BINDING_TABLE_ENTRIES
42 };
43
44 struct brw_blorp_surface_info
45 {
46 struct isl_surf surf;
47 drm_intel_bo *bo;
48 uint32_t offset;
49
50 struct isl_surf aux_surf;
51 drm_intel_bo *aux_bo;
52 uint32_t aux_offset;
53 enum isl_aux_usage aux_usage;
54
55 union isl_color_value clear_color;
56
57 struct isl_view view;
58
59 /* Z offset into a 3-D texture or slice of a 2-D array texture. */
60 uint32_t z_offset;
61
62 uint32_t tile_x_sa, tile_y_sa;
63 };
64
65 void
66 brw_blorp_surface_info_init(struct brw_context *brw,
67 struct brw_blorp_surface_info *info,
68 const struct brw_blorp_surf *surf,
69 unsigned int level, unsigned int layer,
70 enum isl_format format, bool is_render_target);
71
72
73 struct brw_blorp_coord_transform
74 {
75 float multiplier;
76 float offset;
77 };
78
79 /**
80 * Bounding rectangle telling pixel discard which pixels are not to be
81 * touched. This is needed in when surfaces are configured as something else
82 * what they really are:
83 *
84 * - writing W-tiled stencil as Y-tiled
85 * - writing interleaved multisampled as single sampled.
86 *
87 * See blorp_nir_discard_if_outside_rect().
88 */
89 struct brw_blorp_discard_rect
90 {
91 uint32_t x0;
92 uint32_t x1;
93 uint32_t y0;
94 uint32_t y1;
95 };
96
97 /**
98 * Grid needed for blended and scaled blits of integer formats, see
99 * blorp_nir_manual_blend_bilinear().
100 */
101 struct brw_blorp_rect_grid
102 {
103 float x1;
104 float y1;
105 float pad[2];
106 };
107
108 struct brw_blorp_wm_inputs
109 {
110 struct brw_blorp_discard_rect discard_rect;
111 struct brw_blorp_rect_grid rect_grid;
112 struct brw_blorp_coord_transform coord_transform[2];
113
114 /* Minimum layer setting works for all the textures types but texture_3d
115 * for which the setting has no effect. Use the z-coordinate instead.
116 */
117 uint32_t src_z;
118
119 /* Pad out to an integral number of registers */
120 uint32_t pad[3];
121 };
122
123 struct brw_blorp_prog_data
124 {
125 bool dispatch_8;
126 bool dispatch_16;
127
128 uint8_t first_curbe_grf_0;
129 uint8_t first_curbe_grf_2;
130
131 uint32_t ksp_offset_2;
132
133 /**
134 * True if the WM program should be run in MSDISPMODE_PERSAMPLE with more
135 * than one sample per pixel.
136 */
137 bool persample_msaa_dispatch;
138
139 /**
140 * Mask of which FS inputs are marked flat by the shader source. This is
141 * needed for setting up 3DSTATE_SF/SBE.
142 */
143 uint32_t flat_inputs;
144 unsigned num_varying_inputs;
145 GLbitfield64 inputs_read;
146 };
147
148 static inline unsigned
149 brw_blorp_get_urb_length(const struct brw_blorp_prog_data *prog_data)
150 {
151 if (prog_data == NULL)
152 return 1;
153
154 /* From the BSpec: 3D Pipeline - Strips and Fans - 3DSTATE_SBE
155 *
156 * read_length = ceiling((max_source_attr+1)/2)
157 */
158 return MAX2((prog_data->num_varying_inputs + 1) / 2, 1);
159 }
160
161 struct brw_blorp_params
162 {
163 uint32_t x0;
164 uint32_t y0;
165 uint32_t x1;
166 uint32_t y1;
167 struct brw_blorp_surface_info depth;
168 uint32_t depth_format;
169 struct brw_blorp_surface_info src;
170 struct brw_blorp_surface_info dst;
171 enum gen6_hiz_op hiz_op;
172 union {
173 unsigned fast_clear_op;
174 unsigned resolve_type;
175 };
176 bool color_write_disable[4];
177 struct brw_blorp_wm_inputs wm_inputs;
178 unsigned num_draw_buffers;
179 unsigned num_layers;
180 uint32_t wm_prog_kernel;
181 struct brw_blorp_prog_data *wm_prog_data;
182 };
183
184 void
185 brw_blorp_params_init(struct brw_blorp_params *params);
186
187 void
188 brw_blorp_exec(struct brw_context *brw, const struct brw_blorp_params *params);
189
190 void
191 gen6_blorp_exec(struct brw_context *brw,
192 const struct brw_blorp_params *params);
193
194 void
195 gen7_blorp_exec(struct brw_context *brw,
196 const struct brw_blorp_params *params);
197
198 void
199 gen8_blorp_exec(struct brw_context *brw, const struct brw_blorp_params *params);
200
201 struct brw_blorp_blit_prog_key
202 {
203 /* Number of samples per pixel that have been configured in the surface
204 * state for texturing from.
205 */
206 unsigned tex_samples;
207
208 /* MSAA layout that has been configured in the surface state for texturing
209 * from.
210 */
211 enum isl_msaa_layout tex_layout;
212
213 enum isl_aux_usage tex_aux_usage;
214
215 /* Actual number of samples per pixel in the source image. */
216 unsigned src_samples;
217
218 /* Actual MSAA layout used by the source image. */
219 enum isl_msaa_layout src_layout;
220
221 /* Number of samples per pixel that have been configured in the render
222 * target.
223 */
224 unsigned rt_samples;
225
226 /* MSAA layout that has been configured in the render target. */
227 enum isl_msaa_layout rt_layout;
228
229 /* Actual number of samples per pixel in the destination image. */
230 unsigned dst_samples;
231
232 /* Actual MSAA layout used by the destination image. */
233 enum isl_msaa_layout dst_layout;
234
235 /* Type of the data to be read from the texture (one of
236 * BRW_REGISTER_TYPE_{UD,D,F}).
237 */
238 enum brw_reg_type texture_data_type;
239
240 /* True if the source image is W tiled. If true, the surface state for the
241 * source image must be configured as Y tiled, and tex_samples must be 0.
242 */
243 bool src_tiled_w;
244
245 /* True if the destination image is W tiled. If true, the surface state
246 * for the render target must be configured as Y tiled, and rt_samples must
247 * be 0.
248 */
249 bool dst_tiled_w;
250
251 /* True if all source samples should be blended together to produce each
252 * destination pixel. If true, src_tiled_w must be false, tex_samples must
253 * equal src_samples, and tex_samples must be nonzero.
254 */
255 bool blend;
256
257 /* True if the rectangle being sent through the rendering pipeline might be
258 * larger than the destination rectangle, so the WM program should kill any
259 * pixels that are outside the destination rectangle.
260 */
261 bool use_kill;
262
263 /**
264 * True if the WM program should be run in MSDISPMODE_PERSAMPLE with more
265 * than one sample per pixel.
266 */
267 bool persample_msaa_dispatch;
268
269 /* True for scaled blitting. */
270 bool blit_scaled;
271
272 /* Scale factors between the pixel grid and the grid of samples. We're
273 * using grid of samples for bilinear filetring in multisample scaled blits.
274 */
275 float x_scale;
276 float y_scale;
277
278 /* True for blits with filter = GL_LINEAR. */
279 bool bilinear_filter;
280 };
281
282 /**
283 * \name BLORP internals
284 * \{
285 *
286 * Used internally by gen6_blorp_exec() and gen7_blorp_exec().
287 */
288
289 void brw_blorp_init_wm_prog_key(struct brw_wm_prog_key *wm_key);
290
291 const unsigned *
292 brw_blorp_compile_nir_shader(struct brw_context *brw, struct nir_shader *nir,
293 const struct brw_wm_prog_key *wm_key,
294 bool use_repclear,
295 struct brw_blorp_prog_data *prog_data,
296 unsigned *program_size);
297
298 uint32_t
299 brw_blorp_emit_surface_state(struct brw_context *brw,
300 const struct brw_blorp_surface_info *surface,
301 uint32_t read_domains, uint32_t write_domain,
302 bool is_render_target);
303
304 void
305 gen6_blorp_init(struct brw_context *brw);
306
307 void
308 gen6_blorp_emit_vertices(struct brw_context *brw,
309 const struct brw_blorp_params *params);
310
311 uint32_t
312 gen6_blorp_emit_blend_state(struct brw_context *brw,
313 const struct brw_blorp_params *params);
314
315 uint32_t
316 gen6_blorp_emit_cc_state(struct brw_context *brw);
317
318 uint32_t
319 gen6_blorp_emit_wm_constants(struct brw_context *brw,
320 const struct brw_blorp_params *params);
321
322 void
323 gen6_blorp_emit_vs_disable(struct brw_context *brw,
324 const struct brw_blorp_params *params);
325
326 uint32_t
327 gen6_blorp_emit_binding_table(struct brw_context *brw,
328 uint32_t wm_surf_offset_renderbuffer,
329 uint32_t wm_surf_offset_texture);
330
331 uint32_t
332 gen6_blorp_emit_depth_stencil_state(struct brw_context *brw,
333 const struct brw_blorp_params *params);
334
335 void
336 gen6_blorp_emit_gs_disable(struct brw_context *brw,
337 const struct brw_blorp_params *params);
338
339 void
340 gen6_blorp_emit_clip_disable(struct brw_context *brw);
341
342 void
343 gen6_blorp_emit_drawing_rectangle(struct brw_context *brw,
344 const struct brw_blorp_params *params);
345
346 uint32_t
347 gen6_blorp_emit_sampler_state(struct brw_context *brw,
348 unsigned tex_filter, unsigned max_lod,
349 bool non_normalized_coords);
350 void
351 gen7_blorp_emit_urb_config(struct brw_context *brw,
352 const struct brw_blorp_params *params);
353
354 void
355 gen7_blorp_emit_blend_state_pointer(struct brw_context *brw,
356 uint32_t cc_blend_state_offset);
357
358 void
359 gen7_blorp_emit_cc_state_pointer(struct brw_context *brw,
360 uint32_t cc_state_offset);
361
362 void
363 gen7_blorp_emit_cc_viewport(struct brw_context *brw);
364
365 void
366 gen7_blorp_emit_te_disable(struct brw_context *brw);
367
368 void
369 gen7_blorp_emit_binding_table_pointers_ps(struct brw_context *brw,
370 uint32_t wm_bind_bo_offset);
371
372 void
373 gen7_blorp_emit_sampler_state_pointers_ps(struct brw_context *brw,
374 uint32_t sampler_offset);
375
376 void
377 gen7_blorp_emit_clear_params(struct brw_context *brw,
378 const struct brw_blorp_params *params);
379
380 void
381 gen7_blorp_emit_constant_ps(struct brw_context *brw,
382 uint32_t wm_push_const_offset);
383
384 void
385 gen7_blorp_emit_constant_ps_disable(struct brw_context *brw);
386
387 void
388 gen7_blorp_emit_primitive(struct brw_context *brw,
389 const struct brw_blorp_params *params);
390
391 /** \} */
392
393 #ifdef __cplusplus
394 } /* end extern "C" */
395 #endif /* __cplusplus */