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