softpipe: use consistant names for local vars
[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 texImage->RowStride = stImage->transfer->stride / util_format_get_blocksize(stImage->pt->format);
978 }
979 else {
980 /* Otherwise, the image should actually be stored in
981 * texImage->Data. This is pretty confusing for
982 * everybody, I'd much prefer to separate the two functions of
983 * texImage->Data - storage for texture images in main memory
984 * and access (ie mappings) of images. In other words, we'd
985 * create a new texImage->Map field and leave Data simply for
986 * storage.
987 */
988 assert(texImage->Data);
989 }
990
991 depth = texImage->Depth;
992 texImage->Depth = 1;
993
994 dest = (GLubyte *) pixels;
995
996 for (i = 0; i < depth; i++) {
997 if (compressed_dst) {
998 _mesa_get_compressed_teximage(ctx, target, level, dest,
999 texObj, texImage);
1000 }
1001 else {
1002 _mesa_get_teximage(ctx, target, level, format, type, dest,
1003 texObj, texImage);
1004 }
1005
1006 if (stImage->pt && i + 1 < depth) {
1007 /* unmap this slice */
1008 st_texture_image_unmap(st, stImage);
1009 /* map next slice of 3D texture */
1010 texImage->Data = st_texture_image_map(st, stImage, i + 1,
1011 PIPE_TRANSFER_READ, 0, 0,
1012 stImage->base.Width,
1013 stImage->base.Height);
1014 dest += dstImageStride;
1015 }
1016 }
1017
1018 texImage->Depth = depth;
1019
1020 /* Unmap */
1021 if (stImage->pt) {
1022 st_texture_image_unmap(st, stImage);
1023 texImage->Data = NULL;
1024 }
1025 }
1026
1027
1028 static void
1029 st_GetTexImage(GLcontext * ctx, GLenum target, GLint level,
1030 GLenum format, GLenum type, GLvoid * pixels,
1031 struct gl_texture_object *texObj,
1032 struct gl_texture_image *texImage)
1033 {
1034 st_get_tex_image(ctx, target, level, format, type, pixels, texObj, texImage,
1035 GL_FALSE);
1036 }
1037
1038
1039 static void
1040 st_GetCompressedTexImage(GLcontext *ctx, GLenum target, GLint level,
1041 GLvoid *pixels,
1042 struct gl_texture_object *texObj,
1043 struct gl_texture_image *texImage)
1044 {
1045 st_get_tex_image(ctx, target, level, 0, 0, pixels, texObj, texImage,
1046 GL_TRUE);
1047 }
1048
1049
1050
1051 static void
1052 st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level,
1053 GLint xoffset, GLint yoffset, GLint zoffset,
1054 GLint width, GLint height, GLint depth,
1055 GLenum format, GLenum type, const void *pixels,
1056 const struct gl_pixelstore_attrib *packing,
1057 struct gl_texture_object *texObj,
1058 struct gl_texture_image *texImage)
1059 {
1060 struct st_context *st = st_context(ctx);
1061 struct pipe_screen *screen = st->pipe->screen;
1062 struct st_texture_image *stImage = st_texture_image(texImage);
1063 GLuint dstRowStride;
1064 const GLuint srcImageStride =
1065 _mesa_image_image_stride(packing, width, height, format, type);
1066 GLint i;
1067 const GLubyte *src;
1068 /* init to silence warning only: */
1069 enum pipe_transfer_usage transfer_usage = PIPE_TRANSFER_WRITE;
1070
1071 DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__,
1072 _mesa_lookup_enum_by_nr(target),
1073 level, xoffset, yoffset, width, height);
1074
1075 pixels =
1076 _mesa_validate_pbo_teximage(ctx, dims, width, height, depth, format,
1077 type, pixels, packing, "glTexSubImage2D");
1078 if (!pixels)
1079 return;
1080
1081 /* See if we can do texture compression with a blit/render.
1082 */
1083 if (!ctx->Mesa_DXTn &&
1084 _mesa_is_format_compressed(texImage->TexFormat) &&
1085 screen->is_format_supported(screen,
1086 stImage->pt->format,
1087 stImage->pt->target,
1088 PIPE_BIND_RENDER_TARGET, 0)) {
1089 if (compress_with_blit(ctx, target, level,
1090 xoffset, yoffset, zoffset,
1091 width, height, depth,
1092 format, type, pixels, packing, texImage)) {
1093 goto done;
1094 }
1095 }
1096
1097 /* Map buffer if necessary. Need to lock to prevent other contexts
1098 * from uploading the buffer under us.
1099 */
1100 if (stImage->pt) {
1101 unsigned face = _mesa_tex_target_to_face(target);
1102
1103 if (format == GL_DEPTH_COMPONENT &&
1104 util_format_is_depth_and_stencil(stImage->pt->format))
1105 transfer_usage = PIPE_TRANSFER_READ_WRITE;
1106 else
1107 transfer_usage = PIPE_TRANSFER_WRITE;
1108
1109 st_teximage_flush_before_map(st, stImage->pt, face, level,
1110 transfer_usage);
1111 texImage->Data = st_texture_image_map(st, stImage, zoffset,
1112 transfer_usage,
1113 xoffset, yoffset,
1114 width, height);
1115 }
1116
1117 if (!texImage->Data) {
1118 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
1119 goto done;
1120 }
1121
1122 src = (const GLubyte *) pixels;
1123 dstRowStride = stImage->transfer->stride;
1124
1125 for (i = 0; i < depth; i++) {
1126 if (!_mesa_texstore(ctx, dims, texImage->_BaseFormat,
1127 texImage->TexFormat,
1128 texImage->Data,
1129 0, 0, 0,
1130 dstRowStride,
1131 texImage->ImageOffsets,
1132 width, height, 1,
1133 format, type, src, packing)) {
1134 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
1135 }
1136
1137 if (stImage->pt && i + 1 < depth) {
1138 /* unmap this slice */
1139 st_texture_image_unmap(st, stImage);
1140 /* map next slice of 3D texture */
1141 texImage->Data = st_texture_image_map(st, stImage,
1142 zoffset + i + 1,
1143 transfer_usage,
1144 xoffset, yoffset,
1145 width, height);
1146 src += srcImageStride;
1147 }
1148 }
1149
1150 done:
1151 _mesa_unmap_teximage_pbo(ctx, packing);
1152
1153 if (stImage->pt && texImage->Data) {
1154 st_texture_image_unmap(st, stImage);
1155 texImage->Data = NULL;
1156 }
1157 }
1158
1159
1160
1161 static void
1162 st_TexSubImage3D(GLcontext *ctx, GLenum target, GLint level,
1163 GLint xoffset, GLint yoffset, GLint zoffset,
1164 GLsizei width, GLsizei height, GLsizei depth,
1165 GLenum format, GLenum type, const GLvoid *pixels,
1166 const struct gl_pixelstore_attrib *packing,
1167 struct gl_texture_object *texObj,
1168 struct gl_texture_image *texImage)
1169 {
1170 st_TexSubimage(ctx, 3, target, level, xoffset, yoffset, zoffset,
1171 width, height, depth, format, type,
1172 pixels, packing, texObj, texImage);
1173 }
1174
1175
1176 static void
1177 st_TexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
1178 GLint xoffset, GLint yoffset,
1179 GLsizei width, GLsizei height,
1180 GLenum format, GLenum type, const GLvoid * pixels,
1181 const struct gl_pixelstore_attrib *packing,
1182 struct gl_texture_object *texObj,
1183 struct gl_texture_image *texImage)
1184 {
1185 st_TexSubimage(ctx, 2, target, level, xoffset, yoffset, 0,
1186 width, height, 1, format, type,
1187 pixels, packing, texObj, texImage);
1188 }
1189
1190
1191 static void
1192 st_TexSubImage1D(GLcontext *ctx, GLenum target, GLint level,
1193 GLint xoffset, GLsizei width, GLenum format, GLenum type,
1194 const GLvoid * pixels,
1195 const struct gl_pixelstore_attrib *packing,
1196 struct gl_texture_object *texObj,
1197 struct gl_texture_image *texImage)
1198 {
1199 st_TexSubimage(ctx, 1, target, level, xoffset, 0, 0, width, 1, 1,
1200 format, type, pixels, packing, texObj, texImage);
1201 }
1202
1203
1204 static void
1205 st_CompressedTexSubImage1D(GLcontext *ctx, GLenum target, GLint level,
1206 GLint xoffset, GLsizei width,
1207 GLenum format,
1208 GLsizei imageSize, const GLvoid *data,
1209 struct gl_texture_object *texObj,
1210 struct gl_texture_image *texImage)
1211 {
1212 assert(0);
1213 }
1214
1215
1216 static void
1217 st_CompressedTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
1218 GLint xoffset, GLint yoffset,
1219 GLsizei width, GLint height,
1220 GLenum format,
1221 GLsizei imageSize, const GLvoid *data,
1222 struct gl_texture_object *texObj,
1223 struct gl_texture_image *texImage)
1224 {
1225 struct st_context *st = st_context(ctx);
1226 struct st_texture_image *stImage = st_texture_image(texImage);
1227 int srcBlockStride;
1228 int dstBlockStride;
1229 int y;
1230 enum pipe_format pformat;
1231
1232 if (stImage->pt) {
1233 unsigned face = _mesa_tex_target_to_face(target);
1234 pformat = stImage->pt->format;
1235
1236 st_teximage_flush_before_map(st, stImage->pt, face, level,
1237 PIPE_TRANSFER_WRITE);
1238 texImage->Data = st_texture_image_map(st, stImage, 0,
1239 PIPE_TRANSFER_WRITE,
1240 xoffset, yoffset,
1241 width, height);
1242
1243 srcBlockStride = util_format_get_stride(pformat, width);
1244 dstBlockStride = stImage->transfer->stride;
1245 } else {
1246 assert(stImage->pt);
1247 /* TODO find good values for block and strides */
1248 /* TODO also adjust texImage->data for yoffset/xoffset */
1249 return;
1250 }
1251
1252 if (!texImage->Data) {
1253 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage");
1254 return;
1255 }
1256
1257 assert(xoffset % util_format_get_blockwidth(pformat) == 0);
1258 assert(yoffset % util_format_get_blockheight(pformat) == 0);
1259 assert(width % util_format_get_blockwidth(pformat) == 0);
1260 assert(height % util_format_get_blockheight(pformat) == 0);
1261
1262 for (y = 0; y < height; y += util_format_get_blockheight(pformat)) {
1263 /* don't need to adjust for xoffset and yoffset as st_texture_image_map does that */
1264 const char *src = (const char*)data + srcBlockStride * util_format_get_nblocksy(pformat, y);
1265 char *dst = (char*)texImage->Data + dstBlockStride * util_format_get_nblocksy(pformat, y);
1266 memcpy(dst, src, util_format_get_stride(pformat, width));
1267 }
1268
1269 if (stImage->pt) {
1270 st_texture_image_unmap(st, stImage);
1271 texImage->Data = NULL;
1272 }
1273 }
1274
1275
1276 static void
1277 st_CompressedTexSubImage3D(GLcontext *ctx, GLenum target, GLint level,
1278 GLint xoffset, GLint yoffset, GLint zoffset,
1279 GLsizei width, GLint height, GLint depth,
1280 GLenum format,
1281 GLsizei imageSize, const GLvoid *data,
1282 struct gl_texture_object *texObj,
1283 struct gl_texture_image *texImage)
1284 {
1285 assert(0);
1286 }
1287
1288
1289
1290 /**
1291 * Do a CopyTexSubImage operation using a read transfer from the source,
1292 * a write transfer to the destination and get_tile()/put_tile() to access
1293 * the pixels/texels.
1294 *
1295 * Note: srcY=0=TOP of renderbuffer
1296 */
1297 static void
1298 fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
1299 struct st_renderbuffer *strb,
1300 struct st_texture_image *stImage,
1301 GLenum baseFormat,
1302 GLint destX, GLint destY, GLint destZ,
1303 GLint srcX, GLint srcY,
1304 GLsizei width, GLsizei height)
1305 {
1306 struct st_context *st = st_context(ctx);
1307 struct pipe_context *pipe = st->pipe;
1308 struct pipe_transfer *src_trans;
1309 GLvoid *texDest;
1310 enum pipe_transfer_usage transfer_usage;
1311
1312 if (ST_DEBUG & DEBUG_FALLBACK)
1313 debug_printf("%s: fallback processing\n", __FUNCTION__);
1314
1315 assert(width <= MAX_WIDTH);
1316
1317 if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
1318 srcY = strb->Base.Height - srcY - height;
1319 }
1320
1321 src_trans = st_cond_flush_get_tex_transfer( st_context(ctx),
1322 strb->texture,
1323 0, 0, 0,
1324 PIPE_TRANSFER_READ,
1325 srcX, srcY,
1326 width, height);
1327
1328 if ((baseFormat == GL_DEPTH_COMPONENT ||
1329 baseFormat == GL_DEPTH_STENCIL) &&
1330 util_format_is_depth_and_stencil(stImage->pt->format))
1331 transfer_usage = PIPE_TRANSFER_READ_WRITE;
1332 else
1333 transfer_usage = PIPE_TRANSFER_WRITE;
1334
1335 st_teximage_flush_before_map(st, stImage->pt, 0, 0,
1336 transfer_usage);
1337
1338 texDest = st_texture_image_map(st, stImage, 0, transfer_usage,
1339 destX, destY, width, height);
1340
1341 if (baseFormat == GL_DEPTH_COMPONENT ||
1342 baseFormat == GL_DEPTH_STENCIL) {
1343 const GLboolean scaleOrBias = (ctx->Pixel.DepthScale != 1.0F ||
1344 ctx->Pixel.DepthBias != 0.0F);
1345 GLint row, yStep;
1346
1347 /* determine bottom-to-top vs. top-to-bottom order for src buffer */
1348 if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
1349 srcY = height - 1;
1350 yStep = -1;
1351 }
1352 else {
1353 srcY = 0;
1354 yStep = 1;
1355 }
1356
1357 /* To avoid a large temp memory allocation, do copy row by row */
1358 for (row = 0; row < height; row++, srcY += yStep) {
1359 uint data[MAX_WIDTH];
1360 pipe_get_tile_z(pipe, src_trans, 0, srcY, width, 1, data);
1361 if (scaleOrBias) {
1362 _mesa_scale_and_bias_depth_uint(ctx, width, data);
1363 }
1364 pipe_put_tile_z(pipe, stImage->transfer, 0, row, width, 1, data);
1365 }
1366 }
1367 else {
1368 /* RGBA format */
1369 GLfloat *tempSrc =
1370 (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
1371
1372 if (tempSrc && texDest) {
1373 const GLint dims = 2;
1374 const GLint dstRowStride = stImage->transfer->stride;
1375 struct gl_texture_image *texImage = &stImage->base;
1376 struct gl_pixelstore_attrib unpack = ctx->DefaultPacking;
1377
1378 if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
1379 unpack.Invert = GL_TRUE;
1380 }
1381
1382 /* get float/RGBA image from framebuffer */
1383 /* XXX this usually involves a lot of int/float conversion.
1384 * try to avoid that someday.
1385 */
1386 pipe_get_tile_rgba(pipe, src_trans, 0, 0, width, height, tempSrc);
1387
1388 /* Store into texture memory.
1389 * Note that this does some special things such as pixel transfer
1390 * ops and format conversion. In particular, if the dest tex format
1391 * is actually RGBA but the user created the texture as GL_RGB we
1392 * need to fill-in/override the alpha channel with 1.0.
1393 */
1394 _mesa_texstore(ctx, dims,
1395 texImage->_BaseFormat,
1396 texImage->TexFormat,
1397 texDest,
1398 0, 0, 0,
1399 dstRowStride,
1400 texImage->ImageOffsets,
1401 width, height, 1,
1402 GL_RGBA, GL_FLOAT, tempSrc, /* src */
1403 &unpack);
1404 }
1405 else {
1406 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
1407 }
1408
1409 if (tempSrc)
1410 free(tempSrc);
1411 }
1412
1413 st_texture_image_unmap(st, stImage);
1414 pipe->transfer_destroy(pipe, src_trans);
1415 }
1416
1417
1418
1419 /**
1420 * If the format of the src renderbuffer and the format of the dest
1421 * texture are compatible (in terms of blitting), return a TGSI writemask
1422 * to be used during the blit.
1423 * If the src/dest are incompatible, return 0.
1424 */
1425 static unsigned
1426 compatible_src_dst_formats(GLcontext *ctx,
1427 const struct gl_renderbuffer *src,
1428 const struct gl_texture_image *dst)
1429 {
1430 /* Get logical base formats for the src and dest.
1431 * That is, use the user-requested formats and not the actual, device-
1432 * chosen formats.
1433 * For example, the user may have requested an A8 texture but the
1434 * driver may actually be using an RGBA texture format. When we
1435 * copy/blit to that texture, we only want to copy the Alpha channel
1436 * and not the RGB channels.
1437 *
1438 * Similarly, when the src FBO was created an RGB format may have been
1439 * requested but the driver actually chose an RGBA format. In that case,
1440 * we don't want to copy the undefined Alpha channel to the dest texture
1441 * (it should be 1.0).
1442 */
1443 const GLenum srcFormat = _mesa_base_fbo_format(ctx, src->InternalFormat);
1444 const GLenum dstFormat = _mesa_base_tex_format(ctx, dst->InternalFormat);
1445
1446 /**
1447 * XXX when we have red-only and red/green renderbuffers we'll need
1448 * to add more cases here (or implement a general-purpose routine that
1449 * queries the existance of the R,G,B,A channels in the src and dest).
1450 */
1451 if (srcFormat == dstFormat) {
1452 /* This is the same as matching_base_formats, which should
1453 * always pass, as it did previously.
1454 */
1455 return TGSI_WRITEMASK_XYZW;
1456 }
1457 else if (srcFormat == GL_RGB && dstFormat == GL_RGBA) {
1458 /* Make sure that A in the dest is 1. The actual src format
1459 * may be RGBA and have undefined A values.
1460 */
1461 return TGSI_WRITEMASK_XYZ;
1462 }
1463 else if (srcFormat == GL_RGBA && dstFormat == GL_RGB) {
1464 /* Make sure that A in the dest is 1. The actual dst format
1465 * may be RGBA and will need A=1 to provide proper alpha values
1466 * when sampled later.
1467 */
1468 return TGSI_WRITEMASK_XYZ;
1469 }
1470 else {
1471 if (ST_DEBUG & DEBUG_FALLBACK)
1472 debug_printf("%s failed for src %s, dst %s\n",
1473 __FUNCTION__,
1474 _mesa_lookup_enum_by_nr(srcFormat),
1475 _mesa_lookup_enum_by_nr(dstFormat));
1476
1477 /* Otherwise fail.
1478 */
1479 return 0;
1480 }
1481 }
1482
1483
1484
1485 /**
1486 * Do a CopyTex[Sub]Image1/2/3D() using a hardware (blit) path if possible.
1487 * Note that the region to copy has already been clipped so we know we
1488 * won't read from outside the source renderbuffer's bounds.
1489 *
1490 * Note: srcY=0=Bottom of renderbuffer (GL convention)
1491 */
1492 static void
1493 st_copy_texsubimage(GLcontext *ctx,
1494 GLenum target, GLint level,
1495 GLint destX, GLint destY, GLint destZ,
1496 GLint srcX, GLint srcY,
1497 GLsizei width, GLsizei height)
1498 {
1499 struct gl_texture_unit *texUnit =
1500 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1501 struct gl_texture_object *texObj =
1502 _mesa_select_tex_object(ctx, texUnit, target);
1503 struct gl_texture_image *texImage =
1504 _mesa_select_tex_image(ctx, texObj, target, level);
1505 struct st_texture_image *stImage = st_texture_image(texImage);
1506 const GLenum texBaseFormat = texImage->_BaseFormat;
1507 struct gl_framebuffer *fb = ctx->ReadBuffer;
1508 struct st_renderbuffer *strb;
1509 struct st_context *st = st_context(ctx);
1510 struct pipe_context *pipe = st->pipe;
1511 struct pipe_screen *screen = pipe->screen;
1512 enum pipe_format dest_format, src_format;
1513 GLboolean use_fallback = GL_TRUE;
1514 GLboolean matching_base_formats;
1515 GLuint format_writemask;
1516 struct pipe_surface *dest_surface = NULL;
1517 GLboolean do_flip = (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP);
1518
1519 /* any rendering in progress must flushed before we grab the fb image */
1520 st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL);
1521
1522 /* make sure finalize_textures has been called?
1523 */
1524 if (0) st_validate_state(st);
1525
1526 /* determine if copying depth or color data */
1527 if (texBaseFormat == GL_DEPTH_COMPONENT ||
1528 texBaseFormat == GL_DEPTH_STENCIL) {
1529 strb = st_renderbuffer(fb->_DepthBuffer);
1530 }
1531 else {
1532 /* texBaseFormat == GL_RGB, GL_RGBA, GL_ALPHA, etc */
1533 strb = st_renderbuffer(fb->_ColorReadBuffer);
1534 }
1535
1536 if (!strb || !strb->surface || !stImage->pt) {
1537 debug_printf("%s: null strb or stImage\n", __FUNCTION__);
1538 return;
1539 }
1540
1541 if (srcX < 0) {
1542 width -= -srcX;
1543 destX += -srcX;
1544 srcX = 0;
1545 }
1546
1547 if (srcY < 0) {
1548 height -= -srcY;
1549 destY += -srcY;
1550 srcY = 0;
1551 }
1552
1553 if (destX < 0) {
1554 width -= -destX;
1555 srcX += -destX;
1556 destX = 0;
1557 }
1558
1559 if (destY < 0) {
1560 height -= -destY;
1561 srcY += -destY;
1562 destY = 0;
1563 }
1564
1565 if (width < 0 || height < 0)
1566 return;
1567
1568
1569 assert(strb);
1570 assert(strb->surface);
1571 assert(stImage->pt);
1572
1573 src_format = strb->surface->format;
1574 dest_format = stImage->pt->format;
1575
1576 /*
1577 * Determine if the src framebuffer and dest texture have the same
1578 * base format. We need this to detect a case such as the framebuffer
1579 * being GL_RGBA but the texture being GL_RGB. If the actual hardware
1580 * texture format stores RGBA we need to set A=1 (overriding the
1581 * framebuffer's alpha values). We can't do that with the blit or
1582 * textured-quad paths.
1583 */
1584 matching_base_formats =
1585 (_mesa_get_format_base_format(strb->Base.Format) ==
1586 _mesa_get_format_base_format(texImage->TexFormat));
1587 format_writemask = compatible_src_dst_formats(ctx, &strb->Base, texImage);
1588
1589 if (ctx->_ImageTransferState == 0x0) {
1590
1591 if (matching_base_formats &&
1592 src_format == dest_format &&
1593 !do_flip)
1594 {
1595 /* use surface_copy() / blit */
1596
1597 dest_surface = screen->get_tex_surface(screen, stImage->pt,
1598 stImage->face, stImage->level,
1599 destZ,
1600 PIPE_BIND_BLIT_DESTINATION);
1601
1602 /* for surface_copy(), y=0=top, always */
1603 pipe->surface_copy(pipe,
1604 /* dest */
1605 dest_surface,
1606 destX, destY,
1607 /* src */
1608 strb->surface,
1609 srcX, srcY,
1610 /* size */
1611 width, height);
1612 use_fallback = GL_FALSE;
1613 }
1614 else if (format_writemask &&
1615 texBaseFormat != GL_DEPTH_COMPONENT &&
1616 texBaseFormat != GL_DEPTH_STENCIL &&
1617 screen->is_format_supported(screen, src_format,
1618 PIPE_TEXTURE_2D,
1619 PIPE_BIND_SAMPLER_VIEW,
1620 0) &&
1621 screen->is_format_supported(screen, dest_format,
1622 PIPE_TEXTURE_2D,
1623 PIPE_BIND_RENDER_TARGET,
1624 0)) {
1625 /* draw textured quad to do the copy */
1626 GLint srcY0, srcY1;
1627
1628 dest_surface = screen->get_tex_surface(screen, stImage->pt,
1629 stImage->face, stImage->level,
1630 destZ,
1631 PIPE_BIND_BLIT_DESTINATION);
1632
1633 if (do_flip) {
1634 srcY1 = strb->Base.Height - srcY - height;
1635 srcY0 = srcY1 + height;
1636 }
1637 else {
1638 srcY0 = srcY;
1639 srcY1 = srcY0 + height;
1640 }
1641 util_blit_pixels_writemask(st->blit,
1642 strb->surface,
1643 st_get_renderbuffer_sampler_view(strb, pipe),
1644 srcX, srcY0,
1645 srcX + width, srcY1,
1646 dest_surface,
1647 destX, destY,
1648 destX + width, destY + height,
1649 0.0, PIPE_TEX_MIPFILTER_NEAREST,
1650 format_writemask);
1651 use_fallback = GL_FALSE;
1652 }
1653
1654 if (dest_surface)
1655 pipe_surface_reference(&dest_surface, NULL);
1656 }
1657
1658 if (use_fallback) {
1659 /* software fallback */
1660 fallback_copy_texsubimage(ctx, target, level,
1661 strb, stImage, texBaseFormat,
1662 destX, destY, destZ,
1663 srcX, srcY, width, height);
1664 }
1665 }
1666
1667
1668
1669 static void
1670 st_CopyTexImage1D(GLcontext * ctx, GLenum target, GLint level,
1671 GLenum internalFormat,
1672 GLint x, GLint y, GLsizei width, GLint border)
1673 {
1674 struct gl_texture_unit *texUnit =
1675 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1676 struct gl_texture_object *texObj =
1677 _mesa_select_tex_object(ctx, texUnit, target);
1678 struct gl_texture_image *texImage =
1679 _mesa_select_tex_image(ctx, texObj, target, level);
1680
1681 /* Setup or redefine the texture object, texture and texture
1682 * image. Don't populate yet.
1683 */
1684 ctx->Driver.TexImage1D(ctx, target, level, internalFormat,
1685 width, border,
1686 GL_RGBA, CHAN_TYPE, NULL,
1687 &ctx->DefaultPacking, texObj, texImage);
1688
1689 st_copy_texsubimage(ctx, target, level,
1690 0, 0, 0, /* destX,Y,Z */
1691 x, y, width, 1); /* src X, Y, size */
1692 }
1693
1694
1695 static void
1696 st_CopyTexImage2D(GLcontext * ctx, GLenum target, GLint level,
1697 GLenum internalFormat,
1698 GLint x, GLint y, GLsizei width, GLsizei height,
1699 GLint border)
1700 {
1701 struct gl_texture_unit *texUnit =
1702 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1703 struct gl_texture_object *texObj =
1704 _mesa_select_tex_object(ctx, texUnit, target);
1705 struct gl_texture_image *texImage =
1706 _mesa_select_tex_image(ctx, texObj, target, level);
1707
1708 /* Setup or redefine the texture object, texture and texture
1709 * image. Don't populate yet.
1710 */
1711 ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
1712 width, height, border,
1713 GL_RGBA, CHAN_TYPE, NULL,
1714 &ctx->DefaultPacking, texObj, texImage);
1715
1716 st_copy_texsubimage(ctx, target, level,
1717 0, 0, 0, /* destX,Y,Z */
1718 x, y, width, height); /* src X, Y, size */
1719 }
1720
1721
1722 static void
1723 st_CopyTexSubImage1D(GLcontext * ctx, GLenum target, GLint level,
1724 GLint xoffset, GLint x, GLint y, GLsizei width)
1725 {
1726 const GLint yoffset = 0, zoffset = 0;
1727 const GLsizei height = 1;
1728 st_copy_texsubimage(ctx, target, level,
1729 xoffset, yoffset, zoffset, /* destX,Y,Z */
1730 x, y, width, height); /* src X, Y, size */
1731 }
1732
1733
1734 static void
1735 st_CopyTexSubImage2D(GLcontext * ctx, GLenum target, GLint level,
1736 GLint xoffset, GLint yoffset,
1737 GLint x, GLint y, GLsizei width, GLsizei height)
1738 {
1739 const GLint zoffset = 0;
1740 st_copy_texsubimage(ctx, target, level,
1741 xoffset, yoffset, zoffset, /* destX,Y,Z */
1742 x, y, width, height); /* src X, Y, size */
1743 }
1744
1745
1746 static void
1747 st_CopyTexSubImage3D(GLcontext * ctx, GLenum target, GLint level,
1748 GLint xoffset, GLint yoffset, GLint zoffset,
1749 GLint x, GLint y, GLsizei width, GLsizei height)
1750 {
1751 st_copy_texsubimage(ctx, target, level,
1752 xoffset, yoffset, zoffset, /* destX,Y,Z */
1753 x, y, width, height); /* src X, Y, size */
1754 }
1755
1756
1757 static void
1758 copy_image_data_to_texture(struct st_context *st,
1759 struct st_texture_object *stObj,
1760 GLuint dstLevel,
1761 struct st_texture_image *stImage)
1762 {
1763 if (stImage->pt) {
1764 /* Copy potentially with the blitter:
1765 */
1766 st_texture_image_copy(st->pipe,
1767 stObj->pt, dstLevel, /* dest texture, level */
1768 stImage->pt, /* src texture */
1769 stImage->face);
1770
1771 pipe_resource_reference(&stImage->pt, NULL);
1772 }
1773 else if (stImage->base.Data) {
1774 /* More straightforward upload.
1775 */
1776 st_teximage_flush_before_map(st, stObj->pt, stImage->face, dstLevel,
1777 PIPE_TRANSFER_WRITE);
1778
1779 st_texture_image_data(st,
1780 stObj->pt,
1781 stImage->face,
1782 dstLevel,
1783 stImage->base.Data,
1784 stImage->base.RowStride *
1785 util_format_get_blocksize(stObj->pt->format),
1786 stImage->base.RowStride *
1787 stImage->base.Height *
1788 util_format_get_blocksize(stObj->pt->format));
1789 _mesa_align_free(stImage->base.Data);
1790 stImage->base.Data = NULL;
1791 }
1792
1793 pipe_resource_reference(&stImage->pt, stObj->pt);
1794 }
1795
1796
1797 /**
1798 * Called during state validation. When this function is finished,
1799 * the texture object should be ready for rendering.
1800 * \return GL_TRUE for success, GL_FALSE for failure (out of mem)
1801 */
1802 GLboolean
1803 st_finalize_texture(GLcontext *ctx,
1804 struct pipe_context *pipe,
1805 struct gl_texture_object *tObj,
1806 GLboolean *needFlush)
1807 {
1808 struct st_context *st = st_context(ctx);
1809 struct st_texture_object *stObj = st_texture_object(tObj);
1810 const GLuint nr_faces = (stObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
1811 GLuint blockSize, face;
1812 struct st_texture_image *firstImage;
1813
1814 *needFlush = GL_FALSE;
1815
1816 if (stObj->base._Complete) {
1817 /* The texture is complete and we know exactly how many mipmap levels
1818 * are present/needed. This is conditional because we may be called
1819 * from the st_generate_mipmap() function when the texture object is
1820 * incomplete. In that case, we'll have set stObj->lastLevel before
1821 * we get here.
1822 */
1823 if (stObj->base.MinFilter == GL_LINEAR ||
1824 stObj->base.MinFilter == GL_NEAREST)
1825 stObj->lastLevel = stObj->base.BaseLevel;
1826 else
1827 stObj->lastLevel = stObj->base._MaxLevel - stObj->base.BaseLevel;
1828 }
1829
1830 firstImage = st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]);
1831
1832 /* If both firstImage and stObj point to a texture which can contain
1833 * all active images, favour firstImage. Note that because of the
1834 * completeness requirement, we know that the image dimensions
1835 * will match.
1836 */
1837 if (firstImage->pt &&
1838 firstImage->pt != stObj->pt &&
1839 firstImage->pt->last_level >= stObj->lastLevel) {
1840 pipe_resource_reference(&stObj->pt, firstImage->pt);
1841 pipe_sampler_view_reference(&stObj->sampler_view, NULL);
1842 }
1843
1844 /* bytes per pixel block (blocks are usually 1x1) */
1845 blockSize = _mesa_get_format_bytes(firstImage->base.TexFormat);
1846
1847 /* If we already have a gallium texture, check that it matches the texture
1848 * object's format, target, size, num_levels, etc.
1849 */
1850 if (stObj->pt) {
1851 const enum pipe_format fmt =
1852 st_mesa_format_to_pipe_format(firstImage->base.TexFormat);
1853 if (stObj->pt->target != gl_target_to_pipe(stObj->base.Target) ||
1854 stObj->pt->format != fmt ||
1855 stObj->pt->last_level < stObj->lastLevel ||
1856 stObj->pt->width0 != firstImage->base.Width2 ||
1857 stObj->pt->height0 != firstImage->base.Height2 ||
1858 stObj->pt->depth0 != firstImage->base.Depth2)
1859 {
1860 pipe_resource_reference(&stObj->pt, NULL);
1861 pipe_sampler_view_reference(&stObj->sampler_view, NULL);
1862 st->dirty.st |= ST_NEW_FRAMEBUFFER;
1863 }
1864 }
1865
1866 /* May need to create a new gallium texture:
1867 */
1868 if (!stObj->pt) {
1869 const enum pipe_format fmt =
1870 st_mesa_format_to_pipe_format(firstImage->base.TexFormat);
1871 GLuint bindings = default_bindings(st, fmt);
1872
1873 stObj->pt = st_texture_create(st,
1874 gl_target_to_pipe(stObj->base.Target),
1875 fmt,
1876 stObj->lastLevel,
1877 firstImage->base.Width2,
1878 firstImage->base.Height2,
1879 firstImage->base.Depth2,
1880 bindings);
1881
1882 if (!stObj->pt) {
1883 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
1884 return GL_FALSE;
1885 }
1886 }
1887
1888 /* Pull in any images not in the object's texture:
1889 */
1890 for (face = 0; face < nr_faces; face++) {
1891 GLuint level;
1892 for (level = 0; level <= stObj->lastLevel; level++) {
1893 struct st_texture_image *stImage =
1894 st_texture_image(stObj->base.Image[face][stObj->base.BaseLevel + level]);
1895
1896 /* Need to import images in main memory or held in other textures.
1897 */
1898 if (stImage && stObj->pt != stImage->pt) {
1899 copy_image_data_to_texture(st, stObj, level, stImage);
1900 *needFlush = GL_TRUE;
1901 }
1902 }
1903 }
1904
1905 return GL_TRUE;
1906 }
1907
1908
1909 /**
1910 * Returns pointer to a default/dummy texture.
1911 * This is typically used when the current shader has tex/sample instructions
1912 * but the user has not provided a (any) texture(s).
1913 */
1914 struct gl_texture_object *
1915 st_get_default_texture(struct st_context *st)
1916 {
1917 if (!st->default_texture) {
1918 static const GLenum target = GL_TEXTURE_2D;
1919 GLubyte pixels[16][16][4];
1920 struct gl_texture_object *texObj;
1921 struct gl_texture_image *texImg;
1922 GLuint i, j;
1923
1924 /* The ARB_fragment_program spec says (0,0,0,1) should be returned
1925 * when attempting to sample incomplete textures.
1926 */
1927 for (i = 0; i < 16; i++) {
1928 for (j = 0; j < 16; j++) {
1929 pixels[i][j][0] = 0;
1930 pixels[i][j][1] = 0;
1931 pixels[i][j][2] = 0;
1932 pixels[i][j][3] = 255;
1933 }
1934 }
1935
1936 texObj = st->ctx->Driver.NewTextureObject(st->ctx, 0, target);
1937
1938 texImg = _mesa_get_tex_image(st->ctx, texObj, target, 0);
1939
1940 _mesa_init_teximage_fields(st->ctx, target, texImg,
1941 16, 16, 1, 0, /* w, h, d, border */
1942 GL_RGBA);
1943
1944 st_TexImage(st->ctx, 2, target,
1945 0, GL_RGBA, /* level, intformat */
1946 16, 16, 1, 0, /* w, h, d, border */
1947 GL_RGBA, GL_UNSIGNED_BYTE, pixels,
1948 &st->ctx->DefaultPacking,
1949 texObj, texImg,
1950 0, 0);
1951
1952 texObj->MinFilter = GL_NEAREST;
1953 texObj->MagFilter = GL_NEAREST;
1954 texObj->_Complete = GL_TRUE;
1955
1956 st->default_texture = texObj;
1957 }
1958 return st->default_texture;
1959 }
1960
1961
1962 void
1963 st_init_texture_functions(struct dd_function_table *functions)
1964 {
1965 functions->ChooseTextureFormat = st_ChooseTextureFormat;
1966 functions->TexImage1D = st_TexImage1D;
1967 functions->TexImage2D = st_TexImage2D;
1968 functions->TexImage3D = st_TexImage3D;
1969 functions->TexSubImage1D = st_TexSubImage1D;
1970 functions->TexSubImage2D = st_TexSubImage2D;
1971 functions->TexSubImage3D = st_TexSubImage3D;
1972 functions->CompressedTexSubImage1D = st_CompressedTexSubImage1D;
1973 functions->CompressedTexSubImage2D = st_CompressedTexSubImage2D;
1974 functions->CompressedTexSubImage3D = st_CompressedTexSubImage3D;
1975 functions->CopyTexImage1D = st_CopyTexImage1D;
1976 functions->CopyTexImage2D = st_CopyTexImage2D;
1977 functions->CopyTexSubImage1D = st_CopyTexSubImage1D;
1978 functions->CopyTexSubImage2D = st_CopyTexSubImage2D;
1979 functions->CopyTexSubImage3D = st_CopyTexSubImage3D;
1980 functions->GenerateMipmap = st_generate_mipmap;
1981
1982 functions->GetTexImage = st_GetTexImage;
1983
1984 /* compressed texture functions */
1985 functions->CompressedTexImage2D = st_CompressedTexImage2D;
1986 functions->GetCompressedTexImage = st_GetCompressedTexImage;
1987
1988 functions->NewTextureObject = st_NewTextureObject;
1989 functions->NewTextureImage = st_NewTextureImage;
1990 functions->DeleteTexture = st_DeleteTextureObject;
1991 functions->FreeTexImageData = st_FreeTextureImageData;
1992 functions->UpdateTexturePalette = 0;
1993
1994 functions->TextureMemCpy = do_memcpy;
1995
1996 /* XXX Temporary until we can query pipe's texture sizes */
1997 functions->TestProxyTexImage = _mesa_test_proxy_teximage;
1998 }