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