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.
24 #include "pipe/p_defines.h"
25 #include "pipe/p_state.h"
26 #include "pipe/p_context.h"
27 #include "pipe/p_screen.h"
28 #include "util/u_format.h"
29 #include "util/u_inlines.h"
30 #include "util/ralloc.h"
31 #include "intel/blorp/blorp.h"
32 #include "iris_context.h"
33 #include "iris_resource.h"
34 #include "iris_screen.h"
37 iris_blorp_surf_for_resource(struct blorp_surf
*surf
,
38 struct pipe_resource
*p_res
,
39 enum isl_aux_usage aux_usage
,
40 bool is_render_target
)
42 struct iris_resource
*res
= (void *) p_res
;
44 *surf
= (struct blorp_surf
) {
46 .addr
= (struct blorp_address
) {
48 .offset
= 0, // XXX: ???
49 .reloc_flags
= is_render_target
? EXEC_OBJECT_WRITE
: 0,
50 .mocs
= I915_MOCS_CACHED
, // XXX: BDW MOCS, PTE MOCS
52 .aux_usage
= aux_usage
,
55 assert(surf
->aux_usage
== ISL_AUX_USAGE_NONE
);
58 static enum isl_format
59 iris_get_blorp_format(enum pipe_format pf
)
62 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
63 return ISL_FORMAT_R24_UNORM_X8_TYPELESS
;
64 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
65 return ISL_FORMAT_R32_FLOAT
;
67 return iris_isl_format_for_pipe_format(pf
);
72 * The pipe->blit() driver hook.
74 * This performs a blit between two surfaces, which copies data but may
75 * also perform format conversion, scaling, flipping, and so on.
78 iris_blit(struct pipe_context
*ctx
, const struct pipe_blit_info
*info
)
80 struct iris_context
*ice
= (void *) ctx
;
81 struct blorp_surf src_surf
, dst_surf
;
82 iris_blorp_surf_for_resource(&src_surf
, info
->src
.resource
,
83 ISL_AUX_USAGE_NONE
, false);
84 iris_blorp_surf_for_resource(&dst_surf
, info
->dst
.resource
,
85 ISL_AUX_USAGE_NONE
, true);
87 enum isl_format src_isl_format
= iris_get_blorp_format(info
->src
.format
);
88 enum isl_format dst_isl_format
= iris_get_blorp_format(info
->dst
.format
);
90 struct isl_swizzle src_isl_swizzle
= ISL_SWIZZLE_IDENTITY
;
92 int src_x0
= info
->src
.box
.x
;
93 int src_x1
= info
->src
.box
.x
+ info
->src
.box
.width
;
94 int src_y0
= info
->src
.box
.y
;
95 int src_y1
= info
->src
.box
.y
+ info
->src
.box
.height
;
96 int dst_x0
= info
->dst
.box
.x
;
97 int dst_x1
= info
->dst
.box
.x
+ info
->dst
.box
.width
;
98 int dst_y0
= info
->dst
.box
.y
;
99 int dst_y1
= info
->dst
.box
.y
+ info
->dst
.box
.height
;
100 bool mirror_x
= false;
101 bool mirror_y
= false;
102 enum blorp_filter filter
;
104 if (abs(info
->dst
.box
.width
) == abs(info
->src
.box
.width
) &&
105 abs(info
->dst
.box
.height
) == abs(info
->src
.box
.height
)) {
106 if (src_surf
.surf
->samples
> 1 && dst_surf
.surf
->samples
<= 1) {
107 /* The OpenGL ES 3.2 specification, section 16.2.1, says:
109 * "If the read framebuffer is multisampled (its effective
110 * value of SAMPLE_BUFFERS is one) and the draw framebuffer
111 * is not (its value of SAMPLE_BUFFERS is zero), the samples
112 * corresponding to each pixel location in the source are
113 * converted to a single sample before being written to the
114 * destination. The filter parameter is ignored. If the
115 * source formats are integer types or stencil values, a
116 * single sample’s value is selected for each pixel. If the
117 * source formats are floating-point or normalized types,
118 * the sample values for each pixel are resolved in an
119 * implementation-dependent manner. If the source formats
120 * are depth values, sample values are resolved in an
121 * implementation-dependent manner where the result will be
122 * between the minimum and maximum depth values in the pixel."
124 * When selecting a single sample, we always choose sample 0.
126 if (util_format_is_depth_or_stencil(info
->src
.format
) ||
127 util_format_is_pure_integer(info
->src
.format
)) {
128 filter
= BLORP_FILTER_SAMPLE_0
;
130 filter
= BLORP_FILTER_AVERAGE
;
133 /* The OpenGL 4.6 specification, section 18.3.1, says:
135 * "If the source and destination dimensions are identical,
136 * no filtering is applied."
138 * Using BLORP_FILTER_NONE will also handle the upsample case by
139 * replicating the one value in the source to all values in the
142 filter
= BLORP_FILTER_NONE
;
144 } else if (info
->filter
== PIPE_TEX_FILTER_LINEAR
) {
145 filter
= BLORP_FILTER_BILINEAR
;
147 filter
= BLORP_FILTER_NEAREST
;
150 struct iris_batch
*batch
= &ice
->render_batch
;
152 struct blorp_batch blorp_batch
;
153 blorp_batch_init(&ice
->blorp
, &blorp_batch
, batch
, 0);
155 for (int slice
= 0; slice
< info
->dst
.box
.depth
; slice
++) {
156 iris_batch_maybe_flush(batch
, 1500);
158 blorp_blit(&blorp_batch
,
159 &src_surf
, info
->src
.level
, info
->src
.box
.z
+ slice
,
160 src_isl_format
, src_isl_swizzle
,
161 &dst_surf
, info
->dst
.level
, info
->dst
.box
.z
+ slice
,
162 dst_isl_format
, ISL_SWIZZLE_IDENTITY
,
163 src_x0
, src_y0
, src_x1
, src_y1
,
164 dst_x0
, dst_y0
, dst_x1
, dst_y1
,
165 filter
, mirror_x
, mirror_y
);
168 if (util_format_is_depth_and_stencil(info
->dst
.format
) &&
169 util_format_has_stencil(util_format_description(info
->src
.format
))) {
170 struct iris_resource
*src_res
, *dst_res
, *junk
;
171 iris_get_depth_stencil_resources(info
->src
.resource
, &junk
, &src_res
);
172 iris_get_depth_stencil_resources(info
->dst
.resource
, &junk
, &dst_res
);
173 iris_blorp_surf_for_resource(&src_surf
, &src_res
->base
,
174 ISL_AUX_USAGE_NONE
, false);
175 iris_blorp_surf_for_resource(&dst_surf
, &dst_res
->base
,
176 ISL_AUX_USAGE_NONE
, true);
178 for (int slice
= 0; slice
< info
->dst
.box
.depth
; slice
++) {
179 iris_batch_maybe_flush(batch
, 1500);
181 blorp_blit(&blorp_batch
,
182 &src_surf
, info
->src
.level
, info
->src
.box
.z
+ slice
,
183 ISL_FORMAT_R8_UINT
, src_isl_swizzle
,
184 &dst_surf
, info
->dst
.level
, info
->dst
.box
.z
+ slice
,
185 ISL_FORMAT_R8_UINT
, ISL_SWIZZLE_IDENTITY
,
186 src_x0
, src_y0
, src_x1
, src_y1
,
187 dst_x0
, dst_y0
, dst_x1
, dst_y1
,
188 filter
, mirror_x
, mirror_y
);
192 blorp_batch_finish(&blorp_batch
);
196 * The pipe->resource_copy_region() driver hook.
198 * This implements ARB_copy_image semantics - a raw memory copy between
199 * compatible view classes.
202 iris_resource_copy_region(struct pipe_context
*ctx
,
203 struct pipe_resource
*dst
,
205 unsigned dstx
, unsigned dsty
, unsigned dstz
,
206 struct pipe_resource
*src
,
208 const struct pipe_box
*src_box
)
210 struct iris_context
*ice
= (void *) ctx
;
211 struct blorp_surf src_surf
, dst_surf
;
212 iris_blorp_surf_for_resource(&src_surf
, src
, ISL_AUX_USAGE_NONE
, false);
213 iris_blorp_surf_for_resource(&dst_surf
, dst
, ISL_AUX_USAGE_NONE
, true);
216 unsigned dst_layer
= dstz
;
217 unsigned src_layer
= src_box
->z
;
219 assert(src_box
->depth
== 1);
221 struct iris_batch
*batch
= &ice
->render_batch
;
223 iris_batch_maybe_flush(batch
, 1500);
225 struct blorp_batch blorp_batch
;
226 blorp_batch_init(&ice
->blorp
, &blorp_batch
, batch
, 0);
227 blorp_copy(&blorp_batch
, &src_surf
, src_level
, src_layer
,
228 &dst_surf
, dst_level
, dst_layer
,
229 src_box
->x
, src_box
->y
, dstx
, dsty
,
230 src_box
->width
, src_box
->height
);
231 blorp_batch_finish(&blorp_batch
);
235 iris_init_blit_functions(struct pipe_context
*ctx
)
237 ctx
->blit
= iris_blit
;
238 ctx
->resource_copy_region
= iris_resource_copy_region
;