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