2 * Copyright 2003 VMware, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include "main/mtypes.h"
27 #include "main/blit.h"
28 #include "main/context.h"
29 #include "main/enums.h"
30 #include "main/fbobject.h"
32 #include "brw_context.h"
33 #include "brw_defines.h"
34 #include "intel_blit.h"
35 #include "intel_buffers.h"
36 #include "intel_fbo.h"
37 #include "intel_batchbuffer.h"
38 #include "intel_mipmap_tree.h"
40 #define FILE_DEBUG_FLAG DEBUG_BLIT
43 intel_miptree_set_alpha_to_one(struct brw_context
*brw
,
44 struct intel_mipmap_tree
*mt
,
45 int x
, int y
, int width
, int height
);
47 static GLuint
translate_raster_op(GLenum logicop
)
50 case GL_CLEAR
: return 0x00;
51 case GL_AND
: return 0x88;
52 case GL_AND_REVERSE
: return 0x44;
53 case GL_COPY
: return 0xCC;
54 case GL_AND_INVERTED
: return 0x22;
55 case GL_NOOP
: return 0xAA;
56 case GL_XOR
: return 0x66;
57 case GL_OR
: return 0xEE;
58 case GL_NOR
: return 0x11;
59 case GL_EQUIV
: return 0x99;
60 case GL_INVERT
: return 0x55;
61 case GL_OR_REVERSE
: return 0xDD;
62 case GL_COPY_INVERTED
: return 0x33;
63 case GL_OR_INVERTED
: return 0xBB;
64 case GL_NAND
: return 0x77;
65 case GL_SET
: return 0xFF;
85 unreachable("not reached");
90 * Emits the packet for switching the blitter from X to Y tiled or back.
92 * This has to be called in a single BEGIN_BATCH_BLT_TILED() /
93 * ADVANCE_BATCH_TILED(). This is because BCS_SWCTRL is saved and restored as
94 * part of the power context, not a render context, and if the batchbuffer was
95 * to get flushed between setting and blitting, or blitting and restoring, our
96 * tiling state would leak into other unsuspecting applications (like the X
100 set_blitter_tiling(struct brw_context
*brw
,
101 bool dst_y_tiled
, bool src_y_tiled
,
104 assert(brw
->gen
>= 6);
106 /* Idle the blitter before we update how tiling is interpreted. */
107 OUT_BATCH(MI_FLUSH_DW
);
112 OUT_BATCH(MI_LOAD_REGISTER_IMM
| (3 - 2));
113 OUT_BATCH(BCS_SWCTRL
);
114 OUT_BATCH((BCS_SWCTRL_DST_Y
| BCS_SWCTRL_SRC_Y
) << 16 |
115 (dst_y_tiled
? BCS_SWCTRL_DST_Y
: 0) |
116 (src_y_tiled
? BCS_SWCTRL_SRC_Y
: 0));
119 #define SET_BLITTER_TILING(...) __map = set_blitter_tiling(__VA_ARGS__, __map)
121 #define BEGIN_BATCH_BLT_TILED(n, dst_y_tiled, src_y_tiled) \
122 BEGIN_BATCH_BLT(n + ((dst_y_tiled || src_y_tiled) ? 14 : 0)); \
123 if (dst_y_tiled || src_y_tiled) \
124 SET_BLITTER_TILING(brw, dst_y_tiled, src_y_tiled)
126 #define ADVANCE_BATCH_TILED(dst_y_tiled, src_y_tiled) \
127 if (dst_y_tiled || src_y_tiled) \
128 SET_BLITTER_TILING(brw, false, false); \
132 blt_pitch(struct intel_mipmap_tree
*mt
)
134 int pitch
= mt
->pitch
;
141 intel_miptree_blit_compatible_formats(mesa_format src
, mesa_format dst
)
143 /* The BLT doesn't handle sRGB conversion */
144 assert(src
== _mesa_get_srgb_format_linear(src
));
145 assert(dst
== _mesa_get_srgb_format_linear(dst
));
147 /* No swizzle or format conversions possible, except... */
151 /* ...we can either discard the alpha channel when going from A->X,
152 * or we can fill the alpha channel with 0xff when going from X->A
154 if (src
== MESA_FORMAT_B8G8R8A8_UNORM
|| src
== MESA_FORMAT_B8G8R8X8_UNORM
)
155 return (dst
== MESA_FORMAT_B8G8R8A8_UNORM
||
156 dst
== MESA_FORMAT_B8G8R8X8_UNORM
);
158 if (src
== MESA_FORMAT_R8G8B8A8_UNORM
|| src
== MESA_FORMAT_R8G8B8X8_UNORM
)
159 return (dst
== MESA_FORMAT_R8G8B8A8_UNORM
||
160 dst
== MESA_FORMAT_R8G8B8X8_UNORM
);
166 get_blit_intratile_offset_el(const struct brw_context
*brw
,
167 struct intel_mipmap_tree
*mt
,
168 uint32_t total_x_offset_el
,
169 uint32_t total_y_offset_el
,
170 uint32_t *base_address_offset
,
171 uint32_t *x_offset_el
,
172 uint32_t *y_offset_el
)
174 enum isl_tiling tiling
= intel_miptree_get_isl_tiling(mt
);
175 isl_tiling_get_intratile_offset_el(&brw
->isl_dev
,
176 tiling
, mt
->cpp
, mt
->pitch
,
177 total_x_offset_el
, total_y_offset_el
,
179 x_offset_el
, y_offset_el
);
180 if (tiling
== ISL_TILING_LINEAR
) {
181 /* From the Broadwell PRM docs for XY_SRC_COPY_BLT::SourceBaseAddress:
183 * "Base address of the destination surface: X=0, Y=0. Lower 32bits
184 * of the 48bit addressing. When Src Tiling is enabled (Bit_15
185 * enabled), this address must be 4KB-aligned. When Tiling is not
186 * enabled, this address should be CL (64byte) aligned."
188 * The offsets we get from ISL in the tiled case are already aligned.
189 * In the linear case, we need to do some of our own aligning.
191 assert(mt
->pitch
% 64 == 0);
192 uint32_t delta
= *base_address_offset
& 63;
193 assert(delta
% mt
->cpp
== 0);
194 *base_address_offset
-= delta
;
195 *x_offset_el
+= delta
/ mt
->cpp
;
197 assert(*base_address_offset
% 4096 == 0);
202 emit_miptree_blit(struct brw_context
*brw
,
203 struct intel_mipmap_tree
*src_mt
,
204 uint32_t src_x
, uint32_t src_y
,
205 struct intel_mipmap_tree
*dst_mt
,
206 uint32_t dst_x
, uint32_t dst_y
,
207 uint32_t width
, uint32_t height
,
208 bool reverse
, GLenum logicop
)
210 /* According to the Ivy Bridge PRM, Vol1 Part4, section 1.2.1.2 (Graphics
211 * Data Size Limitations):
213 * The BLT engine is capable of transferring very large quantities of
214 * graphics data. Any graphics data read from and written to the
215 * destination is permitted to represent a number of pixels that
216 * occupies up to 65,536 scan lines and up to 32,768 bytes per scan line
217 * at the destination. The maximum number of pixels that may be
218 * represented per scan line’s worth of graphics data depends on the
221 * The blitter's pitch is a signed 16-bit integer, but measured in bytes
222 * for linear surfaces and DWords for tiled surfaces. So the maximum
223 * pitch is 32k linear and 128k tiled.
225 if (blt_pitch(src_mt
) >= 32768 || blt_pitch(dst_mt
) >= 32768) {
226 perf_debug("Falling back due to >= 32k/128k pitch\n");
230 /* We need to split the blit into chunks that each fit within the blitter's
231 * restrictions. We can't use a chunk size of 32768 because we need to
232 * ensure that src_tile_x + chunk_size fits. We choose 16384 because it's
233 * a nice round power of two, big enough that performance won't suffer, and
234 * small enough to guarantee everything fits.
236 const uint32_t max_chunk_size
= 16384;
238 for (uint32_t chunk_x
= 0; chunk_x
< width
; chunk_x
+= max_chunk_size
) {
239 for (uint32_t chunk_y
= 0; chunk_y
< height
; chunk_y
+= max_chunk_size
) {
240 const uint32_t chunk_w
= MIN2(max_chunk_size
, width
- chunk_x
);
241 const uint32_t chunk_h
= MIN2(max_chunk_size
, height
- chunk_y
);
243 uint32_t src_offset
, src_tile_x
, src_tile_y
;
244 get_blit_intratile_offset_el(brw
, src_mt
,
245 src_x
+ chunk_x
, src_y
+ chunk_y
,
246 &src_offset
, &src_tile_x
, &src_tile_y
);
248 uint32_t dst_offset
, dst_tile_x
, dst_tile_y
;
249 get_blit_intratile_offset_el(brw
, dst_mt
,
250 dst_x
+ chunk_x
, dst_y
+ chunk_y
,
251 &dst_offset
, &dst_tile_x
, &dst_tile_y
);
253 if (!intelEmitCopyBlit(brw
,
255 reverse
? -src_mt
->pitch
: src_mt
->pitch
,
256 src_mt
->bo
, src_mt
->offset
+ src_offset
,
259 dst_mt
->bo
, dst_mt
->offset
+ dst_offset
,
261 src_tile_x
, src_tile_y
,
262 dst_tile_x
, dst_tile_y
,
265 /* If this is ever going to fail, it will fail on the first chunk */
266 assert(chunk_x
== 0 && chunk_y
== 0);
276 * Implements a rectangular block transfer (blit) of pixels between two
279 * Our blitter can operate on 1, 2, or 4-byte-per-pixel data, with generous,
280 * but limited, pitches and sizes allowed.
282 * The src/dst coordinates are relative to the given level/slice of the
285 * If @src_flip or @dst_flip is set, then the rectangle within that miptree
286 * will be inverted (including scanline order) when copying. This is common
287 * in GL when copying between window system and user-created
288 * renderbuffers/textures.
291 intel_miptree_blit(struct brw_context
*brw
,
292 struct intel_mipmap_tree
*src_mt
,
293 int src_level
, int src_slice
,
294 uint32_t src_x
, uint32_t src_y
, bool src_flip
,
295 struct intel_mipmap_tree
*dst_mt
,
296 int dst_level
, int dst_slice
,
297 uint32_t dst_x
, uint32_t dst_y
, bool dst_flip
,
298 uint32_t width
, uint32_t height
,
301 /* The blitter doesn't understand multisampling at all. */
302 if (src_mt
->num_samples
> 0 || dst_mt
->num_samples
> 0)
305 /* No sRGB decode or encode is done by the hardware blitter, which is
306 * consistent with what we want in many callers (glCopyTexSubImage(),
307 * texture validation, etc.).
309 mesa_format src_format
= _mesa_get_srgb_format_linear(src_mt
->format
);
310 mesa_format dst_format
= _mesa_get_srgb_format_linear(dst_mt
->format
);
312 /* The blitter doesn't support doing any format conversions. We do also
313 * support blitting ARGB8888 to XRGB8888 (trivial, the values dropped into
314 * the X channel don't matter), and XRGB8888 to ARGB8888 by setting the A
315 * channel to 1.0 at the end.
317 if (!intel_miptree_blit_compatible_formats(src_format
, dst_format
)) {
318 perf_debug("%s: Can't use hardware blitter from %s to %s, "
319 "falling back.\n", __func__
,
320 _mesa_get_format_name(src_format
),
321 _mesa_get_format_name(dst_format
));
325 /* The blitter has no idea about HiZ or fast color clears, so we need to
326 * resolve the miptrees before we do anything.
328 intel_miptree_slice_resolve_depth(brw
, src_mt
, src_level
, src_slice
);
329 intel_miptree_slice_resolve_depth(brw
, dst_mt
, dst_level
, dst_slice
);
330 intel_miptree_resolve_color(brw
, src_mt
, src_level
, src_slice
, 1, 0);
331 intel_miptree_resolve_color(brw
, dst_mt
, dst_level
, dst_slice
, 1, 0);
334 src_y
= minify(src_mt
->physical_height0
, src_level
- src_mt
->first_level
) - src_y
- height
;
337 dst_y
= minify(dst_mt
->physical_height0
, dst_level
- dst_mt
->first_level
) - dst_y
- height
;
339 uint32_t src_image_x
, src_image_y
, dst_image_x
, dst_image_y
;
340 intel_miptree_get_image_offset(src_mt
, src_level
, src_slice
,
341 &src_image_x
, &src_image_y
);
342 intel_miptree_get_image_offset(dst_mt
, dst_level
, dst_slice
,
343 &dst_image_x
, &dst_image_y
);
344 src_x
+= src_image_x
;
345 src_y
+= src_image_y
;
346 dst_x
+= dst_image_x
;
347 dst_y
+= dst_image_y
;
349 if (!emit_miptree_blit(brw
, src_mt
, src_x
, src_y
,
350 dst_mt
, dst_x
, dst_y
, width
, height
,
351 src_flip
!= dst_flip
, logicop
)) {
355 /* XXX This could be done in a single pass using XY_FULL_MONO_PATTERN_BLT */
356 if (_mesa_get_format_bits(src_format
, GL_ALPHA_BITS
) == 0 &&
357 _mesa_get_format_bits(dst_format
, GL_ALPHA_BITS
) > 0) {
358 intel_miptree_set_alpha_to_one(brw
, dst_mt
,
367 intel_miptree_copy(struct brw_context
*brw
,
368 struct intel_mipmap_tree
*src_mt
,
369 int src_level
, int src_slice
,
370 uint32_t src_x
, uint32_t src_y
,
371 struct intel_mipmap_tree
*dst_mt
,
372 int dst_level
, int dst_slice
,
373 uint32_t dst_x
, uint32_t dst_y
,
374 uint32_t src_width
, uint32_t src_height
)
376 /* The blitter doesn't understand multisampling at all. */
377 if (src_mt
->num_samples
> 0 || dst_mt
->num_samples
> 0)
380 if (src_mt
->format
== MESA_FORMAT_S_UINT8
)
383 /* The blitter has no idea about HiZ or fast color clears, so we need to
384 * resolve the miptrees before we do anything.
386 intel_miptree_slice_resolve_depth(brw
, src_mt
, src_level
, src_slice
);
387 intel_miptree_slice_resolve_depth(brw
, dst_mt
, dst_level
, dst_slice
);
388 intel_miptree_resolve_color(brw
, src_mt
, src_level
, src_slice
, 1, 0);
389 intel_miptree_resolve_color(brw
, dst_mt
, dst_level
, dst_slice
, 1, 0);
391 uint32_t src_image_x
, src_image_y
;
392 intel_miptree_get_image_offset(src_mt
, src_level
, src_slice
,
393 &src_image_x
, &src_image_y
);
395 if (_mesa_is_format_compressed(src_mt
->format
)) {
397 _mesa_get_format_block_size(src_mt
->format
, &bw
, &bh
);
399 /* Compressed textures need not have dimensions that are a multiple of
400 * the block size. Rectangles in compressed textures do need to be a
401 * multiple of the block size. The one exception is that the right and
402 * bottom edges may be at the right or bottom edge of the miplevel even
403 * if it's not aligned.
405 assert(src_x
% bw
== 0);
406 assert(src_y
% bh
== 0);
407 assert(src_width
% bw
== 0 ||
408 src_x
+ src_width
== minify(src_mt
->logical_width0
, src_level
));
409 assert(src_height
% bh
== 0 ||
410 src_y
+ src_height
== minify(src_mt
->logical_height0
, src_level
));
414 src_width
= DIV_ROUND_UP(src_width
, (int)bw
);
415 src_height
= DIV_ROUND_UP(src_height
, (int)bh
);
417 src_x
+= src_image_x
;
418 src_y
+= src_image_y
;
420 uint32_t dst_image_x
, dst_image_y
;
421 intel_miptree_get_image_offset(dst_mt
, dst_level
, dst_slice
,
422 &dst_image_x
, &dst_image_y
);
424 if (_mesa_is_format_compressed(dst_mt
->format
)) {
426 _mesa_get_format_block_size(dst_mt
->format
, &bw
, &bh
);
428 assert(dst_x
% bw
== 0);
429 assert(dst_y
% bh
== 0);
434 dst_x
+= dst_image_x
;
435 dst_y
+= dst_image_y
;
437 return emit_miptree_blit(brw
, src_mt
, src_x
, src_y
,
438 dst_mt
, dst_x
, dst_y
,
439 src_width
, src_height
, false, GL_COPY
);
443 alignment_valid(struct brw_context
*brw
, unsigned offset
, uint32_t tiling
)
445 /* Tiled buffers must be page-aligned (4K). */
446 if (tiling
!= I915_TILING_NONE
)
447 return (offset
& 4095) == 0;
449 /* On Gen8+, linear buffers must be cacheline-aligned. */
451 return (offset
& 63) == 0;
457 xy_blit_cmd(uint32_t src_tiling
, uint32_t dst_tiling
, uint32_t cpp
)
465 CMD
= XY_SRC_COPY_BLT_CMD
;
468 CMD
= XY_SRC_COPY_BLT_CMD
| XY_BLT_WRITE_ALPHA
| XY_BLT_WRITE_RGB
;
471 unreachable("not reached");
474 if (dst_tiling
!= I915_TILING_NONE
)
477 if (src_tiling
!= I915_TILING_NONE
)
486 intelEmitCopyBlit(struct brw_context
*brw
,
489 struct brw_bo
*src_buffer
,
493 struct brw_bo
*dst_buffer
,
496 GLshort src_x
, GLshort src_y
,
497 GLshort dst_x
, GLshort dst_y
,
498 GLshort w
, GLshort h
,
502 int dst_y2
= dst_y
+ h
;
503 int dst_x2
= dst_x
+ w
;
504 bool dst_y_tiled
= dst_tiling
== I915_TILING_Y
;
505 bool src_y_tiled
= src_tiling
== I915_TILING_Y
;
506 uint32_t src_tile_w
, src_tile_h
;
507 uint32_t dst_tile_w
, dst_tile_h
;
509 if ((dst_y_tiled
|| src_y_tiled
) && brw
->gen
< 6)
512 const unsigned bo_sizes
= dst_buffer
->size
+ src_buffer
->size
;
514 /* do space check before going any further */
515 if (!brw_batch_has_aperture_space(brw
, bo_sizes
))
516 intel_batchbuffer_flush(brw
);
518 if (!brw_batch_has_aperture_space(brw
, bo_sizes
))
521 unsigned length
= brw
->gen
>= 8 ? 10 : 8;
523 intel_batchbuffer_require_space(brw
, length
* 4, BLT_RING
);
524 DBG("%s src:buf(%p)/%d+%d %d,%d dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n",
526 src_buffer
, src_pitch
, src_offset
, src_x
, src_y
,
527 dst_buffer
, dst_pitch
, dst_offset
, dst_x
, dst_y
, w
, h
);
529 intel_get_tile_dims(src_tiling
, cpp
, &src_tile_w
, &src_tile_h
);
530 intel_get_tile_dims(dst_tiling
, cpp
, &dst_tile_w
, &dst_tile_h
);
532 /* For Tiled surfaces, the pitch has to be a multiple of the Tile width
533 * (X direction width of the Tile). This is ensured while allocating the
536 assert(src_tiling
== I915_TILING_NONE
|| (src_pitch
% src_tile_w
) == 0);
537 assert(dst_tiling
== I915_TILING_NONE
|| (dst_pitch
% dst_tile_w
) == 0);
539 /* For big formats (such as floating point), do the copy using 16 or
540 * 32bpp and multiply the coordinates.
549 assert(cpp
% 4 == 0);
557 if (!alignment_valid(brw
, dst_offset
, dst_tiling
))
559 if (!alignment_valid(brw
, src_offset
, src_tiling
))
562 /* Blit pitch must be dword-aligned. Otherwise, the hardware appears to drop
563 * the low bits. Offsets must be naturally aligned.
565 if (src_pitch
% 4 != 0 || src_offset
% cpp
!= 0 ||
566 dst_pitch
% 4 != 0 || dst_offset
% cpp
!= 0)
570 BR13
= br13_for_cpp(cpp
) | translate_raster_op(logic_op
) << 16;
572 CMD
= xy_blit_cmd(src_tiling
, dst_tiling
, cpp
);
574 /* For tiled source and destination, pitch value should be specified
575 * as a number of Dwords.
577 if (dst_tiling
!= I915_TILING_NONE
)
580 if (src_tiling
!= I915_TILING_NONE
)
583 if (dst_y2
<= dst_y
|| dst_x2
<= dst_x
)
586 assert(dst_x
< dst_x2
);
587 assert(dst_y
< dst_y2
);
589 BEGIN_BATCH_BLT_TILED(length
, dst_y_tiled
, src_y_tiled
);
590 OUT_BATCH(CMD
| (length
- 2));
591 OUT_BATCH(BR13
| (uint16_t)dst_pitch
);
592 OUT_BATCH(SET_FIELD(dst_y
, BLT_Y
) | SET_FIELD(dst_x
, BLT_X
));
593 OUT_BATCH(SET_FIELD(dst_y2
, BLT_Y
) | SET_FIELD(dst_x2
, BLT_X
));
595 OUT_RELOC64(dst_buffer
,
596 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
599 OUT_RELOC(dst_buffer
,
600 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
603 OUT_BATCH(SET_FIELD(src_y
, BLT_Y
) | SET_FIELD(src_x
, BLT_X
));
604 OUT_BATCH((uint16_t)src_pitch
);
606 OUT_RELOC64(src_buffer
,
607 I915_GEM_DOMAIN_RENDER
, 0,
610 OUT_RELOC(src_buffer
,
611 I915_GEM_DOMAIN_RENDER
, 0,
615 ADVANCE_BATCH_TILED(dst_y_tiled
, src_y_tiled
);
617 brw_emit_mi_flush(brw
);
623 intelEmitImmediateColorExpandBlit(struct brw_context
*brw
,
625 GLubyte
*src_bits
, GLuint src_size
,
628 struct brw_bo
*dst_buffer
,
631 GLshort x
, GLshort y
,
632 GLshort w
, GLshort h
,
635 int dwords
= ALIGN(src_size
, 8) / 4;
636 uint32_t opcode
, br13
, blit_cmd
;
638 if (dst_tiling
!= I915_TILING_NONE
) {
639 if (dst_offset
& 4095)
641 if (dst_tiling
== I915_TILING_Y
)
645 assert((logic_op
>= GL_CLEAR
) && (logic_op
<= (GL_CLEAR
+ 0x0f)));
646 assert(dst_pitch
> 0);
651 DBG("%s dst:buf(%p)/%d+%d %d,%d sz:%dx%d, %d bytes %d dwords\n",
653 dst_buffer
, dst_pitch
, dst_offset
, x
, y
, w
, h
, src_size
, dwords
);
655 unsigned xy_setup_blt_length
= brw
->gen
>= 8 ? 10 : 8;
656 intel_batchbuffer_require_space(brw
, (xy_setup_blt_length
* 4) +
657 (3 * 4) + dwords
* 4, BLT_RING
);
659 opcode
= XY_SETUP_BLT_CMD
;
661 opcode
|= XY_BLT_WRITE_ALPHA
| XY_BLT_WRITE_RGB
;
662 if (dst_tiling
!= I915_TILING_NONE
) {
663 opcode
|= XY_DST_TILED
;
667 br13
= dst_pitch
| (translate_raster_op(logic_op
) << 16) | (1 << 29);
668 br13
|= br13_for_cpp(cpp
);
670 blit_cmd
= XY_TEXT_IMMEDIATE_BLIT_CMD
| XY_TEXT_BYTE_PACKED
; /* packing? */
671 if (dst_tiling
!= I915_TILING_NONE
)
672 blit_cmd
|= XY_DST_TILED
;
674 BEGIN_BATCH_BLT(xy_setup_blt_length
+ 3);
675 OUT_BATCH(opcode
| (xy_setup_blt_length
- 2));
677 OUT_BATCH((0 << 16) | 0); /* clip x1, y1 */
678 OUT_BATCH((100 << 16) | 100); /* clip x2, y2 */
680 OUT_RELOC64(dst_buffer
,
681 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
684 OUT_RELOC(dst_buffer
,
685 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
688 OUT_BATCH(0); /* bg */
689 OUT_BATCH(fg_color
); /* fg */
690 OUT_BATCH(0); /* pattern base addr */
694 OUT_BATCH(blit_cmd
| ((3 - 2) + dwords
));
695 OUT_BATCH(SET_FIELD(y
, BLT_Y
) | SET_FIELD(x
, BLT_X
));
696 OUT_BATCH(SET_FIELD(y
+ h
, BLT_Y
) | SET_FIELD(x
+ w
, BLT_X
));
699 intel_batchbuffer_data(brw
, src_bits
, dwords
* 4, BLT_RING
);
701 brw_emit_mi_flush(brw
);
706 /* We don't have a memmove-type blit like some other hardware, so we'll do a
707 * rectangular blit covering a large space, then emit 1-scanline blit at the
708 * end to cover the last if we need.
711 intel_emit_linear_blit(struct brw_context
*brw
,
712 struct brw_bo
*dst_bo
,
713 unsigned int dst_offset
,
714 struct brw_bo
*src_bo
,
715 unsigned int src_offset
,
718 struct gl_context
*ctx
= &brw
->ctx
;
719 GLuint pitch
, height
;
720 int16_t src_x
, dst_x
;
724 /* The pitch given to the GPU must be DWORD aligned, and
725 * we want width to match pitch. Max width is (1 << 15 - 1),
726 * rounding that down to the nearest DWORD is 1 << 15 - 4
728 pitch
= ROUND_DOWN_TO(MIN2(size
, (1 << 15) - 64), 4);
729 height
= (size
< pitch
|| pitch
== 0) ? 1 : size
/ pitch
;
731 src_x
= src_offset
% 64;
732 dst_x
= dst_offset
% 64;
733 pitch
= ALIGN(MIN2(size
, (1 << 15) - 64), 4);
734 assert(src_x
+ pitch
< 1 << 15);
735 assert(dst_x
+ pitch
< 1 << 15);
737 ok
= intelEmitCopyBlit(brw
, 1,
738 pitch
, src_bo
, src_offset
- src_x
, I915_TILING_NONE
,
739 pitch
, dst_bo
, dst_offset
- dst_x
, I915_TILING_NONE
,
740 src_x
, 0, /* src x/y */
741 dst_x
, 0, /* dst x/y */
742 MIN2(size
, pitch
), height
, /* w, h */
745 _mesa_problem(ctx
, "Failed to linear blit %dx%d\n",
746 MIN2(size
, pitch
), height
);
761 * Used to initialize the alpha value of an ARGB8888 miptree after copying
762 * into it from an XRGB8888 source.
764 * This is very common with glCopyTexImage2D(). Note that the coordinates are
765 * relative to the start of the miptree, not relative to a slice within the
769 intel_miptree_set_alpha_to_one(struct brw_context
*brw
,
770 struct intel_mipmap_tree
*mt
,
771 int x
, int y
, int width
, int height
)
779 DBG("%s dst:buf(%p)/%d %d,%d sz:%dx%d\n",
780 __func__
, mt
->bo
, pitch
, x
, y
, width
, height
);
782 BR13
= br13_for_cpp(cpp
) | 0xf0 << 16;
783 CMD
= XY_COLOR_BLT_CMD
;
784 CMD
|= XY_BLT_WRITE_ALPHA
;
786 if (mt
->tiling
!= I915_TILING_NONE
) {
792 /* do space check before going any further */
793 if (!brw_batch_has_aperture_space(brw
, mt
->bo
->size
))
794 intel_batchbuffer_flush(brw
);
796 unsigned length
= brw
->gen
>= 8 ? 7 : 6;
797 bool dst_y_tiled
= mt
->tiling
== I915_TILING_Y
;
799 /* We need to split the blit into chunks that each fit within the blitter's
800 * restrictions. We can't use a chunk size of 32768 because we need to
801 * ensure that src_tile_x + chunk_size fits. We choose 16384 because it's
802 * a nice round power of two, big enough that performance won't suffer, and
803 * small enough to guarantee everything fits.
805 const uint32_t max_chunk_size
= 16384;
807 for (uint32_t chunk_x
= 0; chunk_x
< width
; chunk_x
+= max_chunk_size
) {
808 for (uint32_t chunk_y
= 0; chunk_y
< height
; chunk_y
+= max_chunk_size
) {
809 const uint32_t chunk_w
= MIN2(max_chunk_size
, width
- chunk_x
);
810 const uint32_t chunk_h
= MIN2(max_chunk_size
, height
- chunk_y
);
812 uint32_t offset
, tile_x
, tile_y
;
813 get_blit_intratile_offset_el(brw
, mt
,
814 x
+ chunk_x
, y
+ chunk_y
,
815 &offset
, &tile_x
, &tile_y
);
817 BEGIN_BATCH_BLT_TILED(length
, dst_y_tiled
, false);
818 OUT_BATCH(CMD
| (length
- 2));
820 OUT_BATCH(SET_FIELD(y
+ chunk_y
, BLT_Y
) |
821 SET_FIELD(x
+ chunk_x
, BLT_X
));
822 OUT_BATCH(SET_FIELD(y
+ chunk_y
+ chunk_h
, BLT_Y
) |
823 SET_FIELD(x
+ chunk_x
+ chunk_w
, BLT_X
));
826 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
830 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
833 OUT_BATCH(0xffffffff); /* white, but only alpha gets written */
834 ADVANCE_BATCH_TILED(dst_y_tiled
, false);
838 brw_emit_mi_flush(brw
);