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