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