abaf9d2c353e52d350859f92b75a752a4df3dca3
[mesa.git] / src / mesa / state_tracker / st_cb_texture.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 #include "main/mfeatures.h"
29 #include "main/bufferobj.h"
30 #if FEATURE_convolve
31 #include "main/convolve.h"
32 #endif
33 #include "main/enums.h"
34 #include "main/image.h"
35 #include "main/imports.h"
36 #include "main/macros.h"
37 #include "main/mipmap.h"
38 #include "main/pixel.h"
39 #include "main/texcompress.h"
40 #include "main/texformat.h"
41 #include "main/texgetimage.h"
42 #include "main/teximage.h"
43 #include "main/texobj.h"
44 #include "main/texstore.h"
45
46 #include "state_tracker/st_context.h"
47 #include "state_tracker/st_cb_fbo.h"
48 #include "state_tracker/st_cb_texture.h"
49 #include "state_tracker/st_format.h"
50 #include "state_tracker/st_public.h"
51 #include "state_tracker/st_texture.h"
52 #include "state_tracker/st_gen_mipmap.h"
53 #include "state_tracker/st_inlines.h"
54 #include "state_tracker/st_atom.h"
55
56 #include "pipe/p_context.h"
57 #include "pipe/p_defines.h"
58 #include "pipe/p_inlines.h"
59 #include "pipe/p_shader_tokens.h"
60 #include "util/u_tile.h"
61 #include "util/u_blit.h"
62 #include "util/u_surface.h"
63 #include "util/u_math.h"
64
65
66 #define DBG if (0) printf
67
68
69 static enum pipe_texture_target
70 gl_target_to_pipe(GLenum target)
71 {
72 switch (target) {
73 case GL_TEXTURE_1D:
74 return PIPE_TEXTURE_1D;
75
76 case GL_TEXTURE_2D:
77 case GL_TEXTURE_RECTANGLE_NV:
78 return PIPE_TEXTURE_2D;
79
80 case GL_TEXTURE_3D:
81 return PIPE_TEXTURE_3D;
82
83 case GL_TEXTURE_CUBE_MAP_ARB:
84 return PIPE_TEXTURE_CUBE;
85
86 default:
87 assert(0);
88 return 0;
89 }
90 }
91
92
93 /**
94 * Return nominal bytes per texel for a compressed format, 0 for non-compressed
95 * format.
96 */
97 static GLuint
98 compressed_num_bytes(GLuint mesaFormat)
99 {
100 switch(mesaFormat) {
101 #if FEATURE_texture_fxt1
102 case MESA_FORMAT_RGB_FXT1:
103 case MESA_FORMAT_RGBA_FXT1:
104 #endif
105 #if FEATURE_texture_s3tc
106 case MESA_FORMAT_RGB_DXT1:
107 case MESA_FORMAT_RGBA_DXT1:
108 return 2;
109 case MESA_FORMAT_RGBA_DXT3:
110 case MESA_FORMAT_RGBA_DXT5:
111 return 4;
112 #endif
113 default:
114 return 0;
115 }
116 }
117
118
119 static GLboolean
120 is_compressed_mesa_format(const struct gl_texture_format *format)
121 {
122 switch (format->MesaFormat) {
123 case MESA_FORMAT_RGB_DXT1:
124 case MESA_FORMAT_RGBA_DXT1:
125 case MESA_FORMAT_RGBA_DXT3:
126 case MESA_FORMAT_RGBA_DXT5:
127 case MESA_FORMAT_SRGB_DXT1:
128 case MESA_FORMAT_SRGBA_DXT1:
129 case MESA_FORMAT_SRGBA_DXT3:
130 case MESA_FORMAT_SRGBA_DXT5:
131 return GL_TRUE;
132 default:
133 return GL_FALSE;
134 }
135 }
136
137
138 /** called via ctx->Driver.NewTextureImage() */
139 static struct gl_texture_image *
140 st_NewTextureImage(GLcontext * ctx)
141 {
142 DBG("%s\n", __FUNCTION__);
143 (void) ctx;
144 return (struct gl_texture_image *) ST_CALLOC_STRUCT(st_texture_image);
145 }
146
147
148 /** called via ctx->Driver.NewTextureObject() */
149 static struct gl_texture_object *
150 st_NewTextureObject(GLcontext * ctx, GLuint name, GLenum target)
151 {
152 struct st_texture_object *obj = ST_CALLOC_STRUCT(st_texture_object);
153
154 DBG("%s\n", __FUNCTION__);
155 _mesa_initialize_texture_object(&obj->base, name, target);
156
157 return &obj->base;
158 }
159
160 /** called via ctx->Driver.DeleteTextureImage() */
161 static void
162 st_DeleteTextureObject(GLcontext *ctx,
163 struct gl_texture_object *texObj)
164 {
165 struct st_texture_object *stObj = st_texture_object(texObj);
166 if (stObj->pt)
167 pipe_texture_reference(&stObj->pt, NULL);
168
169 _mesa_delete_texture_object(ctx, texObj);
170 }
171
172
173 /** called via ctx->Driver.FreeTexImageData() */
174 static void
175 st_FreeTextureImageData(GLcontext * ctx, struct gl_texture_image *texImage)
176 {
177 struct st_texture_image *stImage = st_texture_image(texImage);
178
179 DBG("%s\n", __FUNCTION__);
180
181 if (stImage->pt) {
182 pipe_texture_reference(&stImage->pt, NULL);
183 }
184
185 if (texImage->Data) {
186 _mesa_align_free(texImage->Data);
187 texImage->Data = NULL;
188 }
189 }
190
191
192 /**
193 * From linux kernel i386 header files, copes with odd sizes better
194 * than COPY_DWORDS would:
195 * XXX Put this in src/mesa/main/imports.h ???
196 */
197 #if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)
198 static INLINE void *
199 __memcpy(void *to, const void *from, size_t n)
200 {
201 int d0, d1, d2;
202 __asm__ __volatile__("rep ; movsl\n\t"
203 "testb $2,%b4\n\t"
204 "je 1f\n\t"
205 "movsw\n"
206 "1:\ttestb $1,%b4\n\t"
207 "je 2f\n\t"
208 "movsb\n" "2:":"=&c"(d0), "=&D"(d1), "=&S"(d2)
209 :"0"(n / 4), "q"(n), "1"((long) to), "2"((long) from)
210 :"memory");
211 return (to);
212 }
213 #else
214 #define __memcpy(a,b,c) memcpy(a,b,c)
215 #endif
216
217
218 /**
219 * The system memcpy (at least on ubuntu 5.10) has problems copying
220 * to agp (writecombined) memory from a source which isn't 64-byte
221 * aligned - there is a 4x performance falloff.
222 *
223 * The x86 __memcpy is immune to this but is slightly slower
224 * (10%-ish) than the system memcpy.
225 *
226 * The sse_memcpy seems to have a slight cliff at 64/32 bytes, but
227 * isn't much faster than x86_memcpy for agp copies.
228 *
229 * TODO: switch dynamically.
230 */
231 static void *
232 do_memcpy(void *dest, const void *src, size_t n)
233 {
234 if ((((unsigned long) src) & 63) || (((unsigned long) dest) & 63)) {
235 return __memcpy(dest, src, n);
236 }
237 else
238 return memcpy(dest, src, n);
239 }
240
241
242 /**
243 * Return default texture usage bitmask for the given texture format.
244 */
245 static GLuint
246 default_usage(enum pipe_format fmt)
247 {
248 GLuint usage = PIPE_TEXTURE_USAGE_SAMPLER;
249 if (pf_is_depth_stencil(fmt))
250 usage |= PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
251 else
252 usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET;
253 return usage;
254 }
255
256
257 /**
258 * Allocate a pipe_texture object for the given st_texture_object using
259 * the given st_texture_image to guess the mipmap size/levels.
260 *
261 * [comments...]
262 * Otherwise, store it in memory if (Border != 0) or (any dimension ==
263 * 1).
264 *
265 * Otherwise, if max_level >= level >= min_level, create texture with
266 * space for images from min_level down to max_level.
267 *
268 * Otherwise, create texture with space for images from (level 0)..(1x1).
269 * Consider pruning this texture at a validation if the saving is worth it.
270 */
271 static void
272 guess_and_alloc_texture(struct st_context *st,
273 struct st_texture_object *stObj,
274 const struct st_texture_image *stImage)
275 {
276 GLuint firstLevel;
277 GLuint lastLevel;
278 GLuint width = stImage->base.Width2; /* size w/out border */
279 GLuint height = stImage->base.Height2;
280 GLuint depth = stImage->base.Depth2;
281 GLuint i, usage;
282 enum pipe_format fmt;
283
284 DBG("%s\n", __FUNCTION__);
285
286 assert(!stObj->pt);
287
288 if (stObj->pt &&
289 (GLint) stImage->level > stObj->base.BaseLevel &&
290 (stImage->base.Width == 1 ||
291 (stObj->base.Target != GL_TEXTURE_1D &&
292 stImage->base.Height == 1) ||
293 (stObj->base.Target == GL_TEXTURE_3D &&
294 stImage->base.Depth == 1)))
295 return;
296
297 /* If this image disrespects BaseLevel, allocate from level zero.
298 * Usually BaseLevel == 0, so it's unlikely to happen.
299 */
300 if ((GLint) stImage->level < stObj->base.BaseLevel)
301 firstLevel = 0;
302 else
303 firstLevel = stObj->base.BaseLevel;
304
305
306 /* Figure out image dimensions at start level.
307 */
308 for (i = stImage->level; i > firstLevel; i--) {
309 if (width != 1)
310 width <<= 1;
311 if (height != 1)
312 height <<= 1;
313 if (depth != 1)
314 depth <<= 1;
315 }
316
317 if (width == 0 || height == 0 || depth == 0) {
318 /* no texture needed */
319 return;
320 }
321
322 /* Guess a reasonable value for lastLevel. This is probably going
323 * to be wrong fairly often and might mean that we have to look at
324 * resizable buffers, or require that buffers implement lazy
325 * pagetable arrangements.
326 */
327 if ((stObj->base.MinFilter == GL_NEAREST ||
328 stObj->base.MinFilter == GL_LINEAR ||
329 stImage->base._BaseFormat == GL_DEPTH_COMPONENT ||
330 stImage->base._BaseFormat == GL_DEPTH_STENCIL_EXT) &&
331 stImage->level == firstLevel) {
332 lastLevel = firstLevel;
333 }
334 else {
335 GLuint l2width = util_logbase2(width);
336 GLuint l2height = util_logbase2(height);
337 GLuint l2depth = util_logbase2(depth);
338 lastLevel = firstLevel + MAX2(MAX2(l2width, l2height), l2depth);
339 }
340
341 fmt = st_mesa_format_to_pipe_format(stImage->base.TexFormat->MesaFormat);
342
343 usage = default_usage(fmt);
344
345 stObj->pt = st_texture_create(st,
346 gl_target_to_pipe(stObj->base.Target),
347 fmt,
348 lastLevel,
349 width,
350 height,
351 depth,
352 usage);
353
354 DBG("%s - success\n", __FUNCTION__);
355 }
356
357
358 /**
359 * Adjust pixel unpack params and image dimensions to strip off the
360 * texture border.
361 * Gallium doesn't support texture borders. They've seldem been used
362 * and seldom been implemented correctly anyway.
363 * \param unpackNew returns the new pixel unpack parameters
364 */
365 static void
366 strip_texture_border(GLint border,
367 GLint *width, GLint *height, GLint *depth,
368 const struct gl_pixelstore_attrib *unpack,
369 struct gl_pixelstore_attrib *unpackNew)
370 {
371 assert(border > 0); /* sanity check */
372
373 *unpackNew = *unpack;
374
375 if (unpackNew->RowLength == 0)
376 unpackNew->RowLength = *width;
377
378 if (depth && unpackNew->ImageHeight == 0)
379 unpackNew->ImageHeight = *height;
380
381 unpackNew->SkipPixels += border;
382 if (height)
383 unpackNew->SkipRows += border;
384 if (depth)
385 unpackNew->SkipImages += border;
386
387 assert(*width >= 3);
388 *width = *width - 2 * border;
389 if (height && *height >= 3)
390 *height = *height - 2 * border;
391 if (depth && *depth >= 3)
392 *depth = *depth - 2 * border;
393 }
394
395
396 /**
397 * Try to do texture compression via rendering. If the Gallium driver
398 * can render into a compressed surface this will allow us to do texture
399 * compression.
400 * \return GL_TRUE for success, GL_FALSE for failure
401 */
402 static GLboolean
403 compress_with_blit(GLcontext * ctx,
404 GLenum target, GLint level,
405 GLint xoffset, GLint yoffset, GLint zoffset,
406 GLint width, GLint height, GLint depth,
407 GLenum format, GLenum type, const void *pixels,
408 const struct gl_pixelstore_attrib *unpack,
409 struct gl_texture_image *texImage)
410 {
411 const GLuint dstImageOffsets[1] = {0};
412 struct st_texture_image *stImage = st_texture_image(texImage);
413 struct pipe_screen *screen = ctx->st->pipe->screen;
414 const struct gl_texture_format *mesa_format;
415 struct pipe_texture templ;
416 struct pipe_texture *src_tex;
417 struct pipe_surface *dst_surface;
418 struct pipe_transfer *tex_xfer;
419 void *map;
420
421
422 if (!stImage->pt) {
423 /* XXX: Can this happen? Should we assert? */
424 return GL_FALSE;
425 }
426
427 /* get destination surface (in the compressed texture) */
428 dst_surface = screen->get_tex_surface(screen, stImage->pt,
429 stImage->face, stImage->level, 0,
430 PIPE_BUFFER_USAGE_GPU_WRITE);
431 if (!dst_surface) {
432 /* can't render into this format (or other problem) */
433 return GL_FALSE;
434 }
435
436 /* Choose format for the temporary RGBA texture image.
437 */
438 mesa_format = st_ChooseTextureFormat(ctx, GL_RGBA, format, type);
439 assert(mesa_format);
440 if (!mesa_format)
441 return GL_FALSE;
442
443 /* Create the temporary source texture
444 */
445 memset(&templ, 0, sizeof(templ));
446 templ.target = PIPE_TEXTURE_2D;
447 templ.format = st_mesa_format_to_pipe_format(mesa_format->MesaFormat);
448 pf_get_block(templ.format, &templ.block);
449 templ.width[0] = width;
450 templ.height[0] = height;
451 templ.depth[0] = 1;
452 templ.last_level = 0;
453 templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER;
454 src_tex = screen->texture_create(screen, &templ);
455
456 if (!src_tex)
457 return GL_FALSE;
458
459 /* Put user's tex data into the temporary texture
460 */
461 tex_xfer = st_cond_flush_get_tex_transfer(st_context(ctx), src_tex,
462 0, 0, 0, /* face, level are zero */
463 PIPE_TRANSFER_WRITE,
464 0, 0, width, height); /* x, y, w, h */
465 map = screen->transfer_map(screen, tex_xfer);
466
467 mesa_format->StoreImage(ctx, 2, GL_RGBA, mesa_format,
468 map, /* dest ptr */
469 0, 0, 0, /* dest x/y/z offset */
470 tex_xfer->stride, /* dest row stride (bytes) */
471 dstImageOffsets, /* image offsets (for 3D only) */
472 width, height, 1, /* size */
473 format, type, /* source format/type */
474 pixels, /* source data */
475 unpack); /* source data packing */
476
477 screen->transfer_unmap(screen, tex_xfer);
478 screen->tex_transfer_destroy(tex_xfer);
479
480 /* copy / compress image */
481 util_blit_pixels_tex(ctx->st->blit,
482 src_tex, /* pipe_texture (src) */
483 0, 0, /* src x0, y0 */
484 width, height, /* src x1, y1 */
485 dst_surface, /* pipe_surface (dst) */
486 xoffset, yoffset, /* dst x0, y0 */
487 xoffset + width, /* dst x1 */
488 yoffset + height, /* dst y1 */
489 0.0, /* z */
490 PIPE_TEX_MIPFILTER_NEAREST);
491
492 pipe_surface_reference(&dst_surface, NULL);
493 pipe_texture_reference(&src_tex, NULL);
494
495 return GL_TRUE;
496 }
497
498
499 /**
500 * Do glTexImage1/2/3D().
501 */
502 static void
503 st_TexImage(GLcontext * ctx,
504 GLint dims,
505 GLenum target, GLint level,
506 GLint internalFormat,
507 GLint width, GLint height, GLint depth,
508 GLint border,
509 GLenum format, GLenum type, const void *pixels,
510 const struct gl_pixelstore_attrib *unpack,
511 struct gl_texture_object *texObj,
512 struct gl_texture_image *texImage,
513 GLsizei imageSize, GLboolean compressed_src)
514 {
515 struct pipe_screen *screen = ctx->st->pipe->screen;
516 struct st_texture_object *stObj = st_texture_object(texObj);
517 struct st_texture_image *stImage = st_texture_image(texImage);
518 GLint postConvWidth, postConvHeight;
519 GLint texelBytes, sizeInBytes;
520 GLuint dstRowStride = 0;
521 struct gl_pixelstore_attrib unpackNB;
522 enum pipe_transfer_usage transfer_usage = 0;
523
524 DBG("%s target %s level %d %dx%dx%d border %d\n", __FUNCTION__,
525 _mesa_lookup_enum_by_nr(target), level, width, height, depth, border);
526
527 /* switch to "normal" */
528 if (stObj->surface_based) {
529 _mesa_clear_texture_object(ctx, texObj);
530 stObj->surface_based = GL_FALSE;
531 }
532
533 /* gallium does not support texture borders, strip it off */
534 if (border) {
535 strip_texture_border(border, &width, &height, &depth, unpack, &unpackNB);
536 unpack = &unpackNB;
537 texImage->Width = width;
538 texImage->Height = height;
539 texImage->Depth = depth;
540 texImage->Border = 0;
541 border = 0;
542 }
543
544 postConvWidth = width;
545 postConvHeight = height;
546
547 stImage->face = _mesa_tex_target_to_face(target);
548 stImage->level = level;
549
550 #if FEATURE_convolve
551 if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) {
552 _mesa_adjust_image_for_convolution(ctx, dims, &postConvWidth,
553 &postConvHeight);
554 }
555 #endif
556
557 /* choose the texture format */
558 texImage->TexFormat = st_ChooseTextureFormat(ctx, internalFormat,
559 format, type);
560
561 _mesa_set_fetch_functions(texImage, dims);
562
563 if (texImage->TexFormat->TexelBytes == 0) {
564 /* must be a compressed format */
565 texelBytes = 0;
566 texImage->IsCompressed = GL_TRUE;
567 texImage->CompressedSize =
568 ctx->Driver.CompressedTextureSize(ctx, texImage->Width,
569 texImage->Height, texImage->Depth,
570 texImage->TexFormat->MesaFormat);
571 }
572 else {
573 texelBytes = texImage->TexFormat->TexelBytes;
574
575 /* Minimum pitch of 32 bytes */
576 if (postConvWidth * texelBytes < 32) {
577 postConvWidth = 32 / texelBytes;
578 texImage->RowStride = postConvWidth;
579 }
580
581 /* we'll set RowStride elsewhere when the texture is a "mapped" state */
582 /*assert(texImage->RowStride == postConvWidth);*/
583 }
584
585 /* Release the reference to a potentially orphaned buffer.
586 * Release any old malloced memory.
587 */
588 if (stImage->pt) {
589 pipe_texture_reference(&stImage->pt, NULL);
590 assert(!texImage->Data);
591 }
592 else if (texImage->Data) {
593 _mesa_align_free(texImage->Data);
594 }
595
596 if (width == 0 || height == 0 || depth == 0) {
597 /* stop after freeing old image */
598 return;
599 }
600
601 /* If this is the only mipmap level in the texture, could call
602 * bmBufferData with NULL data to free the old block and avoid
603 * waiting on any outstanding fences.
604 */
605 if (stObj->pt) {
606 if (stObj->teximage_realloc ||
607 level > (GLint) stObj->pt->last_level ||
608 (stObj->pt->last_level == level &&
609 stObj->pt->target != PIPE_TEXTURE_CUBE &&
610 !st_texture_match_image(stObj->pt, &stImage->base,
611 stImage->face, stImage->level))) {
612 DBG("release it\n");
613 pipe_texture_reference(&stObj->pt, NULL);
614 assert(!stObj->pt);
615 stObj->teximage_realloc = FALSE;
616 }
617 }
618
619 if (!stObj->pt) {
620 guess_and_alloc_texture(ctx->st, stObj, stImage);
621 if (!stObj->pt) {
622 /* Probably out of memory.
623 * Try flushing any pending rendering, then retry.
624 */
625 st_finish(ctx->st);
626 guess_and_alloc_texture(ctx->st, stObj, stImage);
627 if (!stObj->pt) {
628 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
629 return;
630 }
631 }
632 }
633
634 assert(!stImage->pt);
635
636 if (stObj->pt &&
637 st_texture_match_image(stObj->pt, &stImage->base,
638 stImage->face, stImage->level)) {
639
640 pipe_texture_reference(&stImage->pt, stObj->pt);
641 assert(stImage->pt);
642 }
643
644 if (!stImage->pt)
645 DBG("XXX: Image did not fit into texture - storing in local memory!\n");
646
647 /* st_CopyTexImage calls this function with pixels == NULL, with
648 * the expectation that the texture will be set up but nothing
649 * more will be done. This is where those calls return:
650 */
651 if (compressed_src) {
652 pixels = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, pixels,
653 unpack,
654 "glCompressedTexImage");
655 }
656 else {
657 pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, 1,
658 format, type,
659 pixels, unpack, "glTexImage");
660 }
661 if (!pixels)
662 return;
663
664 /* See if we can do texture compression with a blit/render.
665 */
666 if (!compressed_src &&
667 !ctx->Mesa_DXTn &&
668 is_compressed_mesa_format(texImage->TexFormat) &&
669 screen->is_format_supported(screen,
670 stImage->pt->format,
671 stImage->pt->target,
672 PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
673 if (compress_with_blit(ctx, target, level, 0, 0, 0, width, height, depth,
674 format, type, pixels, unpack, texImage)) {
675 goto done;
676 }
677 }
678
679 if (stImage->pt) {
680 if (format == GL_DEPTH_COMPONENT &&
681 pf_is_depth_and_stencil(stImage->pt->format))
682 transfer_usage = PIPE_TRANSFER_READ_WRITE;
683 else
684 transfer_usage = PIPE_TRANSFER_WRITE;
685
686 texImage->Data = st_texture_image_map(ctx->st, stImage, 0,
687 transfer_usage, 0, 0,
688 stImage->base.Width,
689 stImage->base.Height);
690 if(stImage->transfer)
691 dstRowStride = stImage->transfer->stride;
692 }
693 else {
694 /* Allocate regular memory and store the image there temporarily. */
695 if (texImage->IsCompressed) {
696 sizeInBytes = texImage->CompressedSize;
697 dstRowStride =
698 _mesa_compressed_row_stride(texImage->TexFormat->MesaFormat, width);
699 assert(dims != 3);
700 }
701 else {
702 dstRowStride = postConvWidth * texelBytes;
703 sizeInBytes = depth * dstRowStride * postConvHeight;
704 }
705
706 texImage->Data = _mesa_align_malloc(sizeInBytes, 16);
707 }
708
709 if (!texImage->Data) {
710 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
711 return;
712 }
713
714 DBG("Upload image %dx%dx%d row_len %x pitch %x\n",
715 width, height, depth, width * texelBytes, dstRowStride);
716
717 /* Copy data. Would like to know when it's ok for us to eg. use
718 * the blitter to copy. Or, use the hardware to do the format
719 * conversion and copy:
720 */
721 if (compressed_src) {
722 memcpy(texImage->Data, pixels, imageSize);
723 }
724 else {
725 const GLuint srcImageStride =
726 _mesa_image_image_stride(unpack, width, height, format, type);
727 GLint i;
728 const GLubyte *src = (const GLubyte *) pixels;
729
730 for (i = 0; i < depth; i++) {
731 if (!texImage->TexFormat->StoreImage(ctx, dims,
732 texImage->_BaseFormat,
733 texImage->TexFormat,
734 texImage->Data,
735 0, 0, 0, /* dstX/Y/Zoffset */
736 dstRowStride,
737 texImage->ImageOffsets,
738 width, height, 1,
739 format, type, src, unpack)) {
740 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
741 }
742
743 if (stImage->pt && i + 1 < depth) {
744 /* unmap this slice */
745 st_texture_image_unmap(ctx->st, stImage);
746 /* map next slice of 3D texture */
747 texImage->Data = st_texture_image_map(ctx->st, stImage, i + 1,
748 transfer_usage, 0, 0,
749 stImage->base.Width,
750 stImage->base.Height);
751 src += srcImageStride;
752 }
753 }
754 }
755
756 _mesa_unmap_teximage_pbo(ctx, unpack);
757
758 done:
759 if (stImage->pt && texImage->Data) {
760 st_texture_image_unmap(ctx->st, stImage);
761 texImage->Data = NULL;
762 }
763
764 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
765 ctx->Driver.GenerateMipmap(ctx, target, texObj);
766 }
767 }
768
769
770 static void
771 st_TexImage3D(GLcontext * ctx,
772 GLenum target, GLint level,
773 GLint internalFormat,
774 GLint width, GLint height, GLint depth,
775 GLint border,
776 GLenum format, GLenum type, const void *pixels,
777 const struct gl_pixelstore_attrib *unpack,
778 struct gl_texture_object *texObj,
779 struct gl_texture_image *texImage)
780 {
781 st_TexImage(ctx, 3, target, level, internalFormat, width, height, depth,
782 border, format, type, pixels, unpack, texObj, texImage,
783 0, GL_FALSE);
784 }
785
786
787 static void
788 st_TexImage2D(GLcontext * ctx,
789 GLenum target, GLint level,
790 GLint internalFormat,
791 GLint width, GLint height, GLint border,
792 GLenum format, GLenum type, const void *pixels,
793 const struct gl_pixelstore_attrib *unpack,
794 struct gl_texture_object *texObj,
795 struct gl_texture_image *texImage)
796 {
797 st_TexImage(ctx, 2, target, level, internalFormat, width, height, 1, border,
798 format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE);
799 }
800
801
802 static void
803 st_TexImage1D(GLcontext * ctx,
804 GLenum target, GLint level,
805 GLint internalFormat,
806 GLint width, GLint border,
807 GLenum format, GLenum type, const void *pixels,
808 const struct gl_pixelstore_attrib *unpack,
809 struct gl_texture_object *texObj,
810 struct gl_texture_image *texImage)
811 {
812 st_TexImage(ctx, 1, target, level, internalFormat, width, 1, 1, border,
813 format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE);
814 }
815
816
817 static void
818 st_CompressedTexImage2D(GLcontext *ctx, GLenum target, GLint level,
819 GLint internalFormat,
820 GLint width, GLint height, GLint border,
821 GLsizei imageSize, const GLvoid *data,
822 struct gl_texture_object *texObj,
823 struct gl_texture_image *texImage)
824 {
825 st_TexImage(ctx, 2, target, level, internalFormat, width, height, 1, border,
826 0, 0, data, &ctx->Unpack, texObj, texImage, imageSize, GL_TRUE);
827 }
828
829
830
831 /**
832 * glGetTexImage() helper: decompress a compressed texture by rendering
833 * a textured quad. Store the results in the user's buffer.
834 */
835 static void
836 decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
837 GLenum format, GLenum type, GLvoid *pixels,
838 struct gl_texture_object *texObj,
839 struct gl_texture_image *texImage)
840 {
841 struct pipe_screen *screen = ctx->st->pipe->screen;
842 struct st_texture_image *stImage = st_texture_image(texImage);
843 const GLuint width = texImage->Width;
844 const GLuint height = texImage->Height;
845 struct pipe_surface *dst_surface;
846 struct pipe_texture *dst_texture;
847 struct pipe_transfer *tex_xfer;
848
849 /* create temp / dest surface */
850 if (!util_create_rgba_surface(screen, width, height,
851 &dst_texture, &dst_surface)) {
852 _mesa_problem(ctx, "util_create_rgba_surface() failed "
853 "in decompress_with_blit()");
854 return;
855 }
856
857 /* blit/render/decompress */
858 util_blit_pixels_tex(ctx->st->blit,
859 stImage->pt, /* pipe_texture (src) */
860 0, 0, /* src x0, y0 */
861 width, height, /* src x1, y1 */
862 dst_surface, /* pipe_surface (dst) */
863 0, 0, /* dst x0, y0 */
864 width, height, /* dst x1, y1 */
865 0.0, /* z */
866 PIPE_TEX_MIPFILTER_NEAREST);
867
868 /* map the dst_surface so we can read from it */
869 tex_xfer = st_cond_flush_get_tex_transfer(st_context(ctx),
870 dst_texture, 0, 0, 0,
871 PIPE_TRANSFER_READ,
872 0, 0, width, height);
873
874 pixels = _mesa_map_pbo_dest(ctx, &ctx->Pack, pixels);
875
876 /* copy/pack data into user buffer */
877 if (st_equal_formats(stImage->pt->format, format, type)) {
878 /* memcpy */
879 const uint bytesPerRow = width * pf_get_size(stImage->pt->format);
880 ubyte *map = screen->transfer_map(screen, tex_xfer);
881 GLuint row;
882 for (row = 0; row < height; row++) {
883 GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
884 height, format, type, row, 0);
885 memcpy(dest, map, bytesPerRow);
886 map += tex_xfer->stride;
887 }
888 screen->transfer_unmap(screen, tex_xfer);
889 }
890 else {
891 /* format translation via floats */
892 GLuint row;
893 for (row = 0; row < height; row++) {
894 const GLbitfield transferOps = 0x0; /* bypassed for glGetTexImage() */
895 GLfloat rgba[4 * MAX_WIDTH];
896 GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
897 height, format, type, row, 0);
898
899 /* get float[4] rgba row from surface */
900 pipe_get_tile_rgba(tex_xfer, 0, row, width, 1, rgba);
901
902 _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, format,
903 type, dest, &ctx->Pack, transferOps);
904 }
905 }
906
907 _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
908
909 /* destroy the temp / dest surface */
910 util_destroy_rgba_surface(dst_texture, dst_surface);
911 }
912
913
914
915 /**
916 * Need to map texture image into memory before copying image data,
917 * then unmap it.
918 */
919 static void
920 st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
921 GLenum format, GLenum type, GLvoid * pixels,
922 struct gl_texture_object *texObj,
923 struct gl_texture_image *texImage, GLboolean compressed_dst)
924 {
925 struct st_texture_image *stImage = st_texture_image(texImage);
926 const GLuint dstImageStride =
927 _mesa_image_image_stride(&ctx->Pack, texImage->Width, texImage->Height,
928 format, type);
929 GLuint depth, i;
930 GLubyte *dest;
931
932 if (stImage->pt &&
933 pf_is_compressed(stImage->pt->format) &&
934 !compressed_dst) {
935 /* Need to decompress the texture.
936 * We'll do this by rendering a textured quad.
937 * Note that we only expect RGBA formats (no Z/depth formats).
938 */
939 decompress_with_blit(ctx, target, level, format, type, pixels,
940 texObj, texImage);
941 return;
942 }
943
944 /* Map */
945 if (stImage->pt) {
946 /* Image is stored in hardware format in a buffer managed by the
947 * kernel. Need to explicitly map and unmap it.
948 */
949 unsigned face = _mesa_tex_target_to_face(target);
950
951 st_teximage_flush_before_map(ctx->st, stImage->pt, face, level,
952 PIPE_TRANSFER_READ);
953
954 texImage->Data = st_texture_image_map(ctx->st, stImage, 0,
955 PIPE_TRANSFER_READ, 0, 0,
956 stImage->base.Width,
957 stImage->base.Height);
958 texImage->RowStride = stImage->transfer->stride / stImage->pt->block.size;
959 }
960 else {
961 /* Otherwise, the image should actually be stored in
962 * texImage->Data. This is pretty confusing for
963 * everybody, I'd much prefer to separate the two functions of
964 * texImage->Data - storage for texture images in main memory
965 * and access (ie mappings) of images. In other words, we'd
966 * create a new texImage->Map field and leave Data simply for
967 * storage.
968 */
969 assert(texImage->Data);
970 }
971
972 depth = texImage->Depth;
973 texImage->Depth = 1;
974
975 dest = (GLubyte *) pixels;
976
977 for (i = 0; i < depth; i++) {
978 if (compressed_dst) {
979 _mesa_get_compressed_teximage(ctx, target, level, dest,
980 texObj, texImage);
981 }
982 else {
983 _mesa_get_teximage(ctx, target, level, format, type, dest,
984 texObj, texImage);
985 }
986
987 if (stImage->pt && i + 1 < depth) {
988 /* unmap this slice */
989 st_texture_image_unmap(ctx->st, stImage);
990 /* map next slice of 3D texture */
991 texImage->Data = st_texture_image_map(ctx->st, stImage, i + 1,
992 PIPE_TRANSFER_READ, 0, 0,
993 stImage->base.Width,
994 stImage->base.Height);
995 dest += dstImageStride;
996 }
997 }
998
999 texImage->Depth = depth;
1000
1001 /* Unmap */
1002 if (stImage->pt) {
1003 st_texture_image_unmap(ctx->st, stImage);
1004 texImage->Data = NULL;
1005 }
1006 }
1007
1008
1009 static void
1010 st_GetTexImage(GLcontext * ctx, GLenum target, GLint level,
1011 GLenum format, GLenum type, GLvoid * pixels,
1012 struct gl_texture_object *texObj,
1013 struct gl_texture_image *texImage)
1014 {
1015 st_get_tex_image(ctx, target, level, format, type, pixels, texObj, texImage,
1016 GL_FALSE);
1017 }
1018
1019
1020 static void
1021 st_GetCompressedTexImage(GLcontext *ctx, GLenum target, GLint level,
1022 GLvoid *pixels,
1023 struct gl_texture_object *texObj,
1024 struct gl_texture_image *texImage)
1025 {
1026 st_get_tex_image(ctx, target, level, 0, 0, pixels, texObj, texImage,
1027 GL_TRUE);
1028 }
1029
1030
1031
1032 static void
1033 st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level,
1034 GLint xoffset, GLint yoffset, GLint zoffset,
1035 GLint width, GLint height, GLint depth,
1036 GLenum format, GLenum type, const void *pixels,
1037 const struct gl_pixelstore_attrib *packing,
1038 struct gl_texture_object *texObj,
1039 struct gl_texture_image *texImage)
1040 {
1041 struct pipe_screen *screen = ctx->st->pipe->screen;
1042 struct st_texture_image *stImage = st_texture_image(texImage);
1043 GLuint dstRowStride;
1044 const GLuint srcImageStride =
1045 _mesa_image_image_stride(packing, width, height, format, type);
1046 GLint i;
1047 const GLubyte *src;
1048 /* init to silence warning only: */
1049 enum pipe_transfer_usage transfer_usage = PIPE_TRANSFER_WRITE;
1050
1051 DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__,
1052 _mesa_lookup_enum_by_nr(target),
1053 level, xoffset, yoffset, width, height);
1054
1055 pixels =
1056 _mesa_validate_pbo_teximage(ctx, dims, width, height, depth, format,
1057 type, pixels, packing, "glTexSubImage2D");
1058 if (!pixels)
1059 return;
1060
1061 /* See if we can do texture compression with a blit/render.
1062 */
1063 if (!ctx->Mesa_DXTn &&
1064 is_compressed_mesa_format(texImage->TexFormat) &&
1065 screen->is_format_supported(screen,
1066 stImage->pt->format,
1067 stImage->pt->target,
1068 PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
1069 if (compress_with_blit(ctx, target, level,
1070 xoffset, yoffset, zoffset,
1071 width, height, depth,
1072 format, type, pixels, packing, texImage)) {
1073 goto done;
1074 }
1075 }
1076
1077 /* Map buffer if necessary. Need to lock to prevent other contexts
1078 * from uploading the buffer under us.
1079 */
1080 if (stImage->pt) {
1081 unsigned face = _mesa_tex_target_to_face(target);
1082
1083 if (format == GL_DEPTH_COMPONENT &&
1084 pf_is_depth_and_stencil(stImage->pt->format))
1085 transfer_usage = PIPE_TRANSFER_READ_WRITE;
1086 else
1087 transfer_usage = PIPE_TRANSFER_WRITE;
1088
1089 st_teximage_flush_before_map(ctx->st, stImage->pt, face, level,
1090 transfer_usage);
1091 texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset,
1092 transfer_usage,
1093 xoffset, yoffset,
1094 width, height);
1095 }
1096
1097 if (!texImage->Data) {
1098 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
1099 return;
1100 }
1101
1102 src = (const GLubyte *) pixels;
1103 dstRowStride = stImage->transfer->stride;
1104
1105 for (i = 0; i < depth; i++) {
1106 if (!texImage->TexFormat->StoreImage(ctx, dims, texImage->_BaseFormat,
1107 texImage->TexFormat,
1108 texImage->Data,
1109 0, 0, 0,
1110 dstRowStride,
1111 texImage->ImageOffsets,
1112 width, height, 1,
1113 format, type, src, packing)) {
1114 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
1115 }
1116
1117 if (stImage->pt && i + 1 < depth) {
1118 /* unmap this slice */
1119 st_texture_image_unmap(ctx->st, stImage);
1120 /* map next slice of 3D texture */
1121 texImage->Data = st_texture_image_map(ctx->st, stImage,
1122 zoffset + i + 1,
1123 transfer_usage,
1124 xoffset, yoffset,
1125 width, height);
1126 src += srcImageStride;
1127 }
1128 }
1129
1130 _mesa_unmap_teximage_pbo(ctx, packing);
1131
1132 done:
1133 if (stImage->pt) {
1134 st_texture_image_unmap(ctx->st, stImage);
1135 texImage->Data = NULL;
1136 }
1137
1138 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
1139 ctx->Driver.GenerateMipmap(ctx, target, texObj);
1140 }
1141 }
1142
1143
1144
1145 static void
1146 st_TexSubImage3D(GLcontext *ctx, GLenum target, GLint level,
1147 GLint xoffset, GLint yoffset, GLint zoffset,
1148 GLsizei width, GLsizei height, GLsizei depth,
1149 GLenum format, GLenum type, const GLvoid *pixels,
1150 const struct gl_pixelstore_attrib *packing,
1151 struct gl_texture_object *texObj,
1152 struct gl_texture_image *texImage)
1153 {
1154 st_TexSubimage(ctx, 3, target, level, xoffset, yoffset, zoffset,
1155 width, height, depth, format, type,
1156 pixels, packing, texObj, texImage);
1157 }
1158
1159
1160 static void
1161 st_TexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
1162 GLint xoffset, GLint yoffset,
1163 GLsizei width, GLsizei height,
1164 GLenum format, GLenum type, const GLvoid * pixels,
1165 const struct gl_pixelstore_attrib *packing,
1166 struct gl_texture_object *texObj,
1167 struct gl_texture_image *texImage)
1168 {
1169 st_TexSubimage(ctx, 2, target, level, xoffset, yoffset, 0,
1170 width, height, 1, format, type,
1171 pixels, packing, texObj, texImage);
1172 }
1173
1174
1175 static void
1176 st_TexSubImage1D(GLcontext *ctx, GLenum target, GLint level,
1177 GLint xoffset, GLsizei width, GLenum format, GLenum type,
1178 const GLvoid * pixels,
1179 const struct gl_pixelstore_attrib *packing,
1180 struct gl_texture_object *texObj,
1181 struct gl_texture_image *texImage)
1182 {
1183 st_TexSubimage(ctx, 1, target, level, xoffset, 0, 0, width, 1, 1,
1184 format, type, pixels, packing, texObj, texImage);
1185 }
1186
1187
1188 static void
1189 st_CompressedTexSubImage1D(GLcontext *ctx, GLenum target, GLint level,
1190 GLint xoffset, GLsizei width,
1191 GLenum format,
1192 GLsizei imageSize, const GLvoid *data,
1193 struct gl_texture_object *texObj,
1194 struct gl_texture_image *texImage)
1195 {
1196 assert(0);
1197 }
1198
1199
1200 static void
1201 st_CompressedTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
1202 GLint xoffset, GLint yoffset,
1203 GLsizei width, GLint height,
1204 GLenum format,
1205 GLsizei imageSize, const GLvoid *data,
1206 struct gl_texture_object *texObj,
1207 struct gl_texture_image *texImage)
1208 {
1209 struct st_texture_image *stImage = st_texture_image(texImage);
1210 struct pipe_format_block block;
1211 int srcBlockStride;
1212 int dstBlockStride;
1213 int y;
1214
1215 if (stImage->pt) {
1216 unsigned face = _mesa_tex_target_to_face(target);
1217
1218 st_teximage_flush_before_map(ctx->st, stImage->pt, face, level,
1219 PIPE_TRANSFER_WRITE);
1220 texImage->Data = st_texture_image_map(ctx->st, stImage, 0,
1221 PIPE_TRANSFER_WRITE,
1222 xoffset, yoffset,
1223 width, height);
1224
1225 block = stImage->pt->block;
1226 srcBlockStride = pf_get_stride(&block, width);
1227 dstBlockStride = stImage->transfer->stride;
1228 } else {
1229 assert(stImage->pt);
1230 /* TODO find good values for block and strides */
1231 /* TODO also adjust texImage->data for yoffset/xoffset */
1232 return;
1233 }
1234
1235 if (!texImage->Data) {
1236 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage");
1237 return;
1238 }
1239
1240 assert(xoffset % block.width == 0);
1241 assert(yoffset % block.height == 0);
1242 assert(width % block.width == 0);
1243 assert(height % block.height == 0);
1244
1245 for (y = 0; y < height; y += block.height) {
1246 /* don't need to adjust for xoffset and yoffset as st_texture_image_map does that */
1247 const char *src = (const char*)data + srcBlockStride * pf_get_nblocksy(&block, y);
1248 char *dst = (char*)texImage->Data + dstBlockStride * pf_get_nblocksy(&block, y);
1249 memcpy(dst, src, pf_get_stride(&block, width));
1250 }
1251
1252 if (stImage->pt) {
1253 st_texture_image_unmap(ctx->st, stImage);
1254 texImage->Data = NULL;
1255 }
1256 }
1257
1258
1259 static void
1260 st_CompressedTexSubImage3D(GLcontext *ctx, GLenum target, GLint level,
1261 GLint xoffset, GLint yoffset, GLint zoffset,
1262 GLsizei width, GLint height, GLint depth,
1263 GLenum format,
1264 GLsizei imageSize, const GLvoid *data,
1265 struct gl_texture_object *texObj,
1266 struct gl_texture_image *texImage)
1267 {
1268 assert(0);
1269 }
1270
1271
1272
1273 /**
1274 * Do a CopyTexSubImage operation using a read transfer from the source,
1275 * a write transfer to the destination and get_tile()/put_tile() to access
1276 * the pixels/texels.
1277 *
1278 * Note: srcY=0=TOP of renderbuffer
1279 */
1280 static void
1281 fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
1282 struct st_renderbuffer *strb,
1283 struct st_texture_image *stImage,
1284 GLenum baseFormat,
1285 GLint destX, GLint destY, GLint destZ,
1286 GLint srcX, GLint srcY,
1287 GLsizei width, GLsizei height)
1288 {
1289 struct pipe_context *pipe = ctx->st->pipe;
1290 struct pipe_screen *screen = pipe->screen;
1291 struct pipe_transfer *src_trans;
1292 GLvoid *texDest;
1293 enum pipe_transfer_usage transfer_usage;
1294
1295 assert(width <= MAX_WIDTH);
1296
1297 if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
1298 srcY = strb->Base.Height - srcY - height;
1299 }
1300
1301 src_trans = st_cond_flush_get_tex_transfer( st_context(ctx),
1302 strb->texture,
1303 0, 0, 0,
1304 PIPE_TRANSFER_READ,
1305 srcX, srcY,
1306 width, height);
1307
1308 if (baseFormat == GL_DEPTH_COMPONENT &&
1309 pf_is_depth_and_stencil(stImage->pt->format))
1310 transfer_usage = PIPE_TRANSFER_READ_WRITE;
1311 else
1312 transfer_usage = PIPE_TRANSFER_WRITE;
1313
1314 st_teximage_flush_before_map(ctx->st, stImage->pt, 0, 0,
1315 transfer_usage);
1316
1317 texDest = st_texture_image_map(ctx->st, stImage, 0, transfer_usage,
1318 destX, destY, width, height);
1319
1320 if (baseFormat == GL_DEPTH_COMPONENT ||
1321 baseFormat == GL_DEPTH24_STENCIL8) {
1322 const GLboolean scaleOrBias = (ctx->Pixel.DepthScale != 1.0F ||
1323 ctx->Pixel.DepthBias != 0.0F);
1324 GLint row, yStep;
1325
1326 /* determine bottom-to-top vs. top-to-bottom order for src buffer */
1327 if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
1328 srcY = height - 1;
1329 yStep = -1;
1330 }
1331 else {
1332 srcY = 0;
1333 yStep = 1;
1334 }
1335
1336 /* To avoid a large temp memory allocation, do copy row by row */
1337 for (row = 0; row < height; row++, srcY += yStep) {
1338 uint data[MAX_WIDTH];
1339 pipe_get_tile_z(src_trans, 0, srcY, width, 1, data);
1340 if (scaleOrBias) {
1341 _mesa_scale_and_bias_depth_uint(ctx, width, data);
1342 }
1343 pipe_put_tile_z(stImage->transfer, 0, row, width, 1, data);
1344 }
1345 }
1346 else {
1347 /* RGBA format */
1348 GLfloat *tempSrc =
1349 (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat));
1350
1351 if (tempSrc && texDest) {
1352 const GLint dims = 2;
1353 const GLint dstRowStride = stImage->transfer->stride;
1354 struct gl_texture_image *texImage = &stImage->base;
1355 struct gl_pixelstore_attrib unpack = ctx->DefaultPacking;
1356
1357 if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
1358 unpack.Invert = GL_TRUE;
1359 }
1360
1361 /* get float/RGBA image from framebuffer */
1362 /* XXX this usually involves a lot of int/float conversion.
1363 * try to avoid that someday.
1364 */
1365 pipe_get_tile_rgba(src_trans, 0, 0, width, height, tempSrc);
1366
1367 /* Store into texture memory.
1368 * Note that this does some special things such as pixel transfer
1369 * ops and format conversion. In particular, if the dest tex format
1370 * is actually RGBA but the user created the texture as GL_RGB we
1371 * need to fill-in/override the alpha channel with 1.0.
1372 */
1373 texImage->TexFormat->StoreImage(ctx, dims,
1374 texImage->_BaseFormat,
1375 texImage->TexFormat,
1376 texDest,
1377 0, 0, 0,
1378 dstRowStride,
1379 texImage->ImageOffsets,
1380 width, height, 1,
1381 GL_RGBA, GL_FLOAT, tempSrc, /* src */
1382 &unpack);
1383 }
1384 else {
1385 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
1386 }
1387
1388 if (tempSrc)
1389 _mesa_free(tempSrc);
1390 }
1391
1392 st_texture_image_unmap(ctx->st, stImage);
1393 screen->tex_transfer_destroy(src_trans);
1394 }
1395
1396
1397 static unsigned
1398 compatible_src_dst_formats(const struct gl_renderbuffer *src,
1399 const struct gl_texture_image *dst)
1400 {
1401 const GLenum srcFormat = src->_BaseFormat;
1402 const GLenum dstLogicalFormat = dst->_BaseFormat;
1403
1404 if (srcFormat == dstLogicalFormat) {
1405 /* This is the same as matching_base_formats, which should
1406 * always pass, as it did previously.
1407 */
1408 return TGSI_WRITEMASK_XYZW;
1409 }
1410 else if (srcFormat == GL_RGBA &&
1411 dstLogicalFormat == GL_RGB) {
1412 /* Add a single special case to cope with RGBA->RGB transfers,
1413 * setting A to 1.0 to cope with situations where the RGB
1414 * destination is actually stored as RGBA.
1415 */
1416 return TGSI_WRITEMASK_XYZ; /* A ==> 1.0 */
1417 }
1418 else {
1419 /* Otherwise fail.
1420 */
1421 return 0;
1422 }
1423 }
1424
1425
1426
1427 /**
1428 * Do a CopyTex[Sub]Image1/2/3D() using a hardware (blit) path if possible.
1429 * Note that the region to copy has already been clipped so we know we
1430 * won't read from outside the source renderbuffer's bounds.
1431 *
1432 * Note: srcY=0=Bottom of renderbuffer (GL convention)
1433 */
1434 static void
1435 st_copy_texsubimage(GLcontext *ctx,
1436 GLenum target, GLint level,
1437 GLint destX, GLint destY, GLint destZ,
1438 GLint srcX, GLint srcY,
1439 GLsizei width, GLsizei height)
1440 {
1441 struct gl_texture_unit *texUnit =
1442 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1443 struct gl_texture_object *texObj =
1444 _mesa_select_tex_object(ctx, texUnit, target);
1445 struct gl_texture_image *texImage =
1446 _mesa_select_tex_image(ctx, texObj, target, level);
1447 struct st_texture_image *stImage = st_texture_image(texImage);
1448 const GLenum texBaseFormat = texImage->InternalFormat;
1449 struct gl_framebuffer *fb = ctx->ReadBuffer;
1450 struct st_renderbuffer *strb;
1451 struct pipe_context *pipe = ctx->st->pipe;
1452 struct pipe_screen *screen = pipe->screen;
1453 enum pipe_format dest_format, src_format;
1454 GLboolean use_fallback = GL_TRUE;
1455 GLboolean matching_base_formats;
1456 GLuint format_writemask;
1457 struct pipe_surface *dest_surface = NULL;
1458 GLboolean do_flip = (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP);
1459
1460 /* any rendering in progress must flushed before we grab the fb image */
1461 st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
1462
1463 /* make sure finalize_textures has been called?
1464 */
1465 if (0) st_validate_state(ctx->st);
1466
1467 /* determine if copying depth or color data */
1468 if (texBaseFormat == GL_DEPTH_COMPONENT ||
1469 texBaseFormat == GL_DEPTH24_STENCIL8) {
1470 strb = st_renderbuffer(fb->_DepthBuffer);
1471 }
1472 else if (texBaseFormat == GL_DEPTH_STENCIL_EXT) {
1473 strb = st_renderbuffer(fb->_StencilBuffer);
1474 }
1475 else {
1476 /* texBaseFormat == GL_RGB, GL_RGBA, GL_ALPHA, etc */
1477 strb = st_renderbuffer(fb->_ColorReadBuffer);
1478 }
1479
1480 if (!strb || !strb->surface || !stImage->pt) {
1481 debug_printf("%s: null strb or stImage\n", __FUNCTION__);
1482 return;
1483 }
1484
1485 if (srcX < 0) {
1486 width -= -srcX;
1487 destX += -srcX;
1488 srcX = 0;
1489 }
1490
1491 if (srcY < 0) {
1492 height -= -srcY;
1493 destY += -srcY;
1494 srcY = 0;
1495 }
1496
1497 if (destX < 0) {
1498 width -= -destX;
1499 srcX += -destX;
1500 destX = 0;
1501 }
1502
1503 if (destY < 0) {
1504 height -= -destY;
1505 srcY += -destY;
1506 destY = 0;
1507 }
1508
1509 if (width < 0 || height < 0)
1510 return;
1511
1512
1513 assert(strb);
1514 assert(strb->surface);
1515 assert(stImage->pt);
1516
1517 src_format = strb->surface->format;
1518 dest_format = stImage->pt->format;
1519
1520 /*
1521 * Determine if the src framebuffer and dest texture have the same
1522 * base format. We need this to detect a case such as the framebuffer
1523 * being GL_RGBA but the texture being GL_RGB. If the actual hardware
1524 * texture format stores RGBA we need to set A=1 (overriding the
1525 * framebuffer's alpha values). We can't do that with the blit or
1526 * textured-quad paths.
1527 */
1528 matching_base_formats = (strb->Base._BaseFormat == texImage->_BaseFormat);
1529 format_writemask = compatible_src_dst_formats(&strb->Base, texImage);
1530
1531 if (ctx->_ImageTransferState == 0x0) {
1532
1533 if (matching_base_formats &&
1534 src_format == dest_format &&
1535 !do_flip)
1536 {
1537 /* use surface_copy() / blit */
1538
1539 dest_surface = screen->get_tex_surface(screen, stImage->pt,
1540 stImage->face, stImage->level,
1541 destZ,
1542 PIPE_BUFFER_USAGE_GPU_WRITE);
1543
1544 /* for surface_copy(), y=0=top, always */
1545 pipe->surface_copy(pipe,
1546 /* dest */
1547 dest_surface,
1548 destX, destY,
1549 /* src */
1550 strb->surface,
1551 srcX, srcY,
1552 /* size */
1553 width, height);
1554 use_fallback = GL_FALSE;
1555 }
1556 else if (format_writemask &&
1557 screen->is_format_supported(screen, src_format,
1558 PIPE_TEXTURE_2D,
1559 PIPE_TEXTURE_USAGE_SAMPLER,
1560 0) &&
1561 screen->is_format_supported(screen, dest_format,
1562 PIPE_TEXTURE_2D,
1563 PIPE_TEXTURE_USAGE_RENDER_TARGET,
1564 0)) {
1565 /* draw textured quad to do the copy */
1566 GLint srcY0, srcY1;
1567
1568 dest_surface = screen->get_tex_surface(screen, stImage->pt,
1569 stImage->face, stImage->level,
1570 destZ,
1571 PIPE_BUFFER_USAGE_GPU_WRITE);
1572
1573 if (do_flip) {
1574 srcY1 = strb->Base.Height - srcY - height;
1575 srcY0 = srcY1 + height;
1576 }
1577 else {
1578 srcY0 = srcY;
1579 srcY1 = srcY0 + height;
1580 }
1581 util_blit_pixels_writemask(ctx->st->blit,
1582 strb->surface,
1583 srcX, srcY0,
1584 srcX + width, srcY1,
1585 dest_surface,
1586 destX, destY,
1587 destX + width, destY + height,
1588 0.0, PIPE_TEX_MIPFILTER_NEAREST,
1589 format_writemask);
1590 use_fallback = GL_FALSE;
1591 }
1592
1593 if (dest_surface)
1594 pipe_surface_reference(&dest_surface, NULL);
1595 }
1596
1597 if (use_fallback) {
1598 /* software fallback */
1599 fallback_copy_texsubimage(ctx, target, level,
1600 strb, stImage, texBaseFormat,
1601 destX, destY, destZ,
1602 srcX, srcY, width, height);
1603 }
1604
1605 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
1606 ctx->Driver.GenerateMipmap(ctx, target, texObj);
1607 }
1608 }
1609
1610
1611
1612 static void
1613 st_CopyTexImage1D(GLcontext * ctx, GLenum target, GLint level,
1614 GLenum internalFormat,
1615 GLint x, GLint y, GLsizei width, GLint border)
1616 {
1617 struct gl_texture_unit *texUnit =
1618 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1619 struct gl_texture_object *texObj =
1620 _mesa_select_tex_object(ctx, texUnit, target);
1621 struct gl_texture_image *texImage =
1622 _mesa_select_tex_image(ctx, texObj, target, level);
1623
1624 /* Setup or redefine the texture object, texture and texture
1625 * image. Don't populate yet.
1626 */
1627 ctx->Driver.TexImage1D(ctx, target, level, internalFormat,
1628 width, border,
1629 GL_RGBA, CHAN_TYPE, NULL,
1630 &ctx->DefaultPacking, texObj, texImage);
1631
1632 st_copy_texsubimage(ctx, target, level,
1633 0, 0, 0, /* destX,Y,Z */
1634 x, y, width, 1); /* src X, Y, size */
1635 }
1636
1637
1638 static void
1639 st_CopyTexImage2D(GLcontext * ctx, GLenum target, GLint level,
1640 GLenum internalFormat,
1641 GLint x, GLint y, GLsizei width, GLsizei height,
1642 GLint border)
1643 {
1644 struct gl_texture_unit *texUnit =
1645 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1646 struct gl_texture_object *texObj =
1647 _mesa_select_tex_object(ctx, texUnit, target);
1648 struct gl_texture_image *texImage =
1649 _mesa_select_tex_image(ctx, texObj, target, level);
1650
1651 /* Setup or redefine the texture object, texture and texture
1652 * image. Don't populate yet.
1653 */
1654 ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
1655 width, height, border,
1656 GL_RGBA, CHAN_TYPE, NULL,
1657 &ctx->DefaultPacking, texObj, texImage);
1658
1659 st_copy_texsubimage(ctx, target, level,
1660 0, 0, 0, /* destX,Y,Z */
1661 x, y, width, height); /* src X, Y, size */
1662 }
1663
1664
1665 static void
1666 st_CopyTexSubImage1D(GLcontext * ctx, GLenum target, GLint level,
1667 GLint xoffset, GLint x, GLint y, GLsizei width)
1668 {
1669 const GLint yoffset = 0, zoffset = 0;
1670 const GLsizei height = 1;
1671 st_copy_texsubimage(ctx, target, level,
1672 xoffset, yoffset, zoffset, /* destX,Y,Z */
1673 x, y, width, height); /* src X, Y, size */
1674 }
1675
1676
1677 static void
1678 st_CopyTexSubImage2D(GLcontext * ctx, GLenum target, GLint level,
1679 GLint xoffset, GLint yoffset,
1680 GLint x, GLint y, GLsizei width, GLsizei height)
1681 {
1682 const GLint zoffset = 0;
1683 st_copy_texsubimage(ctx, target, level,
1684 xoffset, yoffset, zoffset, /* destX,Y,Z */
1685 x, y, width, height); /* src X, Y, size */
1686 }
1687
1688
1689 static void
1690 st_CopyTexSubImage3D(GLcontext * ctx, GLenum target, GLint level,
1691 GLint xoffset, GLint yoffset, GLint zoffset,
1692 GLint x, GLint y, GLsizei width, GLsizei height)
1693 {
1694 st_copy_texsubimage(ctx, target, level,
1695 xoffset, yoffset, zoffset, /* destX,Y,Z */
1696 x, y, width, height); /* src X, Y, size */
1697 }
1698
1699
1700 /**
1701 * Compute which mipmap levels that really need to be sent to the hardware.
1702 * This depends on the base image size, GL_TEXTURE_MIN_LOD,
1703 * GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL, and GL_TEXTURE_MAX_LEVEL.
1704 */
1705 static void
1706 calculate_first_last_level(struct st_texture_object *stObj)
1707 {
1708 struct gl_texture_object *tObj = &stObj->base;
1709
1710 /* These must be signed values. MinLod and MaxLod can be negative numbers,
1711 * and having firstLevel and lastLevel as signed prevents the need for
1712 * extra sign checks.
1713 */
1714 GLint firstLevel;
1715 GLint lastLevel;
1716
1717 /* Yes, this looks overly complicated, but it's all needed.
1718 */
1719 switch (tObj->Target) {
1720 case GL_TEXTURE_1D:
1721 case GL_TEXTURE_2D:
1722 case GL_TEXTURE_3D:
1723 case GL_TEXTURE_CUBE_MAP:
1724 if (tObj->MinFilter == GL_NEAREST || tObj->MinFilter == GL_LINEAR) {
1725 /* GL_NEAREST and GL_LINEAR only care about GL_TEXTURE_BASE_LEVEL.
1726 */
1727 firstLevel = lastLevel = tObj->BaseLevel;
1728 }
1729 else {
1730 firstLevel = 0;
1731 lastLevel = MIN2(tObj->MaxLevel,
1732 (int) tObj->Image[0][tObj->BaseLevel]->WidthLog2);
1733 }
1734 break;
1735 case GL_TEXTURE_RECTANGLE_NV:
1736 case GL_TEXTURE_4D_SGIS:
1737 firstLevel = lastLevel = 0;
1738 break;
1739 default:
1740 return;
1741 }
1742
1743 stObj->lastLevel = lastLevel;
1744 }
1745
1746
1747 static void
1748 copy_image_data_to_texture(struct st_context *st,
1749 struct st_texture_object *stObj,
1750 GLuint dstLevel,
1751 struct st_texture_image *stImage)
1752 {
1753 if (stImage->pt) {
1754 /* Copy potentially with the blitter:
1755 */
1756 st_texture_image_copy(st->pipe,
1757 stObj->pt, dstLevel, /* dest texture, level */
1758 stImage->pt, /* src texture */
1759 stImage->face
1760 );
1761
1762 pipe_texture_reference(&stImage->pt, NULL);
1763 }
1764 else if (stImage->base.Data) {
1765 assert(stImage->base.Data != NULL);
1766
1767 /* More straightforward upload.
1768 */
1769
1770 st_teximage_flush_before_map(st, stObj->pt, stImage->face, dstLevel,
1771 PIPE_TRANSFER_WRITE);
1772
1773
1774 st_texture_image_data(st,
1775 stObj->pt,
1776 stImage->face,
1777 dstLevel,
1778 stImage->base.Data,
1779 stImage->base.RowStride *
1780 stObj->pt->block.size,
1781 stImage->base.RowStride *
1782 stImage->base.Height *
1783 stObj->pt->block.size);
1784 _mesa_align_free(stImage->base.Data);
1785 stImage->base.Data = NULL;
1786 }
1787
1788 pipe_texture_reference(&stImage->pt, stObj->pt);
1789 }
1790
1791
1792 /**
1793 * Called during state validation. When this function is finished,
1794 * the texture object should be ready for rendering.
1795 * \return GL_TRUE for success, GL_FALSE for failure (out of mem)
1796 */
1797 GLboolean
1798 st_finalize_texture(GLcontext *ctx,
1799 struct pipe_context *pipe,
1800 struct gl_texture_object *tObj,
1801 GLboolean *needFlush)
1802 {
1803 struct st_texture_object *stObj = st_texture_object(tObj);
1804 const GLuint nr_faces = (stObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
1805 GLuint cpp, face;
1806 struct st_texture_image *firstImage;
1807
1808 *needFlush = GL_FALSE;
1809
1810 /* We know/require this is true by now:
1811 */
1812 assert(stObj->base._Complete);
1813
1814 /* What levels must the texture include at a minimum?
1815 */
1816 calculate_first_last_level(stObj);
1817 firstImage = st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]);
1818
1819 /* If both firstImage and stObj point to a texture which can contain
1820 * all active images, favour firstImage. Note that because of the
1821 * completeness requirement, we know that the image dimensions
1822 * will match.
1823 */
1824 if (firstImage->pt &&
1825 firstImage->pt != stObj->pt &&
1826 firstImage->pt->last_level >= stObj->lastLevel) {
1827 pipe_texture_reference(&stObj->pt, firstImage->pt);
1828 }
1829
1830 /* FIXME: determine format block instead of cpp */
1831 if (firstImage->base.IsCompressed) {
1832 cpp = compressed_num_bytes(firstImage->base.TexFormat->MesaFormat);
1833 }
1834 else {
1835 cpp = firstImage->base.TexFormat->TexelBytes;
1836 }
1837
1838 /* If we already have a gallium texture, check that it matches the texture
1839 * object's format, target, size, num_levels, etc.
1840 */
1841 if (stObj->pt) {
1842 const enum pipe_format fmt =
1843 st_mesa_format_to_pipe_format(firstImage->base.TexFormat->MesaFormat);
1844 if (stObj->pt->target != gl_target_to_pipe(stObj->base.Target) ||
1845 stObj->pt->format != fmt ||
1846 stObj->pt->last_level < stObj->lastLevel ||
1847 stObj->pt->width[0] != firstImage->base.Width2 ||
1848 stObj->pt->height[0] != firstImage->base.Height2 ||
1849 stObj->pt->depth[0] != firstImage->base.Depth2 ||
1850 /* Nominal bytes per pixel: */
1851 stObj->pt->block.size / stObj->pt->block.width != cpp)
1852 {
1853 pipe_texture_reference(&stObj->pt, NULL);
1854 ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER;
1855 }
1856 }
1857
1858 /* May need to create a new gallium texture:
1859 */
1860 if (!stObj->pt) {
1861 const enum pipe_format fmt =
1862 st_mesa_format_to_pipe_format(firstImage->base.TexFormat->MesaFormat);
1863 GLuint usage = default_usage(fmt);
1864
1865 stObj->pt = st_texture_create(ctx->st,
1866 gl_target_to_pipe(stObj->base.Target),
1867 fmt,
1868 stObj->lastLevel,
1869 firstImage->base.Width2,
1870 firstImage->base.Height2,
1871 firstImage->base.Depth2,
1872 usage);
1873
1874 if (!stObj->pt) {
1875 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
1876 return GL_FALSE;
1877 }
1878 }
1879
1880 /* Pull in any images not in the object's texture:
1881 */
1882 for (face = 0; face < nr_faces; face++) {
1883 GLuint level;
1884 for (level = 0; level <= stObj->lastLevel; level++) {
1885 struct st_texture_image *stImage =
1886 st_texture_image(stObj->base.Image[face][stObj->base.BaseLevel + level]);
1887
1888 /* Need to import images in main memory or held in other textures.
1889 */
1890 if (stImage && stObj->pt != stImage->pt) {
1891 copy_image_data_to_texture(ctx->st, stObj, level, stImage);
1892 *needFlush = GL_TRUE;
1893 }
1894 }
1895 }
1896
1897 return GL_TRUE;
1898 }
1899
1900
1901 /**
1902 * Returns pointer to a default/dummy texture.
1903 * This is typically used when the current shader has tex/sample instructions
1904 * but the user has not provided a (any) texture(s).
1905 */
1906 struct gl_texture_object *
1907 st_get_default_texture(struct st_context *st)
1908 {
1909 if (!st->default_texture) {
1910 static const GLenum target = GL_TEXTURE_2D;
1911 GLubyte pixels[16][16][4];
1912 struct gl_texture_object *texObj;
1913 struct gl_texture_image *texImg;
1914 GLuint i, j;
1915
1916 /* The ARB_fragment_program spec says (0,0,0,1) should be returned
1917 * when attempting to sample incomplete textures.
1918 */
1919 for (i = 0; i < 16; i++) {
1920 for (j = 0; j < 16; j++) {
1921 pixels[i][j][0] = 0;
1922 pixels[i][j][1] = 0;
1923 pixels[i][j][2] = 0;
1924 pixels[i][j][3] = 255;
1925 }
1926 }
1927
1928 texObj = st->ctx->Driver.NewTextureObject(st->ctx, 0, target);
1929
1930 texImg = _mesa_get_tex_image(st->ctx, texObj, target, 0);
1931
1932 _mesa_init_teximage_fields(st->ctx, target, texImg,
1933 16, 16, 1, 0, /* w, h, d, border */
1934 GL_RGBA);
1935
1936 st_TexImage(st->ctx, 2, target,
1937 0, GL_RGBA, /* level, intformat */
1938 16, 16, 1, 0, /* w, h, d, border */
1939 GL_RGBA, GL_UNSIGNED_BYTE, pixels,
1940 &st->ctx->DefaultPacking,
1941 texObj, texImg,
1942 0, 0);
1943
1944 texObj->MinFilter = GL_NEAREST;
1945 texObj->MagFilter = GL_NEAREST;
1946 texObj->_Complete = GL_TRUE;
1947
1948 st->default_texture = texObj;
1949 }
1950 return st->default_texture;
1951 }
1952
1953
1954 void
1955 st_init_texture_functions(struct dd_function_table *functions)
1956 {
1957 functions->ChooseTextureFormat = st_ChooseTextureFormat;
1958 functions->TexImage1D = st_TexImage1D;
1959 functions->TexImage2D = st_TexImage2D;
1960 functions->TexImage3D = st_TexImage3D;
1961 functions->TexSubImage1D = st_TexSubImage1D;
1962 functions->TexSubImage2D = st_TexSubImage2D;
1963 functions->TexSubImage3D = st_TexSubImage3D;
1964 functions->CompressedTexSubImage1D = st_CompressedTexSubImage1D;
1965 functions->CompressedTexSubImage2D = st_CompressedTexSubImage2D;
1966 functions->CompressedTexSubImage3D = st_CompressedTexSubImage3D;
1967 functions->CopyTexImage1D = st_CopyTexImage1D;
1968 functions->CopyTexImage2D = st_CopyTexImage2D;
1969 functions->CopyTexSubImage1D = st_CopyTexSubImage1D;
1970 functions->CopyTexSubImage2D = st_CopyTexSubImage2D;
1971 functions->CopyTexSubImage3D = st_CopyTexSubImage3D;
1972 functions->GenerateMipmap = st_generate_mipmap;
1973
1974 functions->GetTexImage = st_GetTexImage;
1975
1976 /* compressed texture functions */
1977 functions->CompressedTexImage2D = st_CompressedTexImage2D;
1978 functions->GetCompressedTexImage = st_GetCompressedTexImage;
1979 functions->CompressedTextureSize = _mesa_compressed_texture_size;
1980
1981 functions->NewTextureObject = st_NewTextureObject;
1982 functions->NewTextureImage = st_NewTextureImage;
1983 functions->DeleteTexture = st_DeleteTextureObject;
1984 functions->FreeTexImageData = st_FreeTextureImageData;
1985 functions->UpdateTexturePalette = 0;
1986
1987 functions->TextureMemCpy = do_memcpy;
1988
1989 /* XXX Temporary until we can query pipe's texture sizes */
1990 functions->TestProxyTexImage = _mesa_test_proxy_teximage;
1991 }