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