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