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