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