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