i965: extend fast texture upload
[mesa.git] / src / mesa / drivers / dri / i965 / intel_tex_subimage.c
1
2 /**************************************************************************
3 *
4 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29 #include "main/bufferobj.h"
30 #include "main/macros.h"
31 #include "main/mtypes.h"
32 #include "main/pbo.h"
33 #include "main/texobj.h"
34 #include "main/texstore.h"
35 #include "main/texcompress.h"
36 #include "main/enums.h"
37
38 #include "brw_context.h"
39 #include "intel_batchbuffer.h"
40 #include "intel_tex.h"
41 #include "intel_mipmap_tree.h"
42 #include "intel_blit.h"
43
44 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
45
46 #define ALIGN_DOWN(a, b) ROUND_DOWN_TO(a, b)
47 #define ALIGN_UP(a, b) ALIGN(a, b)
48
49 /* Tile dimensions.
50 * Width and span are in bytes, height is in pixels (i.e. unitless).
51 * A "span" is the most number of bytes we can copy from linear to tiled
52 * without needing to calculate a new destination address.
53 */
54 static const uint32_t xtile_width = 512;
55 static const uint32_t xtile_height = 8;
56 static const uint32_t xtile_span = 64;
57 static const uint32_t ytile_width = 128;
58 static const uint32_t ytile_height = 32;
59 static const uint32_t ytile_span = 16;
60
61 typedef void *(*mem_copy_fn)(void *dest, const void *src, size_t n);
62
63 /**
64 * Each row from y0 to y1 is copied in three parts: [x0,x1), [x1,x2), [x2,x3).
65 * These ranges are in bytes, i.e. pixels * bytes-per-pixel.
66 * The first and last ranges must be shorter than a "span" (the longest linear
67 * stretch within a tile) and the middle must equal a whole number of spans.
68 * Ranges may be empty. The region copied must land entirely within one tile.
69 * 'dst' is the start of the tile and 'src' is the corresponding
70 * address to copy from, though copying begins at (x0, y0).
71 * To enable swizzling 'swizzle_bit' must be 1<<6, otherwise zero.
72 * Swizzling flips bit 6 in the copy destination offset, when certain other
73 * bits are set in it.
74 */
75 typedef void (*tile_copy_fn)(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
76 uint32_t y0, uint32_t y1,
77 char *dst, const char *src,
78 uint32_t src_pitch,
79 uint32_t swizzle_bit,
80 mem_copy_fn mem_copy);
81
82
83 static bool
84 intel_blit_texsubimage(struct gl_context * ctx,
85 struct gl_texture_image *texImage,
86 GLint xoffset, GLint yoffset,
87 GLint width, GLint height,
88 GLenum format, GLenum type, const void *pixels,
89 const struct gl_pixelstore_attrib *packing)
90 {
91 struct brw_context *brw = brw_context(ctx);
92 struct intel_texture_image *intelImage = intel_texture_image(texImage);
93
94 /* Try to do a blit upload of the subimage if the texture is
95 * currently busy.
96 */
97 if (!intelImage->mt)
98 return false;
99
100 /* The blitter can't handle Y tiling */
101 if (intelImage->mt->region->tiling == I915_TILING_Y)
102 return false;
103
104 if (texImage->TexObject->Target != GL_TEXTURE_2D)
105 return false;
106
107 /* On gen6, it's probably not worth swapping to the blit ring to do
108 * this because of all the overhead involved.
109 */
110 if (brw->gen >= 6)
111 return false;
112
113 if (!drm_intel_bo_busy(intelImage->mt->region->bo))
114 return false;
115
116 DBG("BLT subimage %s target %s level %d offset %d,%d %dx%d\n",
117 __FUNCTION__,
118 _mesa_lookup_enum_by_nr(texImage->TexObject->Target),
119 texImage->Level, xoffset, yoffset, width, height);
120
121 pixels = _mesa_validate_pbo_teximage(ctx, 2, width, height, 1,
122 format, type, pixels, packing,
123 "glTexSubImage");
124 if (!pixels)
125 return false;
126
127 struct intel_mipmap_tree *temp_mt =
128 intel_miptree_create(brw, GL_TEXTURE_2D, texImage->TexFormat,
129 0, 0,
130 width, height, 1,
131 false, 0, INTEL_MIPTREE_TILING_NONE);
132 if (!temp_mt)
133 goto err;
134
135 GLubyte *dst = intel_miptree_map_raw(brw, temp_mt);
136 if (!dst)
137 goto err;
138
139 if (!_mesa_texstore(ctx, 2, texImage->_BaseFormat,
140 texImage->TexFormat,
141 temp_mt->region->pitch,
142 &dst,
143 width, height, 1,
144 format, type, pixels, packing)) {
145 _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
146 }
147
148 intel_miptree_unmap_raw(brw, temp_mt);
149
150 bool ret;
151
152 ret = intel_miptree_blit(brw,
153 temp_mt, 0, 0,
154 0, 0, false,
155 intelImage->mt, texImage->Level, texImage->Face,
156 xoffset, yoffset, false,
157 width, height, GL_COPY);
158 assert(ret);
159
160 intel_miptree_release(&temp_mt);
161 _mesa_unmap_teximage_pbo(ctx, packing);
162
163 return ret;
164
165 err:
166 _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
167 intel_miptree_release(&temp_mt);
168 _mesa_unmap_teximage_pbo(ctx, packing);
169 return false;
170 }
171
172 #ifdef __SSSE3__
173 static const uint8_t rgba8_permutation[16] =
174 { 2,1,0,3, 6,5,4,7, 10,9,8,11, 14,13,12,15 };
175
176 typedef char v16 __attribute__((vector_size(16)));
177
178 /* NOTE: dst must be 16 byte aligned */
179 #define rgba8_copy_16(dst, src) \
180 *(v16*)(dst) = __builtin_ia32_pshufb128( \
181 (v16) __builtin_ia32_loadups((float*)(src)), \
182 *(v16*) rgba8_permutation \
183 )
184 #endif
185
186 /**
187 * Copy RGBA to BGRA - swap R and B.
188 */
189 static inline void *
190 rgba8_copy(void *dst, const void *src, size_t bytes)
191 {
192 uint8_t *d = dst;
193 uint8_t const *s = src;
194
195 #ifdef __SSSE3__
196 /* Fast copying for tile spans.
197 *
198 * As long as the destination texture is 16 aligned,
199 * any 16 or 64 spans we get here should also be 16 aligned.
200 */
201
202 if (bytes == 16) {
203 assert(!(((uintptr_t)dst) & 0xf));
204 rgba8_copy_16(d+ 0, s+ 0);
205 return dst;
206 }
207
208 if (bytes == 64) {
209 assert(!(((uintptr_t)dst) & 0xf));
210 rgba8_copy_16(d+ 0, s+ 0);
211 rgba8_copy_16(d+16, s+16);
212 rgba8_copy_16(d+32, s+32);
213 rgba8_copy_16(d+48, s+48);
214 return dst;
215 }
216 #endif
217
218 while (bytes >= 4) {
219 d[0] = s[2];
220 d[1] = s[1];
221 d[2] = s[0];
222 d[3] = s[3];
223 d += 4;
224 s += 4;
225 bytes -= 4;
226 }
227 return dst;
228 }
229
230 /**
231 * Copy texture data from linear to X tile layout.
232 *
233 * \copydoc tile_copy_fn
234 */
235 static inline void
236 xtile_copy(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
237 uint32_t y0, uint32_t y1,
238 char *dst, const char *src,
239 uint32_t src_pitch,
240 uint32_t swizzle_bit,
241 mem_copy_fn mem_copy)
242 {
243 /* The copy destination offset for each range copied is the sum of
244 * an X offset 'x0' or 'xo' and a Y offset 'yo.'
245 */
246 uint32_t xo, yo;
247
248 src += y0 * src_pitch;
249
250 for (yo = y0 * xtile_width; yo < y1 * xtile_width; yo += xtile_width) {
251 /* Bits 9 and 10 of the copy destination offset control swizzling.
252 * Only 'yo' contributes to those bits in the total offset,
253 * so calculate 'swizzle' just once per row.
254 * Move bits 9 and 10 three and four places respectively down
255 * to bit 6 and xor them.
256 */
257 uint32_t swizzle = ((yo >> 3) ^ (yo >> 4)) & swizzle_bit;
258
259 mem_copy(dst + ((x0 + yo) ^ swizzle), src + x0, x1 - x0);
260
261 for (xo = x1; xo < x2; xo += xtile_span) {
262 mem_copy(dst + ((xo + yo) ^ swizzle), src + xo, xtile_span);
263 }
264
265 mem_copy(dst + ((xo + yo) ^ swizzle), src + x2, x3 - x2);
266
267 src += src_pitch;
268 }
269 }
270
271 /**
272 * Copy texture data from linear to Y tile layout.
273 *
274 * \copydoc tile_copy_fn
275 */
276 static inline void
277 ytile_copy(
278 uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
279 uint32_t y0, uint32_t y1,
280 char *dst, const char *src,
281 uint32_t src_pitch,
282 uint32_t swizzle_bit,
283 mem_copy_fn mem_copy)
284 {
285 /* Y tiles consist of columns that are 'ytile_span' wide (and the same height
286 * as the tile). Thus the destination offset for (x,y) is the sum of:
287 * (x % column_width) // position within column
288 * (x / column_width) * bytes_per_column // column number * bytes per column
289 * y * column_width
290 *
291 * The copy destination offset for each range copied is the sum of
292 * an X offset 'xo0' or 'xo' and a Y offset 'yo.'
293 */
294 const uint32_t column_width = ytile_span;
295 const uint32_t bytes_per_column = column_width * ytile_height;
296
297 uint32_t xo0 = (x0 % ytile_span) + (x0 / ytile_span) * bytes_per_column;
298 uint32_t xo1 = (x1 % ytile_span) + (x1 / ytile_span) * bytes_per_column;
299
300 /* Bit 9 of the destination offset control swizzling.
301 * Only the X offset contributes to bit 9 of the total offset,
302 * so swizzle can be calculated in advance for these X positions.
303 * Move bit 9 three places down to bit 6.
304 */
305 uint32_t swizzle0 = (xo0 >> 3) & swizzle_bit;
306 uint32_t swizzle1 = (xo1 >> 3) & swizzle_bit;
307
308 uint32_t x, yo;
309
310 src += y0 * src_pitch;
311
312 for (yo = y0 * column_width; yo < y1 * column_width; yo += column_width) {
313 uint32_t xo = xo1;
314 uint32_t swizzle = swizzle1;
315
316 mem_copy(dst + ((xo0 + yo) ^ swizzle0), src + x0, x1 - x0);
317
318 /* Step by spans/columns. As it happens, the swizzle bit flips
319 * at each step so we don't need to calculate it explicitly.
320 */
321 for (x = x1; x < x2; x += ytile_span) {
322 mem_copy(dst + ((xo + yo) ^ swizzle), src + x, ytile_span);
323 xo += bytes_per_column;
324 swizzle ^= swizzle_bit;
325 }
326
327 mem_copy(dst + ((xo + yo) ^ swizzle), src + x2, x3 - x2);
328
329 src += src_pitch;
330 }
331 }
332
333 /**
334 * Copy texture data from linear to X tile layout, faster.
335 *
336 * Same as \ref xtile_copy but faster, because it passes constant parameters
337 * for common cases, allowing the compiler to inline code optimized for those
338 * cases.
339 *
340 * \copydoc tile_copy_fn
341 */
342 static void
343 xtile_copy_faster(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
344 uint32_t y0, uint32_t y1,
345 char *dst, const char *src,
346 uint32_t src_pitch,
347 uint32_t swizzle_bit,
348 mem_copy_fn mem_copy)
349 {
350 if (x0 == 0 && x3 == xtile_width && y0 == 0 && y1 == xtile_height) {
351 if (mem_copy == memcpy)
352 return xtile_copy(0, 0, xtile_width, xtile_width, 0, xtile_height,
353 dst, src, src_pitch, swizzle_bit, memcpy);
354 else if (mem_copy == rgba8_copy)
355 return xtile_copy(0, 0, xtile_width, xtile_width, 0, xtile_height,
356 dst, src, src_pitch, swizzle_bit, rgba8_copy);
357 } else {
358 if (mem_copy == memcpy)
359 return xtile_copy(x0, x1, x2, x3, y0, y1,
360 dst, src, src_pitch, swizzle_bit, memcpy);
361 else if (mem_copy == rgba8_copy)
362 return xtile_copy(x0, x1, x2, x3, y0, y1,
363 dst, src, src_pitch, swizzle_bit, rgba8_copy);
364 }
365 xtile_copy(x0, x1, x2, x3, y0, y1,
366 dst, src, src_pitch, swizzle_bit, mem_copy);
367 }
368
369 /**
370 * Copy texture data from linear to Y tile layout, faster.
371 *
372 * Same as \ref ytile_copy but faster, because it passes constant parameters
373 * for common cases, allowing the compiler to inline code optimized for those
374 * cases.
375 *
376 * \copydoc tile_copy_fn
377 */
378 static void
379 ytile_copy_faster(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
380 uint32_t y0, uint32_t y1,
381 char *dst, const char *src,
382 uint32_t src_pitch,
383 uint32_t swizzle_bit,
384 mem_copy_fn mem_copy)
385 {
386 if (x0 == 0 && x3 == ytile_width && y0 == 0 && y1 == ytile_height) {
387 if (mem_copy == memcpy)
388 return ytile_copy(0, 0, ytile_width, ytile_width, 0, ytile_height,
389 dst, src, src_pitch, swizzle_bit, memcpy);
390 else if (mem_copy == rgba8_copy)
391 return ytile_copy(0, 0, ytile_width, ytile_width, 0, ytile_height,
392 dst, src, src_pitch, swizzle_bit, rgba8_copy);
393 } else {
394 if (mem_copy == memcpy)
395 return ytile_copy(x0, x1, x2, x3, y0, y1,
396 dst, src, src_pitch, swizzle_bit, memcpy);
397 else if (mem_copy == rgba8_copy)
398 return ytile_copy(x0, x1, x2, x3, y0, y1,
399 dst, src, src_pitch, swizzle_bit, rgba8_copy);
400 }
401 ytile_copy(x0, x1, x2, x3, y0, y1,
402 dst, src, src_pitch, swizzle_bit, mem_copy);
403 }
404
405 /**
406 * Copy from linear to tiled texture.
407 *
408 * Divide the region given by X range [xt1, xt2) and Y range [yt1, yt2) into
409 * pieces that do not cross tile boundaries and copy each piece with a tile
410 * copy function (\ref tile_copy_fn).
411 * The X range is in bytes, i.e. pixels * bytes-per-pixel.
412 * The Y range is in pixels (i.e. unitless).
413 * 'dst' is the start of the texture and 'src' is the corresponding
414 * address to copy from, though copying begins at (xt1, yt1).
415 */
416 static void
417 linear_to_tiled(uint32_t xt1, uint32_t xt2,
418 uint32_t yt1, uint32_t yt2,
419 char *dst, const char *src,
420 uint32_t dst_pitch, uint32_t src_pitch,
421 bool has_swizzling,
422 uint32_t tiling,
423 mem_copy_fn mem_copy)
424 {
425 tile_copy_fn tile_copy;
426 uint32_t xt0, xt3;
427 uint32_t yt0, yt3;
428 uint32_t xt, yt;
429 uint32_t tw, th, span;
430 uint32_t swizzle_bit = has_swizzling ? 1<<6 : 0;
431
432 if (tiling == I915_TILING_X) {
433 tw = xtile_width;
434 th = xtile_height;
435 span = xtile_span;
436 tile_copy = xtile_copy_faster;
437 } else if (tiling == I915_TILING_Y) {
438 tw = ytile_width;
439 th = ytile_height;
440 span = ytile_span;
441 tile_copy = ytile_copy_faster;
442 } else {
443 assert(!"unsupported tiling");
444 return;
445 }
446
447 /* Round out to tile boundaries. */
448 xt0 = ALIGN_DOWN(xt1, tw);
449 xt3 = ALIGN_UP (xt2, tw);
450 yt0 = ALIGN_DOWN(yt1, th);
451 yt3 = ALIGN_UP (yt2, th);
452
453 /* Loop over all tiles to which we have something to copy.
454 * 'xt' and 'yt' are the origin of the destination tile, whether copying
455 * copying a full or partial tile.
456 * tile_copy() copies one tile or partial tile.
457 * Looping x inside y is the faster memory access pattern.
458 */
459 for (yt = yt0; yt < yt3; yt += th) {
460 for (xt = xt0; xt < xt3; xt += tw) {
461 /* The area to update is [x0,x3) x [y0,y1).
462 * May not want the whole tile, hence the min and max.
463 */
464 uint32_t x0 = MAX2(xt1, xt);
465 uint32_t y0 = MAX2(yt1, yt);
466 uint32_t x3 = MIN2(xt2, xt + tw);
467 uint32_t y1 = MIN2(yt2, yt + th);
468
469 /* [x0,x3) is split into [x0,x1), [x1,x2), [x2,x3) such that
470 * the middle interval is the longest span-aligned part.
471 * The sub-ranges could be empty.
472 */
473 uint32_t x1, x2;
474 x1 = ALIGN_UP(x0, span);
475 if (x1 > x3)
476 x1 = x2 = x3;
477 else
478 x2 = ALIGN_DOWN(x3, span);
479
480 assert(x0 <= x1 && x1 <= x2 && x2 <= x3);
481 assert(x1 - x0 < span && x3 - x2 < span);
482 assert(x3 - x0 <= tw);
483 assert((x2 - x1) % span == 0);
484
485 /* Translate by (xt,yt) for single-tile copier. */
486 tile_copy(x0-xt, x1-xt, x2-xt, x3-xt,
487 y0-yt, y1-yt,
488 dst + xt * th + yt * dst_pitch,
489 src + xt + yt * src_pitch,
490 src_pitch,
491 swizzle_bit,
492 mem_copy);
493 }
494 }
495 }
496
497 /**
498 * \brief A fast path for glTexImage and glTexSubImage.
499 *
500 * \param for_glTexImage Was this called from glTexImage or glTexSubImage?
501 *
502 * This fast path is taken when the texture format is BGRA, RGBA,
503 * A or L and when the texture memory is X- or Y-tiled. It uploads
504 * the texture data by mapping the texture memory without a GTT fence, thus
505 * acquiring a tiled view of the memory, and then copying sucessive
506 * spans within each tile.
507 *
508 * This is a performance win over the conventional texture upload path because
509 * it avoids the performance penalty of writing through the write-combine
510 * buffer. In the conventional texture upload path,
511 * texstore.c:store_texsubimage(), the texture memory is mapped through a GTT
512 * fence, thus acquiring a linear view of the memory, then each row in the
513 * image is memcpy'd. In this fast path, we replace each row's copy with
514 * a sequence of copies over each linear span in tile.
515 *
516 * One use case is Google Chrome's paint rectangles. Chrome (as
517 * of version 21) renders each page as a tiling of 256x256 GL_BGRA textures.
518 * Each page's content is initially uploaded with glTexImage2D and damaged
519 * regions are updated with glTexSubImage2D. On some workloads, the
520 * performance gain of this fastpath on Sandybridge is over 5x.
521 */
522 bool
523 intel_texsubimage_tiled_memcpy(struct gl_context * ctx,
524 GLuint dims,
525 struct gl_texture_image *texImage,
526 GLint xoffset, GLint yoffset, GLint zoffset,
527 GLsizei width, GLsizei height, GLsizei depth,
528 GLenum format, GLenum type,
529 const GLvoid *pixels,
530 const struct gl_pixelstore_attrib *packing,
531 bool for_glTexImage)
532 {
533 struct brw_context *brw = brw_context(ctx);
534 struct intel_texture_image *image = intel_texture_image(texImage);
535
536 /* The miptree's buffer. */
537 drm_intel_bo *bo;
538
539 int error = 0;
540
541 uint32_t cpp;
542 mem_copy_fn mem_copy = NULL;
543
544 /* This fastpath is restricted to specific texture types: level 0 of
545 * a 2D BGRA, RGBA, L8 or A8 texture. It could be generalized to support
546 * more types.
547 */
548 if (!brw->has_llc ||
549 type != GL_UNSIGNED_BYTE ||
550 texImage->TexObject->Target != GL_TEXTURE_2D ||
551 texImage->Level != 0 ||
552 pixels == NULL ||
553 _mesa_is_bufferobj(packing->BufferObj) ||
554 packing->Alignment > 4 ||
555 packing->SkipPixels > 0 ||
556 packing->SkipRows > 0 ||
557 (packing->RowLength != 0 && packing->RowLength != width) ||
558 packing->SwapBytes ||
559 packing->LsbFirst ||
560 packing->Invert)
561 return false;
562
563 if ((texImage->TexFormat == MESA_FORMAT_L8 && format == GL_LUMINANCE) ||
564 (texImage->TexFormat == MESA_FORMAT_A8 && format == GL_ALPHA)) {
565 cpp = 1;
566 mem_copy = memcpy;
567 } else if (texImage->TexFormat == MESA_FORMAT_ARGB8888) {
568 cpp = 4;
569 if (format == GL_BGRA) {
570 mem_copy = memcpy;
571 } else if (format == GL_RGBA) {
572 mem_copy = rgba8_copy;
573 }
574 }
575 if (!mem_copy)
576 return false;
577
578 if (for_glTexImage)
579 ctx->Driver.AllocTextureImageBuffer(ctx, texImage);
580
581 if (!image->mt ||
582 (image->mt->region->tiling != I915_TILING_X &&
583 image->mt->region->tiling != I915_TILING_Y)) {
584 /* The algorithm is written only for X- or Y-tiled memory. */
585 return false;
586 }
587
588 /* Since we are going to write raw data to the miptree, we need to resolve
589 * any pending fast color clears before we start.
590 */
591 intel_miptree_resolve_color(brw, image->mt);
592
593 bo = image->mt->region->bo;
594
595 if (drm_intel_bo_references(brw->batch.bo, bo)) {
596 perf_debug("Flushing before mapping a referenced bo.\n");
597 intel_batchbuffer_flush(brw);
598 }
599
600 if (unlikely(brw->perf_debug)) {
601 if (drm_intel_bo_busy(bo)) {
602 perf_debug("Mapping a busy BO, causing a stall on the GPU.\n");
603 }
604 }
605
606 error = drm_intel_bo_map(bo, true /*write_enable*/);
607 if (error || bo->virtual == NULL) {
608 DBG("%s: failed to map bo\n", __FUNCTION__);
609 return false;
610 }
611
612 /* We postponed printing this message until having committed to executing
613 * the function.
614 */
615 DBG("%s: level=%d offset=(%d,%d) (w,h)=(%d,%d)\n",
616 __FUNCTION__, texImage->Level, xoffset, yoffset, width, height);
617
618 linear_to_tiled(
619 xoffset * cpp, (xoffset + width) * cpp,
620 yoffset, yoffset + height,
621 bo->virtual, pixels - (xoffset + yoffset * width) * cpp,
622 image->mt->region->pitch, width * cpp,
623 brw->has_swizzling,
624 image->mt->region->tiling,
625 mem_copy
626 );
627
628 drm_intel_bo_unmap(bo);
629 return true;
630 }
631
632 static void
633 intelTexSubImage(struct gl_context * ctx,
634 GLuint dims,
635 struct gl_texture_image *texImage,
636 GLint xoffset, GLint yoffset, GLint zoffset,
637 GLsizei width, GLsizei height, GLsizei depth,
638 GLenum format, GLenum type,
639 const GLvoid * pixels,
640 const struct gl_pixelstore_attrib *packing)
641 {
642 bool ok;
643
644 ok = intel_texsubimage_tiled_memcpy(ctx, dims, texImage,
645 xoffset, yoffset, zoffset,
646 width, height, depth,
647 format, type, pixels, packing,
648 false /*for_glTexImage*/);
649 if (ok)
650 return;
651
652 /* The intel_blit_texsubimage() function only handles 2D images */
653 if (dims != 2 || !intel_blit_texsubimage(ctx, texImage,
654 xoffset, yoffset,
655 width, height,
656 format, type, pixels, packing)) {
657 _mesa_store_texsubimage(ctx, dims, texImage,
658 xoffset, yoffset, zoffset,
659 width, height, depth,
660 format, type, pixels, packing);
661 }
662 }
663
664 void
665 intelInitTextureSubImageFuncs(struct dd_function_table *functions)
666 {
667 functions->TexSubImage = intelTexSubImage;
668 }