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