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
24 #include "main/context.h"
25 #include "main/teximage.h"
26 #include "main/blend.h"
27 #include "main/fbobject.h"
28 #include "main/renderbuffer.h"
29 #include "main/glformats.h"
31 #include "brw_blorp.h"
32 #include "brw_context.h"
33 #include "brw_meta_util.h"
34 #include "brw_state.h"
35 #include "intel_fbo.h"
36 #include "intel_debug.h"
38 #define FILE_DEBUG_FLAG DEBUG_BLORP
41 apply_gen6_stencil_hiz_offset(struct isl_surf
*surf
,
42 struct intel_mipmap_tree
*mt
,
46 assert(mt
->array_layout
== ALL_SLICES_AT_EACH_LOD
);
48 if (mt
->format
== MESA_FORMAT_S_UINT8
) {
49 /* Note: we can't compute the stencil offset using
50 * intel_miptree_get_aligned_offset(), because the miptree
51 * claims that the region is untiled even though it's W tiled.
53 *offset
= mt
->level
[lod
].level_y
* mt
->pitch
+
54 mt
->level
[lod
].level_x
* 64;
56 *offset
= intel_miptree_get_aligned_offset(mt
,
57 mt
->level
[lod
].level_x
,
58 mt
->level
[lod
].level_y
,
62 surf
->logical_level0_px
.width
= minify(surf
->logical_level0_px
.width
, lod
);
63 surf
->logical_level0_px
.height
= minify(surf
->logical_level0_px
.height
, lod
);
64 surf
->phys_level0_sa
.width
= minify(surf
->phys_level0_sa
.width
, lod
);
65 surf
->phys_level0_sa
.height
= minify(surf
->phys_level0_sa
.height
, lod
);
67 surf
->array_pitch_el_rows
=
68 ALIGN(surf
->phys_level0_sa
.height
, surf
->image_alignment_el
.height
);
72 brw_blorp_surf_for_miptree(struct brw_context
*brw
,
73 struct brw_blorp_surf
*surf
,
74 struct intel_mipmap_tree
*mt
,
75 bool is_render_target
,
77 struct isl_surf tmp_surfs
[2])
79 intel_miptree_get_isl_surf(brw
, mt
, &tmp_surfs
[0]);
80 surf
->surf
= &tmp_surfs
[0];
82 surf
->offset
= mt
->offset
;
84 if (brw
->gen
== 6 && mt
->format
== MESA_FORMAT_S_UINT8
&&
85 mt
->array_layout
== ALL_SLICES_AT_EACH_LOD
) {
86 /* Sandy bridge stencil and HiZ use this ALL_SLICES_AT_EACH_LOD hack in
87 * order to allow for layered rendering. The hack makes each LOD of the
88 * stencil or HiZ buffer a single tightly packed array surface at some
89 * offset into the surface. Since ISL doesn't know how to deal with the
90 * crazy ALL_SLICES_AT_EACH_LOD layout and since we have to do a manual
91 * offset of it anyway, we might as well do the offset here and keep the
92 * hacks inside the i965 driver.
94 * See also gen6_depth_stencil_state.c
97 apply_gen6_stencil_hiz_offset(&tmp_surfs
[0], mt
, *level
, &offset
);
98 surf
->offset
+= offset
;
102 struct isl_surf
*aux_surf
= &tmp_surfs
[1];
103 intel_miptree_get_aux_isl_surf(brw
, mt
, aux_surf
, &surf
->aux_usage
);
105 /* For textures that are in the RESOLVED state, we ignore the MCS */
106 if (mt
->mcs_mt
&& !is_render_target
&&
107 mt
->fast_clear_state
== INTEL_FAST_CLEAR_STATE_RESOLVED
)
108 surf
->aux_usage
= ISL_AUX_USAGE_NONE
;
110 if (surf
->aux_usage
!= ISL_AUX_USAGE_NONE
) {
111 /* We only really need a clear color if we also have an auxiliary
112 * surface. Without one, it does nothing.
114 surf
->clear_color
= intel_miptree_get_isl_clear_color(brw
, mt
);
116 surf
->aux_surf
= aux_surf
;
118 surf
->aux_bo
= mt
->mcs_mt
->bo
;
119 surf
->aux_offset
= mt
->mcs_mt
->offset
;
121 assert(surf
->aux_usage
== ISL_AUX_USAGE_HIZ
);
122 struct intel_mipmap_tree
*hiz_mt
= mt
->hiz_buf
->mt
;
124 surf
->aux_bo
= hiz_mt
->bo
;
126 hiz_mt
->array_layout
== ALL_SLICES_AT_EACH_LOD
) {
127 /* gen6 requires the HiZ buffer to be manually offset to the
128 * right location. We could fixup the surf but it doesn't
129 * matter since most of those fields don't matter.
131 apply_gen6_stencil_hiz_offset(aux_surf
, hiz_mt
, *level
,
134 surf
->aux_offset
= 0;
136 assert(hiz_mt
->pitch
== aux_surf
->row_pitch
);
138 surf
->aux_bo
= mt
->hiz_buf
->bo
;
139 surf
->aux_offset
= 0;
144 surf
->aux_offset
= 0;
145 memset(&surf
->clear_color
, 0, sizeof(surf
->clear_color
));
147 assert((surf
->aux_usage
== ISL_AUX_USAGE_NONE
) == (surf
->aux_bo
== NULL
));
150 static enum isl_format
151 brw_blorp_to_isl_format(struct brw_context
*brw
, mesa_format format
,
152 bool is_render_target
)
155 case MESA_FORMAT_NONE
:
156 return ISL_FORMAT_UNSUPPORTED
;
157 case MESA_FORMAT_S_UINT8
:
158 return ISL_FORMAT_R8_UINT
;
159 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
160 return ISL_FORMAT_R24_UNORM_X8_TYPELESS
;
161 case MESA_FORMAT_Z_FLOAT32
:
162 return ISL_FORMAT_R32_FLOAT
;
163 case MESA_FORMAT_Z_UNORM16
:
164 return ISL_FORMAT_R16_UNORM
;
166 if (is_render_target
) {
167 assert(brw
->format_supported_as_render_target
[format
]);
168 return brw
->render_target_format
[format
];
170 return brw_format_for_mesa_format(format
);
178 * Note: if the src (or dst) is a 2D multisample array texture on Gen7+ using
179 * INTEL_MSAA_LAYOUT_UMS or INTEL_MSAA_LAYOUT_CMS, src_layer (dst_layer) is
180 * the physical layer holding sample 0. So, for example, if
181 * src_mt->num_samples == 4, then logical layer n corresponds to src_layer ==
185 brw_blorp_blit_miptrees(struct brw_context
*brw
,
186 struct intel_mipmap_tree
*src_mt
,
187 unsigned src_level
, unsigned src_layer
,
188 mesa_format src_format
, int src_swizzle
,
189 struct intel_mipmap_tree
*dst_mt
,
190 unsigned dst_level
, unsigned dst_layer
,
191 mesa_format dst_format
,
192 float src_x0
, float src_y0
,
193 float src_x1
, float src_y1
,
194 float dst_x0
, float dst_y0
,
195 float dst_x1
, float dst_y1
,
196 GLenum filter
, bool mirror_x
, bool mirror_y
,
197 bool decode_srgb
, bool encode_srgb
)
199 /* Get ready to blit. This includes depth resolving the src and dst
200 * buffers if necessary. Note: it's not necessary to do a color resolve on
201 * the destination buffer because we use the standard render path to render
202 * to destination color buffers, and the standard render path is
205 intel_miptree_resolve_color(brw
, src_mt
, INTEL_MIPTREE_IGNORE_CCS_E
);
206 intel_miptree_slice_resolve_depth(brw
, src_mt
, src_level
, src_layer
);
207 intel_miptree_slice_resolve_depth(brw
, dst_mt
, dst_level
, dst_layer
);
209 intel_miptree_prepare_mcs(brw
, dst_mt
);
211 DBG("%s from %dx %s mt %p %d %d (%f,%f) (%f,%f)"
212 "to %dx %s mt %p %d %d (%f,%f) (%f,%f) (flip %d,%d)\n",
214 src_mt
->num_samples
, _mesa_get_format_name(src_mt
->format
), src_mt
,
215 src_level
, src_layer
, src_x0
, src_y0
, src_x1
, src_y1
,
216 dst_mt
->num_samples
, _mesa_get_format_name(dst_mt
->format
), dst_mt
,
217 dst_level
, dst_layer
, dst_x0
, dst_y0
, dst_x1
, dst_y1
,
220 if (!decode_srgb
&& _mesa_get_format_color_encoding(src_format
) == GL_SRGB
)
221 src_format
= _mesa_get_srgb_format_linear(src_format
);
223 if (!encode_srgb
&& _mesa_get_format_color_encoding(dst_format
) == GL_SRGB
)
224 dst_format
= _mesa_get_srgb_format_linear(dst_format
);
226 /* When doing a multisample resolve of a GL_LUMINANCE32F or GL_INTENSITY32F
227 * texture, the above code configures the source format for L32_FLOAT or
228 * I32_FLOAT, and the destination format for R32_FLOAT. On Sandy Bridge,
229 * the SAMPLE message appears to handle multisampled L32_FLOAT and
230 * I32_FLOAT textures incorrectly, resulting in blocky artifacts. So work
231 * around the problem by using a source format of R32_FLOAT. This
232 * shouldn't affect rendering correctness, since the destination format is
233 * R32_FLOAT, so only the contents of the red channel matters.
236 src_mt
->num_samples
> 1 && dst_mt
->num_samples
<= 1 &&
237 src_mt
->format
== dst_mt
->format
&&
238 (dst_format
== MESA_FORMAT_L_FLOAT32
||
239 dst_format
== MESA_FORMAT_I_FLOAT32
)) {
240 src_format
= dst_format
= MESA_FORMAT_R_FLOAT32
;
243 intel_miptree_check_level_layer(src_mt
, src_level
, src_layer
);
244 intel_miptree_check_level_layer(dst_mt
, dst_level
, dst_layer
);
245 intel_miptree_used_for_rendering(dst_mt
);
247 struct isl_surf tmp_surfs
[4];
248 struct brw_blorp_surf src_surf
, dst_surf
;
249 brw_blorp_surf_for_miptree(brw
, &src_surf
, src_mt
, false,
250 &src_level
, &tmp_surfs
[0]);
251 brw_blorp_surf_for_miptree(brw
, &dst_surf
, dst_mt
, true,
252 &dst_level
, &tmp_surfs
[2]);
254 brw_blorp_blit(brw
, &src_surf
, src_level
, src_layer
,
255 brw_blorp_to_isl_format(brw
, src_format
, false), src_swizzle
,
256 &dst_surf
, dst_level
, dst_layer
,
257 brw_blorp_to_isl_format(brw
, dst_format
, true),
258 src_x0
, src_y0
, src_x1
, src_y1
,
259 dst_x0
, dst_y0
, dst_x1
, dst_y1
,
260 filter
, mirror_x
, mirror_y
);
262 intel_miptree_slice_set_needs_hiz_resolve(dst_mt
, dst_level
, dst_layer
);
264 if (intel_miptree_is_lossless_compressed(brw
, dst_mt
))
265 dst_mt
->fast_clear_state
= INTEL_FAST_CLEAR_STATE_UNRESOLVED
;
268 static struct intel_mipmap_tree
*
269 find_miptree(GLbitfield buffer_bit
, struct intel_renderbuffer
*irb
)
271 struct intel_mipmap_tree
*mt
= irb
->mt
;
272 if (buffer_bit
== GL_STENCIL_BUFFER_BIT
&& mt
->stencil_mt
)
278 blorp_get_texture_swizzle(const struct intel_renderbuffer
*irb
)
280 return irb
->Base
.Base
._BaseFormat
== GL_RGB
?
281 MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_ONE
) :
286 do_blorp_blit(struct brw_context
*brw
, GLbitfield buffer_bit
,
287 struct intel_renderbuffer
*src_irb
, mesa_format src_format
,
288 struct intel_renderbuffer
*dst_irb
, mesa_format dst_format
,
289 GLfloat srcX0
, GLfloat srcY0
, GLfloat srcX1
, GLfloat srcY1
,
290 GLfloat dstX0
, GLfloat dstY0
, GLfloat dstX1
, GLfloat dstY1
,
291 GLenum filter
, bool mirror_x
, bool mirror_y
)
293 const struct gl_context
*ctx
= &brw
->ctx
;
295 /* Find source/dst miptrees */
296 struct intel_mipmap_tree
*src_mt
= find_miptree(buffer_bit
, src_irb
);
297 struct intel_mipmap_tree
*dst_mt
= find_miptree(buffer_bit
, dst_irb
);
299 const bool do_srgb
= ctx
->Color
.sRGBEnabled
;
302 brw_blorp_blit_miptrees(brw
,
303 src_mt
, src_irb
->mt_level
, src_irb
->mt_layer
,
304 src_format
, blorp_get_texture_swizzle(src_irb
),
305 dst_mt
, dst_irb
->mt_level
, dst_irb
->mt_layer
,
307 srcX0
, srcY0
, srcX1
, srcY1
,
308 dstX0
, dstY0
, dstX1
, dstY1
,
309 filter
, mirror_x
, mirror_y
,
312 dst_irb
->need_downsample
= true;
316 try_blorp_blit(struct brw_context
*brw
,
317 const struct gl_framebuffer
*read_fb
,
318 const struct gl_framebuffer
*draw_fb
,
319 GLfloat srcX0
, GLfloat srcY0
, GLfloat srcX1
, GLfloat srcY1
,
320 GLfloat dstX0
, GLfloat dstY0
, GLfloat dstX1
, GLfloat dstY1
,
321 GLenum filter
, GLbitfield buffer_bit
)
323 struct gl_context
*ctx
= &brw
->ctx
;
325 /* Sync up the state of window system buffers. We need to do this before
326 * we go looking for the buffers.
328 intel_prepare_render(brw
);
330 bool mirror_x
, mirror_y
;
331 if (brw_meta_mirror_clip_and_scissor(ctx
, read_fb
, draw_fb
,
332 &srcX0
, &srcY0
, &srcX1
, &srcY1
,
333 &dstX0
, &dstY0
, &dstX1
, &dstY1
,
334 &mirror_x
, &mirror_y
))
338 struct intel_renderbuffer
*src_irb
;
339 struct intel_renderbuffer
*dst_irb
;
340 struct intel_mipmap_tree
*src_mt
;
341 struct intel_mipmap_tree
*dst_mt
;
342 switch (buffer_bit
) {
343 case GL_COLOR_BUFFER_BIT
:
344 src_irb
= intel_renderbuffer(read_fb
->_ColorReadBuffer
);
345 for (unsigned i
= 0; i
< draw_fb
->_NumColorDrawBuffers
; ++i
) {
346 dst_irb
= intel_renderbuffer(draw_fb
->_ColorDrawBuffers
[i
]);
348 do_blorp_blit(brw
, buffer_bit
,
349 src_irb
, src_irb
->Base
.Base
.Format
,
350 dst_irb
, dst_irb
->Base
.Base
.Format
,
351 srcX0
, srcY0
, srcX1
, srcY1
,
352 dstX0
, dstY0
, dstX1
, dstY1
,
353 filter
, mirror_x
, mirror_y
);
356 case GL_DEPTH_BUFFER_BIT
:
358 intel_renderbuffer(read_fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
360 intel_renderbuffer(draw_fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
361 src_mt
= find_miptree(buffer_bit
, src_irb
);
362 dst_mt
= find_miptree(buffer_bit
, dst_irb
);
364 /* We can't handle format conversions between Z24 and other formats
365 * since we have to lie about the surface format. See the comments in
366 * brw_blorp_surface_info::set().
368 if ((src_mt
->format
== MESA_FORMAT_Z24_UNORM_X8_UINT
) !=
369 (dst_mt
->format
== MESA_FORMAT_Z24_UNORM_X8_UINT
))
372 do_blorp_blit(brw
, buffer_bit
, src_irb
, MESA_FORMAT_NONE
,
373 dst_irb
, MESA_FORMAT_NONE
, srcX0
, srcY0
,
374 srcX1
, srcY1
, dstX0
, dstY0
, dstX1
, dstY1
,
375 filter
, mirror_x
, mirror_y
);
377 case GL_STENCIL_BUFFER_BIT
:
379 intel_renderbuffer(read_fb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
381 intel_renderbuffer(draw_fb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
382 do_blorp_blit(brw
, buffer_bit
, src_irb
, MESA_FORMAT_NONE
,
383 dst_irb
, MESA_FORMAT_NONE
, srcX0
, srcY0
,
384 srcX1
, srcY1
, dstX0
, dstY0
, dstX1
, dstY1
,
385 filter
, mirror_x
, mirror_y
);
388 unreachable("not reached");
395 brw_blorp_copytexsubimage(struct brw_context
*brw
,
396 struct gl_renderbuffer
*src_rb
,
397 struct gl_texture_image
*dst_image
,
399 int srcX0
, int srcY0
,
400 int dstX0
, int dstY0
,
401 int width
, int height
)
403 struct gl_context
*ctx
= &brw
->ctx
;
404 struct intel_renderbuffer
*src_irb
= intel_renderbuffer(src_rb
);
405 struct intel_texture_image
*intel_image
= intel_texture_image(dst_image
);
407 /* No pixel transfer operations (zoom, bias, mapping), just a blit */
408 if (brw
->ctx
._ImageTransferState
)
411 /* Sync up the state of window system buffers. We need to do this before
412 * we go looking at the src renderbuffer's miptree.
414 intel_prepare_render(brw
);
416 struct intel_mipmap_tree
*src_mt
= src_irb
->mt
;
417 struct intel_mipmap_tree
*dst_mt
= intel_image
->mt
;
419 /* There is support for only up to eight samples. */
420 if (src_mt
->num_samples
> 8 || dst_mt
->num_samples
> 8)
423 /* BLORP is only supported from Gen6 onwards. */
427 if (_mesa_get_format_base_format(src_rb
->Format
) !=
428 _mesa_get_format_base_format(dst_image
->TexFormat
)) {
432 /* We can't handle format conversions between Z24 and other formats since
433 * we have to lie about the surface format. See the comments in
434 * brw_blorp_surface_info::set().
436 if ((src_mt
->format
== MESA_FORMAT_Z24_UNORM_X8_UINT
) !=
437 (dst_mt
->format
== MESA_FORMAT_Z24_UNORM_X8_UINT
)) {
441 if (!brw
->format_supported_as_render_target
[dst_image
->TexFormat
])
444 /* Source clipping shouldn't be necessary, since copytexsubimage (in
445 * src/mesa/main/teximage.c) calls _mesa_clip_copytexsubimage() which
448 * Destination clipping shouldn't be necessary since the restrictions on
449 * glCopyTexSubImage prevent the user from specifying a destination rectangle
450 * that falls outside the bounds of the destination texture.
451 * See error_check_subtexture_dimensions().
454 int srcY1
= srcY0
+ height
;
455 int srcX1
= srcX0
+ width
;
456 int dstX1
= dstX0
+ width
;
457 int dstY1
= dstY0
+ height
;
459 /* Account for the fact that in the system framebuffer, the origin is at
462 bool mirror_y
= false;
463 if (_mesa_is_winsys_fbo(ctx
->ReadBuffer
)) {
464 GLint tmp
= src_rb
->Height
- srcY0
;
465 srcY0
= src_rb
->Height
- srcY1
;
470 /* Account for face selection and texture view MinLayer */
471 int dst_slice
= slice
+ dst_image
->TexObject
->MinLayer
+ dst_image
->Face
;
472 int dst_level
= dst_image
->Level
+ dst_image
->TexObject
->MinLevel
;
474 brw_blorp_blit_miptrees(brw
,
475 src_mt
, src_irb
->mt_level
, src_irb
->mt_layer
,
476 src_rb
->Format
, blorp_get_texture_swizzle(src_irb
),
477 dst_mt
, dst_level
, dst_slice
,
478 dst_image
->TexFormat
,
479 srcX0
, srcY0
, srcX1
, srcY1
,
480 dstX0
, dstY0
, dstX1
, dstY1
,
481 GL_NEAREST
, false, mirror_y
,
484 /* If we're copying to a packed depth stencil texture and the source
485 * framebuffer has separate stencil, we need to also copy the stencil data
488 src_rb
= ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
489 if (_mesa_get_format_bits(dst_image
->TexFormat
, GL_STENCIL_BITS
) > 0 &&
491 src_irb
= intel_renderbuffer(src_rb
);
492 src_mt
= src_irb
->mt
;
494 if (src_mt
->stencil_mt
)
495 src_mt
= src_mt
->stencil_mt
;
496 if (dst_mt
->stencil_mt
)
497 dst_mt
= dst_mt
->stencil_mt
;
499 if (src_mt
!= dst_mt
) {
500 brw_blorp_blit_miptrees(brw
,
501 src_mt
, src_irb
->mt_level
, src_irb
->mt_layer
,
503 blorp_get_texture_swizzle(src_irb
),
504 dst_mt
, dst_level
, dst_slice
,
506 srcX0
, srcY0
, srcX1
, srcY1
,
507 dstX0
, dstY0
, dstX1
, dstY1
,
508 GL_NEAREST
, false, mirror_y
,
518 brw_blorp_framebuffer(struct brw_context
*brw
,
519 struct gl_framebuffer
*readFb
,
520 struct gl_framebuffer
*drawFb
,
521 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
522 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
523 GLbitfield mask
, GLenum filter
)
525 /* BLORP is not supported before Gen6. */
529 static GLbitfield buffer_bits
[] = {
532 GL_STENCIL_BUFFER_BIT
,
535 for (unsigned int i
= 0; i
< ARRAY_SIZE(buffer_bits
); ++i
) {
536 if ((mask
& buffer_bits
[i
]) &&
537 try_blorp_blit(brw
, readFb
, drawFb
,
538 srcX0
, srcY0
, srcX1
, srcY1
,
539 dstX0
, dstY0
, dstX1
, dstY1
,
540 filter
, buffer_bits
[i
])) {
541 mask
&= ~buffer_bits
[i
];
549 set_write_disables(const struct intel_renderbuffer
*irb
,
550 const GLubyte
*color_mask
, bool *color_write_disable
)
552 /* Format information in the renderbuffer represents the requirements
553 * given by the client. There are cases where the backing miptree uses,
554 * for example, RGBA to represent RGBX. Since the client is only expecting
555 * RGB we can treat alpha as not used and write whatever we like into it.
557 const GLenum base_format
= irb
->Base
.Base
._BaseFormat
;
558 const int components
= _mesa_base_format_component_count(base_format
);
559 bool disables
= false;
561 assert(components
> 0);
563 for (int i
= 0; i
< components
; i
++) {
564 color_write_disable
[i
] = !color_mask
[i
];
565 disables
= disables
|| !color_mask
[i
];
572 do_single_blorp_clear(struct brw_context
*brw
, struct gl_framebuffer
*fb
,
573 struct gl_renderbuffer
*rb
, unsigned buf
,
574 bool partial_clear
, bool encode_srgb
, unsigned layer
)
576 struct gl_context
*ctx
= &brw
->ctx
;
577 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
578 mesa_format format
= irb
->mt
->format
;
579 uint32_t x0
, x1
, y0
, y1
;
581 if (!encode_srgb
&& _mesa_get_format_color_encoding(format
) == GL_SRGB
)
582 format
= _mesa_get_srgb_format_linear(format
);
590 y0
= rb
->Height
- fb
->_Ymax
;
591 y1
= rb
->Height
- fb
->_Ymin
;
594 bool can_fast_clear
= !partial_clear
;
596 bool color_write_disable
[4] = { false, false, false, false };
597 if (set_write_disables(irb
, ctx
->Color
.ColorMask
[buf
], color_write_disable
))
598 can_fast_clear
= false;
600 if (irb
->mt
->fast_clear_state
== INTEL_FAST_CLEAR_STATE_NO_MCS
||
601 !brw_is_color_fast_clear_compatible(brw
, irb
->mt
, &ctx
->Color
.ClearColor
))
602 can_fast_clear
= false;
604 if (can_fast_clear
) {
605 /* Record the clear color in the miptree so that it will be
606 * programmed in SURFACE_STATE by later rendering and resolve
609 const bool color_updated
= brw_meta_set_fast_clear_color(
610 brw
, irb
->mt
, &ctx
->Color
.ClearColor
);
612 /* If the buffer is already in INTEL_FAST_CLEAR_STATE_CLEAR, the clear
613 * is redundant and can be skipped.
615 if (!color_updated
&&
616 irb
->mt
->fast_clear_state
== INTEL_FAST_CLEAR_STATE_CLEAR
)
619 /* If the MCS buffer hasn't been allocated yet, we need to allocate
622 if (!irb
->mt
->mcs_mt
) {
623 if (!intel_miptree_alloc_non_msrt_mcs(brw
, irb
->mt
)) {
624 /* MCS allocation failed--probably this will only happen in
625 * out-of-memory conditions. But in any case, try to recover
626 * by falling back to a non-blorp clear technique.
633 intel_miptree_check_level_layer(irb
->mt
, irb
->mt_level
, layer
);
634 intel_miptree_used_for_rendering(irb
->mt
);
636 /* We can't setup the blorp_surf until we've allocated the MCS above */
637 struct isl_surf isl_tmp
[2];
638 struct brw_blorp_surf surf
;
639 unsigned level
= irb
->mt_level
;
640 brw_blorp_surf_for_miptree(brw
, &surf
, irb
->mt
, true, &level
, isl_tmp
);
642 if (can_fast_clear
) {
643 DBG("%s (fast) to mt %p level %d layer %d\n", __FUNCTION__
,
644 irb
->mt
, irb
->mt_level
, irb
->mt_layer
);
646 blorp_fast_clear(brw
, &surf
, level
, layer
, x0
, y0
, x1
, y1
);
648 /* Now that the fast clear has occurred, put the buffer in
649 * INTEL_FAST_CLEAR_STATE_CLEAR so that we won't waste time doing
652 irb
->mt
->fast_clear_state
= INTEL_FAST_CLEAR_STATE_CLEAR
;
654 DBG("%s (slow) to mt %p level %d layer %d\n", __FUNCTION__
,
655 irb
->mt
, irb
->mt_level
, irb
->mt_layer
);
657 union isl_color_value clear_color
;
658 memcpy(clear_color
.f32
, ctx
->Color
.ClearColor
.f
, sizeof(float) * 4);
660 blorp_clear(brw
, &surf
, level
, layer
, x0
, y0
, x1
, y1
,
661 (enum isl_format
)brw
->render_target_format
[format
],
662 clear_color
, color_write_disable
);
664 if (intel_miptree_is_lossless_compressed(brw
, irb
->mt
)) {
665 /* Compressed buffers can be cleared also using normal rep-clear. In
666 * such case they bahave such as if they were drawn using normal 3D
667 * render pipeline, and we simply mark the mcs as dirty.
669 assert(partial_clear
);
670 irb
->mt
->fast_clear_state
= INTEL_FAST_CLEAR_STATE_UNRESOLVED
;
678 brw_blorp_clear_color(struct brw_context
*brw
, struct gl_framebuffer
*fb
,
679 GLbitfield mask
, bool partial_clear
, bool encode_srgb
)
681 for (unsigned buf
= 0; buf
< fb
->_NumColorDrawBuffers
; buf
++) {
682 struct gl_renderbuffer
*rb
= fb
->_ColorDrawBuffers
[buf
];
683 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
685 /* Only clear the buffers present in the provided mask */
686 if (((1 << fb
->_ColorDrawBufferIndexes
[buf
]) & mask
) == 0)
689 /* If this is an ES2 context or GL_ARB_ES2_compatibility is supported,
690 * the framebuffer can be complete with some attachments missing. In
691 * this case the _ColorDrawBuffers pointer will be NULL.
696 if (fb
->MaxNumLayers
> 0) {
697 unsigned layer_multiplier
=
698 (irb
->mt
->msaa_layout
== INTEL_MSAA_LAYOUT_UMS
||
699 irb
->mt
->msaa_layout
== INTEL_MSAA_LAYOUT_CMS
) ?
700 irb
->mt
->num_samples
: 1;
701 unsigned num_layers
= irb
->layer_count
;
702 for (unsigned layer
= 0; layer
< num_layers
; layer
++) {
703 if (!do_single_blorp_clear(
704 brw
, fb
, rb
, buf
, partial_clear
, encode_srgb
,
705 irb
->mt_layer
+ layer
* layer_multiplier
)) {
710 unsigned layer
= irb
->mt_layer
;
711 if (!do_single_blorp_clear(brw
, fb
, rb
, buf
, partial_clear
,
716 irb
->need_downsample
= true;
723 brw_blorp_resolve_color(struct brw_context
*brw
, struct intel_mipmap_tree
*mt
)
725 DBG("%s to mt %p\n", __FUNCTION__
, mt
);
727 const mesa_format format
= _mesa_get_srgb_format_linear(mt
->format
);
729 intel_miptree_check_level_layer(mt
, 0 /* level */, 0 /* layer */);
730 intel_miptree_used_for_rendering(mt
);
732 struct isl_surf isl_tmp
[2];
733 struct brw_blorp_surf surf
;
735 brw_blorp_surf_for_miptree(brw
, &surf
, mt
, true, &level
, isl_tmp
);
737 brw_blorp_ccs_resolve(brw
, &surf
, brw_blorp_to_isl_format(brw
, format
, true));
739 mt
->fast_clear_state
= INTEL_FAST_CLEAR_STATE_RESOLVED
;
743 gen6_blorp_hiz_exec(struct brw_context
*brw
, struct intel_mipmap_tree
*mt
,
744 unsigned int level
, unsigned int layer
, enum gen6_hiz_op op
)
746 intel_miptree_check_level_layer(mt
, level
, layer
);
747 intel_miptree_used_for_rendering(mt
);
749 assert(intel_miptree_level_has_hiz(mt
, level
));
751 struct isl_surf isl_tmp
[2];
752 struct brw_blorp_surf surf
;
753 brw_blorp_surf_for_miptree(brw
, &surf
, mt
, true, &level
, isl_tmp
);
755 blorp_gen6_hiz_op(brw
, &surf
, level
, layer
, op
);
759 * Perform a HiZ or depth resolve operation.
761 * For an overview of HiZ ops, see the following sections of the Sandy Bridge
762 * PRM, Volume 1, Part 2:
763 * - 7.5.3.1 Depth Buffer Clear
764 * - 7.5.3.2 Depth Buffer Resolve
765 * - 7.5.3.3 Hierarchical Depth Buffer Resolve
768 intel_hiz_exec(struct brw_context
*brw
, struct intel_mipmap_tree
*mt
,
769 unsigned int level
, unsigned int layer
, enum gen6_hiz_op op
)
771 const char *opname
= NULL
;
774 case GEN6_HIZ_OP_DEPTH_RESOLVE
:
775 opname
= "depth resolve";
777 case GEN6_HIZ_OP_HIZ_RESOLVE
:
778 opname
= "hiz ambiguate";
780 case GEN6_HIZ_OP_DEPTH_CLEAR
:
781 opname
= "depth clear";
783 case GEN6_HIZ_OP_NONE
:
788 DBG("%s %s to mt %p level %d layer %d\n",
789 __func__
, opname
, mt
, level
, layer
);
792 gen8_hiz_exec(brw
, mt
, level
, layer
, op
);
794 gen6_blorp_hiz_exec(brw
, mt
, level
, layer
, op
);