Merge remote-tracking branch 'mesa-public/master' into vulkan
[mesa.git] / src / mesa / drivers / dri / i965 / intel_blit.c
1 /**************************************************************************
2 *
3 * Copyright 2003 VMware, Inc.
4 * All Rights Reserved.
5 *
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, sub license, 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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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 NON-INFRINGEMENT.
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.
25 *
26 **************************************************************************/
27
28
29 #include "main/mtypes.h"
30 #include "main/context.h"
31 #include "main/enums.h"
32 #include "main/colormac.h"
33 #include "main/fbobject.h"
34
35 #include "brw_context.h"
36 #include "brw_defines.h"
37 #include "intel_blit.h"
38 #include "intel_buffers.h"
39 #include "intel_fbo.h"
40 #include "intel_reg.h"
41 #include "intel_batchbuffer.h"
42 #include "intel_mipmap_tree.h"
43
44 #define FILE_DEBUG_FLAG DEBUG_BLIT
45
46 static void
47 intel_miptree_set_alpha_to_one(struct brw_context *brw,
48 struct intel_mipmap_tree *mt,
49 int x, int y, int width, int height);
50
51 static GLuint translate_raster_op(GLenum logicop)
52 {
53 switch(logicop) {
54 case GL_CLEAR: return 0x00;
55 case GL_AND: return 0x88;
56 case GL_AND_REVERSE: return 0x44;
57 case GL_COPY: return 0xCC;
58 case GL_AND_INVERTED: return 0x22;
59 case GL_NOOP: return 0xAA;
60 case GL_XOR: return 0x66;
61 case GL_OR: return 0xEE;
62 case GL_NOR: return 0x11;
63 case GL_EQUIV: return 0x99;
64 case GL_INVERT: return 0x55;
65 case GL_OR_REVERSE: return 0xDD;
66 case GL_COPY_INVERTED: return 0x33;
67 case GL_OR_INVERTED: return 0xBB;
68 case GL_NAND: return 0x77;
69 case GL_SET: return 0xFF;
70 default: return 0;
71 }
72 }
73
74 static uint32_t
75 br13_for_cpp(int cpp)
76 {
77 switch (cpp) {
78 case 4:
79 return BR13_8888;
80 case 2:
81 return BR13_565;
82 case 1:
83 return BR13_8;
84 default:
85 unreachable("not reached");
86 }
87 }
88
89 /**
90 * Emits the packet for switching the blitter from X to Y tiled or back.
91 *
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
97 * server).
98 */
99 static void
100 set_blitter_tiling(struct brw_context *brw,
101 bool dst_y_tiled, bool src_y_tiled)
102 {
103 assert(brw->gen >= 6);
104
105 /* Idle the blitter before we update how tiling is interpreted. */
106 OUT_BATCH(MI_FLUSH_DW);
107 OUT_BATCH(0);
108 OUT_BATCH(0);
109 OUT_BATCH(0);
110
111 OUT_BATCH(MI_LOAD_REGISTER_IMM | (3 - 2));
112 OUT_BATCH(BCS_SWCTRL);
113 OUT_BATCH((BCS_SWCTRL_DST_Y | BCS_SWCTRL_SRC_Y) << 16 |
114 (dst_y_tiled ? BCS_SWCTRL_DST_Y : 0) |
115 (src_y_tiled ? BCS_SWCTRL_SRC_Y : 0));
116 }
117
118 #define BEGIN_BATCH_BLT_TILED(n, dst_y_tiled, src_y_tiled) do { \
119 BEGIN_BATCH_BLT(n + ((dst_y_tiled || src_y_tiled) ? 14 : 0)); \
120 if (dst_y_tiled || src_y_tiled) \
121 set_blitter_tiling(brw, dst_y_tiled, src_y_tiled); \
122 } while (0)
123
124 #define ADVANCE_BATCH_TILED(dst_y_tiled, src_y_tiled) do { \
125 if (dst_y_tiled || src_y_tiled) \
126 set_blitter_tiling(brw, false, false); \
127 ADVANCE_BATCH(); \
128 } while (0)
129
130 static int
131 blt_pitch(struct intel_mipmap_tree *mt)
132 {
133 int pitch = mt->pitch;
134 if (mt->tiling)
135 pitch /= 4;
136 return pitch;
137 }
138
139 bool
140 intel_miptree_blit_compatible_formats(mesa_format src, mesa_format dst)
141 {
142 /* The BLT doesn't handle sRGB conversion */
143 assert(src == _mesa_get_srgb_format_linear(src));
144 assert(dst == _mesa_get_srgb_format_linear(dst));
145
146 /* No swizzle or format conversions possible, except... */
147 if (src == dst)
148 return true;
149
150 /* ...we can either discard the alpha channel when going from A->X,
151 * or we can fill the alpha channel with 0xff when going from X->A
152 */
153 if (src == MESA_FORMAT_B8G8R8A8_UNORM || src == MESA_FORMAT_B8G8R8X8_UNORM)
154 return (dst == MESA_FORMAT_B8G8R8A8_UNORM ||
155 dst == MESA_FORMAT_B8G8R8X8_UNORM);
156
157 if (src == MESA_FORMAT_R8G8B8A8_UNORM || src == MESA_FORMAT_R8G8B8X8_UNORM)
158 return (dst == MESA_FORMAT_R8G8B8A8_UNORM ||
159 dst == MESA_FORMAT_R8G8B8X8_UNORM);
160
161 return false;
162 }
163
164 /**
165 * Implements a rectangular block transfer (blit) of pixels between two
166 * miptrees.
167 *
168 * Our blitter can operate on 1, 2, or 4-byte-per-pixel data, with generous,
169 * but limited, pitches and sizes allowed.
170 *
171 * The src/dst coordinates are relative to the given level/slice of the
172 * miptree.
173 *
174 * If @src_flip or @dst_flip is set, then the rectangle within that miptree
175 * will be inverted (including scanline order) when copying. This is common
176 * in GL when copying between window system and user-created
177 * renderbuffers/textures.
178 */
179 bool
180 intel_miptree_blit(struct brw_context *brw,
181 struct intel_mipmap_tree *src_mt,
182 int src_level, int src_slice,
183 uint32_t src_x, uint32_t src_y, bool src_flip,
184 struct intel_mipmap_tree *dst_mt,
185 int dst_level, int dst_slice,
186 uint32_t dst_x, uint32_t dst_y, bool dst_flip,
187 uint32_t width, uint32_t height,
188 GLenum logicop)
189 {
190 /* The blitter doesn't understand multisampling at all. */
191 if (src_mt->num_samples > 0 || dst_mt->num_samples > 0)
192 return false;
193
194 /* No sRGB decode or encode is done by the hardware blitter, which is
195 * consistent with what we want in the callers (glCopyTexSubImage(),
196 * glBlitFramebuffer(), texture validation, etc.).
197 */
198 mesa_format src_format = _mesa_get_srgb_format_linear(src_mt->format);
199 mesa_format dst_format = _mesa_get_srgb_format_linear(dst_mt->format);
200
201 /* The blitter doesn't support doing any format conversions. We do also
202 * support blitting ARGB8888 to XRGB8888 (trivial, the values dropped into
203 * the X channel don't matter), and XRGB8888 to ARGB8888 by setting the A
204 * channel to 1.0 at the end.
205 */
206 if (!intel_miptree_blit_compatible_formats(src_format, dst_format)) {
207 perf_debug("%s: Can't use hardware blitter from %s to %s, "
208 "falling back.\n", __func__,
209 _mesa_get_format_name(src_format),
210 _mesa_get_format_name(dst_format));
211 return false;
212 }
213
214 /* According to the Ivy Bridge PRM, Vol1 Part4, section 1.2.1.2 (Graphics
215 * Data Size Limitations):
216 *
217 * The BLT engine is capable of transferring very large quantities of
218 * graphics data. Any graphics data read from and written to the
219 * destination is permitted to represent a number of pixels that
220 * occupies up to 65,536 scan lines and up to 32,768 bytes per scan line
221 * at the destination. The maximum number of pixels that may be
222 * represented per scan line’s worth of graphics data depends on the
223 * color depth.
224 *
225 * Furthermore, intelEmitCopyBlit (which is called below) uses a signed
226 * 16-bit integer to represent buffer pitch, so it can only handle buffer
227 * pitches < 32k. However, the pitch is measured in bytes for linear buffers
228 * and dwords for tiled buffers.
229 *
230 * As a result of these two limitations, we can only use the blitter to do
231 * this copy when the miptree's pitch is less than 32k linear or 128k tiled.
232 */
233 if (blt_pitch(src_mt) >= 32768 || blt_pitch(dst_mt) >= 32768) {
234 perf_debug("Falling back due to >= 32k/128k pitch\n");
235 return false;
236 }
237
238 /* The blitter has no idea about HiZ or fast color clears, so we need to
239 * resolve the miptrees before we do anything.
240 */
241 intel_miptree_slice_resolve_depth(brw, src_mt, src_level, src_slice);
242 intel_miptree_slice_resolve_depth(brw, dst_mt, dst_level, dst_slice);
243 intel_miptree_resolve_color(brw, src_mt);
244 intel_miptree_resolve_color(brw, dst_mt);
245
246 if (src_flip)
247 src_y = minify(src_mt->physical_height0, src_level - src_mt->first_level) - src_y - height;
248
249 if (dst_flip)
250 dst_y = minify(dst_mt->physical_height0, dst_level - dst_mt->first_level) - dst_y - height;
251
252 int src_pitch = src_mt->pitch;
253 if (src_flip != dst_flip)
254 src_pitch = -src_pitch;
255
256 uint32_t src_image_x, src_image_y, dst_image_x, dst_image_y;
257 intel_miptree_get_image_offset(src_mt, src_level, src_slice,
258 &src_image_x, &src_image_y);
259 intel_miptree_get_image_offset(dst_mt, dst_level, dst_slice,
260 &dst_image_x, &dst_image_y);
261 src_x += src_image_x;
262 src_y += src_image_y;
263 dst_x += dst_image_x;
264 dst_y += dst_image_y;
265
266 /* The blitter interprets the 16-bit destination x/y as a signed 16-bit
267 * value. The values we're working with are unsigned, so make sure we don't
268 * overflow.
269 */
270 if (src_x >= 32768 || src_y >= 32768 || dst_x >= 32768 || dst_y >= 32768) {
271 perf_debug("Falling back due to >=32k offset [src(%d, %d) dst(%d, %d)]\n",
272 src_x, src_y, dst_x, dst_y);
273 return false;
274 }
275
276 if (!intelEmitCopyBlit(brw,
277 src_mt->cpp,
278 src_pitch,
279 src_mt->bo, src_mt->offset,
280 src_mt->tiling,
281 dst_mt->pitch,
282 dst_mt->bo, dst_mt->offset,
283 dst_mt->tiling,
284 src_x, src_y,
285 dst_x, dst_y,
286 width, height,
287 logicop)) {
288 return false;
289 }
290
291 /* XXX This could be done in a single pass using XY_FULL_MONO_PATTERN_BLT */
292 if (_mesa_get_format_bits(src_format, GL_ALPHA_BITS) == 0 &&
293 _mesa_get_format_bits(dst_format, GL_ALPHA_BITS) > 0) {
294 intel_miptree_set_alpha_to_one(brw, dst_mt,
295 dst_x, dst_y,
296 width, height);
297 }
298
299 return true;
300 }
301
302 static bool
303 alignment_valid(struct brw_context *brw, unsigned offset, uint32_t tiling)
304 {
305 /* Tiled buffers must be page-aligned (4K). */
306 if (tiling != I915_TILING_NONE)
307 return (offset & 4095) == 0;
308
309 /* On Gen8+, linear buffers must be cacheline-aligned. */
310 if (brw->gen >= 8)
311 return (offset & 63) == 0;
312
313 return true;
314 }
315
316 /* Copy BitBlt
317 */
318 bool
319 intelEmitCopyBlit(struct brw_context *brw,
320 GLuint cpp,
321 GLshort src_pitch,
322 drm_intel_bo *src_buffer,
323 GLuint src_offset,
324 uint32_t src_tiling,
325 GLshort dst_pitch,
326 drm_intel_bo *dst_buffer,
327 GLuint dst_offset,
328 uint32_t dst_tiling,
329 GLshort src_x, GLshort src_y,
330 GLshort dst_x, GLshort dst_y,
331 GLshort w, GLshort h,
332 GLenum logic_op)
333 {
334 GLuint CMD, BR13, pass = 0;
335 int dst_y2 = dst_y + h;
336 int dst_x2 = dst_x + w;
337 drm_intel_bo *aper_array[3];
338 bool dst_y_tiled = dst_tiling == I915_TILING_Y;
339 bool src_y_tiled = src_tiling == I915_TILING_Y;
340
341 if (!alignment_valid(brw, dst_offset, dst_tiling))
342 return false;
343 if (!alignment_valid(brw, src_offset, src_tiling))
344 return false;
345
346 if ((dst_y_tiled || src_y_tiled) && brw->gen < 6)
347 return false;
348
349 assert(!dst_y_tiled || (dst_pitch % 128) == 0);
350 assert(!src_y_tiled || (src_pitch % 128) == 0);
351
352 /* do space check before going any further */
353 do {
354 aper_array[0] = brw->batch.bo;
355 aper_array[1] = dst_buffer;
356 aper_array[2] = src_buffer;
357
358 if (dri_bufmgr_check_aperture_space(aper_array, 3) != 0) {
359 intel_batchbuffer_flush(brw);
360 pass++;
361 } else
362 break;
363 } while (pass < 2);
364
365 if (pass >= 2)
366 return false;
367
368 unsigned length = brw->gen >= 8 ? 10 : 8;
369
370 intel_batchbuffer_require_space(brw, length * 4, BLT_RING);
371 DBG("%s src:buf(%p)/%d+%d %d,%d dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n",
372 __func__,
373 src_buffer, src_pitch, src_offset, src_x, src_y,
374 dst_buffer, dst_pitch, dst_offset, dst_x, dst_y, w, h);
375
376 /* Blit pitch must be dword-aligned. Otherwise, the hardware appears to drop
377 * the low bits. Offsets must be naturally aligned.
378 */
379 if (src_pitch % 4 != 0 || src_offset % cpp != 0 ||
380 dst_pitch % 4 != 0 || dst_offset % cpp != 0)
381 return false;
382
383 /* For big formats (such as floating point), do the copy using 16 or 32bpp
384 * and multiply the coordinates.
385 */
386 if (cpp > 4) {
387 if (cpp % 4 == 2) {
388 dst_x *= cpp / 2;
389 dst_x2 *= cpp / 2;
390 src_x *= cpp / 2;
391 cpp = 2;
392 } else {
393 assert(cpp % 4 == 0);
394 dst_x *= cpp / 4;
395 dst_x2 *= cpp / 4;
396 src_x *= cpp / 4;
397 cpp = 4;
398 }
399 }
400
401 BR13 = br13_for_cpp(cpp) | translate_raster_op(logic_op) << 16;
402
403 switch (cpp) {
404 case 1:
405 case 2:
406 CMD = XY_SRC_COPY_BLT_CMD;
407 break;
408 case 4:
409 CMD = XY_SRC_COPY_BLT_CMD | XY_BLT_WRITE_ALPHA | XY_BLT_WRITE_RGB;
410 break;
411 default:
412 return false;
413 }
414
415 if (dst_tiling != I915_TILING_NONE) {
416 CMD |= XY_DST_TILED;
417 dst_pitch /= 4;
418 }
419 if (src_tiling != I915_TILING_NONE) {
420 CMD |= XY_SRC_TILED;
421 src_pitch /= 4;
422 }
423
424 if (dst_y2 <= dst_y || dst_x2 <= dst_x) {
425 return true;
426 }
427
428 assert(dst_x < dst_x2);
429 assert(dst_y < dst_y2);
430 assert(src_offset + (src_y + h - 1) * abs(src_pitch) +
431 (w * cpp) <= src_buffer->size);
432 assert(dst_offset + (dst_y + h - 1) * abs(dst_pitch) +
433 (w * cpp) <= dst_buffer->size);
434
435 BEGIN_BATCH_BLT_TILED(length, dst_y_tiled, src_y_tiled);
436 OUT_BATCH(CMD | (length - 2));
437 OUT_BATCH(BR13 | (uint16_t)dst_pitch);
438 OUT_BATCH(SET_FIELD(dst_y, BLT_Y) | SET_FIELD(dst_x, BLT_X));
439 OUT_BATCH(SET_FIELD(dst_y2, BLT_Y) | SET_FIELD(dst_x2, BLT_X));
440 if (brw->gen >= 8) {
441 OUT_RELOC64(dst_buffer,
442 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
443 dst_offset);
444 } else {
445 OUT_RELOC(dst_buffer,
446 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
447 dst_offset);
448 }
449 OUT_BATCH(SET_FIELD(src_y, BLT_Y) | SET_FIELD(src_x, BLT_X));
450 OUT_BATCH((uint16_t)src_pitch);
451 if (brw->gen >= 8) {
452 OUT_RELOC64(src_buffer,
453 I915_GEM_DOMAIN_RENDER, 0,
454 src_offset);
455 } else {
456 OUT_RELOC(src_buffer,
457 I915_GEM_DOMAIN_RENDER, 0,
458 src_offset);
459 }
460
461 ADVANCE_BATCH_TILED(dst_y_tiled, src_y_tiled);
462
463 intel_batchbuffer_emit_mi_flush(brw);
464
465 return true;
466 }
467
468 bool
469 intelEmitImmediateColorExpandBlit(struct brw_context *brw,
470 GLuint cpp,
471 GLubyte *src_bits, GLuint src_size,
472 GLuint fg_color,
473 GLshort dst_pitch,
474 drm_intel_bo *dst_buffer,
475 GLuint dst_offset,
476 uint32_t dst_tiling,
477 GLshort x, GLshort y,
478 GLshort w, GLshort h,
479 GLenum logic_op)
480 {
481 int dwords = ALIGN(src_size, 8) / 4;
482 uint32_t opcode, br13, blit_cmd;
483
484 if (dst_tiling != I915_TILING_NONE) {
485 if (dst_offset & 4095)
486 return false;
487 if (dst_tiling == I915_TILING_Y)
488 return false;
489 }
490
491 assert((logic_op >= GL_CLEAR) && (logic_op <= (GL_CLEAR + 0x0f)));
492 assert(dst_pitch > 0);
493
494 if (w < 0 || h < 0)
495 return true;
496
497 DBG("%s dst:buf(%p)/%d+%d %d,%d sz:%dx%d, %d bytes %d dwords\n",
498 __func__,
499 dst_buffer, dst_pitch, dst_offset, x, y, w, h, src_size, dwords);
500
501 unsigned xy_setup_blt_length = brw->gen >= 8 ? 10 : 8;
502 intel_batchbuffer_require_space(brw, (xy_setup_blt_length * 4) +
503 (3 * 4) + dwords * 4, BLT_RING);
504
505 opcode = XY_SETUP_BLT_CMD;
506 if (cpp == 4)
507 opcode |= XY_BLT_WRITE_ALPHA | XY_BLT_WRITE_RGB;
508 if (dst_tiling != I915_TILING_NONE) {
509 opcode |= XY_DST_TILED;
510 dst_pitch /= 4;
511 }
512
513 br13 = dst_pitch | (translate_raster_op(logic_op) << 16) | (1 << 29);
514 br13 |= br13_for_cpp(cpp);
515
516 blit_cmd = XY_TEXT_IMMEDIATE_BLIT_CMD | XY_TEXT_BYTE_PACKED; /* packing? */
517 if (dst_tiling != I915_TILING_NONE)
518 blit_cmd |= XY_DST_TILED;
519
520 BEGIN_BATCH_BLT(xy_setup_blt_length + 3);
521 OUT_BATCH(opcode | (xy_setup_blt_length - 2));
522 OUT_BATCH(br13);
523 OUT_BATCH((0 << 16) | 0); /* clip x1, y1 */
524 OUT_BATCH((100 << 16) | 100); /* clip x2, y2 */
525 if (brw->gen >= 8) {
526 OUT_RELOC64(dst_buffer,
527 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
528 dst_offset);
529 } else {
530 OUT_RELOC(dst_buffer,
531 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
532 dst_offset);
533 }
534 OUT_BATCH(0); /* bg */
535 OUT_BATCH(fg_color); /* fg */
536 OUT_BATCH(0); /* pattern base addr */
537 if (brw->gen >= 8)
538 OUT_BATCH(0);
539
540 OUT_BATCH(blit_cmd | ((3 - 2) + dwords));
541 OUT_BATCH(SET_FIELD(y, BLT_Y) | SET_FIELD(x, BLT_X));
542 OUT_BATCH(SET_FIELD(y + h, BLT_Y) | SET_FIELD(x + w, BLT_X));
543 ADVANCE_BATCH();
544
545 intel_batchbuffer_data(brw, src_bits, dwords * 4, BLT_RING);
546
547 intel_batchbuffer_emit_mi_flush(brw);
548
549 return true;
550 }
551
552 /* We don't have a memmove-type blit like some other hardware, so we'll do a
553 * rectangular blit covering a large space, then emit 1-scanline blit at the
554 * end to cover the last if we need.
555 */
556 void
557 intel_emit_linear_blit(struct brw_context *brw,
558 drm_intel_bo *dst_bo,
559 unsigned int dst_offset,
560 drm_intel_bo *src_bo,
561 unsigned int src_offset,
562 unsigned int size)
563 {
564 struct gl_context *ctx = &brw->ctx;
565 GLuint pitch, height;
566 int16_t src_x, dst_x;
567 bool ok;
568
569 /* The pitch given to the GPU must be DWORD aligned, and
570 * we want width to match pitch. Max width is (1 << 15 - 1),
571 * rounding that down to the nearest DWORD is 1 << 15 - 4
572 */
573 pitch = ROUND_DOWN_TO(MIN2(size, (1 << 15) - 1), 4);
574 height = (pitch == 0) ? 1 : size / pitch;
575 src_x = src_offset % 64;
576 dst_x = dst_offset % 64;
577 ok = intelEmitCopyBlit(brw, 1,
578 pitch, src_bo, src_offset - src_x, I915_TILING_NONE,
579 pitch, dst_bo, dst_offset - dst_x, I915_TILING_NONE,
580 src_x, 0, /* src x/y */
581 dst_x, 0, /* dst x/y */
582 pitch, height, /* w, h */
583 GL_COPY);
584 if (!ok)
585 _mesa_problem(ctx, "Failed to linear blit %dx%d\n", pitch, height);
586
587 src_offset += pitch * height;
588 dst_offset += pitch * height;
589 src_x = src_offset % 64;
590 dst_x = dst_offset % 64;
591 size -= pitch * height;
592 assert (size < (1 << 15));
593 pitch = ALIGN(size, 4);
594
595 if (size != 0) {
596 ok = intelEmitCopyBlit(brw, 1,
597 pitch, src_bo, src_offset - src_x, I915_TILING_NONE,
598 pitch, dst_bo, dst_offset - dst_x, I915_TILING_NONE,
599 src_x, 0, /* src x/y */
600 dst_x, 0, /* dst x/y */
601 size, 1, /* w, h */
602 GL_COPY);
603 if (!ok)
604 _mesa_problem(ctx, "Failed to linear blit %dx%d\n", size, 1);
605 }
606 }
607
608 /**
609 * Used to initialize the alpha value of an ARGB8888 miptree after copying
610 * into it from an XRGB8888 source.
611 *
612 * This is very common with glCopyTexImage2D(). Note that the coordinates are
613 * relative to the start of the miptree, not relative to a slice within the
614 * miptree.
615 */
616 static void
617 intel_miptree_set_alpha_to_one(struct brw_context *brw,
618 struct intel_mipmap_tree *mt,
619 int x, int y, int width, int height)
620 {
621 uint32_t BR13, CMD;
622 int pitch, cpp;
623 drm_intel_bo *aper_array[2];
624
625 pitch = mt->pitch;
626 cpp = mt->cpp;
627
628 DBG("%s dst:buf(%p)/%d %d,%d sz:%dx%d\n",
629 __func__, mt->bo, pitch, x, y, width, height);
630
631 BR13 = br13_for_cpp(cpp) | 0xf0 << 16;
632 CMD = XY_COLOR_BLT_CMD;
633 CMD |= XY_BLT_WRITE_ALPHA;
634
635 if (mt->tiling != I915_TILING_NONE) {
636 CMD |= XY_DST_TILED;
637 pitch /= 4;
638 }
639 BR13 |= pitch;
640
641 /* do space check before going any further */
642 aper_array[0] = brw->batch.bo;
643 aper_array[1] = mt->bo;
644
645 if (drm_intel_bufmgr_check_aperture_space(aper_array,
646 ARRAY_SIZE(aper_array)) != 0) {
647 intel_batchbuffer_flush(brw);
648 }
649
650 unsigned length = brw->gen >= 8 ? 7 : 6;
651 bool dst_y_tiled = mt->tiling == I915_TILING_Y;
652
653 BEGIN_BATCH_BLT_TILED(length, dst_y_tiled, false);
654 OUT_BATCH(CMD | (length - 2));
655 OUT_BATCH(BR13);
656 OUT_BATCH(SET_FIELD(y, BLT_Y) | SET_FIELD(x, BLT_X));
657 OUT_BATCH(SET_FIELD(y + height, BLT_Y) | SET_FIELD(x + width, BLT_X));
658 if (brw->gen >= 8) {
659 OUT_RELOC64(mt->bo,
660 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
661 0);
662 } else {
663 OUT_RELOC(mt->bo,
664 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
665 0);
666 }
667 OUT_BATCH(0xffffffff); /* white, but only alpha gets written */
668 ADVANCE_BATCH_TILED(dst_y_tiled, false);
669
670 intel_batchbuffer_emit_mi_flush(brw);
671 }