2 * Copyright © 2017 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 shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
25 #include "pipe/p_defines.h"
26 #include "pipe/p_state.h"
27 #include "pipe/p_context.h"
28 #include "pipe/p_screen.h"
29 #include "util/u_inlines.h"
30 #include "util/u_format.h"
31 #include "util/u_upload_mgr.h"
32 #include "util/ralloc.h"
33 #include "iris_context.h"
34 #include "iris_resource.h"
35 #include "iris_screen.h"
36 #include "intel/compiler/brw_compiler.h"
39 clear_color(struct iris_context
*ice
,
40 struct pipe_resource
*p_res
,
42 const struct pipe_box
*box
,
43 bool render_condition_enabled
,
44 enum isl_format format
,
45 union isl_color_value color
)
47 struct iris_resource
*res
= (void *) p_res
;
49 struct iris_batch
*batch
= &ice
->batches
[IRIS_BATCH_RENDER
];
50 const struct gen_device_info
*devinfo
= &batch
->screen
->devinfo
;
51 enum blorp_batch_flags blorp_flags
= 0;
53 if (render_condition_enabled
) {
54 if (ice
->state
.predicate
== IRIS_PREDICATE_STATE_DONT_RENDER
)
57 if (ice
->state
.predicate
== IRIS_PREDICATE_STATE_USE_BIT
)
58 blorp_flags
|= BLORP_BATCH_PREDICATE_ENABLE
;
61 iris_batch_maybe_flush(batch
, 1500);
63 struct blorp_batch blorp_batch
;
64 blorp_batch_init(&ice
->blorp
, &blorp_batch
, batch
, blorp_flags
);
66 bool color_write_disable
[4] = { false, false, false, false };
67 struct blorp_surf surf
;
68 iris_blorp_surf_for_resource(&surf
, p_res
, ISL_AUX_USAGE_NONE
, true);
70 if (!isl_format_supports_rendering(devinfo
, format
) &&
71 isl_format_is_rgbx(format
))
72 format
= isl_format_rgbx_to_rgba(format
);
74 blorp_clear(&blorp_batch
, &surf
, format
, ISL_SWIZZLE_IDENTITY
,
75 level
, box
->z
, box
->depth
, box
->x
, box
->y
,
76 box
->x
+ box
->width
, box
->y
+ box
->height
,
77 color
, color_write_disable
);
79 blorp_batch_finish(&blorp_batch
);
80 iris_flush_and_dirty_for_history(ice
, batch
, res
);
85 clear_depth_stencil(struct iris_context
*ice
,
86 struct pipe_resource
*p_res
,
88 const struct pipe_box
*box
,
89 bool render_condition_enabled
,
95 struct iris_resource
*res
= (void *) p_res
;
97 struct iris_batch
*batch
= &ice
->batches
[IRIS_BATCH_RENDER
];
98 enum blorp_batch_flags blorp_flags
= 0;
100 if (render_condition_enabled
) {
101 if (ice
->state
.predicate
== IRIS_PREDICATE_STATE_DONT_RENDER
)
104 if (ice
->state
.predicate
== IRIS_PREDICATE_STATE_USE_BIT
)
105 blorp_flags
|= BLORP_BATCH_PREDICATE_ENABLE
;
108 iris_batch_maybe_flush(batch
, 1500);
110 struct blorp_batch blorp_batch
;
111 blorp_batch_init(&ice
->blorp
, &blorp_batch
, batch
, blorp_flags
);
113 struct iris_resource
*z_res
;
114 struct iris_resource
*stencil_res
;
115 struct blorp_surf z_surf
;
116 struct blorp_surf stencil_surf
;
118 iris_get_depth_stencil_resources(p_res
, &z_res
, &stencil_res
);
121 iris_blorp_surf_for_resource(&z_surf
, &z_res
->base
,
122 ISL_AUX_USAGE_NONE
, true);
126 iris_blorp_surf_for_resource(&stencil_surf
, &stencil_res
->base
,
127 ISL_AUX_USAGE_NONE
, true);
130 blorp_clear_depth_stencil(&blorp_batch
, &z_surf
, &stencil_surf
,
131 level
, box
->z
, box
->depth
,
134 box
->y
+ box
->height
,
135 clear_depth
&& z_res
, depth
,
136 clear_stencil
&& stencil_res
? 0xff : 0, stencil
);
138 blorp_batch_finish(&blorp_batch
);
139 iris_flush_and_dirty_for_history(ice
, batch
, res
);
143 * The pipe->clear() driver hook.
145 * This clears buffers attached to the current draw framebuffer.
148 iris_clear(struct pipe_context
*ctx
,
150 const union pipe_color_union
*p_color
,
154 struct iris_context
*ice
= (void *) ctx
;
155 struct pipe_framebuffer_state
*cso_fb
= &ice
->state
.framebuffer
;
157 assert(buffers
!= 0);
159 if (buffers
& PIPE_CLEAR_DEPTHSTENCIL
) {
160 struct pipe_surface
*psurf
= cso_fb
->zsbuf
;
161 struct pipe_box box
= {
162 .width
= cso_fb
->width
,
163 .height
= cso_fb
->height
,
164 .depth
= psurf
->u
.tex
.last_layer
- psurf
->u
.tex
.first_layer
+ 1,
165 .z
= psurf
->u
.tex
.first_layer
,
168 clear_depth_stencil(ice
, psurf
->texture
, psurf
->u
.tex
.level
, &box
, true,
169 buffers
& PIPE_CLEAR_DEPTH
,
170 buffers
& PIPE_CLEAR_STENCIL
,
174 if (buffers
& PIPE_CLEAR_COLOR
) {
175 /* pipe_color_union and isl_color_value are interchangeable */
176 union isl_color_value
*color
= (void *) p_color
;
178 for (unsigned i
= 0; i
< cso_fb
->nr_cbufs
; i
++) {
179 if (buffers
& (PIPE_CLEAR_COLOR0
<< i
)) {
180 struct pipe_surface
*psurf
= cso_fb
->cbufs
[i
];
181 struct iris_surface
*isurf
= (void *) psurf
;
182 struct pipe_box box
= {
183 .width
= cso_fb
->width
,
184 .height
= cso_fb
->height
,
185 .depth
= psurf
->u
.tex
.last_layer
- psurf
->u
.tex
.first_layer
+ 1,
186 .z
= psurf
->u
.tex
.first_layer
,
189 clear_color(ice
, psurf
->texture
, psurf
->u
.tex
.level
, &box
,
190 true, isurf
->view
.format
, *color
);
197 * The pipe->clear_texture() driver hook.
199 * This clears the given texture resource.
202 iris_clear_texture(struct pipe_context
*ctx
,
203 struct pipe_resource
*p_res
,
205 const struct pipe_box
*box
,
208 struct iris_context
*ice
= (void *) ctx
;
209 struct iris_screen
*screen
= (void *) ctx
->screen
;
210 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
212 if (util_format_is_depth_or_stencil(p_res
->format
)) {
213 const struct util_format_description
*fmt_desc
=
214 util_format_description(p_res
->format
);
219 if (fmt_desc
->unpack_z_float
)
220 fmt_desc
->unpack_z_float(&depth
, 0, data
, 0, 1, 1);
222 if (fmt_desc
->unpack_s_8uint
)
223 fmt_desc
->unpack_s_8uint(&stencil
, 0, data
, 0, 1, 1);
225 clear_depth_stencil(ice
, p_res
, level
, box
, true, true, true,
228 union isl_color_value color
;
229 struct iris_resource
*res
= (void *) p_res
;
230 enum isl_format format
= res
->surf
.format
;
232 if (!isl_format_supports_rendering(devinfo
, format
)) {
233 const struct isl_format_layout
*fmtl
= isl_format_get_layout(format
);
234 // XXX: actually just get_copy_format_for_bpb from BLORP
235 // XXX: don't cut and paste this
237 case 8: format
= ISL_FORMAT_R8_UINT
; break;
238 case 16: format
= ISL_FORMAT_R8G8_UINT
; break;
239 case 24: format
= ISL_FORMAT_R8G8B8_UINT
; break;
240 case 32: format
= ISL_FORMAT_R8G8B8A8_UINT
; break;
241 case 48: format
= ISL_FORMAT_R16G16B16_UINT
; break;
242 case 64: format
= ISL_FORMAT_R16G16B16A16_UINT
; break;
243 case 96: format
= ISL_FORMAT_R32G32B32_UINT
; break;
244 case 128: format
= ISL_FORMAT_R32G32B32A32_UINT
; break;
246 unreachable("Unknown format bpb");
250 isl_color_value_unpack(&color
, format
, data
);
252 clear_color(ice
, p_res
, level
, box
, true, format
, color
);
257 * The pipe->clear_render_target() driver hook.
259 * This clears the given render target surface.
262 iris_clear_render_target(struct pipe_context
*ctx
,
263 struct pipe_surface
*psurf
,
264 const union pipe_color_union
*p_color
,
265 unsigned dst_x
, unsigned dst_y
,
266 unsigned width
, unsigned height
,
267 bool render_condition_enabled
)
269 struct iris_context
*ice
= (void *) ctx
;
270 struct iris_surface
*isurf
= (void *) psurf
;
271 struct pipe_box box
= {
274 .z
= psurf
->u
.tex
.first_layer
,
277 .depth
= psurf
->u
.tex
.last_layer
- psurf
->u
.tex
.first_layer
+ 1
280 /* pipe_color_union and isl_color_value are interchangeable */
281 union isl_color_value
*color
= (void *) p_color
;
283 clear_color(ice
, psurf
->texture
, psurf
->u
.tex
.level
, &box
, true,
284 isurf
->view
.format
, *color
);
288 * The pipe->clear_depth_stencil() driver hook.
290 * This clears the given depth/stencil surface.
293 iris_clear_depth_stencil(struct pipe_context
*ctx
,
294 struct pipe_surface
*psurf
,
298 unsigned dst_x
, unsigned dst_y
,
299 unsigned width
, unsigned height
,
300 bool render_condition_enabled
)
302 struct iris_context
*ice
= (void *) ctx
;
303 struct pipe_box box
= {
306 .z
= psurf
->u
.tex
.first_layer
,
309 .depth
= psurf
->u
.tex
.last_layer
- psurf
->u
.tex
.first_layer
+ 1
312 assert(util_format_is_depth_or_stencil(psurf
->texture
->format
));
314 clear_depth_stencil(ice
, psurf
->texture
, psurf
->u
.tex
.level
, &box
, true,
315 flags
& PIPE_CLEAR_DEPTH
, flags
& PIPE_CLEAR_STENCIL
,
320 iris_init_clear_functions(struct pipe_context
*ctx
)
322 ctx
->clear
= iris_clear
;
323 ctx
->clear_texture
= iris_clear_texture
;
324 ctx
->clear_render_target
= iris_clear_render_target
;
325 ctx
->clear_depth_stencil
= iris_clear_depth_stencil
;