a291aff4525e396828012c47438c75b288780116
[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
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 void
38 brw_blorp_blit_miptrees(struct brw_context *brw,
39 struct intel_mipmap_tree *src_mt,
40 unsigned src_level, unsigned src_layer,
41 mesa_format src_format, int src_swizzle,
42 struct intel_mipmap_tree *dst_mt,
43 unsigned dst_level, unsigned dst_layer,
44 mesa_format dst_format,
45 float src_x0, float src_y0,
46 float src_x1, float src_y1,
47 float dst_x0, float dst_y0,
48 float dst_x1, float dst_y1,
49 GLenum filter, bool mirror_x, bool mirror_y,
50 bool decode_srgb, bool encode_srgb);
51
52 #ifdef __cplusplus
53 } /* end extern "C" */
54
55 /**
56 * Binding table indices used by BLORP.
57 */
58 enum {
59 BRW_BLORP_TEXTURE_BINDING_TABLE_INDEX,
60 BRW_BLORP_RENDERBUFFER_BINDING_TABLE_INDEX,
61 BRW_BLORP_NUM_BINDING_TABLE_ENTRIES
62 };
63
64
65 class brw_blorp_mip_info
66 {
67 public:
68 brw_blorp_mip_info();
69
70 void set(struct intel_mipmap_tree *mt,
71 unsigned int level, unsigned int layer);
72
73 struct intel_mipmap_tree *mt;
74
75 /**
76 * The miplevel to use.
77 */
78 uint32_t level;
79
80 /**
81 * The 2D layer within the miplevel. Combined, level and layer define the
82 * 2D miptree slice to use.
83 *
84 * Note: if mt is a 2D multisample array texture on Gen7+ using
85 * INTEL_MSAA_LAYOUT_UMS or INTEL_MSAA_LAYOUT_CMS, layer is the physical
86 * layer holding sample 0. So, for example, if mt->num_samples == 4, then
87 * logical layer n corresponds to layer == 4*n.
88 */
89 uint32_t layer;
90
91 /**
92 * Width of the miplevel to be used. For surfaces using
93 * INTEL_MSAA_LAYOUT_IMS, this is measured in samples, not pixels.
94 */
95 uint32_t width;
96
97 /**
98 * Height 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 height;
102
103 /**
104 * X offset within the surface to texture from (or render to). For
105 * surfaces using INTEL_MSAA_LAYOUT_IMS, this is measured in samples, not
106 * pixels.
107 */
108 uint32_t x_offset;
109
110 /**
111 * Y offset within the surface to texture from (or render to). For
112 * surfaces using INTEL_MSAA_LAYOUT_IMS, this is measured in samples, not
113 * pixels.
114 */
115 uint32_t y_offset;
116 };
117
118 class brw_blorp_surface_info : public brw_blorp_mip_info
119 {
120 public:
121 brw_blorp_surface_info();
122
123 void set(struct brw_context *brw,
124 struct intel_mipmap_tree *mt,
125 unsigned int level, unsigned int layer,
126 mesa_format format, bool is_render_target);
127
128 uint32_t compute_tile_offsets(uint32_t *tile_x, uint32_t *tile_y) const;
129
130 /* Setting this flag indicates that the buffer's contents are W-tiled
131 * stencil data, but the surface state should be set up for Y tiled
132 * MESA_FORMAT_R_UNORM8 data (this is necessary because surface states don't
133 * support W tiling).
134 *
135 * Since W tiles are 64 pixels wide by 64 pixels high, whereas Y tiles of
136 * MESA_FORMAT_R_UNORM8 data are 128 pixels wide by 32 pixels high, the width and
137 * pitch stored in the surface state will be multiplied by 2, and the
138 * height will be halved. Also, since W and Y tiles store their data in a
139 * different order, the width and height will be rounded up to a multiple
140 * of the tile size, to ensure that the WM program can access the full
141 * width and height of the buffer.
142 */
143 bool map_stencil_as_y_tiled;
144
145 unsigned num_samples;
146
147 /**
148 * Indicates if we use the standard miptree layout (ALL_LOD_IN_EACH_SLICE),
149 * or if we tightly pack array slices at each LOD (ALL_SLICES_AT_EACH_LOD).
150 *
151 * If ALL_SLICES_AT_EACH_LOD is set, then ARYSPC_LOD0 can be used. Ignored
152 * prior to Gen7.
153 */
154 enum miptree_array_layout array_layout;
155
156 /**
157 * Format that should be used when setting up the surface state for this
158 * surface. Should correspond to one of the BRW_SURFACEFORMAT_* enums.
159 */
160 uint32_t brw_surfaceformat;
161
162 /**
163 * For MSAA surfaces, MSAA layout that should be used when setting up the
164 * surface state for this surface.
165 */
166 intel_msaa_layout msaa_layout;
167
168 /**
169 * In order to support cases where RGBA format is backing client requested
170 * RGB, one needs to have means to force alpha channel to one when user
171 * requested RGB surface is used as blit source. This is possible by
172 * setting source swizzle for the texture surface.
173 */
174 int swizzle;
175 };
176
177
178 struct brw_blorp_coord_transform_params
179 {
180 void setup(GLfloat src0, GLfloat src1, GLfloat dst0, GLfloat dst1,
181 bool mirror);
182
183 float multiplier;
184 float offset;
185 };
186
187
188 struct brw_blorp_wm_push_constants
189 {
190 uint32_t dst_x0;
191 uint32_t dst_x1;
192 uint32_t dst_y0;
193 uint32_t dst_y1;
194 /* Top right coordinates of the rectangular grid used for scaled blitting */
195 float rect_grid_x1;
196 float rect_grid_y1;
197 brw_blorp_coord_transform_params x_transform;
198 brw_blorp_coord_transform_params y_transform;
199
200 /* Minimum layer setting works for all the textures types but texture_3d
201 * for which the setting has no effect. Use the z-coordinate instead.
202 */
203 uint32_t src_z;
204
205 /* Pad out to an integral number of registers */
206 uint32_t pad[5];
207 };
208
209 /* Every 32 bytes of push constant data constitutes one GEN register. */
210 const unsigned int BRW_BLORP_NUM_PUSH_CONST_REGS =
211 sizeof(brw_blorp_wm_push_constants) / 32;
212
213 struct brw_blorp_prog_data
214 {
215 unsigned int first_curbe_grf;
216
217 /**
218 * True if the WM program should be run in MSDISPMODE_PERSAMPLE with more
219 * than one sample per pixel.
220 */
221 bool persample_msaa_dispatch;
222 };
223
224
225 class brw_blorp_params
226 {
227 public:
228 brw_blorp_params(unsigned num_varyings = 0,
229 unsigned num_draw_buffers = 1,
230 unsigned num_layers = 1);
231
232 virtual uint32_t get_wm_prog(struct brw_context *brw,
233 brw_blorp_prog_data **prog_data) const = 0;
234
235 uint32_t x0;
236 uint32_t y0;
237 uint32_t x1;
238 uint32_t y1;
239 brw_blorp_mip_info depth;
240 uint32_t depth_format;
241 brw_blorp_surface_info src;
242 brw_blorp_surface_info dst;
243 enum gen6_hiz_op hiz_op;
244 unsigned fast_clear_op;
245 bool use_wm_prog;
246 brw_blorp_wm_push_constants wm_push_consts;
247 const unsigned num_varyings;
248 const unsigned num_draw_buffers;
249 const unsigned num_layers;
250 };
251
252
253 void
254 brw_blorp_exec(struct brw_context *brw, const brw_blorp_params *params);
255
256 void
257 gen6_blorp_exec(struct brw_context *brw,
258 const brw_blorp_params *params);
259
260 void
261 gen7_blorp_exec(struct brw_context *brw,
262 const brw_blorp_params *params);
263
264 void
265 gen8_blorp_exec(struct brw_context *brw, const brw_blorp_params *params);
266
267 /**
268 * Parameters for a HiZ or depth resolve operation.
269 *
270 * For an overview of HiZ ops, see the following sections of the Sandy Bridge
271 * PRM, Volume 1, Part 2:
272 * - 7.5.3.1 Depth Buffer Clear
273 * - 7.5.3.2 Depth Buffer Resolve
274 * - 7.5.3.3 Hierarchical Depth Buffer Resolve
275 */
276 class brw_hiz_op_params : public brw_blorp_params
277 {
278 public:
279 brw_hiz_op_params(struct intel_mipmap_tree *mt,
280 unsigned int level, unsigned int layer,
281 gen6_hiz_op op);
282
283 virtual uint32_t get_wm_prog(struct brw_context *brw,
284 brw_blorp_prog_data **prog_data) const;
285 };
286
287 struct brw_blorp_blit_prog_key
288 {
289 /* Number of samples per pixel that have been configured in the surface
290 * state for texturing from.
291 */
292 unsigned tex_samples;
293
294 /* MSAA layout that has been configured in the surface state for texturing
295 * from.
296 */
297 intel_msaa_layout tex_layout;
298
299 /* Actual number of samples per pixel in the source image. */
300 unsigned src_samples;
301
302 /* Actual MSAA layout used by the source image. */
303 intel_msaa_layout src_layout;
304
305 /* Number of samples per pixel that have been configured in the render
306 * target.
307 */
308 unsigned rt_samples;
309
310 /* MSAA layout that has been configured in the render target. */
311 intel_msaa_layout rt_layout;
312
313 /* Actual number of samples per pixel in the destination image. */
314 unsigned dst_samples;
315
316 /* Actual MSAA layout used by the destination image. */
317 intel_msaa_layout dst_layout;
318
319 /* Type of the data to be read from the texture (one of
320 * BRW_REGISTER_TYPE_{UD,D,F}).
321 */
322 enum brw_reg_type texture_data_type;
323
324 /* True if the source image is W tiled. If true, the surface state for the
325 * source image must be configured as Y tiled, and tex_samples must be 0.
326 */
327 bool src_tiled_w;
328
329 /* True if the destination image is W tiled. If true, the surface state
330 * for the render target must be configured as Y tiled, and rt_samples must
331 * be 0.
332 */
333 bool dst_tiled_w;
334
335 /* True if all source samples should be blended together to produce each
336 * destination pixel. If true, src_tiled_w must be false, tex_samples must
337 * equal src_samples, and tex_samples must be nonzero.
338 */
339 bool blend;
340
341 /* True if the rectangle being sent through the rendering pipeline might be
342 * larger than the destination rectangle, so the WM program should kill any
343 * pixels that are outside the destination rectangle.
344 */
345 bool use_kill;
346
347 /**
348 * True if the WM program should be run in MSDISPMODE_PERSAMPLE with more
349 * than one sample per pixel.
350 */
351 bool persample_msaa_dispatch;
352
353 /* True for scaled blitting. */
354 bool blit_scaled;
355
356 /* Scale factors between the pixel grid and the grid of samples. We're
357 * using grid of samples for bilinear filetring in multisample scaled blits.
358 */
359 float x_scale;
360 float y_scale;
361
362 /* True for blits with filter = GL_LINEAR. */
363 bool bilinear_filter;
364 };
365
366 class brw_blorp_blit_params : public brw_blorp_params
367 {
368 public:
369 brw_blorp_blit_params(struct brw_context *brw,
370 struct intel_mipmap_tree *src_mt,
371 unsigned src_level, unsigned src_layer,
372 mesa_format src_format,
373 struct intel_mipmap_tree *dst_mt,
374 unsigned dst_level, unsigned dst_layer,
375 mesa_format dst_format,
376 GLfloat src_x0, GLfloat src_y0,
377 GLfloat src_x1, GLfloat src_y1,
378 GLfloat dst_x0, GLfloat dst_y0,
379 GLfloat dst_x1, GLfloat dst_y1,
380 GLenum filter, bool mirror_x, bool mirror_y);
381
382 virtual uint32_t get_wm_prog(struct brw_context *brw,
383 brw_blorp_prog_data **prog_data) const;
384
385 private:
386 brw_blorp_blit_prog_key wm_prog_key;
387 };
388
389 /**
390 * \name BLORP internals
391 * \{
392 *
393 * Used internally by gen6_blorp_exec() and gen7_blorp_exec().
394 */
395
396 void
397 gen6_blorp_init(struct brw_context *brw);
398
399 void
400 gen6_blorp_emit_state_base_address(struct brw_context *brw,
401 const brw_blorp_params *params);
402
403 void
404 gen6_blorp_emit_vertices(struct brw_context *brw,
405 const brw_blorp_params *params);
406
407 uint32_t
408 gen6_blorp_emit_blend_state(struct brw_context *brw,
409 const brw_blorp_params *params);
410
411 uint32_t
412 gen6_blorp_emit_cc_state(struct brw_context *brw);
413
414 uint32_t
415 gen6_blorp_emit_wm_constants(struct brw_context *brw,
416 const brw_blorp_params *params);
417
418 void
419 gen6_blorp_emit_vs_disable(struct brw_context *brw,
420 const brw_blorp_params *params);
421
422 uint32_t
423 gen6_blorp_emit_binding_table(struct brw_context *brw,
424 uint32_t wm_surf_offset_renderbuffer,
425 uint32_t wm_surf_offset_texture);
426
427 uint32_t
428 gen6_blorp_emit_depth_stencil_state(struct brw_context *brw,
429 const brw_blorp_params *params);
430
431 void
432 gen6_blorp_emit_gs_disable(struct brw_context *brw,
433 const brw_blorp_params *params);
434
435 void
436 gen6_blorp_emit_clip_disable(struct brw_context *brw);
437
438 void
439 gen6_blorp_emit_drawing_rectangle(struct brw_context *brw,
440 const brw_blorp_params *params);
441
442 uint32_t
443 gen6_blorp_emit_sampler_state(struct brw_context *brw,
444 unsigned tex_filter, unsigned max_lod,
445 bool non_normalized_coords);
446 void
447 gen7_blorp_emit_urb_config(struct brw_context *brw);
448
449 void
450 gen7_blorp_emit_blend_state_pointer(struct brw_context *brw,
451 uint32_t cc_blend_state_offset);
452
453 void
454 gen7_blorp_emit_cc_state_pointer(struct brw_context *brw,
455 uint32_t cc_state_offset);
456
457 void
458 gen7_blorp_emit_cc_viewport(struct brw_context *brw);
459
460 void
461 gen7_blorp_emit_te_disable(struct brw_context *brw);
462
463 void
464 gen7_blorp_emit_binding_table_pointers_ps(struct brw_context *brw,
465 uint32_t wm_bind_bo_offset);
466
467 void
468 gen7_blorp_emit_sampler_state_pointers_ps(struct brw_context *brw,
469 uint32_t sampler_offset);
470
471 void
472 gen7_blorp_emit_clear_params(struct brw_context *brw,
473 const brw_blorp_params *params);
474
475 void
476 gen7_blorp_emit_constant_ps(struct brw_context *brw,
477 uint32_t wm_push_const_offset);
478
479 void
480 gen7_blorp_emit_constant_ps_disable(struct brw_context *brw);
481
482 void
483 gen7_blorp_emit_primitive(struct brw_context *brw,
484 const brw_blorp_params *params);
485
486 /** \} */
487
488 #endif /* __cplusplus */