i965/blorp: Get rid of brw_context
[mesa.git] / src / mesa / drivers / dri / i965 / 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 #pragma once
25
26 #include <stdint.h>
27
28 #include "compiler/nir/nir.h"
29
30 #include "blorp.h"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 /**
37 * Binding table indices used by BLORP.
38 */
39 enum {
40 BLORP_RENDERBUFFER_BT_INDEX,
41 BLORP_TEXTURE_BT_INDEX,
42 BLORP_NUM_BT_ENTRIES
43 };
44
45 struct brw_blorp_surface_info
46 {
47 struct isl_surf surf;
48 struct blorp_address addr;
49
50 struct isl_surf aux_surf;
51 struct blorp_address aux_addr;
52 enum isl_aux_usage aux_usage;
53
54 union isl_color_value clear_color;
55
56 struct isl_view view;
57
58 /* Z offset into a 3-D texture or slice of a 2-D array texture. */
59 uint32_t z_offset;
60
61 uint32_t tile_x_sa, tile_y_sa;
62 };
63
64 void
65 brw_blorp_surface_info_init(struct blorp_context *blorp,
66 struct brw_blorp_surface_info *info,
67 const struct brw_blorp_surf *surf,
68 unsigned int level, unsigned int layer,
69 enum isl_format format, bool is_render_target);
70
71
72 struct brw_blorp_coord_transform
73 {
74 float multiplier;
75 float offset;
76 };
77
78 /**
79 * Bounding rectangle telling pixel discard which pixels are not to be
80 * touched. This is needed in when surfaces are configured as something else
81 * what they really are:
82 *
83 * - writing W-tiled stencil as Y-tiled
84 * - writing interleaved multisampled as single sampled.
85 *
86 * See blorp_nir_discard_if_outside_rect().
87 */
88 struct brw_blorp_discard_rect
89 {
90 uint32_t x0;
91 uint32_t x1;
92 uint32_t y0;
93 uint32_t y1;
94 };
95
96 /**
97 * Grid needed for blended and scaled blits of integer formats, see
98 * blorp_nir_manual_blend_bilinear().
99 */
100 struct brw_blorp_rect_grid
101 {
102 float x1;
103 float y1;
104 float pad[2];
105 };
106
107 struct brw_blorp_wm_inputs
108 {
109 struct brw_blorp_discard_rect discard_rect;
110 struct brw_blorp_rect_grid rect_grid;
111 struct brw_blorp_coord_transform coord_transform[2];
112
113 /* Minimum layer setting works for all the textures types but texture_3d
114 * for which the setting has no effect. Use the z-coordinate instead.
115 */
116 uint32_t src_z;
117
118 /* Pad out to an integral number of registers */
119 uint32_t pad[3];
120 };
121
122 struct brw_blorp_prog_data
123 {
124 bool dispatch_8;
125 bool dispatch_16;
126
127 uint8_t first_curbe_grf_0;
128 uint8_t first_curbe_grf_2;
129
130 uint32_t ksp_offset_2;
131
132 /**
133 * True if the WM program should be run in MSDISPMODE_PERSAMPLE with more
134 * than one sample per pixel.
135 */
136 bool persample_msaa_dispatch;
137
138 /**
139 * Mask of which FS inputs are marked flat by the shader source. This is
140 * needed for setting up 3DSTATE_SF/SBE.
141 */
142 uint32_t flat_inputs;
143 unsigned num_varying_inputs;
144 uint64_t inputs_read;
145 };
146
147 static inline unsigned
148 brw_blorp_get_urb_length(const struct brw_blorp_prog_data *prog_data)
149 {
150 if (prog_data == NULL)
151 return 1;
152
153 /* From the BSpec: 3D Pipeline - Strips and Fans - 3DSTATE_SBE
154 *
155 * read_length = ceiling((max_source_attr+1)/2)
156 */
157 return MAX2((prog_data->num_varying_inputs + 1) / 2, 1);
158 }
159
160 struct brw_blorp_params
161 {
162 uint32_t x0;
163 uint32_t y0;
164 uint32_t x1;
165 uint32_t y1;
166 struct brw_blorp_surface_info depth;
167 uint32_t depth_format;
168 struct brw_blorp_surface_info src;
169 struct brw_blorp_surface_info dst;
170 enum gen6_hiz_op hiz_op;
171 union {
172 unsigned fast_clear_op;
173 unsigned resolve_type;
174 };
175 bool color_write_disable[4];
176 struct brw_blorp_wm_inputs wm_inputs;
177 unsigned num_draw_buffers;
178 unsigned num_layers;
179 uint32_t wm_prog_kernel;
180 struct brw_blorp_prog_data *wm_prog_data;
181 };
182
183 void
184 brw_blorp_params_init(struct brw_blorp_params *params);
185
186 struct brw_blorp_blit_prog_key
187 {
188 /* Number of samples per pixel that have been configured in the surface
189 * state for texturing from.
190 */
191 unsigned tex_samples;
192
193 /* MSAA layout that has been configured in the surface state for texturing
194 * from.
195 */
196 enum isl_msaa_layout tex_layout;
197
198 enum isl_aux_usage tex_aux_usage;
199
200 /* Actual number of samples per pixel in the source image. */
201 unsigned src_samples;
202
203 /* Actual MSAA layout used by the source image. */
204 enum isl_msaa_layout src_layout;
205
206 /* Number of samples per pixel that have been configured in the render
207 * target.
208 */
209 unsigned rt_samples;
210
211 /* MSAA layout that has been configured in the render target. */
212 enum isl_msaa_layout rt_layout;
213
214 /* Actual number of samples per pixel in the destination image. */
215 unsigned dst_samples;
216
217 /* Actual MSAA layout used by the destination image. */
218 enum isl_msaa_layout dst_layout;
219
220 /* Type of the data to be read from the texture (one of
221 * nir_type_(int|uint|float)).
222 */
223 nir_alu_type texture_data_type;
224
225 /* True if the source image is W tiled. If true, the surface state for the
226 * source image must be configured as Y tiled, and tex_samples must be 0.
227 */
228 bool src_tiled_w;
229
230 /* True if the destination image is W tiled. If true, the surface state
231 * for the render target must be configured as Y tiled, and rt_samples must
232 * be 0.
233 */
234 bool dst_tiled_w;
235
236 /* True if all source samples should be blended together to produce each
237 * destination pixel. If true, src_tiled_w must be false, tex_samples must
238 * equal src_samples, and tex_samples must be nonzero.
239 */
240 bool blend;
241
242 /* True if the rectangle being sent through the rendering pipeline might be
243 * larger than the destination rectangle, so the WM program should kill any
244 * pixels that are outside the destination rectangle.
245 */
246 bool use_kill;
247
248 /**
249 * True if the WM program should be run in MSDISPMODE_PERSAMPLE with more
250 * than one sample per pixel.
251 */
252 bool persample_msaa_dispatch;
253
254 /* True for scaled blitting. */
255 bool blit_scaled;
256
257 /* Scale factors between the pixel grid and the grid of samples. We're
258 * using grid of samples for bilinear filetring in multisample scaled blits.
259 */
260 float x_scale;
261 float y_scale;
262
263 /* True for blits with filter = GL_LINEAR. */
264 bool bilinear_filter;
265 };
266
267 /**
268 * \name BLORP internals
269 * \{
270 *
271 * Used internally by gen6_blorp_exec() and gen7_blorp_exec().
272 */
273
274 void brw_blorp_init_wm_prog_key(struct brw_wm_prog_key *wm_key);
275
276 const unsigned *
277 brw_blorp_compile_nir_shader(struct blorp_context *blorp, struct nir_shader *nir,
278 const struct brw_wm_prog_key *wm_key,
279 bool use_repclear,
280 struct brw_blorp_prog_data *prog_data,
281 unsigned *program_size);
282
283 /** \} */
284
285 #ifdef __cplusplus
286 } /* end extern "C" */
287 #endif /* __cplusplus */