6d57b2b7dd1090f73b2b318d33b4ac39135a4cc4
[mesa.git] / src / mesa / drivers / dri / intel / intel_tex_image.c
1
2 #include <stdlib.h>
3 #include <stdio.h>
4
5 #include "glheader.h"
6 #include "macros.h"
7 #include "mtypes.h"
8 #include "enums.h"
9 #include "colortab.h"
10 #include "convolve.h"
11 #include "context.h"
12 #include "simple_list.h"
13 #include "texcompress.h"
14 #include "texformat.h"
15 #include "texobj.h"
16 #include "texstore.h"
17 #include "teximage.h"
18
19 #include "intel_context.h"
20 #include "intel_mipmap_tree.h"
21 #include "intel_buffer_objects.h"
22 #include "intel_batchbuffer.h"
23 #include "intel_tex.h"
24 #include "intel_ioctl.h"
25 #include "intel_blit.h"
26 #include "intel_fbo.h"
27
28 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
29
30 /* Functions to store texture images. Where possible, mipmap_tree's
31 * will be created or further instantiated with image data, otherwise
32 * images will be stored in malloc'd memory. A validation step is
33 * required to pull those images into a mipmap tree, or otherwise
34 * decide a fallback is required.
35 */
36
37
38 static int
39 logbase2(int n)
40 {
41 GLint i = 1;
42 GLint log2 = 0;
43
44 while (n > i) {
45 i *= 2;
46 log2++;
47 }
48
49 return log2;
50 }
51
52
53 /* Otherwise, store it in memory if (Border != 0) or (any dimension ==
54 * 1).
55 *
56 * Otherwise, if max_level >= level >= min_level, create tree with
57 * space for textures from min_level down to max_level.
58 *
59 * Otherwise, create tree with space for textures from (level
60 * 0)..(1x1). Consider pruning this tree at a validation if the
61 * saving is worth it.
62 */
63 static void
64 guess_and_alloc_mipmap_tree(struct intel_context *intel,
65 struct intel_texture_object *intelObj,
66 struct intel_texture_image *intelImage)
67 {
68 GLuint firstLevel;
69 GLuint lastLevel;
70 GLuint width = intelImage->base.Width;
71 GLuint height = intelImage->base.Height;
72 GLuint depth = intelImage->base.Depth;
73 GLuint l2width, l2height, l2depth;
74 GLuint i, comp_byte = 0;
75
76 DBG("%s\n", __FUNCTION__);
77
78 if (intelImage->base.Border)
79 return;
80
81 if (intelImage->level > intelObj->base.BaseLevel &&
82 (intelImage->base.Width == 1 ||
83 (intelObj->base.Target != GL_TEXTURE_1D &&
84 intelImage->base.Height == 1) ||
85 (intelObj->base.Target == GL_TEXTURE_3D &&
86 intelImage->base.Depth == 1)))
87 return;
88
89 /* If this image disrespects BaseLevel, allocate from level zero.
90 * Usually BaseLevel == 0, so it's unlikely to happen.
91 */
92 if (intelImage->level < intelObj->base.BaseLevel)
93 firstLevel = 0;
94 else
95 firstLevel = intelObj->base.BaseLevel;
96
97
98 /* Figure out image dimensions at start level.
99 */
100 for (i = intelImage->level; i > firstLevel; i--) {
101 width <<= 1;
102 if (height != 1)
103 height <<= 1;
104 if (depth != 1)
105 depth <<= 1;
106 }
107
108 /* Guess a reasonable value for lastLevel. This is probably going
109 * to be wrong fairly often and might mean that we have to look at
110 * resizable buffers, or require that buffers implement lazy
111 * pagetable arrangements.
112 */
113 if ((intelObj->base.MinFilter == GL_NEAREST ||
114 intelObj->base.MinFilter == GL_LINEAR) &&
115 intelImage->level == firstLevel) {
116 lastLevel = firstLevel;
117 }
118 else {
119 l2width = logbase2(width);
120 l2height = logbase2(height);
121 l2depth = logbase2(depth);
122 lastLevel = firstLevel + MAX2(MAX2(l2width, l2height), l2depth);
123 }
124
125 assert(!intelObj->mt);
126 if (intelImage->base.IsCompressed)
127 comp_byte = intel_compressed_num_bytes(intelImage->base.TexFormat->MesaFormat);
128 intelObj->mt = intel_miptree_create(intel,
129 intelObj->base.Target,
130 intelImage->base.InternalFormat,
131 firstLevel,
132 lastLevel,
133 width,
134 height,
135 depth,
136 intelImage->base.TexFormat->TexelBytes,
137 comp_byte);
138
139 DBG("%s - success\n", __FUNCTION__);
140 }
141
142
143
144
145 static GLuint
146 target_to_face(GLenum target)
147 {
148 switch (target) {
149 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
150 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
151 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
152 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
153 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
154 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
155 return ((GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X);
156 default:
157 return 0;
158 }
159 }
160
161 /* There are actually quite a few combinations this will work for,
162 * more than what I've listed here.
163 */
164 static GLboolean
165 check_pbo_format(GLint internalFormat,
166 GLenum format, GLenum type,
167 const struct gl_texture_format *mesa_format)
168 {
169 switch (internalFormat) {
170 case 4:
171 case GL_RGBA:
172 return (format == GL_BGRA &&
173 (type == GL_UNSIGNED_BYTE ||
174 type == GL_UNSIGNED_INT_8_8_8_8_REV) &&
175 mesa_format == &_mesa_texformat_argb8888);
176 case 3:
177 case GL_RGB:
178 return (format == GL_RGB &&
179 type == GL_UNSIGNED_SHORT_5_6_5 &&
180 mesa_format == &_mesa_texformat_rgb565);
181 case GL_YCBCR_MESA:
182 return (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE);
183 default:
184 return GL_FALSE;
185 }
186 }
187
188
189 /* XXX: Do this for TexSubImage also:
190 */
191 static GLboolean
192 try_pbo_upload(struct intel_context *intel,
193 struct intel_texture_image *intelImage,
194 const struct gl_pixelstore_attrib *unpack,
195 GLint internalFormat,
196 GLint width, GLint height,
197 GLenum format, GLenum type, const void *pixels)
198 {
199 struct intel_buffer_object *pbo = intel_buffer_object(unpack->BufferObj);
200 GLuint src_offset, src_stride;
201 GLuint dst_offset, dst_stride;
202
203 if (!pbo ||
204 intel->ctx._ImageTransferState ||
205 unpack->SkipPixels || unpack->SkipRows) {
206 _mesa_printf("%s: failure 1\n", __FUNCTION__);
207 return GL_FALSE;
208 }
209
210 src_offset = (GLuint) pixels;
211
212 if (unpack->RowLength > 0)
213 src_stride = unpack->RowLength;
214 else
215 src_stride = width;
216
217 dst_offset = intel_miptree_image_offset(intelImage->mt,
218 intelImage->face,
219 intelImage->level);
220
221 dst_stride = intelImage->mt->pitch;
222
223 intelFlush(&intel->ctx);
224 LOCK_HARDWARE(intel);
225 {
226 dri_bo *src_buffer = intel_bufferobj_buffer(intel, pbo, INTEL_READ);
227 dri_bo *dst_buffer = intel_region_buffer(intel,
228 intelImage->mt->region,
229 INTEL_WRITE_FULL);
230
231
232 intelEmitCopyBlit(intel,
233 intelImage->mt->cpp,
234 src_stride, src_buffer, src_offset, GL_FALSE,
235 dst_stride, dst_buffer, dst_offset, GL_FALSE,
236 0, 0, 0, 0, width, height,
237 GL_COPY);
238 }
239 UNLOCK_HARDWARE(intel);
240
241 return GL_TRUE;
242 }
243
244
245
246 static GLboolean
247 try_pbo_zcopy(struct intel_context *intel,
248 struct intel_texture_image *intelImage,
249 const struct gl_pixelstore_attrib *unpack,
250 GLint internalFormat,
251 GLint width, GLint height,
252 GLenum format, GLenum type, const void *pixels)
253 {
254 struct intel_buffer_object *pbo = intel_buffer_object(unpack->BufferObj);
255 GLuint src_offset, src_stride;
256 GLuint dst_offset, dst_stride;
257
258 if (!pbo ||
259 intel->ctx._ImageTransferState ||
260 unpack->SkipPixels || unpack->SkipRows) {
261 _mesa_printf("%s: failure 1\n", __FUNCTION__);
262 return GL_FALSE;
263 }
264
265 src_offset = (GLuint) pixels;
266
267 if (unpack->RowLength > 0)
268 src_stride = unpack->RowLength;
269 else
270 src_stride = width;
271
272 dst_offset = intel_miptree_image_offset(intelImage->mt,
273 intelImage->face,
274 intelImage->level);
275
276 dst_stride = intelImage->mt->pitch;
277
278 if (src_stride != dst_stride || dst_offset != 0 || src_offset != 0) {
279 _mesa_printf("%s: failure 2\n", __FUNCTION__);
280 return GL_FALSE;
281 }
282
283 intel_region_attach_pbo(intel, intelImage->mt->region, pbo);
284
285 return GL_TRUE;
286 }
287
288
289
290
291
292
293 static void
294 intelTexImage(GLcontext * ctx,
295 GLint dims,
296 GLenum target, GLint level,
297 GLint internalFormat,
298 GLint width, GLint height, GLint depth,
299 GLint border,
300 GLenum format, GLenum type, const void *pixels,
301 const struct gl_pixelstore_attrib *unpack,
302 struct gl_texture_object *texObj,
303 struct gl_texture_image *texImage, GLsizei imageSize, int compressed)
304 {
305 struct intel_context *intel = intel_context(ctx);
306 struct intel_texture_object *intelObj = intel_texture_object(texObj);
307 struct intel_texture_image *intelImage = intel_texture_image(texImage);
308 GLint postConvWidth = width;
309 GLint postConvHeight = height;
310 GLint texelBytes, sizeInBytes;
311 GLuint dstRowStride, srcRowStride = texImage->RowStride;
312
313
314 DBG("%s target %s level %d %dx%dx%d border %d\n", __FUNCTION__,
315 _mesa_lookup_enum_by_nr(target), level, width, height, depth, border);
316
317 intelFlush(ctx);
318
319 intelImage->face = target_to_face(target);
320 intelImage->level = level;
321
322 if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) {
323 _mesa_adjust_image_for_convolution(ctx, dims, &postConvWidth,
324 &postConvHeight);
325 }
326
327 /* choose the texture format */
328 texImage->TexFormat = intelChooseTextureFormat(ctx, internalFormat,
329 format, type);
330
331 _mesa_set_fetch_functions(texImage, dims);
332
333 if (texImage->TexFormat->TexelBytes == 0) {
334 /* must be a compressed format */
335 texelBytes = 0;
336 texImage->IsCompressed = GL_TRUE;
337 texImage->CompressedSize =
338 ctx->Driver.CompressedTextureSize(ctx, texImage->Width,
339 texImage->Height, texImage->Depth,
340 texImage->TexFormat->MesaFormat);
341 } else {
342 texelBytes = texImage->TexFormat->TexelBytes;
343
344 /* Minimum pitch of 32 bytes */
345 if (postConvWidth * texelBytes < 32) {
346 postConvWidth = 32 / texelBytes;
347 texImage->RowStride = postConvWidth;
348 }
349
350 if (!intelImage->mt) {
351 assert(texImage->RowStride == postConvWidth);
352 }
353 }
354
355 /* Release the reference to a potentially orphaned buffer.
356 * Release any old malloced memory.
357 */
358 if (intelImage->mt) {
359 intel_miptree_release(intel, &intelImage->mt);
360 assert(!texImage->Data);
361 }
362 else if (texImage->Data) {
363 _mesa_free_texmemory(texImage->Data);
364 texImage->Data = NULL;
365 }
366
367 /* If this is the only texture image in the tree, could call
368 * bmBufferData with NULL data to free the old block and avoid
369 * waiting on any outstanding fences.
370 */
371 if (intelObj->mt &&
372 intelObj->mt->first_level == level &&
373 intelObj->mt->last_level == level &&
374 intelObj->mt->target != GL_TEXTURE_CUBE_MAP_ARB &&
375 !intel_miptree_match_image(intelObj->mt, &intelImage->base,
376 intelImage->face, intelImage->level)) {
377
378 DBG("release it\n");
379 intel_miptree_release(intel, &intelObj->mt);
380 assert(!intelObj->mt);
381 }
382
383 if (!intelObj->mt) {
384 guess_and_alloc_mipmap_tree(intel, intelObj, intelImage);
385 if (!intelObj->mt) {
386 DBG("guess_and_alloc_mipmap_tree: failed\n");
387 }
388 }
389
390 assert(!intelImage->mt);
391
392 if (intelObj->mt &&
393 intel_miptree_match_image(intelObj->mt, &intelImage->base,
394 intelImage->face, intelImage->level)) {
395
396 intel_miptree_reference(&intelImage->mt, intelObj->mt);
397 assert(intelImage->mt);
398 }
399
400 if (!intelImage->mt)
401 DBG("XXX: Image did not fit into tree - storing in local memory!\n");
402
403 /* PBO fastpaths:
404 */
405 if (dims <= 2 &&
406 intelImage->mt &&
407 intel_buffer_object(unpack->BufferObj) &&
408 check_pbo_format(internalFormat, format,
409 type, intelImage->base.TexFormat)) {
410
411 DBG("trying pbo upload\n");
412
413 /* Attempt to texture directly from PBO data (zero copy upload).
414 *
415 * Currently disable as it can lead to worse as well as better
416 * performance (in particular when intel_region_cow() is
417 * required).
418 */
419 if (intelObj->mt == intelImage->mt &&
420 intelObj->mt->first_level == level &&
421 intelObj->mt->last_level == level) {
422
423 if (try_pbo_zcopy(intel, intelImage, unpack,
424 internalFormat,
425 width, height, format, type, pixels)) {
426
427 DBG("pbo zcopy upload succeeded\n");
428 return;
429 }
430 }
431
432
433 /* Otherwise, attempt to use the blitter for PBO image uploads.
434 */
435 if (try_pbo_upload(intel, intelImage, unpack,
436 internalFormat,
437 width, height, format, type, pixels)) {
438 DBG("pbo upload succeeded\n");
439 return;
440 }
441
442 DBG("pbo upload failed\n");
443 }
444
445
446
447 /* intelCopyTexImage calls this function with pixels == NULL, with
448 * the expectation that the mipmap tree will be set up but nothing
449 * more will be done. This is where those calls return:
450 */
451 if (compressed) {
452 pixels = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, pixels,
453 unpack,
454 "glCompressedTexImage");
455 } else {
456 pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, 1,
457 format, type,
458 pixels, unpack, "glTexImage");
459 }
460
461 LOCK_HARDWARE(intel);
462
463 if (intelImage->mt) {
464 texImage->Data = intel_miptree_image_map(intel,
465 intelImage->mt,
466 intelImage->face,
467 intelImage->level,
468 &dstRowStride,
469 intelImage->base.ImageOffsets);
470 texImage->RowStride = dstRowStride / intelImage->mt->cpp;
471 }
472 else {
473 /* Allocate regular memory and store the image there temporarily. */
474 if (texImage->IsCompressed) {
475 sizeInBytes = texImage->CompressedSize;
476 dstRowStride =
477 _mesa_compressed_row_stride(texImage->TexFormat->MesaFormat, width);
478 assert(dims != 3);
479 }
480 else {
481 dstRowStride = postConvWidth * texelBytes;
482 sizeInBytes = depth * dstRowStride * postConvHeight;
483 }
484
485 texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
486 }
487
488 DBG("Upload image %dx%dx%d row_len %d "
489 "pitch %d\n",
490 width, height, depth, width * texelBytes, dstRowStride);
491
492 /* Copy data. Would like to know when it's ok for us to eg. use
493 * the blitter to copy. Or, use the hardware to do the format
494 * conversion and copy:
495 */
496 if (pixels) {
497 if (compressed) {
498 if (intelImage->mt) {
499 struct intel_region *dst = intelImage->mt->region;
500 _mesa_copy_rect(texImage->Data, dst->cpp, dst->pitch,
501 0, 0,
502 intelImage->mt->level[level].width,
503 intelImage->mt->level[level].height/4,
504 pixels,
505 srcRowStride,
506 0, 0);
507 } else
508 memcpy(texImage->Data, pixels, imageSize);
509 } else if (!texImage->TexFormat->StoreImage(ctx, dims,
510 texImage->_BaseFormat,
511 texImage->TexFormat,
512 texImage->Data, 0, 0, 0, /* dstX/Y/Zoffset */
513 dstRowStride,
514 texImage->ImageOffsets,
515 width, height, depth,
516 format, type, pixels, unpack)) {
517 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
518 }
519 }
520
521 /* GL_SGIS_generate_mipmap */
522 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
523 intel_generate_mipmap(ctx, target, texObj);
524 }
525
526 _mesa_unmap_teximage_pbo(ctx, unpack);
527
528 if (intelImage->mt) {
529 intel_miptree_image_unmap(intel, intelImage->mt);
530 texImage->Data = NULL;
531 }
532
533 UNLOCK_HARDWARE(intel);
534 }
535
536 void
537 intelTexImage3D(GLcontext * ctx,
538 GLenum target, GLint level,
539 GLint internalFormat,
540 GLint width, GLint height, GLint depth,
541 GLint border,
542 GLenum format, GLenum type, const void *pixels,
543 const struct gl_pixelstore_attrib *unpack,
544 struct gl_texture_object *texObj,
545 struct gl_texture_image *texImage)
546 {
547 intelTexImage(ctx, 3, target, level,
548 internalFormat, width, height, depth, border,
549 format, type, pixels, unpack, texObj, texImage, 0, 0);
550 }
551
552
553 void
554 intelTexImage2D(GLcontext * ctx,
555 GLenum target, GLint level,
556 GLint internalFormat,
557 GLint width, GLint height, GLint border,
558 GLenum format, GLenum type, const void *pixels,
559 const struct gl_pixelstore_attrib *unpack,
560 struct gl_texture_object *texObj,
561 struct gl_texture_image *texImage)
562 {
563 intelTexImage(ctx, 2, target, level,
564 internalFormat, width, height, 1, border,
565 format, type, pixels, unpack, texObj, texImage, 0, 0);
566 }
567
568 void
569 intelTexImage1D(GLcontext * ctx,
570 GLenum target, GLint level,
571 GLint internalFormat,
572 GLint width, GLint border,
573 GLenum format, GLenum type, const void *pixels,
574 const struct gl_pixelstore_attrib *unpack,
575 struct gl_texture_object *texObj,
576 struct gl_texture_image *texImage)
577 {
578 intelTexImage(ctx, 1, target, level,
579 internalFormat, width, 1, 1, border,
580 format, type, pixels, unpack, texObj, texImage, 0, 0);
581 }
582
583 void intelCompressedTexImage2D( GLcontext *ctx, GLenum target, GLint level,
584 GLint internalFormat,
585 GLint width, GLint height, GLint border,
586 GLsizei imageSize, const GLvoid *data,
587 struct gl_texture_object *texObj,
588 struct gl_texture_image *texImage )
589 {
590 intelTexImage(ctx, 2, target, level,
591 internalFormat, width, height, 1, border,
592 0, 0, data, &ctx->Unpack, texObj, texImage, imageSize, 1);
593 }
594
595 /**
596 * Need to map texture image into memory before copying image data,
597 * then unmap it.
598 */
599 static void
600 intel_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
601 GLenum format, GLenum type, GLvoid * pixels,
602 struct gl_texture_object *texObj,
603 struct gl_texture_image *texImage, int compressed)
604 {
605 struct intel_context *intel = intel_context(ctx);
606 struct intel_texture_image *intelImage = intel_texture_image(texImage);
607
608 /* Map */
609 if (intelImage->mt) {
610 /* Image is stored in hardware format in a buffer managed by the
611 * kernel. Need to explicitly map and unmap it.
612 */
613 intelImage->base.Data =
614 intel_miptree_image_map(intel,
615 intelImage->mt,
616 intelImage->face,
617 intelImage->level,
618 &intelImage->base.RowStride,
619 intelImage->base.ImageOffsets);
620 intelImage->base.RowStride /= intelImage->mt->cpp;
621 }
622 else {
623 /* Otherwise, the image should actually be stored in
624 * intelImage->base.Data. This is pretty confusing for
625 * everybody, I'd much prefer to separate the two functions of
626 * texImage->Data - storage for texture images in main memory
627 * and access (ie mappings) of images. In other words, we'd
628 * create a new texImage->Map field and leave Data simply for
629 * storage.
630 */
631 assert(intelImage->base.Data);
632 }
633
634
635 if (compressed) {
636 _mesa_get_compressed_teximage(ctx, target, level, pixels,
637 texObj, texImage);
638 } else {
639 _mesa_get_teximage(ctx, target, level, format, type, pixels,
640 texObj, texImage);
641 }
642
643
644 /* Unmap */
645 if (intelImage->mt) {
646 intel_miptree_image_unmap(intel, intelImage->mt);
647 intelImage->base.Data = NULL;
648 }
649 }
650
651 void
652 intelGetTexImage(GLcontext * ctx, GLenum target, GLint level,
653 GLenum format, GLenum type, GLvoid * pixels,
654 struct gl_texture_object *texObj,
655 struct gl_texture_image *texImage)
656 {
657 intel_get_tex_image(ctx, target, level, format, type, pixels,
658 texObj, texImage, 0);
659
660
661 }
662
663 void
664 intelGetCompressedTexImage(GLcontext *ctx, GLenum target, GLint level,
665 GLvoid *pixels,
666 struct gl_texture_object *texObj,
667 struct gl_texture_image *texImage)
668 {
669 intel_get_tex_image(ctx, target, level, 0, 0, pixels,
670 texObj, texImage, 1);
671 }
672
673 void
674 intelSetTexOffset(__DRIcontext *pDRICtx, GLint texname,
675 unsigned long long offset, GLint depth, GLuint pitch)
676 {
677 struct intel_context *intel = pDRICtx->driverPrivate;
678 struct gl_texture_object *tObj = _mesa_lookup_texture(&intel->ctx, texname);
679 struct intel_texture_object *intelObj = intel_texture_object(tObj);
680
681 if (!intelObj)
682 return;
683
684 if (intelObj->mt)
685 intel_miptree_release(intel, &intelObj->mt);
686
687 intelObj->imageOverride = GL_TRUE;
688 intelObj->depthOverride = depth;
689 intelObj->pitchOverride = pitch;
690
691 if (offset)
692 intelObj->textureOffset = offset;
693 }
694
695 void
696 intelSetTexBuffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *dPriv)
697 {
698 struct intel_framebuffer *intel_fb = dPriv->driverPrivate;
699 struct intel_context *intel = pDRICtx->driverPrivate;
700 struct intel_texture_object *intelObj;
701 struct intel_texture_image *intelImage;
702 struct intel_mipmap_tree *mt;
703 struct intel_renderbuffer *rb;
704 struct gl_texture_unit *texUnit;
705 struct gl_texture_object *texObj;
706 struct gl_texture_image *texImage;
707 int level = 0, type, format, internalFormat;
708
709 texUnit = &intel->ctx.Texture.Unit[intel->ctx.Texture.CurrentUnit];
710 texObj = _mesa_select_tex_object(&intel->ctx, texUnit, target);
711 intelObj = intel_texture_object(texObj);
712
713 if (!intelObj)
714 return;
715
716 __driParseEvents(pDRICtx, dPriv);
717
718 rb = intel_fb->color_rb[0];
719 type = GL_BGRA;
720 format = GL_UNSIGNED_BYTE;
721 internalFormat = (rb->region->cpp == 3 ? 3 : 4);
722
723 mt = intel_miptree_create_for_region(intel, target,
724 internalFormat,
725 0, 0, rb->region, 1, 0);
726 if (mt == NULL)
727 return;
728
729 _mesa_lock_texture(&intel->ctx, texObj);
730
731 if (intelObj->mt)
732 intel_miptree_release(intel, &intelObj->mt);
733
734 intelObj->mt = mt;
735 texImage = _mesa_get_tex_image(&intel->ctx, texObj, target, level);
736 _mesa_init_teximage_fields(&intel->ctx, target, texImage,
737 rb->region->pitch, rb->region->height, 1,
738 0, internalFormat);
739
740 intelImage = intel_texture_image(texImage);
741 intelImage->face = target_to_face(target);
742 intelImage->level = level;
743 texImage->TexFormat = intelChooseTextureFormat(&intel->ctx, internalFormat,
744 type, format);
745 _mesa_set_fetch_functions(texImage, 2);
746 texImage->RowStride = rb->region->pitch;
747 intel_miptree_reference(&intelImage->mt, intelObj->mt);
748
749 if (!intel_miptree_match_image(intelObj->mt, &intelImage->base,
750 intelImage->face, intelImage->level)) {
751 fprintf(stderr, "miptree doesn't match image\n");
752 }
753
754 _mesa_unlock_texture(&intel->ctx, texObj);
755 }