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_defines.h"
34 #include "brw_meta_util.h"
35 #include "brw_state.h"
36 #include "intel_fbo.h"
37 #include "intel_debug.h"
39 #define FILE_DEBUG_FLAG DEBUG_BLORP
42 brw_blorp_lookup_shader(struct blorp_context
*blorp
,
43 const void *key
, uint32_t key_size
,
44 uint32_t *kernel_out
, void *prog_data_out
)
46 struct brw_context
*brw
= blorp
->driver_ctx
;
47 return brw_search_cache(&brw
->cache
, BRW_CACHE_BLORP_PROG
,
48 key
, key_size
, kernel_out
, prog_data_out
);
52 brw_blorp_upload_shader(struct blorp_context
*blorp
,
53 const void *key
, uint32_t key_size
,
54 const void *kernel
, uint32_t kernel_size
,
55 const void *prog_data
, uint32_t prog_data_size
,
56 uint32_t *kernel_out
, void *prog_data_out
)
58 struct brw_context
*brw
= blorp
->driver_ctx
;
59 brw_upload_cache(&brw
->cache
, BRW_CACHE_BLORP_PROG
, key
, key_size
,
60 kernel
, kernel_size
, prog_data
, prog_data_size
,
61 kernel_out
, prog_data_out
);
65 brw_blorp_init(struct brw_context
*brw
)
67 blorp_init(&brw
->blorp
, brw
, &brw
->isl_dev
);
69 brw
->blorp
.compiler
= brw
->intelScreen
->compiler
;
73 brw
->blorp
.mocs
.tex
= 0;
74 brw
->blorp
.mocs
.rb
= 0;
75 brw
->blorp
.mocs
.vb
= 0;
76 brw
->blorp
.exec
= gen6_blorp_exec
;
79 brw
->blorp
.mocs
.tex
= GEN7_MOCS_L3
;
80 brw
->blorp
.mocs
.rb
= GEN7_MOCS_L3
;
81 brw
->blorp
.mocs
.vb
= GEN7_MOCS_L3
;
82 if (brw
->is_haswell
) {
83 brw
->blorp
.exec
= gen75_blorp_exec
;
85 brw
->blorp
.exec
= gen7_blorp_exec
;
89 brw
->blorp
.mocs
.tex
= BDW_MOCS_WB
;
90 brw
->blorp
.mocs
.rb
= BDW_MOCS_PTE
;
91 brw
->blorp
.mocs
.vb
= BDW_MOCS_WB
;
92 brw
->blorp
.exec
= gen8_blorp_exec
;
95 brw
->blorp
.mocs
.tex
= SKL_MOCS_WB
;
96 brw
->blorp
.mocs
.rb
= SKL_MOCS_PTE
;
97 brw
->blorp
.mocs
.vb
= SKL_MOCS_WB
;
98 brw
->blorp
.exec
= gen9_blorp_exec
;
101 unreachable("Invalid gen");
104 brw
->blorp
.lookup_shader
= brw_blorp_lookup_shader
;
105 brw
->blorp
.upload_shader
= brw_blorp_upload_shader
;
109 apply_gen6_stencil_hiz_offset(struct isl_surf
*surf
,
110 struct intel_mipmap_tree
*mt
,
114 assert(mt
->array_layout
== ALL_SLICES_AT_EACH_LOD
);
116 if (mt
->format
== MESA_FORMAT_S_UINT8
) {
117 /* Note: we can't compute the stencil offset using
118 * intel_miptree_get_aligned_offset(), because the miptree
119 * claims that the region is untiled even though it's W tiled.
121 *offset
= mt
->level
[lod
].level_y
* mt
->pitch
+
122 mt
->level
[lod
].level_x
* 64;
124 *offset
= intel_miptree_get_aligned_offset(mt
,
125 mt
->level
[lod
].level_x
,
126 mt
->level
[lod
].level_y
,
130 surf
->logical_level0_px
.width
= minify(surf
->logical_level0_px
.width
, lod
);
131 surf
->logical_level0_px
.height
= minify(surf
->logical_level0_px
.height
, lod
);
132 surf
->phys_level0_sa
.width
= minify(surf
->phys_level0_sa
.width
, lod
);
133 surf
->phys_level0_sa
.height
= minify(surf
->phys_level0_sa
.height
, lod
);
135 surf
->array_pitch_el_rows
=
136 ALIGN(surf
->phys_level0_sa
.height
, surf
->image_alignment_el
.height
);
140 brw_blorp_surf_for_miptree(struct brw_context
*brw
,
141 struct brw_blorp_surf
*surf
,
142 struct intel_mipmap_tree
*mt
,
143 bool is_render_target
,
145 struct isl_surf tmp_surfs
[2])
147 intel_miptree_get_isl_surf(brw
, mt
, &tmp_surfs
[0]);
148 surf
->surf
= &tmp_surfs
[0];
149 surf
->addr
= (struct blorp_address
) {
151 .offset
= mt
->offset
,
152 .read_domains
= is_render_target
? I915_GEM_DOMAIN_RENDER
:
153 I915_GEM_DOMAIN_SAMPLER
,
154 .write_domain
= is_render_target
? I915_GEM_DOMAIN_RENDER
: 0,
157 if (brw
->gen
== 6 && mt
->format
== MESA_FORMAT_S_UINT8
&&
158 mt
->array_layout
== ALL_SLICES_AT_EACH_LOD
) {
159 /* Sandy bridge stencil and HiZ use this ALL_SLICES_AT_EACH_LOD hack in
160 * order to allow for layered rendering. The hack makes each LOD of the
161 * stencil or HiZ buffer a single tightly packed array surface at some
162 * offset into the surface. Since ISL doesn't know how to deal with the
163 * crazy ALL_SLICES_AT_EACH_LOD layout and since we have to do a manual
164 * offset of it anyway, we might as well do the offset here and keep the
165 * hacks inside the i965 driver.
167 * See also gen6_depth_stencil_state.c
170 apply_gen6_stencil_hiz_offset(&tmp_surfs
[0], mt
, *level
, &offset
);
171 surf
->addr
.offset
+= offset
;
175 struct isl_surf
*aux_surf
= &tmp_surfs
[1];
176 intel_miptree_get_aux_isl_surf(brw
, mt
, aux_surf
, &surf
->aux_usage
);
178 /* For textures that are in the RESOLVED state, we ignore the MCS */
179 if (mt
->mcs_mt
&& !is_render_target
&&
180 mt
->fast_clear_state
== INTEL_FAST_CLEAR_STATE_RESOLVED
)
181 surf
->aux_usage
= ISL_AUX_USAGE_NONE
;
183 if (surf
->aux_usage
!= ISL_AUX_USAGE_NONE
) {
184 /* We only really need a clear color if we also have an auxiliary
185 * surface. Without one, it does nothing.
187 surf
->clear_color
= intel_miptree_get_isl_clear_color(brw
, mt
);
189 surf
->aux_surf
= aux_surf
;
190 surf
->aux_addr
= (struct blorp_address
) {
191 .read_domains
= is_render_target
? I915_GEM_DOMAIN_RENDER
:
192 I915_GEM_DOMAIN_SAMPLER
,
193 .write_domain
= is_render_target
? I915_GEM_DOMAIN_RENDER
: 0,
197 surf
->aux_addr
.buffer
= mt
->mcs_mt
->bo
;
198 surf
->aux_addr
.offset
= mt
->mcs_mt
->offset
;
200 assert(surf
->aux_usage
== ISL_AUX_USAGE_HIZ
);
201 struct intel_mipmap_tree
*hiz_mt
= mt
->hiz_buf
->mt
;
203 surf
->aux_addr
.buffer
= hiz_mt
->bo
;
205 hiz_mt
->array_layout
== ALL_SLICES_AT_EACH_LOD
) {
206 /* gen6 requires the HiZ buffer to be manually offset to the
207 * right location. We could fixup the surf but it doesn't
208 * matter since most of those fields don't matter.
210 apply_gen6_stencil_hiz_offset(aux_surf
, hiz_mt
, *level
,
211 &surf
->aux_addr
.offset
);
213 surf
->aux_addr
.offset
= 0;
215 assert(hiz_mt
->pitch
== aux_surf
->row_pitch
);
217 surf
->aux_addr
.buffer
= mt
->hiz_buf
->bo
;
218 surf
->aux_addr
.offset
= 0;
222 surf
->aux_addr
= (struct blorp_address
) {
225 memset(&surf
->clear_color
, 0, sizeof(surf
->clear_color
));
227 assert((surf
->aux_usage
== ISL_AUX_USAGE_NONE
) ==
228 (surf
->aux_addr
.buffer
== NULL
));
231 static enum isl_format
232 brw_blorp_to_isl_format(struct brw_context
*brw
, mesa_format format
,
233 bool is_render_target
)
236 case MESA_FORMAT_NONE
:
237 return ISL_FORMAT_UNSUPPORTED
;
238 case MESA_FORMAT_S_UINT8
:
239 return ISL_FORMAT_R8_UINT
;
240 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
241 return ISL_FORMAT_R24_UNORM_X8_TYPELESS
;
242 case MESA_FORMAT_Z_FLOAT32
:
243 return ISL_FORMAT_R32_FLOAT
;
244 case MESA_FORMAT_Z_UNORM16
:
245 return ISL_FORMAT_R16_UNORM
;
247 if (is_render_target
) {
248 assert(brw
->format_supported_as_render_target
[format
]);
249 return brw
->render_target_format
[format
];
251 return brw_format_for_mesa_format(format
);
259 * Note: if the src (or dst) is a 2D multisample array texture on Gen7+ using
260 * INTEL_MSAA_LAYOUT_UMS or INTEL_MSAA_LAYOUT_CMS, src_layer (dst_layer) is
261 * the physical layer holding sample 0. So, for example, if
262 * src_mt->num_samples == 4, then logical layer n corresponds to src_layer ==
266 brw_blorp_blit_miptrees(struct brw_context
*brw
,
267 struct intel_mipmap_tree
*src_mt
,
268 unsigned src_level
, unsigned src_layer
,
269 mesa_format src_format
, int src_swizzle
,
270 struct intel_mipmap_tree
*dst_mt
,
271 unsigned dst_level
, unsigned dst_layer
,
272 mesa_format dst_format
,
273 float src_x0
, float src_y0
,
274 float src_x1
, float src_y1
,
275 float dst_x0
, float dst_y0
,
276 float dst_x1
, float dst_y1
,
277 GLenum filter
, bool mirror_x
, bool mirror_y
,
278 bool decode_srgb
, bool encode_srgb
)
280 /* Get ready to blit. This includes depth resolving the src and dst
281 * buffers if necessary. Note: it's not necessary to do a color resolve on
282 * the destination buffer because we use the standard render path to render
283 * to destination color buffers, and the standard render path is
286 intel_miptree_resolve_color(brw
, src_mt
, INTEL_MIPTREE_IGNORE_CCS_E
);
287 intel_miptree_slice_resolve_depth(brw
, src_mt
, src_level
, src_layer
);
288 intel_miptree_slice_resolve_depth(brw
, dst_mt
, dst_level
, dst_layer
);
290 intel_miptree_prepare_mcs(brw
, dst_mt
);
292 DBG("%s from %dx %s mt %p %d %d (%f,%f) (%f,%f)"
293 "to %dx %s mt %p %d %d (%f,%f) (%f,%f) (flip %d,%d)\n",
295 src_mt
->num_samples
, _mesa_get_format_name(src_mt
->format
), src_mt
,
296 src_level
, src_layer
, src_x0
, src_y0
, src_x1
, src_y1
,
297 dst_mt
->num_samples
, _mesa_get_format_name(dst_mt
->format
), dst_mt
,
298 dst_level
, dst_layer
, dst_x0
, dst_y0
, dst_x1
, dst_y1
,
301 if (!decode_srgb
&& _mesa_get_format_color_encoding(src_format
) == GL_SRGB
)
302 src_format
= _mesa_get_srgb_format_linear(src_format
);
304 if (!encode_srgb
&& _mesa_get_format_color_encoding(dst_format
) == GL_SRGB
)
305 dst_format
= _mesa_get_srgb_format_linear(dst_format
);
307 /* When doing a multisample resolve of a GL_LUMINANCE32F or GL_INTENSITY32F
308 * texture, the above code configures the source format for L32_FLOAT or
309 * I32_FLOAT, and the destination format for R32_FLOAT. On Sandy Bridge,
310 * the SAMPLE message appears to handle multisampled L32_FLOAT and
311 * I32_FLOAT textures incorrectly, resulting in blocky artifacts. So work
312 * around the problem by using a source format of R32_FLOAT. This
313 * shouldn't affect rendering correctness, since the destination format is
314 * R32_FLOAT, so only the contents of the red channel matters.
317 src_mt
->num_samples
> 1 && dst_mt
->num_samples
<= 1 &&
318 src_mt
->format
== dst_mt
->format
&&
319 (dst_format
== MESA_FORMAT_L_FLOAT32
||
320 dst_format
== MESA_FORMAT_I_FLOAT32
)) {
321 src_format
= dst_format
= MESA_FORMAT_R_FLOAT32
;
324 intel_miptree_check_level_layer(src_mt
, src_level
, src_layer
);
325 intel_miptree_check_level_layer(dst_mt
, dst_level
, dst_layer
);
326 intel_miptree_used_for_rendering(dst_mt
);
328 struct isl_surf tmp_surfs
[4];
329 struct brw_blorp_surf src_surf
, dst_surf
;
330 brw_blorp_surf_for_miptree(brw
, &src_surf
, src_mt
, false,
331 &src_level
, &tmp_surfs
[0]);
332 brw_blorp_surf_for_miptree(brw
, &dst_surf
, dst_mt
, true,
333 &dst_level
, &tmp_surfs
[2]);
335 brw_blorp_blit(brw
, &src_surf
, src_level
, src_layer
,
336 brw_blorp_to_isl_format(brw
, src_format
, false), src_swizzle
,
337 &dst_surf
, dst_level
, dst_layer
,
338 brw_blorp_to_isl_format(brw
, dst_format
, true),
339 src_x0
, src_y0
, src_x1
, src_y1
,
340 dst_x0
, dst_y0
, dst_x1
, dst_y1
,
341 filter
, mirror_x
, mirror_y
);
343 intel_miptree_slice_set_needs_hiz_resolve(dst_mt
, dst_level
, dst_layer
);
345 if (intel_miptree_is_lossless_compressed(brw
, dst_mt
))
346 dst_mt
->fast_clear_state
= INTEL_FAST_CLEAR_STATE_UNRESOLVED
;
349 static struct intel_mipmap_tree
*
350 find_miptree(GLbitfield buffer_bit
, struct intel_renderbuffer
*irb
)
352 struct intel_mipmap_tree
*mt
= irb
->mt
;
353 if (buffer_bit
== GL_STENCIL_BUFFER_BIT
&& mt
->stencil_mt
)
359 blorp_get_texture_swizzle(const struct intel_renderbuffer
*irb
)
361 return irb
->Base
.Base
._BaseFormat
== GL_RGB
?
362 MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_ONE
) :
367 do_blorp_blit(struct brw_context
*brw
, GLbitfield buffer_bit
,
368 struct intel_renderbuffer
*src_irb
, mesa_format src_format
,
369 struct intel_renderbuffer
*dst_irb
, mesa_format dst_format
,
370 GLfloat srcX0
, GLfloat srcY0
, GLfloat srcX1
, GLfloat srcY1
,
371 GLfloat dstX0
, GLfloat dstY0
, GLfloat dstX1
, GLfloat dstY1
,
372 GLenum filter
, bool mirror_x
, bool mirror_y
)
374 const struct gl_context
*ctx
= &brw
->ctx
;
376 /* Find source/dst miptrees */
377 struct intel_mipmap_tree
*src_mt
= find_miptree(buffer_bit
, src_irb
);
378 struct intel_mipmap_tree
*dst_mt
= find_miptree(buffer_bit
, dst_irb
);
380 const bool do_srgb
= ctx
->Color
.sRGBEnabled
;
383 brw_blorp_blit_miptrees(brw
,
384 src_mt
, src_irb
->mt_level
, src_irb
->mt_layer
,
385 src_format
, blorp_get_texture_swizzle(src_irb
),
386 dst_mt
, dst_irb
->mt_level
, dst_irb
->mt_layer
,
388 srcX0
, srcY0
, srcX1
, srcY1
,
389 dstX0
, dstY0
, dstX1
, dstY1
,
390 filter
, mirror_x
, mirror_y
,
393 dst_irb
->need_downsample
= true;
397 try_blorp_blit(struct brw_context
*brw
,
398 const struct gl_framebuffer
*read_fb
,
399 const struct gl_framebuffer
*draw_fb
,
400 GLfloat srcX0
, GLfloat srcY0
, GLfloat srcX1
, GLfloat srcY1
,
401 GLfloat dstX0
, GLfloat dstY0
, GLfloat dstX1
, GLfloat dstY1
,
402 GLenum filter
, GLbitfield buffer_bit
)
404 struct gl_context
*ctx
= &brw
->ctx
;
406 /* Sync up the state of window system buffers. We need to do this before
407 * we go looking for the buffers.
409 intel_prepare_render(brw
);
411 bool mirror_x
, mirror_y
;
412 if (brw_meta_mirror_clip_and_scissor(ctx
, read_fb
, draw_fb
,
413 &srcX0
, &srcY0
, &srcX1
, &srcY1
,
414 &dstX0
, &dstY0
, &dstX1
, &dstY1
,
415 &mirror_x
, &mirror_y
))
419 struct intel_renderbuffer
*src_irb
;
420 struct intel_renderbuffer
*dst_irb
;
421 struct intel_mipmap_tree
*src_mt
;
422 struct intel_mipmap_tree
*dst_mt
;
423 switch (buffer_bit
) {
424 case GL_COLOR_BUFFER_BIT
:
425 src_irb
= intel_renderbuffer(read_fb
->_ColorReadBuffer
);
426 for (unsigned i
= 0; i
< draw_fb
->_NumColorDrawBuffers
; ++i
) {
427 dst_irb
= intel_renderbuffer(draw_fb
->_ColorDrawBuffers
[i
]);
429 do_blorp_blit(brw
, buffer_bit
,
430 src_irb
, src_irb
->Base
.Base
.Format
,
431 dst_irb
, dst_irb
->Base
.Base
.Format
,
432 srcX0
, srcY0
, srcX1
, srcY1
,
433 dstX0
, dstY0
, dstX1
, dstY1
,
434 filter
, mirror_x
, mirror_y
);
437 case GL_DEPTH_BUFFER_BIT
:
439 intel_renderbuffer(read_fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
441 intel_renderbuffer(draw_fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
442 src_mt
= find_miptree(buffer_bit
, src_irb
);
443 dst_mt
= find_miptree(buffer_bit
, dst_irb
);
445 /* We can't handle format conversions between Z24 and other formats
446 * since we have to lie about the surface format. See the comments in
447 * brw_blorp_surface_info::set().
449 if ((src_mt
->format
== MESA_FORMAT_Z24_UNORM_X8_UINT
) !=
450 (dst_mt
->format
== MESA_FORMAT_Z24_UNORM_X8_UINT
))
453 do_blorp_blit(brw
, buffer_bit
, src_irb
, MESA_FORMAT_NONE
,
454 dst_irb
, MESA_FORMAT_NONE
, srcX0
, srcY0
,
455 srcX1
, srcY1
, dstX0
, dstY0
, dstX1
, dstY1
,
456 filter
, mirror_x
, mirror_y
);
458 case GL_STENCIL_BUFFER_BIT
:
460 intel_renderbuffer(read_fb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
462 intel_renderbuffer(draw_fb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
463 do_blorp_blit(brw
, buffer_bit
, src_irb
, MESA_FORMAT_NONE
,
464 dst_irb
, MESA_FORMAT_NONE
, srcX0
, srcY0
,
465 srcX1
, srcY1
, dstX0
, dstY0
, dstX1
, dstY1
,
466 filter
, mirror_x
, mirror_y
);
469 unreachable("not reached");
476 brw_blorp_copytexsubimage(struct brw_context
*brw
,
477 struct gl_renderbuffer
*src_rb
,
478 struct gl_texture_image
*dst_image
,
480 int srcX0
, int srcY0
,
481 int dstX0
, int dstY0
,
482 int width
, int height
)
484 struct gl_context
*ctx
= &brw
->ctx
;
485 struct intel_renderbuffer
*src_irb
= intel_renderbuffer(src_rb
);
486 struct intel_texture_image
*intel_image
= intel_texture_image(dst_image
);
488 /* No pixel transfer operations (zoom, bias, mapping), just a blit */
489 if (brw
->ctx
._ImageTransferState
)
492 /* Sync up the state of window system buffers. We need to do this before
493 * we go looking at the src renderbuffer's miptree.
495 intel_prepare_render(brw
);
497 struct intel_mipmap_tree
*src_mt
= src_irb
->mt
;
498 struct intel_mipmap_tree
*dst_mt
= intel_image
->mt
;
500 /* There is support for only up to eight samples. */
501 if (src_mt
->num_samples
> 8 || dst_mt
->num_samples
> 8)
504 /* BLORP is only supported from Gen6 onwards. */
508 if (_mesa_get_format_base_format(src_rb
->Format
) !=
509 _mesa_get_format_base_format(dst_image
->TexFormat
)) {
513 /* We can't handle format conversions between Z24 and other formats since
514 * we have to lie about the surface format. See the comments in
515 * brw_blorp_surface_info::set().
517 if ((src_mt
->format
== MESA_FORMAT_Z24_UNORM_X8_UINT
) !=
518 (dst_mt
->format
== MESA_FORMAT_Z24_UNORM_X8_UINT
)) {
522 if (!brw
->format_supported_as_render_target
[dst_image
->TexFormat
])
525 /* Source clipping shouldn't be necessary, since copytexsubimage (in
526 * src/mesa/main/teximage.c) calls _mesa_clip_copytexsubimage() which
529 * Destination clipping shouldn't be necessary since the restrictions on
530 * glCopyTexSubImage prevent the user from specifying a destination rectangle
531 * that falls outside the bounds of the destination texture.
532 * See error_check_subtexture_dimensions().
535 int srcY1
= srcY0
+ height
;
536 int srcX1
= srcX0
+ width
;
537 int dstX1
= dstX0
+ width
;
538 int dstY1
= dstY0
+ height
;
540 /* Account for the fact that in the system framebuffer, the origin is at
543 bool mirror_y
= false;
544 if (_mesa_is_winsys_fbo(ctx
->ReadBuffer
)) {
545 GLint tmp
= src_rb
->Height
- srcY0
;
546 srcY0
= src_rb
->Height
- srcY1
;
551 /* Account for face selection and texture view MinLayer */
552 int dst_slice
= slice
+ dst_image
->TexObject
->MinLayer
+ dst_image
->Face
;
553 int dst_level
= dst_image
->Level
+ dst_image
->TexObject
->MinLevel
;
555 brw_blorp_blit_miptrees(brw
,
556 src_mt
, src_irb
->mt_level
, src_irb
->mt_layer
,
557 src_rb
->Format
, blorp_get_texture_swizzle(src_irb
),
558 dst_mt
, dst_level
, dst_slice
,
559 dst_image
->TexFormat
,
560 srcX0
, srcY0
, srcX1
, srcY1
,
561 dstX0
, dstY0
, dstX1
, dstY1
,
562 GL_NEAREST
, false, mirror_y
,
565 /* If we're copying to a packed depth stencil texture and the source
566 * framebuffer has separate stencil, we need to also copy the stencil data
569 src_rb
= ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
570 if (_mesa_get_format_bits(dst_image
->TexFormat
, GL_STENCIL_BITS
) > 0 &&
572 src_irb
= intel_renderbuffer(src_rb
);
573 src_mt
= src_irb
->mt
;
575 if (src_mt
->stencil_mt
)
576 src_mt
= src_mt
->stencil_mt
;
577 if (dst_mt
->stencil_mt
)
578 dst_mt
= dst_mt
->stencil_mt
;
580 if (src_mt
!= dst_mt
) {
581 brw_blorp_blit_miptrees(brw
,
582 src_mt
, src_irb
->mt_level
, src_irb
->mt_layer
,
584 blorp_get_texture_swizzle(src_irb
),
585 dst_mt
, dst_level
, dst_slice
,
587 srcX0
, srcY0
, srcX1
, srcY1
,
588 dstX0
, dstY0
, dstX1
, dstY1
,
589 GL_NEAREST
, false, mirror_y
,
599 brw_blorp_framebuffer(struct brw_context
*brw
,
600 struct gl_framebuffer
*readFb
,
601 struct gl_framebuffer
*drawFb
,
602 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
603 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
604 GLbitfield mask
, GLenum filter
)
606 /* BLORP is not supported before Gen6. */
610 static GLbitfield buffer_bits
[] = {
613 GL_STENCIL_BUFFER_BIT
,
616 for (unsigned int i
= 0; i
< ARRAY_SIZE(buffer_bits
); ++i
) {
617 if ((mask
& buffer_bits
[i
]) &&
618 try_blorp_blit(brw
, readFb
, drawFb
,
619 srcX0
, srcY0
, srcX1
, srcY1
,
620 dstX0
, dstY0
, dstX1
, dstY1
,
621 filter
, buffer_bits
[i
])) {
622 mask
&= ~buffer_bits
[i
];
630 set_write_disables(const struct intel_renderbuffer
*irb
,
631 const GLubyte
*color_mask
, bool *color_write_disable
)
633 /* Format information in the renderbuffer represents the requirements
634 * given by the client. There are cases where the backing miptree uses,
635 * for example, RGBA to represent RGBX. Since the client is only expecting
636 * RGB we can treat alpha as not used and write whatever we like into it.
638 const GLenum base_format
= irb
->Base
.Base
._BaseFormat
;
639 const int components
= _mesa_base_format_component_count(base_format
);
640 bool disables
= false;
642 assert(components
> 0);
644 for (int i
= 0; i
< components
; i
++) {
645 color_write_disable
[i
] = !color_mask
[i
];
646 disables
= disables
|| !color_mask
[i
];
653 do_single_blorp_clear(struct brw_context
*brw
, struct gl_framebuffer
*fb
,
654 struct gl_renderbuffer
*rb
, unsigned buf
,
655 bool partial_clear
, bool encode_srgb
, unsigned layer
)
657 struct gl_context
*ctx
= &brw
->ctx
;
658 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
659 mesa_format format
= irb
->mt
->format
;
660 uint32_t x0
, x1
, y0
, y1
;
662 if (!encode_srgb
&& _mesa_get_format_color_encoding(format
) == GL_SRGB
)
663 format
= _mesa_get_srgb_format_linear(format
);
671 y0
= rb
->Height
- fb
->_Ymax
;
672 y1
= rb
->Height
- fb
->_Ymin
;
675 /* If the clear region is empty, just return. */
676 if (x0
== x1
|| y0
== y1
)
679 bool can_fast_clear
= !partial_clear
;
681 bool color_write_disable
[4] = { false, false, false, false };
682 if (set_write_disables(irb
, ctx
->Color
.ColorMask
[buf
], color_write_disable
))
683 can_fast_clear
= false;
685 if (irb
->mt
->fast_clear_state
== INTEL_FAST_CLEAR_STATE_NO_MCS
||
686 !brw_is_color_fast_clear_compatible(brw
, irb
->mt
, &ctx
->Color
.ClearColor
))
687 can_fast_clear
= false;
689 if (can_fast_clear
) {
690 /* Record the clear color in the miptree so that it will be
691 * programmed in SURFACE_STATE by later rendering and resolve
694 const bool color_updated
= brw_meta_set_fast_clear_color(
695 brw
, irb
->mt
, &ctx
->Color
.ClearColor
);
697 /* If the buffer is already in INTEL_FAST_CLEAR_STATE_CLEAR, the clear
698 * is redundant and can be skipped.
700 if (!color_updated
&&
701 irb
->mt
->fast_clear_state
== INTEL_FAST_CLEAR_STATE_CLEAR
)
704 /* If the MCS buffer hasn't been allocated yet, we need to allocate
707 if (!irb
->mt
->mcs_mt
) {
708 if (!intel_miptree_alloc_non_msrt_mcs(brw
, irb
->mt
)) {
709 /* MCS allocation failed--probably this will only happen in
710 * out-of-memory conditions. But in any case, try to recover
711 * by falling back to a non-blorp clear technique.
718 intel_miptree_check_level_layer(irb
->mt
, irb
->mt_level
, layer
);
719 intel_miptree_used_for_rendering(irb
->mt
);
721 /* We can't setup the blorp_surf until we've allocated the MCS above */
722 struct isl_surf isl_tmp
[2];
723 struct brw_blorp_surf surf
;
724 unsigned level
= irb
->mt_level
;
725 brw_blorp_surf_for_miptree(brw
, &surf
, irb
->mt
, true, &level
, isl_tmp
);
727 if (can_fast_clear
) {
728 DBG("%s (fast) to mt %p level %d layer %d\n", __FUNCTION__
,
729 irb
->mt
, irb
->mt_level
, irb
->mt_layer
);
731 blorp_fast_clear(brw
, &surf
, level
, layer
, x0
, y0
, x1
, y1
);
733 /* Now that the fast clear has occurred, put the buffer in
734 * INTEL_FAST_CLEAR_STATE_CLEAR so that we won't waste time doing
737 irb
->mt
->fast_clear_state
= INTEL_FAST_CLEAR_STATE_CLEAR
;
739 DBG("%s (slow) to mt %p level %d layer %d\n", __FUNCTION__
,
740 irb
->mt
, irb
->mt_level
, irb
->mt_layer
);
742 union isl_color_value clear_color
;
743 memcpy(clear_color
.f32
, ctx
->Color
.ClearColor
.f
, sizeof(float) * 4);
745 blorp_clear(brw
, &surf
, level
, layer
, x0
, y0
, x1
, y1
,
746 (enum isl_format
)brw
->render_target_format
[format
],
747 clear_color
, color_write_disable
);
749 if (intel_miptree_is_lossless_compressed(brw
, irb
->mt
)) {
750 /* Compressed buffers can be cleared also using normal rep-clear. In
751 * such case they bahave such as if they were drawn using normal 3D
752 * render pipeline, and we simply mark the mcs as dirty.
754 assert(partial_clear
);
755 irb
->mt
->fast_clear_state
= INTEL_FAST_CLEAR_STATE_UNRESOLVED
;
763 brw_blorp_clear_color(struct brw_context
*brw
, struct gl_framebuffer
*fb
,
764 GLbitfield mask
, bool partial_clear
, bool encode_srgb
)
766 for (unsigned buf
= 0; buf
< fb
->_NumColorDrawBuffers
; buf
++) {
767 struct gl_renderbuffer
*rb
= fb
->_ColorDrawBuffers
[buf
];
768 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
770 /* Only clear the buffers present in the provided mask */
771 if (((1 << fb
->_ColorDrawBufferIndexes
[buf
]) & mask
) == 0)
774 /* If this is an ES2 context or GL_ARB_ES2_compatibility is supported,
775 * the framebuffer can be complete with some attachments missing. In
776 * this case the _ColorDrawBuffers pointer will be NULL.
781 if (fb
->MaxNumLayers
> 0) {
782 unsigned layer_multiplier
=
783 (irb
->mt
->msaa_layout
== INTEL_MSAA_LAYOUT_UMS
||
784 irb
->mt
->msaa_layout
== INTEL_MSAA_LAYOUT_CMS
) ?
785 irb
->mt
->num_samples
: 1;
786 unsigned num_layers
= irb
->layer_count
;
787 for (unsigned layer
= 0; layer
< num_layers
; layer
++) {
788 if (!do_single_blorp_clear(
789 brw
, fb
, rb
, buf
, partial_clear
, encode_srgb
,
790 irb
->mt_layer
+ layer
* layer_multiplier
)) {
795 unsigned layer
= irb
->mt_layer
;
796 if (!do_single_blorp_clear(brw
, fb
, rb
, buf
, partial_clear
,
801 irb
->need_downsample
= true;
808 brw_blorp_resolve_color(struct brw_context
*brw
, struct intel_mipmap_tree
*mt
)
810 DBG("%s to mt %p\n", __FUNCTION__
, mt
);
812 const mesa_format format
= _mesa_get_srgb_format_linear(mt
->format
);
814 intel_miptree_check_level_layer(mt
, 0 /* level */, 0 /* layer */);
815 intel_miptree_used_for_rendering(mt
);
817 struct isl_surf isl_tmp
[2];
818 struct brw_blorp_surf surf
;
820 brw_blorp_surf_for_miptree(brw
, &surf
, mt
, true, &level
, isl_tmp
);
822 brw_blorp_ccs_resolve(brw
, &surf
, brw_blorp_to_isl_format(brw
, format
, true));
824 mt
->fast_clear_state
= INTEL_FAST_CLEAR_STATE_RESOLVED
;
828 gen6_blorp_hiz_exec(struct brw_context
*brw
, struct intel_mipmap_tree
*mt
,
829 unsigned int level
, unsigned int layer
, enum gen6_hiz_op op
)
831 intel_miptree_check_level_layer(mt
, level
, layer
);
832 intel_miptree_used_for_rendering(mt
);
834 assert(intel_miptree_level_has_hiz(mt
, level
));
836 struct isl_surf isl_tmp
[2];
837 struct brw_blorp_surf surf
;
838 brw_blorp_surf_for_miptree(brw
, &surf
, mt
, true, &level
, isl_tmp
);
840 blorp_gen6_hiz_op(brw
, &surf
, level
, layer
, op
);
844 * Perform a HiZ or depth resolve operation.
846 * For an overview of HiZ ops, see the following sections of the Sandy Bridge
847 * PRM, Volume 1, Part 2:
848 * - 7.5.3.1 Depth Buffer Clear
849 * - 7.5.3.2 Depth Buffer Resolve
850 * - 7.5.3.3 Hierarchical Depth Buffer Resolve
853 intel_hiz_exec(struct brw_context
*brw
, struct intel_mipmap_tree
*mt
,
854 unsigned int level
, unsigned int layer
, enum gen6_hiz_op op
)
856 const char *opname
= NULL
;
859 case GEN6_HIZ_OP_DEPTH_RESOLVE
:
860 opname
= "depth resolve";
862 case GEN6_HIZ_OP_HIZ_RESOLVE
:
863 opname
= "hiz ambiguate";
865 case GEN6_HIZ_OP_DEPTH_CLEAR
:
866 opname
= "depth clear";
868 case GEN6_HIZ_OP_NONE
:
873 DBG("%s %s to mt %p level %d layer %d\n",
874 __func__
, opname
, mt
, level
, layer
);
877 gen8_hiz_exec(brw
, mt
, level
, layer
, op
);
879 gen6_blorp_hiz_exec(brw
, mt
, level
, layer
, op
);