2 * Copyright 2003 VMware, Inc.
3 * Copyright 2009, 2012 Intel Corporation.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "main/mtypes.h"
28 #include "main/condrender.h"
29 #include "swrast/swrast.h"
30 #include "drivers/common/meta.h"
32 #include "intel_batchbuffer.h"
33 #include "intel_blit.h"
34 #include "intel_fbo.h"
35 #include "intel_mipmap_tree.h"
37 #include "brw_context.h"
38 #include "brw_blorp.h"
39 #include "brw_defines.h"
41 #define FILE_DEBUG_FLAG DEBUG_BLIT
43 static const char *buffer_names
[] = {
44 [BUFFER_FRONT_LEFT
] = "front",
45 [BUFFER_BACK_LEFT
] = "back",
46 [BUFFER_FRONT_RIGHT
] = "front right",
47 [BUFFER_BACK_RIGHT
] = "back right",
48 [BUFFER_DEPTH
] = "depth",
49 [BUFFER_STENCIL
] = "stencil",
50 [BUFFER_ACCUM
] = "accum",
51 [BUFFER_AUX0
] = "aux0",
52 [BUFFER_COLOR0
] = "color0",
53 [BUFFER_COLOR1
] = "color1",
54 [BUFFER_COLOR2
] = "color2",
55 [BUFFER_COLOR3
] = "color3",
56 [BUFFER_COLOR4
] = "color4",
57 [BUFFER_COLOR5
] = "color5",
58 [BUFFER_COLOR6
] = "color6",
59 [BUFFER_COLOR7
] = "color7",
63 debug_mask(const char *name
, GLbitfield mask
)
67 if (unlikely(INTEL_DEBUG
& DEBUG_BLIT
)) {
68 DBG("%s clear:", name
);
69 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
71 DBG(" %s", buffer_names
[i
]);
78 * Returns true if the scissor is a noop (cuts out nothing).
81 noop_scissor(struct gl_framebuffer
*fb
)
83 return fb
->_Xmin
<= 0 &&
85 fb
->_Xmax
>= fb
->Width
&&
86 fb
->_Ymax
>= fb
->Height
;
90 * Implements fast depth clears on gen6+.
92 * Fast clears basically work by setting a flag in each of the subspans
93 * represented in the HiZ buffer that says "When you need the depth values for
94 * this subspan, it's the hardware's current clear value." Then later rendering
95 * can just use the static clear value instead of referencing memory.
97 * The tricky part of the implementation is that you have to have the clear
98 * value that was used on the depth buffer in place for all further rendering,
99 * at least until a resolve to the real depth buffer happens.
102 brw_fast_clear_depth(struct gl_context
*ctx
)
104 struct brw_context
*brw
= brw_context(ctx
);
105 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
106 struct intel_renderbuffer
*depth_irb
=
107 intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
108 struct intel_mipmap_tree
*mt
= depth_irb
->mt
;
109 struct gl_renderbuffer_attachment
*depth_att
= &fb
->Attachment
[BUFFER_DEPTH
];
114 if (!intel_renderbuffer_has_hiz(depth_irb
))
117 /* We only handle full buffer clears -- otherwise you'd have to track whether
118 * a previous clear had happened at a different clear value and resolve it
121 if ((ctx
->Scissor
.EnableFlags
& 1) && !noop_scissor(fb
)) {
122 perf_debug("Failed to fast clear %dx%d depth because of scissors. "
123 "Possible 5%% performance win if avoided.\n",
124 mt
->logical_width0
, mt
->logical_height0
);
128 switch (mt
->format
) {
129 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
130 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
131 /* From the Sandy Bridge PRM, volume 2 part 1, page 314:
133 * "[DevSNB+]: Several cases exist where Depth Buffer Clear cannot be
134 * enabled (the legacy method of clearing must be performed):
136 * - If the depth buffer format is D32_FLOAT_S8X24_UINT or
141 case MESA_FORMAT_Z_UNORM16
:
142 /* From the Sandy Bridge PRM, volume 2 part 1, page 314:
144 * "[DevSNB+]: Several cases exist where Depth Buffer Clear cannot be
145 * enabled (the legacy method of clearing must be performed):
147 * - DevSNB{W/A}]: When depth buffer format is D16_UNORM and the
148 * width of the map (LOD0) is not multiple of 16, fast clear
149 * optimization must be disabled.
152 (minify(mt
->physical_width0
,
153 depth_irb
->mt_level
- mt
->first_level
) % 16) != 0)
161 /* If we're clearing to a new clear value, then we need to resolve any clear
162 * flags out of the HiZ buffer into the real depth buffer.
164 if (mt
->fast_clear_color
.f32
[0] != ctx
->Depth
.Clear
) {
165 intel_miptree_all_slices_resolve_depth(brw
, mt
);
166 mt
->fast_clear_color
.f32
[0] = ctx
->Depth
.Clear
;
169 if (fb
->MaxNumLayers
> 0) {
170 intel_hiz_exec(brw
, mt
, depth_irb
->mt_level
,
171 depth_irb
->mt_layer
, depth_irb
->layer_count
,
172 BLORP_HIZ_OP_DEPTH_CLEAR
);
174 intel_hiz_exec(brw
, mt
, depth_irb
->mt_level
, depth_irb
->mt_layer
, 1,
175 BLORP_HIZ_OP_DEPTH_CLEAR
);
178 /* Now, the HiZ buffer contains data that needs to be resolved to the depth
181 intel_renderbuffer_att_set_needs_depth_resolve(depth_att
);
187 * Called by ctx->Driver.Clear.
190 brw_clear(struct gl_context
*ctx
, GLbitfield mask
)
192 struct brw_context
*brw
= brw_context(ctx
);
193 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
194 bool partial_clear
= ctx
->Scissor
.EnableFlags
&& !noop_scissor(fb
);
196 if (!_mesa_check_conditional_render(ctx
))
199 if (mask
& (BUFFER_BIT_FRONT_LEFT
| BUFFER_BIT_FRONT_RIGHT
)) {
200 brw
->front_buffer_dirty
= true;
203 intel_prepare_render(brw
);
204 brw_workaround_depthstencil_alignment(brw
, partial_clear
? 0 : mask
);
206 if (mask
& BUFFER_BIT_DEPTH
) {
207 if (brw_fast_clear_depth(ctx
)) {
208 DBG("fast clear: depth\n");
209 mask
&= ~BUFFER_BIT_DEPTH
;
213 if (mask
& BUFFER_BIT_STENCIL
) {
214 struct intel_renderbuffer
*stencil_irb
=
215 intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
216 struct intel_mipmap_tree
*mt
= stencil_irb
->mt
;
217 if (mt
&& mt
->stencil_mt
)
218 mt
->stencil_mt
->r8stencil_needs_update
= true;
221 if (mask
& BUFFER_BITS_COLOR
) {
222 const bool encode_srgb
= ctx
->Color
.sRGBEnabled
;
223 if (brw_blorp_clear_color(brw
, fb
, mask
, partial_clear
, encode_srgb
)) {
224 debug_mask("blorp color", mask
& BUFFER_BITS_COLOR
);
225 mask
&= ~BUFFER_BITS_COLOR
;
229 GLbitfield tri_mask
= mask
& (BUFFER_BITS_COLOR
|
234 debug_mask("tri", tri_mask
);
237 if (ctx
->API
== API_OPENGLES
) {
238 _mesa_meta_Clear(&brw
->ctx
, tri_mask
);
240 _mesa_meta_glsl_Clear(&brw
->ctx
, tri_mask
);
244 /* Any strange buffers get passed off to swrast */
246 debug_mask("swrast", mask
);
247 _swrast_Clear(ctx
, mask
);
253 intelInitClearFuncs(struct dd_function_table
*functions
)
255 functions
->Clear
= brw_clear
;