intel/blorp: Add support for binding an actual stencil buffer
[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 "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 enum blorp_fast_clear_op {
48 BLORP_FAST_CLEAR_OP_NONE = 0,
49 BLORP_FAST_CLEAR_OP_CLEAR,
50 BLORP_FAST_CLEAR_OP_RESOLVE_PARTIAL,
51 BLORP_FAST_CLEAR_OP_RESOLVE_FULL,
52 };
53
54 struct brw_blorp_surface_info
55 {
56 struct isl_surf surf;
57 struct blorp_address addr;
58
59 struct isl_surf aux_surf;
60 struct blorp_address aux_addr;
61 enum isl_aux_usage aux_usage;
62
63 union isl_color_value clear_color;
64
65 struct isl_view view;
66
67 /* Z offset into a 3-D texture or slice of a 2-D array texture. */
68 uint32_t z_offset;
69
70 uint32_t tile_x_sa, tile_y_sa;
71 };
72
73 void
74 brw_blorp_surface_info_init(struct blorp_context *blorp,
75 struct brw_blorp_surface_info *info,
76 const struct blorp_surf *surf,
77 unsigned int level, unsigned int layer,
78 enum isl_format format, bool is_render_target);
79
80
81 struct brw_blorp_coord_transform
82 {
83 float multiplier;
84 float offset;
85 };
86
87 /**
88 * Bounding rectangle telling pixel discard which pixels are not to be
89 * touched. This is needed in when surfaces are configured as something else
90 * what they really are:
91 *
92 * - writing W-tiled stencil as Y-tiled
93 * - writing interleaved multisampled as single sampled.
94 *
95 * See blorp_nir_discard_if_outside_rect().
96 */
97 struct brw_blorp_discard_rect
98 {
99 uint32_t x0;
100 uint32_t x1;
101 uint32_t y0;
102 uint32_t y1;
103 };
104
105 /**
106 * Grid needed for blended and scaled blits of integer formats, see
107 * blorp_nir_manual_blend_bilinear().
108 */
109 struct brw_blorp_rect_grid
110 {
111 float x1;
112 float y1;
113 float pad[2];
114 };
115
116 struct blorp_surf_offset {
117 uint32_t x;
118 uint32_t y;
119 };
120
121 struct brw_blorp_wm_inputs
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 /* Minimum layer setting works for all the textures types but texture_3d
131 * for which the setting has no effect. Use the z-coordinate instead.
132 */
133 uint32_t src_z;
134
135 /* Pad out to an integral number of registers */
136 uint32_t pad[1];
137 };
138
139 struct brw_blorp_prog_data
140 {
141 bool dispatch_8;
142 bool dispatch_16;
143
144 uint8_t first_curbe_grf_0;
145 uint8_t first_curbe_grf_2;
146
147 uint32_t ksp_offset_2;
148
149 /**
150 * True if the WM program should be run in MSDISPMODE_PERSAMPLE with more
151 * than one sample per pixel.
152 */
153 bool persample_msaa_dispatch;
154
155 /**
156 * Mask of which FS inputs are marked flat by the shader source. This is
157 * needed for setting up 3DSTATE_SF/SBE.
158 */
159 uint32_t flat_inputs;
160 unsigned num_varying_inputs;
161 uint64_t inputs_read;
162 };
163
164 static inline unsigned
165 brw_blorp_get_urb_length(const struct brw_blorp_prog_data *prog_data)
166 {
167 if (prog_data == NULL)
168 return 1;
169
170 /* From the BSpec: 3D Pipeline - Strips and Fans - 3DSTATE_SBE
171 *
172 * read_length = ceiling((max_source_attr+1)/2)
173 */
174 return MAX2((prog_data->num_varying_inputs + 1) / 2, 1);
175 }
176
177 struct blorp_params
178 {
179 uint32_t x0;
180 uint32_t y0;
181 uint32_t x1;
182 uint32_t y1;
183 float z;
184 struct brw_blorp_surface_info depth;
185 struct brw_blorp_surface_info stencil;
186 uint32_t depth_format;
187 struct brw_blorp_surface_info src;
188 struct brw_blorp_surface_info dst;
189 enum blorp_hiz_op hiz_op;
190 enum blorp_fast_clear_op fast_clear_op;
191 bool color_write_disable[4];
192 struct brw_blorp_wm_inputs wm_inputs;
193 unsigned num_draw_buffers;
194 unsigned num_layers;
195 uint32_t wm_prog_kernel;
196 struct brw_blorp_prog_data *wm_prog_data;
197 };
198
199 void blorp_params_init(struct blorp_params *params);
200
201 struct brw_blorp_blit_prog_key
202 {
203 /* Number of samples per pixel that have been configured in the surface
204 * state for texturing from.
205 */
206 unsigned tex_samples;
207
208 /* MSAA layout that has been configured in the surface state for texturing
209 * from.
210 */
211 enum isl_msaa_layout tex_layout;
212
213 enum isl_aux_usage tex_aux_usage;
214
215 /* Actual number of samples per pixel in the source image. */
216 unsigned src_samples;
217
218 /* Actual MSAA layout used by the source image. */
219 enum isl_msaa_layout src_layout;
220
221 /* Number of samples per pixel that have been configured in the render
222 * target.
223 */
224 unsigned rt_samples;
225
226 /* MSAA layout that has been configured in the render target. */
227 enum isl_msaa_layout rt_layout;
228
229 /* Actual number of samples per pixel in the destination image. */
230 unsigned dst_samples;
231
232 /* Actual MSAA layout used by the destination image. */
233 enum isl_msaa_layout dst_layout;
234
235 /* Type of the data to be read from the texture (one of
236 * nir_type_(int|uint|float)).
237 */
238 nir_alu_type texture_data_type;
239
240 /* True if the source image is W tiled. If true, the surface state for the
241 * source image must be configured as Y tiled, and tex_samples must be 0.
242 */
243 bool src_tiled_w;
244
245 /* True if the destination image is W tiled. If true, the surface state
246 * for the render target must be configured as Y tiled, and rt_samples must
247 * be 0.
248 */
249 bool dst_tiled_w;
250
251 /* True if the destination is an RGB format. If true, the surface state
252 * for the render target must be configured as red with three times the
253 * normal width. We need to do this because you cannot render to
254 * non-power-of-two formats.
255 */
256 bool dst_rgb;
257
258 /* True if all source samples should be blended together to produce each
259 * destination pixel. If true, src_tiled_w must be false, tex_samples must
260 * equal src_samples, and tex_samples must be nonzero.
261 */
262 bool blend;
263
264 /* True if the rectangle being sent through the rendering pipeline might be
265 * larger than the destination rectangle, so the WM program should kill any
266 * pixels that are outside the destination rectangle.
267 */
268 bool use_kill;
269
270 /**
271 * True if the WM program should be run in MSDISPMODE_PERSAMPLE with more
272 * than one sample per pixel.
273 */
274 bool persample_msaa_dispatch;
275
276 /* True for scaled blitting. */
277 bool blit_scaled;
278
279 /* True if this blit operation may involve intratile offsets on the source.
280 * In this case, we need to add the offset before texturing.
281 */
282 bool need_src_offset;
283
284 /* True if this blit operation may involve intratile offsets on the
285 * destination. In this case, we need to add the offset to gl_FragCoord.
286 */
287 bool need_dst_offset;
288
289 /* Scale factors between the pixel grid and the grid of samples. We're
290 * using grid of samples for bilinear filetring in multisample scaled blits.
291 */
292 float x_scale;
293 float y_scale;
294
295 /* True for blits with filter = GL_LINEAR. */
296 bool bilinear_filter;
297 };
298
299 /**
300 * \name BLORP internals
301 * \{
302 *
303 * Used internally by gen6_blorp_exec() and gen7_blorp_exec().
304 */
305
306 void brw_blorp_init_wm_prog_key(struct brw_wm_prog_key *wm_key);
307
308 const unsigned *
309 brw_blorp_compile_nir_shader(struct blorp_context *blorp, struct nir_shader *nir,
310 const struct brw_wm_prog_key *wm_key,
311 bool use_repclear,
312 struct brw_blorp_prog_data *prog_data,
313 unsigned *program_size);
314
315 /** \} */
316
317 #ifdef __cplusplus
318 } /* end extern "C" */
319 #endif /* __cplusplus */
320
321 #endif /* BLORP_PRIV_H */