2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
29 #include "main/glheader.h"
30 #include "main/macros.h"
31 #include "main/mtypes.h"
32 #include "main/enums.h"
33 #include "main/formats.h"
34 #include "main/colortab.h"
35 #include "main/convolve.h"
36 #include "main/context.h"
37 #include "main/mipmap.h"
39 #include "main/simple_list.h"
40 #include "main/texobj.h"
41 #include "main/texstore.h"
43 #include "via_context.h"
46 #include "via_ioctl.h"
47 #include "via_3d_reg.h"
50 viaChooseTexFormat( GLcontext
*ctx
, GLint internalFormat
,
51 GLenum format
, GLenum type
)
53 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
54 const GLboolean do32bpt
= ( vmesa
->viaScreen
->bitsPerPixel
== 32
55 /* && vmesa->viaScreen->textureSize > 4*1024*1024 */
59 switch ( internalFormat
) {
62 case GL_COMPRESSED_RGBA
:
63 if ( format
== GL_BGRA
) {
64 if ( type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
65 type
== GL_UNSIGNED_BYTE
) {
66 return MESA_FORMAT_ARGB8888
;
68 else if ( type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
69 return MESA_FORMAT_ARGB4444
;
71 else if ( type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
72 return MESA_FORMAT_ARGB1555
;
75 else if ( type
== GL_UNSIGNED_BYTE
||
76 type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
77 type
== GL_UNSIGNED_INT_8_8_8_8
) {
78 return MESA_FORMAT_ARGB8888
;
80 return do32bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB4444
;
84 case GL_COMPRESSED_RGB
:
85 if ( format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) {
86 return MESA_FORMAT_RGB565
;
88 else if ( type
== GL_UNSIGNED_BYTE
) {
89 return MESA_FORMAT_ARGB8888
;
91 return do32bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_RGB565
;
97 return MESA_FORMAT_ARGB8888
;
101 return MESA_FORMAT_ARGB4444
;
104 return MESA_FORMAT_ARGB1555
;
110 return MESA_FORMAT_ARGB8888
;
115 return MESA_FORMAT_RGB565
;
122 case GL_COMPRESSED_ALPHA
:
123 return MESA_FORMAT_A8
;
131 case GL_COMPRESSED_LUMINANCE
:
132 return MESA_FORMAT_L8
;
135 case GL_LUMINANCE_ALPHA
:
136 case GL_LUMINANCE4_ALPHA4
:
137 case GL_LUMINANCE6_ALPHA2
:
138 case GL_LUMINANCE8_ALPHA8
:
139 case GL_LUMINANCE12_ALPHA4
:
140 case GL_LUMINANCE12_ALPHA12
:
141 case GL_LUMINANCE16_ALPHA16
:
142 case GL_COMPRESSED_LUMINANCE_ALPHA
:
143 return MESA_FORMAT_AL88
;
150 case GL_COMPRESSED_INTENSITY
:
151 return MESA_FORMAT_I8
;
154 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
155 type
== GL_UNSIGNED_BYTE
)
156 return MESA_FORMAT_YCBCR
;
158 return MESA_FORMAT_YCBCR_REV
;
160 case GL_COMPRESSED_RGB_FXT1_3DFX
:
161 return MESA_FORMAT_RGB_FXT1
;
162 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
163 return MESA_FORMAT_RGBA_FXT1
;
167 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
168 return MESA_FORMAT_RGB_DXT1
;
170 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
171 return MESA_FORMAT_RGBA_DXT1
;
175 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
176 return MESA_FORMAT_RGBA_DXT3
;
178 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
179 return MESA_FORMAT_RGBA_DXT5
;
182 case GL_COLOR_INDEX1_EXT
:
183 case GL_COLOR_INDEX2_EXT
:
184 case GL_COLOR_INDEX4_EXT
:
185 case GL_COLOR_INDEX8_EXT
:
186 case GL_COLOR_INDEX12_EXT
:
187 case GL_COLOR_INDEX16_EXT
:
188 return MESA_FORMAT_CI8
;
191 fprintf(stderr
, "unexpected texture format %s in %s\n",
192 _mesa_lookup_enum_by_nr(internalFormat
),
194 return MESA_FORMAT_NONE
;
197 return MESA_FORMAT_NONE
; /* never get here */
200 static int logbase2(int n
)
213 static const char *get_memtype_name( GLint memType
)
215 static const char *names
[] = {
223 return names
[memType
];
227 static GLboolean
viaMoveTexBuffers( struct via_context
*vmesa
,
228 struct via_tex_buffer
**buffers
,
232 struct via_tex_buffer
*newTexBuf
[VIA_MAX_TEXLEVELS
];
235 if (VIA_DEBUG
& DEBUG_TEXTURE
)
236 fprintf(stderr
, "%s to %s\n",
238 get_memtype_name(newMemType
));
240 memset(newTexBuf
, 0, sizeof(newTexBuf
));
242 /* First do all the allocations (or fail):
244 for (i
= 0; i
< nr
; i
++) {
245 if (buffers
[i
]->memType
!= newMemType
) {
247 /* Don't allow uploads in a thrash state. Should try and
248 * catch this earlier.
250 if (vmesa
->thrashing
&& newMemType
!= VIA_MEM_SYSTEM
)
253 newTexBuf
[i
] = via_alloc_texture(vmesa
,
262 /* Now copy all the image data and free the old texture memory.
264 for (i
= 0; i
< nr
; i
++) {
266 memcpy(newTexBuf
[i
]->bufAddr
,
270 newTexBuf
[i
]->image
= buffers
[i
]->image
;
271 newTexBuf
[i
]->image
->texMem
= newTexBuf
[i
];
272 newTexBuf
[i
]->image
->image
.Data
= newTexBuf
[i
]->bufAddr
;
273 via_free_texture(vmesa
, buffers
[i
]);
277 if (VIA_DEBUG
& DEBUG_TEXTURE
)
278 fprintf(stderr
, "%s - success\n", __FUNCTION__
);
283 /* Release any allocations made prior to failure:
285 if (VIA_DEBUG
& DEBUG_TEXTURE
)
286 fprintf(stderr
, "%s - failed\n", __FUNCTION__
);
288 for (i
= 0; i
< nr
; i
++) {
290 via_free_texture(vmesa
, newTexBuf
[i
]);
298 static GLboolean
viaMoveTexObject( struct via_context
*vmesa
,
299 struct via_texture_object
*viaObj
,
302 struct via_texture_image
**viaImage
=
303 (struct via_texture_image
**)&viaObj
->obj
.Image
[0][0];
304 struct via_tex_buffer
*buffers
[VIA_MAX_TEXLEVELS
];
307 for (i
= viaObj
->firstLevel
; i
<= viaObj
->lastLevel
; i
++)
308 buffers
[nr
++] = viaImage
[i
]->texMem
;
310 if (viaMoveTexBuffers( vmesa
, &buffers
[0], nr
, newMemType
)) {
311 viaObj
->memType
= newMemType
;
320 static GLboolean
viaSwapInTexObject( struct via_context
*vmesa
,
321 struct via_texture_object
*viaObj
)
323 const struct via_texture_image
*baseImage
=
324 (struct via_texture_image
*)viaObj
->obj
.Image
[0][viaObj
->obj
.BaseLevel
];
326 if (VIA_DEBUG
& DEBUG_TEXTURE
)
327 fprintf(stderr
, "%s\n", __FUNCTION__
);
329 if (baseImage
->texMem
->memType
!= VIA_MEM_SYSTEM
)
330 return viaMoveTexObject( vmesa
, viaObj
, baseImage
->texMem
->memType
);
332 return (viaMoveTexObject( vmesa
, viaObj
, VIA_MEM_AGP
) ||
333 viaMoveTexObject( vmesa
, viaObj
, VIA_MEM_VIDEO
));
337 /* This seems crude, but it asks a fairly pertinent question and gives
338 * an accurate answer:
340 static GLboolean
viaIsTexMemLow( struct via_context
*vmesa
,
343 struct via_tex_buffer
*buf
= via_alloc_texture(vmesa
, 512 * 1024, heap
);
347 via_free_texture(vmesa
, buf
);
352 /* Speculatively move texture images which haven't been used in a
353 * while back to system memory.
355 * TODO: only do this when texture memory is low.
359 * TODO: keep the fb/agp version hanging around and use the local
360 * version as backing store, so re-upload might be avoided.
362 * TODO: do this properly in the kernel...
364 GLboolean
viaSwapOutWork( struct via_context
*vmesa
)
366 struct via_tex_buffer
*s
, *tmp
;
370 if (VIA_DEBUG
& DEBUG_TEXTURE
)
371 fprintf(stderr
, "%s VID %d AGP %d SYS %d\n", __FUNCTION__
,
372 vmesa
->total_alloc
[VIA_MEM_VIDEO
],
373 vmesa
->total_alloc
[VIA_MEM_AGP
],
374 vmesa
->total_alloc
[VIA_MEM_SYSTEM
]);
377 for (heap
= VIA_MEM_VIDEO
; heap
<= VIA_MEM_AGP
; heap
++) {
378 GLuint nr
= 0, sz
= 0;
380 if (vmesa
->thrashing
) {
381 if (VIA_DEBUG
& DEBUG_TEXTURE
)
382 fprintf(stderr
, "Heap %d: trash flag\n", heap
);
383 target
= 1*1024*1024;
385 else if (viaIsTexMemLow(vmesa
, heap
)) {
386 if (VIA_DEBUG
& DEBUG_TEXTURE
)
387 fprintf(stderr
, "Heap %d: low memory\n", heap
);
391 if (VIA_DEBUG
& DEBUG_TEXTURE
)
392 fprintf(stderr
, "Heap %d: nothing to do\n", heap
);
396 foreach_s( s
, tmp
, &vmesa
->tex_image_list
[heap
] ) {
397 if (s
->lastUsed
< vmesa
->lastSwap
[1]) {
398 struct via_texture_object
*viaObj
=
399 (struct via_texture_object
*) s
->image
->image
.TexObject
;
401 if (VIA_DEBUG
& DEBUG_TEXTURE
)
403 "back copy tex sz %d, lastUsed %d lastSwap %d\n",
404 s
->size
, s
->lastUsed
, vmesa
->lastSwap
[1]);
406 if (viaMoveTexBuffers( vmesa
, &s
, 1, VIA_MEM_SYSTEM
)) {
407 viaObj
->memType
= VIA_MEM_MIXED
;
411 if (VIA_DEBUG
& DEBUG_TEXTURE
)
412 fprintf(stderr
, "Failed to back copy texture!\n");
422 vmesa
->thrashing
= GL_FALSE
; /* might not get set otherwise? */
427 assert(sz
== vmesa
->total_alloc
[heap
]);
429 if (VIA_DEBUG
& DEBUG_TEXTURE
)
430 fprintf(stderr
, "Heap %d: nr %d tot sz %d\n", heap
, nr
, sz
);
439 /* Basically, just collect the image dimensions and addresses for each
440 * image and update the texture object state accordingly.
442 static GLboolean
viaSetTexImages(GLcontext
*ctx
,
443 struct gl_texture_object
*texObj
)
445 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
446 struct via_texture_object
*viaObj
= (struct via_texture_object
*)texObj
;
447 const struct via_texture_image
*baseImage
=
448 (struct via_texture_image
*)texObj
->Image
[0][texObj
->BaseLevel
];
449 GLint firstLevel
, lastLevel
, numLevels
;
452 GLint i
, j
= 0, k
= 0, l
= 0, m
= 0;
456 GLuint heightExp
= 0;
458 switch (baseImage
->image
.TexFormat
) {
459 case MESA_FORMAT_ARGB8888
:
460 texFormat
= HC_HTXnFM_ARGB8888
;
462 case MESA_FORMAT_ARGB4444
:
463 texFormat
= HC_HTXnFM_ARGB4444
;
465 case MESA_FORMAT_RGB565
:
466 texFormat
= HC_HTXnFM_RGB565
;
468 case MESA_FORMAT_ARGB1555
:
469 texFormat
= HC_HTXnFM_ARGB1555
;
471 case MESA_FORMAT_RGB888
:
472 texFormat
= HC_HTXnFM_ARGB0888
;
475 texFormat
= HC_HTXnFM_L8
;
478 texFormat
= HC_HTXnFM_T8
;
480 case MESA_FORMAT_CI8
:
481 texFormat
= HC_HTXnFM_Index8
;
483 case MESA_FORMAT_AL88
:
484 texFormat
= HC_HTXnFM_AL88
;
487 texFormat
= HC_HTXnFM_A8
;
490 _mesa_problem(vmesa
->glCtx
, "Bad texture format in viaSetTexImages");
494 /* Compute which mipmap levels we really want to send to the hardware.
495 * This depends on the base image size, GL_TEXTURE_MIN_LOD,
496 * GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL, and GL_TEXTURE_MAX_LEVEL.
497 * Yes, this looks overly complicated, but it's all needed.
499 if (texObj
->MinFilter
== GL_LINEAR
|| texObj
->MinFilter
== GL_NEAREST
) {
500 firstLevel
= lastLevel
= texObj
->BaseLevel
;
503 firstLevel
= texObj
->BaseLevel
+ (GLint
)(texObj
->MinLod
+ 0.5);
504 firstLevel
= MAX2(firstLevel
, texObj
->BaseLevel
);
505 lastLevel
= texObj
->BaseLevel
+ (GLint
)(texObj
->MaxLod
+ 0.5);
506 lastLevel
= MAX2(lastLevel
, texObj
->BaseLevel
);
507 lastLevel
= MIN2(lastLevel
, texObj
->BaseLevel
+ baseImage
->image
.MaxLog2
);
508 lastLevel
= MIN2(lastLevel
, texObj
->MaxLevel
);
509 lastLevel
= MAX2(firstLevel
, lastLevel
); /* need at least one level */
512 numLevels
= lastLevel
- firstLevel
+ 1;
514 /* The hardware supports only 10 mipmap levels; ignore higher levels.
516 if ((numLevels
> 10) && (ctx
->Const
.MaxTextureLevels
> 10)) {
517 lastLevel
-= numLevels
- 10;
521 /* save these values, check if they effect the residency of the
524 if (viaObj
->firstLevel
!= firstLevel
||
525 viaObj
->lastLevel
!= lastLevel
) {
526 viaObj
->firstLevel
= firstLevel
;
527 viaObj
->lastLevel
= lastLevel
;
528 viaObj
->memType
= VIA_MEM_MIXED
;
531 if (VIA_DEBUG
& DEBUG_TEXTURE
& 0)
532 fprintf(stderr
, "%s, current memType: %s\n",
534 get_memtype_name(viaObj
->memType
));
537 if (viaObj
->memType
== VIA_MEM_MIXED
||
538 viaObj
->memType
== VIA_MEM_SYSTEM
) {
539 if (!viaSwapInTexObject(vmesa
, viaObj
)) {
540 if (VIA_DEBUG
& DEBUG_TEXTURE
)
541 if (!vmesa
->thrashing
)
542 fprintf(stderr
, "Thrashing flag set for frame %d\n",
544 vmesa
->thrashing
= GL_TRUE
;
549 if (viaObj
->memType
== VIA_MEM_AGP
)
550 viaObj
->regTexFM
= (HC_SubA_HTXnFM
<< 24) | HC_HTXnLoc_AGP
| texFormat
;
552 viaObj
->regTexFM
= (HC_SubA_HTXnFM
<< 24) | HC_HTXnLoc_Local
| texFormat
;
555 for (i
= 0; i
< numLevels
; i
++) {
556 struct via_texture_image
*viaImage
=
557 (struct via_texture_image
*)texObj
->Image
[0][firstLevel
+ i
];
559 w
= viaImage
->image
.WidthLog2
;
560 h
= viaImage
->image
.HeightLog2
;
561 p
= viaImage
->pitchLog2
;
563 assert(viaImage
->texMem
->memType
== viaObj
->memType
);
565 texBase
= viaImage
->texMem
->texBase
;
567 if (VIA_DEBUG
& DEBUG_TEXTURE
)
568 fprintf(stderr
, "%s: no texBase[%d]\n", __FUNCTION__
, i
);
572 /* Image has to remain resident until the coming fence is retired.
574 move_to_head( &vmesa
->tex_image_list
[viaImage
->texMem
->memType
],
576 viaImage
->texMem
->lastUsed
= vmesa
->lastBreadcrumbWrite
;
579 viaObj
->regTexBaseAndPitch
[i
].baseL
=
580 ((HC_SubA_HTXnL0BasL
+ i
) << 24) | (texBase
& 0xFFFFFF);
582 viaObj
->regTexBaseAndPitch
[i
].pitchLog2
=
583 ((HC_SubA_HTXnL0Pit
+ i
) << 24) | (p
<< 20);
586 /* The base high bytes for each 3 levels are packed
587 * together into one register:
591 basH
|= ((texBase
& 0xFF000000) >> (k
<< 3));
593 viaObj
->regTexBaseH
[j
] = ((j
+ HC_SubA_HTXnL012BasH
) << 24) | basH
;
597 /* Likewise, sets of 6 log2width and log2height values are
598 * packed into individual registers:
602 widthExp
|= (((GLuint
)w
& 0xF) << (m
<< 2));
603 heightExp
|= (((GLuint
)h
& 0xF) << (m
<< 2));
605 viaObj
->regTexWidthLog2
[l
] =
606 (l
+ HC_SubA_HTXnL0_5WE
) << 24 | widthExp
;
607 viaObj
->regTexHeightLog2
[l
] =
608 (l
+ HC_SubA_HTXnL0_5HE
) << 24 | heightExp
;
618 viaObj
->regTexBaseH
[j
] = ((j
+ HC_SubA_HTXnL012BasH
) << 24) | basH
;
621 viaObj
->regTexWidthLog2
[l
] = (l
+ HC_SubA_HTXnL0_5WE
) << 24 | widthExp
;
622 viaObj
->regTexHeightLog2
[l
] = (l
+ HC_SubA_HTXnL0_5HE
) << 24 | heightExp
;
629 GLboolean
viaUpdateTextureState( GLcontext
*ctx
)
631 struct gl_texture_unit
*texUnit
= ctx
->Texture
.Unit
;
634 for (i
= 0; i
< 2; i
++) {
635 if (texUnit
[i
]._ReallyEnabled
== TEXTURE_2D_BIT
||
636 texUnit
[i
]._ReallyEnabled
== TEXTURE_1D_BIT
) {
638 if (!viaSetTexImages(ctx
, texUnit
[i
]._Current
))
641 else if (texUnit
[i
]._ReallyEnabled
) {
656 static void viaTexImage(GLcontext
*ctx
,
658 GLenum target
, GLint level
,
659 GLint internalFormat
,
660 GLint width
, GLint height
, GLint border
,
661 GLenum format
, GLenum type
, const void *pixels
,
662 const struct gl_pixelstore_attrib
*packing
,
663 struct gl_texture_object
*texObj
,
664 struct gl_texture_image
*texImage
)
666 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
667 GLint postConvWidth
= width
;
668 GLint postConvHeight
= height
;
669 GLint texelBytes
, sizeInBytes
;
670 struct via_texture_object
*viaObj
= (struct via_texture_object
*)texObj
;
671 struct via_texture_image
*viaImage
= (struct via_texture_image
*)texImage
;
672 int heaps
[3], nheaps
, i
;
674 if (!is_empty_list(&vmesa
->freed_tex_buffers
)) {
675 viaCheckBreadcrumb(vmesa
, 0);
676 via_release_pending_textures(vmesa
);
679 if (ctx
->_ImageTransferState
& IMAGE_CONVOLUTION_BIT
) {
680 _mesa_adjust_image_for_convolution(ctx
, dims
, &postConvWidth
,
684 /* choose the texture format */
685 texImage
->TexFormat
= viaChooseTexFormat(ctx
, internalFormat
,
688 assert(texImage
->TexFormat
);
690 texelBytes
= _mesa_get_format_bytes(texImage
->TexFormat
);
692 /* Minimum pitch of 32 bytes */
693 if (postConvWidth
* texelBytes
< 32) {
694 postConvWidth
= 32 / texelBytes
;
695 texImage
->RowStride
= postConvWidth
;
698 assert(texImage
->RowStride
== postConvWidth
);
699 viaImage
->pitchLog2
= logbase2(postConvWidth
* texelBytes
);
701 /* allocate memory */
702 if (_mesa_is_format_compressed(texImage
->TexFormat
))
703 sizeInBytes
= _mesa_format_image_size(texImage
->TexFormat
,
708 sizeInBytes
= postConvWidth
* postConvHeight
* texelBytes
;
711 /* Attempt to allocate texture memory directly, otherwise use main
712 * memory and this texture will always be a fallback. FIXME!
714 * TODO: make room in agp if this fails.
715 * TODO: use fb ram for textures as well.
719 switch (viaObj
->memType
) {
720 case VIA_MEM_UNKNOWN
:
721 heaps
[0] = VIA_MEM_AGP
;
722 heaps
[1] = VIA_MEM_VIDEO
;
723 heaps
[2] = VIA_MEM_SYSTEM
;
728 heaps
[0] = viaObj
->memType
;
729 heaps
[1] = VIA_MEM_SYSTEM
;
735 heaps
[0] = VIA_MEM_SYSTEM
;
740 for (i
= 0; i
< nheaps
&& !viaImage
->texMem
; i
++) {
741 if (VIA_DEBUG
& DEBUG_TEXTURE
)
742 fprintf(stderr
, "try %s (obj %s)\n", get_memtype_name(heaps
[i
]),
743 get_memtype_name(viaObj
->memType
));
744 viaImage
->texMem
= via_alloc_texture(vmesa
, sizeInBytes
, heaps
[i
]);
747 if (!viaImage
->texMem
) {
748 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
752 if (VIA_DEBUG
& DEBUG_TEXTURE
)
753 fprintf(stderr
, "upload %d bytes to %s\n", sizeInBytes
,
754 get_memtype_name(viaImage
->texMem
->memType
));
756 viaImage
->texMem
->image
= viaImage
;
757 texImage
->Data
= viaImage
->texMem
->bufAddr
;
759 if (viaObj
->memType
== VIA_MEM_UNKNOWN
)
760 viaObj
->memType
= viaImage
->texMem
->memType
;
761 else if (viaObj
->memType
!= viaImage
->texMem
->memType
)
762 viaObj
->memType
= VIA_MEM_MIXED
;
764 if (VIA_DEBUG
& DEBUG_TEXTURE
)
765 fprintf(stderr
, "%s, obj %s, image : %s\n",
767 get_memtype_name(viaObj
->memType
),
768 get_memtype_name(viaImage
->texMem
->memType
));
770 vmesa
->clearTexCache
= 1;
772 pixels
= _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, 1,
774 pixels
, packing
, "glTexImage");
776 /* Note: we check for a NULL image pointer here, _after_ we allocated
777 * memory for the texture. That's what the GL spec calls for.
785 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
786 dstRowStride
= _mesa_format_row_stride(texImage
->TexFormat
, width
);
789 dstRowStride
= postConvWidth
* _mesa_get_format_bytes(texImage
->TexFormat
);
791 success
= _mesa_texstore(ctx
, dims
,
792 texImage
->_BaseFormat
,
795 0, 0, 0, /* dstX/Y/Zoffset */
797 texImage
->ImageOffsets
,
799 format
, type
, pixels
, packing
);
801 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
805 _mesa_unmap_teximage_pbo(ctx
, packing
);
808 static void viaTexImage2D(GLcontext
*ctx
,
809 GLenum target
, GLint level
,
810 GLint internalFormat
,
811 GLint width
, GLint height
, GLint border
,
812 GLenum format
, GLenum type
, const void *pixels
,
813 const struct gl_pixelstore_attrib
*packing
,
814 struct gl_texture_object
*texObj
,
815 struct gl_texture_image
*texImage
)
817 viaTexImage( ctx
, 2, target
, level
,
818 internalFormat
, width
, height
, border
,
819 format
, type
, pixels
,
820 packing
, texObj
, texImage
);
823 static void viaTexSubImage2D(GLcontext
*ctx
,
826 GLint xoffset
, GLint yoffset
,
827 GLsizei width
, GLsizei height
,
828 GLenum format
, GLenum type
,
829 const GLvoid
*pixels
,
830 const struct gl_pixelstore_attrib
*packing
,
831 struct gl_texture_object
*texObj
,
832 struct gl_texture_image
*texImage
)
834 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
836 viaWaitIdle(vmesa
, GL_TRUE
);
837 vmesa
->clearTexCache
= 1;
839 _mesa_store_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
, width
,
840 height
, format
, type
, pixels
, packing
, texObj
,
844 static void viaTexImage1D(GLcontext
*ctx
,
845 GLenum target
, GLint level
,
846 GLint internalFormat
,
847 GLint width
, GLint border
,
848 GLenum format
, GLenum type
, const void *pixels
,
849 const struct gl_pixelstore_attrib
*packing
,
850 struct gl_texture_object
*texObj
,
851 struct gl_texture_image
*texImage
)
853 viaTexImage( ctx
, 1, target
, level
,
854 internalFormat
, width
, 1, border
,
855 format
, type
, pixels
,
856 packing
, texObj
, texImage
);
859 static void viaTexSubImage1D(GLcontext
*ctx
,
864 GLenum format
, GLenum type
,
865 const GLvoid
*pixels
,
866 const struct gl_pixelstore_attrib
*packing
,
867 struct gl_texture_object
*texObj
,
868 struct gl_texture_image
*texImage
)
870 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
872 viaWaitIdle(vmesa
, GL_TRUE
);
873 vmesa
->clearTexCache
= 1;
875 _mesa_store_texsubimage1d(ctx
, target
, level
, xoffset
, width
,
876 format
, type
, pixels
, packing
, texObj
,
882 static GLboolean
viaIsTextureResident(GLcontext
*ctx
,
883 struct gl_texture_object
*texObj
)
885 struct via_texture_object
*viaObj
=
886 (struct via_texture_object
*)texObj
;
888 return (viaObj
->memType
== VIA_MEM_AGP
||
889 viaObj
->memType
== VIA_MEM_VIDEO
);
894 static struct gl_texture_image
*viaNewTextureImage( GLcontext
*ctx
)
897 return (struct gl_texture_image
*)CALLOC_STRUCT(via_texture_image
);
901 static struct gl_texture_object
*viaNewTextureObject( GLcontext
*ctx
,
905 struct via_texture_object
*obj
= CALLOC_STRUCT(via_texture_object
);
907 _mesa_initialize_texture_object(&obj
->obj
, name
, target
);
910 obj
->memType
= VIA_MEM_UNKNOWN
;
916 static void viaFreeTextureImageData( GLcontext
*ctx
,
917 struct gl_texture_image
*texImage
)
919 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
920 struct via_texture_image
*image
= (struct via_texture_image
*)texImage
;
923 via_free_texture(vmesa
, image
->texMem
);
924 image
->texMem
= NULL
;
927 texImage
->Data
= NULL
;
933 void viaInitTextureFuncs(struct dd_function_table
* functions
)
935 functions
->ChooseTextureFormat
= viaChooseTexFormat
;
936 functions
->TexImage1D
= viaTexImage1D
;
937 functions
->TexImage2D
= viaTexImage2D
;
938 functions
->TexSubImage1D
= viaTexSubImage1D
;
939 functions
->TexSubImage2D
= viaTexSubImage2D
;
941 functions
->NewTextureObject
= viaNewTextureObject
;
942 functions
->NewTextureImage
= viaNewTextureImage
;
943 functions
->DeleteTexture
= _mesa_delete_texture_object
;
944 functions
->FreeTexImageData
= viaFreeTextureImageData
;
946 #if 0 && defined( USE_SSE_ASM )
948 * XXX this code is disabled for now because the via_sse_memcpy()
949 * routine causes segfaults with flightgear.
950 * See Mesa3d-dev mail list messages from 7/15/2005 for details.
951 * Note that this function is currently disabled in via_tris.c too.
953 if (getenv("VIA_NO_SSE"))
954 functions
->TextureMemCpy
= _mesa_memcpy
;
956 functions
->TextureMemCpy
= via_sse_memcpy
;
958 functions
->TextureMemCpy
= _mesa_memcpy
;
961 functions
->UpdateTexturePalette
= 0;
962 functions
->IsTextureResident
= viaIsTextureResident
;