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