2 * Copyright © 2012 Intel Corporation
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:
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
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
29 #include "compiler/nir/nir.h"
30 #include "brw_compiler.h"
39 * Binding table indices used by BLORP.
42 BLORP_RENDERBUFFER_BT_INDEX
,
43 BLORP_TEXTURE_BT_INDEX
,
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
,
54 struct brw_blorp_surface_info
59 struct blorp_address addr
;
61 struct isl_surf aux_surf
;
62 struct blorp_address aux_addr
;
63 enum isl_aux_usage aux_usage
;
65 union isl_color_value clear_color
;
69 /* Z offset into a 3-D texture or slice of a 2-D array texture. */
72 uint32_t tile_x_sa
, tile_y_sa
;
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
);
83 struct brw_blorp_coord_transform
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:
94 * - writing W-tiled stencil as Y-tiled
95 * - writing interleaved multisampled as single sampled.
97 * See blorp_nir_discard_if_outside_rect().
99 struct brw_blorp_discard_rect
108 * Grid needed for blended and scaled blits of integer formats, see
109 * blorp_nir_manual_blend_bilinear().
111 struct brw_blorp_rect_grid
118 struct blorp_surf_offset
{
123 struct brw_blorp_wm_inputs
125 uint32_t clear_color
[4];
127 struct brw_blorp_discard_rect discard_rect
;
128 struct brw_blorp_rect_grid rect_grid
;
129 struct brw_blorp_coord_transform coord_transform
[2];
131 struct blorp_surf_offset src_offset
;
132 struct blorp_surf_offset dst_offset
;
134 /* Minimum layer setting works for all the textures types but texture_3d
135 * for which the setting has no effect. Use the z-coordinate instead.
139 /* Pad out to an integral number of registers */
143 #define BLORP_CREATE_NIR_INPUT(shader, name, type) ({ \
144 nir_variable *input = nir_variable_create((shader), nir_var_shader_in, \
146 if ((shader)->stage == MESA_SHADER_FRAGMENT) \
147 input->data.interpolation = INTERP_MODE_FLAT; \
148 input->data.location = VARYING_SLOT_VAR0 + \
149 offsetof(struct brw_blorp_wm_inputs, name) / (4 * sizeof(float)); \
150 input->data.location_frac = \
151 (offsetof(struct brw_blorp_wm_inputs, name) / sizeof(float)) % 4; \
155 static inline unsigned
156 brw_blorp_get_urb_length(const struct brw_wm_prog_data
*prog_data
)
158 if (prog_data
== NULL
)
161 /* From the BSpec: 3D Pipeline - Strips and Fans - 3DSTATE_SBE
163 * read_length = ceiling((max_source_attr+1)/2)
165 return MAX2((prog_data
->num_varying_inputs
+ 1) / 2, 1);
175 uint8_t stencil_mask
;
177 struct brw_blorp_surface_info depth
;
178 struct brw_blorp_surface_info stencil
;
179 uint32_t depth_format
;
180 struct brw_blorp_surface_info src
;
181 struct brw_blorp_surface_info dst
;
182 enum blorp_hiz_op hiz_op
;
183 enum blorp_fast_clear_op fast_clear_op
;
184 bool color_write_disable
[4];
185 struct brw_blorp_wm_inputs wm_inputs
;
186 unsigned num_samples
;
187 unsigned num_draw_buffers
;
189 uint32_t wm_prog_kernel
;
190 struct brw_wm_prog_data
*wm_prog_data
;
193 void blorp_params_init(struct blorp_params
*params
);
195 enum blorp_shader_type
{
196 BLORP_SHADER_TYPE_BLIT
,
197 BLORP_SHADER_TYPE_CLEAR
,
200 struct brw_blorp_blit_prog_key
202 enum blorp_shader_type shader_type
; /* Must be BLORP_SHADER_TYPE_BLIT */
204 /* Number of samples per pixel that have been configured in the surface
205 * state for texturing from.
207 unsigned tex_samples
;
209 /* MSAA layout that has been configured in the surface state for texturing
212 enum isl_msaa_layout tex_layout
;
214 enum isl_aux_usage tex_aux_usage
;
216 /* Actual number of samples per pixel in the source image. */
217 unsigned src_samples
;
219 /* Actual MSAA layout used by the source image. */
220 enum isl_msaa_layout src_layout
;
222 /* Number of samples per pixel that have been configured in the render
227 /* MSAA layout that has been configured in the render target. */
228 enum isl_msaa_layout rt_layout
;
230 /* Actual number of samples per pixel in the destination image. */
231 unsigned dst_samples
;
233 /* Actual MSAA layout used by the destination image. */
234 enum isl_msaa_layout dst_layout
;
236 /* Type of the data to be read from the texture (one of
237 * nir_type_(int|uint|float)).
239 nir_alu_type texture_data_type
;
241 /* True if the source image is W tiled. If true, the surface state for the
242 * source image must be configured as Y tiled, and tex_samples must be 0.
246 /* True if the destination image is W tiled. If true, the surface state
247 * for the render target must be configured as Y tiled, and rt_samples must
252 /* True if the destination is an RGB format. If true, the surface state
253 * for the render target must be configured as red with three times the
254 * normal width. We need to do this because you cannot render to
255 * non-power-of-two formats.
259 /* True if all source samples should be blended together to produce each
260 * destination pixel. If true, src_tiled_w must be false, tex_samples must
261 * equal src_samples, and tex_samples must be nonzero.
265 /* True if the rectangle being sent through the rendering pipeline might be
266 * larger than the destination rectangle, so the WM program should kill any
267 * pixels that are outside the destination rectangle.
272 * True if the WM program should be run in MSDISPMODE_PERSAMPLE with more
273 * than one sample per pixel.
275 bool persample_msaa_dispatch
;
277 /* True for scaled blitting. */
280 /* True if this blit operation may involve intratile offsets on the source.
281 * In this case, we need to add the offset before texturing.
283 bool need_src_offset
;
285 /* True if this blit operation may involve intratile offsets on the
286 * destination. In this case, we need to add the offset to gl_FragCoord.
288 bool need_dst_offset
;
290 /* Scale factors between the pixel grid and the grid of samples. We're
291 * using grid of samples for bilinear filetring in multisample scaled blits.
296 /* True for blits with filter = GL_LINEAR. */
297 bool bilinear_filter
;
301 * \name BLORP internals
304 * Used internally by gen6_blorp_exec() and gen7_blorp_exec().
307 void brw_blorp_init_wm_prog_key(struct brw_wm_prog_key
*wm_key
);
310 blorp_compile_fs(struct blorp_context
*blorp
, void *mem_ctx
,
311 struct nir_shader
*nir
,
312 const struct brw_wm_prog_key
*wm_key
,
314 struct brw_wm_prog_data
*wm_prog_data
,
315 unsigned *program_size
);
320 } /* end extern "C" */
321 #endif /* __cplusplus */
323 #endif /* BLORP_PRIV_H */