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