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