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