intel/blorp: Handle gen6 stencil/HiZ offsets in the back-end
[mesa.git] / src / intel / blorp / 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 #ifndef BLORP_PRIV_H
25 #define BLORP_PRIV_H
26
27 #include <stdint.h>
28
29 #include "compiler/nir/nir.h"
30 #include "compiler/brw_compiler.h"
31
32 #include "blorp.h"
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 /**
39 * Binding table indices used by BLORP.
40 */
41 enum {
42 BLORP_RENDERBUFFER_BT_INDEX,
43 BLORP_TEXTURE_BT_INDEX,
44 BLORP_NUM_BT_ENTRIES
45 };
46
47 struct brw_blorp_surface_info
48 {
49 bool enabled;
50
51 struct isl_surf surf;
52 struct blorp_address addr;
53
54 struct isl_surf aux_surf;
55 struct blorp_address aux_addr;
56 enum isl_aux_usage aux_usage;
57
58 union isl_color_value clear_color;
59
60 struct isl_view view;
61
62 /* Z offset into a 3-D texture or slice of a 2-D array texture. */
63 uint32_t z_offset;
64
65 uint32_t tile_x_sa, tile_y_sa;
66 };
67
68 void
69 brw_blorp_surface_info_init(struct blorp_context *blorp,
70 struct brw_blorp_surface_info *info,
71 const struct blorp_surf *surf,
72 unsigned int level, unsigned int layer,
73 enum isl_format format, bool is_render_target);
74 void
75 blorp_surf_convert_to_single_slice(const struct isl_device *isl_dev,
76 struct brw_blorp_surface_info *info);
77
78
79 struct brw_blorp_coord_transform
80 {
81 float multiplier;
82 float offset;
83 };
84
85 /**
86 * Bounding rectangle telling pixel discard which pixels are not to be
87 * touched. This is needed in when surfaces are configured as something else
88 * what they really are:
89 *
90 * - writing W-tiled stencil as Y-tiled
91 * - writing interleaved multisampled as single sampled.
92 *
93 * See blorp_nir_discard_if_outside_rect().
94 */
95 struct brw_blorp_discard_rect
96 {
97 uint32_t x0;
98 uint32_t x1;
99 uint32_t y0;
100 uint32_t y1;
101 };
102
103 /**
104 * Grid needed for blended and scaled blits of integer formats, see
105 * blorp_nir_manual_blend_bilinear().
106 */
107 struct brw_blorp_rect_grid
108 {
109 float x1;
110 float y1;
111 float pad[2];
112 };
113
114 struct blorp_surf_offset {
115 uint32_t x;
116 uint32_t y;
117 };
118
119 struct brw_blorp_wm_inputs
120 {
121 uint32_t clear_color[4];
122
123 struct brw_blorp_discard_rect discard_rect;
124 struct brw_blorp_rect_grid rect_grid;
125 struct brw_blorp_coord_transform coord_transform[2];
126
127 struct blorp_surf_offset src_offset;
128 struct blorp_surf_offset dst_offset;
129
130 /* (1/width, 1/height) for the source surface */
131 float src_inv_size[2];
132
133 /* Minimum layer setting works for all the textures types but texture_3d
134 * for which the setting has no effect. Use the z-coordinate instead.
135 */
136 uint32_t src_z;
137
138 /* Pad out to an integral number of registers */
139 uint32_t pad[1];
140 };
141
142 #define BLORP_CREATE_NIR_INPUT(shader, name, type) ({ \
143 nir_variable *input = nir_variable_create((shader), nir_var_shader_in, \
144 type, #name); \
145 if ((shader)->stage == MESA_SHADER_FRAGMENT) \
146 input->data.interpolation = INTERP_MODE_FLAT; \
147 input->data.location = VARYING_SLOT_VAR0 + \
148 offsetof(struct brw_blorp_wm_inputs, name) / (4 * sizeof(float)); \
149 input->data.location_frac = \
150 (offsetof(struct brw_blorp_wm_inputs, name) / sizeof(float)) % 4; \
151 input; \
152 })
153
154 struct blorp_vs_inputs {
155 uint32_t base_layer;
156 uint32_t _instance_id; /* Set in hardware by SGVS */
157 uint32_t pad[2];
158 };
159
160 static inline unsigned
161 brw_blorp_get_urb_length(const struct brw_wm_prog_data *prog_data)
162 {
163 if (prog_data == NULL)
164 return 1;
165
166 /* From the BSpec: 3D Pipeline - Strips and Fans - 3DSTATE_SBE
167 *
168 * read_length = ceiling((max_source_attr+1)/2)
169 */
170 return MAX2((prog_data->num_varying_inputs + 1) / 2, 1);
171 }
172
173 struct blorp_params
174 {
175 uint32_t x0;
176 uint32_t y0;
177 uint32_t x1;
178 uint32_t y1;
179 float z;
180 uint8_t stencil_mask;
181 uint8_t stencil_ref;
182 struct brw_blorp_surface_info depth;
183 struct brw_blorp_surface_info stencil;
184 uint32_t depth_format;
185 struct brw_blorp_surface_info src;
186 struct brw_blorp_surface_info dst;
187 enum blorp_hiz_op hiz_op;
188 enum blorp_fast_clear_op fast_clear_op;
189 bool color_write_disable[4];
190 struct brw_blorp_wm_inputs wm_inputs;
191 struct blorp_vs_inputs vs_inputs;
192 unsigned num_samples;
193 unsigned num_draw_buffers;
194 unsigned num_layers;
195 uint32_t vs_prog_kernel;
196 struct brw_vs_prog_data *vs_prog_data;
197 uint32_t sf_prog_kernel;
198 struct brw_sf_prog_data *sf_prog_data;
199 uint32_t wm_prog_kernel;
200 struct brw_wm_prog_data *wm_prog_data;
201
202 bool use_pre_baked_binding_table;
203 uint32_t pre_baked_binding_table_offset;
204 };
205
206 void blorp_params_init(struct blorp_params *params);
207
208 enum blorp_shader_type {
209 BLORP_SHADER_TYPE_BLIT,
210 BLORP_SHADER_TYPE_CLEAR,
211 BLORP_SHADER_TYPE_LAYER_OFFSET_VS,
212 BLORP_SHADER_TYPE_GEN4_SF,
213 };
214
215 struct brw_blorp_blit_prog_key
216 {
217 enum blorp_shader_type shader_type; /* Must be BLORP_SHADER_TYPE_BLIT */
218
219 /* Number of samples per pixel that have been configured in the surface
220 * state for texturing from.
221 */
222 unsigned tex_samples;
223
224 /* MSAA layout that has been configured in the surface state for texturing
225 * from.
226 */
227 enum isl_msaa_layout tex_layout;
228
229 enum isl_aux_usage tex_aux_usage;
230
231 /* Actual number of samples per pixel in the source image. */
232 unsigned src_samples;
233
234 /* Actual MSAA layout used by the source image. */
235 enum isl_msaa_layout src_layout;
236
237 /* Number of bits per channel in the source image. */
238 uint8_t src_bpc;
239
240 /* True if the source requires normalized coordinates */
241 bool src_coords_normalized;
242
243 /* Number of samples per pixel that have been configured in the render
244 * target.
245 */
246 unsigned rt_samples;
247
248 /* MSAA layout that has been configured in the render target. */
249 enum isl_msaa_layout rt_layout;
250
251 /* Actual number of samples per pixel in the destination image. */
252 unsigned dst_samples;
253
254 /* Actual MSAA layout used by the destination image. */
255 enum isl_msaa_layout dst_layout;
256
257 /* Number of bits per channel in the destination image. */
258 uint8_t dst_bpc;
259
260 /* Type of the data to be read from the texture (one of
261 * nir_type_(int|uint|float)).
262 */
263 nir_alu_type texture_data_type;
264
265 /* True if the source image is W tiled. If true, the surface state for the
266 * source image must be configured as Y tiled, and tex_samples must be 0.
267 */
268 bool src_tiled_w;
269
270 /* True if the destination image is W tiled. If true, the surface state
271 * for the render target must be configured as Y tiled, and rt_samples must
272 * be 0.
273 */
274 bool dst_tiled_w;
275
276 /* True if the destination is an RGB format. If true, the surface state
277 * for the render target must be configured as red with three times the
278 * normal width. We need to do this because you cannot render to
279 * non-power-of-two formats.
280 */
281 bool dst_rgb;
282
283 /* True if all source samples should be blended together to produce each
284 * destination pixel. If true, src_tiled_w must be false, tex_samples must
285 * equal src_samples, and tex_samples must be nonzero.
286 */
287 bool blend;
288
289 /* True if the rectangle being sent through the rendering pipeline might be
290 * larger than the destination rectangle, so the WM program should kill any
291 * pixels that are outside the destination rectangle.
292 */
293 bool use_kill;
294
295 /**
296 * True if the WM program should be run in MSDISPMODE_PERSAMPLE with more
297 * than one sample per pixel.
298 */
299 bool persample_msaa_dispatch;
300
301 /* True for scaled blitting. */
302 bool blit_scaled;
303
304 /* True if this blit operation may involve intratile offsets on the source.
305 * In this case, we need to add the offset before texturing.
306 */
307 bool need_src_offset;
308
309 /* True if this blit operation may involve intratile offsets on the
310 * destination. In this case, we need to add the offset to gl_FragCoord.
311 */
312 bool need_dst_offset;
313
314 /* Scale factors between the pixel grid and the grid of samples. We're
315 * using grid of samples for bilinear filetring in multisample scaled blits.
316 */
317 float x_scale;
318 float y_scale;
319
320 /* True for blits with filter = GL_LINEAR. */
321 bool bilinear_filter;
322 };
323
324 /**
325 * \name BLORP internals
326 * \{
327 *
328 * Used internally by gen6_blorp_exec() and gen7_blorp_exec().
329 */
330
331 void brw_blorp_init_wm_prog_key(struct brw_wm_prog_key *wm_key);
332
333 const unsigned *
334 blorp_compile_fs(struct blorp_context *blorp, void *mem_ctx,
335 struct nir_shader *nir,
336 struct brw_wm_prog_key *wm_key,
337 bool use_repclear,
338 struct brw_wm_prog_data *wm_prog_data,
339 unsigned *program_size);
340
341 const unsigned *
342 blorp_compile_vs(struct blorp_context *blorp, void *mem_ctx,
343 struct nir_shader *nir,
344 struct brw_vs_prog_data *vs_prog_data,
345 unsigned *program_size);
346
347 bool
348 blorp_ensure_sf_program(struct blorp_context *blorp,
349 struct blorp_params *params);
350
351 /** \} */
352
353 #ifdef __cplusplus
354 } /* end extern "C" */
355 #endif /* __cplusplus */
356
357 #endif /* BLORP_PRIV_H */