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/context.h"
36 #include "main/mipmap.h"
38 #include "main/simple_list.h"
39 #include "main/texobj.h"
40 #include "main/texstore.h"
42 #include "via_context.h"
45 #include "via_ioctl.h"
46 #include "via_3d_reg.h"
49 viaChooseTexFormat( GLcontext
*ctx
, GLint internalFormat
,
50 GLenum format
, GLenum type
)
52 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
53 const GLboolean do32bpt
= ( vmesa
->viaScreen
->bitsPerPixel
== 32
54 /* && vmesa->viaScreen->textureSize > 4*1024*1024 */
58 switch ( internalFormat
) {
61 case GL_COMPRESSED_RGBA
:
62 if ( format
== GL_BGRA
) {
63 if ( type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
64 type
== GL_UNSIGNED_BYTE
) {
65 return MESA_FORMAT_ARGB8888
;
67 else if ( type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
68 return MESA_FORMAT_ARGB4444
;
70 else if ( type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
71 return MESA_FORMAT_ARGB1555
;
74 else if ( type
== GL_UNSIGNED_BYTE
||
75 type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
76 type
== GL_UNSIGNED_INT_8_8_8_8
) {
77 return MESA_FORMAT_ARGB8888
;
79 return do32bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB4444
;
83 case GL_COMPRESSED_RGB
:
84 if ( format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) {
85 return MESA_FORMAT_RGB565
;
87 else if ( type
== GL_UNSIGNED_BYTE
) {
88 return MESA_FORMAT_ARGB8888
;
90 return do32bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_RGB565
;
96 return MESA_FORMAT_ARGB8888
;
100 return MESA_FORMAT_ARGB4444
;
103 return MESA_FORMAT_ARGB1555
;
109 return MESA_FORMAT_ARGB8888
;
114 return MESA_FORMAT_RGB565
;
121 case GL_COMPRESSED_ALPHA
:
122 return MESA_FORMAT_A8
;
130 case GL_COMPRESSED_LUMINANCE
:
131 return MESA_FORMAT_L8
;
134 case GL_LUMINANCE_ALPHA
:
135 case GL_LUMINANCE4_ALPHA4
:
136 case GL_LUMINANCE6_ALPHA2
:
137 case GL_LUMINANCE8_ALPHA8
:
138 case GL_LUMINANCE12_ALPHA4
:
139 case GL_LUMINANCE12_ALPHA12
:
140 case GL_LUMINANCE16_ALPHA16
:
141 case GL_COMPRESSED_LUMINANCE_ALPHA
:
142 return MESA_FORMAT_AL88
;
149 case GL_COMPRESSED_INTENSITY
:
150 return MESA_FORMAT_I8
;
153 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
154 type
== GL_UNSIGNED_BYTE
)
155 return MESA_FORMAT_YCBCR
;
157 return MESA_FORMAT_YCBCR_REV
;
159 case GL_COMPRESSED_RGB_FXT1_3DFX
:
160 return MESA_FORMAT_RGB_FXT1
;
161 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
162 return MESA_FORMAT_RGBA_FXT1
;
166 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
167 return MESA_FORMAT_RGB_DXT1
;
169 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
170 return MESA_FORMAT_RGBA_DXT1
;
174 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
175 return MESA_FORMAT_RGBA_DXT3
;
177 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
178 return MESA_FORMAT_RGBA_DXT5
;
181 case GL_COLOR_INDEX1_EXT
:
182 case GL_COLOR_INDEX2_EXT
:
183 case GL_COLOR_INDEX4_EXT
:
184 case GL_COLOR_INDEX8_EXT
:
185 case GL_COLOR_INDEX12_EXT
:
186 case GL_COLOR_INDEX16_EXT
:
187 return MESA_FORMAT_CI8
;
190 fprintf(stderr
, "unexpected texture format %s in %s\n",
191 _mesa_lookup_enum_by_nr(internalFormat
),
193 return MESA_FORMAT_NONE
;
196 return MESA_FORMAT_NONE
; /* never get here */
199 static int logbase2(int n
)
212 static const char *get_memtype_name( GLint memType
)
214 static const char *names
[] = {
222 return names
[memType
];
226 static GLboolean
viaMoveTexBuffers( struct via_context
*vmesa
,
227 struct via_tex_buffer
**buffers
,
231 struct via_tex_buffer
*newTexBuf
[VIA_MAX_TEXLEVELS
];
234 if (VIA_DEBUG
& DEBUG_TEXTURE
)
235 fprintf(stderr
, "%s to %s\n",
237 get_memtype_name(newMemType
));
239 memset(newTexBuf
, 0, sizeof(newTexBuf
));
241 /* First do all the allocations (or fail):
243 for (i
= 0; i
< nr
; i
++) {
244 if (buffers
[i
]->memType
!= newMemType
) {
246 /* Don't allow uploads in a thrash state. Should try and
247 * catch this earlier.
249 if (vmesa
->thrashing
&& newMemType
!= VIA_MEM_SYSTEM
)
252 newTexBuf
[i
] = via_alloc_texture(vmesa
,
261 /* Now copy all the image data and free the old texture memory.
263 for (i
= 0; i
< nr
; i
++) {
265 memcpy(newTexBuf
[i
]->bufAddr
,
269 newTexBuf
[i
]->image
= buffers
[i
]->image
;
270 newTexBuf
[i
]->image
->texMem
= newTexBuf
[i
];
271 newTexBuf
[i
]->image
->image
.Data
= newTexBuf
[i
]->bufAddr
;
272 via_free_texture(vmesa
, buffers
[i
]);
276 if (VIA_DEBUG
& DEBUG_TEXTURE
)
277 fprintf(stderr
, "%s - success\n", __FUNCTION__
);
282 /* Release any allocations made prior to failure:
284 if (VIA_DEBUG
& DEBUG_TEXTURE
)
285 fprintf(stderr
, "%s - failed\n", __FUNCTION__
);
287 for (i
= 0; i
< nr
; i
++) {
289 via_free_texture(vmesa
, newTexBuf
[i
]);
297 static GLboolean
viaMoveTexObject( struct via_context
*vmesa
,
298 struct via_texture_object
*viaObj
,
301 struct via_texture_image
**viaImage
=
302 (struct via_texture_image
**)&viaObj
->obj
.Image
[0][0];
303 struct via_tex_buffer
*buffers
[VIA_MAX_TEXLEVELS
];
306 for (i
= viaObj
->firstLevel
; i
<= viaObj
->lastLevel
; i
++)
307 buffers
[nr
++] = viaImage
[i
]->texMem
;
309 if (viaMoveTexBuffers( vmesa
, &buffers
[0], nr
, newMemType
)) {
310 viaObj
->memType
= newMemType
;
319 static GLboolean
viaSwapInTexObject( struct via_context
*vmesa
,
320 struct via_texture_object
*viaObj
)
322 const struct via_texture_image
*baseImage
=
323 (struct via_texture_image
*)viaObj
->obj
.Image
[0][viaObj
->obj
.BaseLevel
];
325 if (VIA_DEBUG
& DEBUG_TEXTURE
)
326 fprintf(stderr
, "%s\n", __FUNCTION__
);
328 if (baseImage
->texMem
->memType
!= VIA_MEM_SYSTEM
)
329 return viaMoveTexObject( vmesa
, viaObj
, baseImage
->texMem
->memType
);
331 return (viaMoveTexObject( vmesa
, viaObj
, VIA_MEM_AGP
) ||
332 viaMoveTexObject( vmesa
, viaObj
, VIA_MEM_VIDEO
));
336 /* This seems crude, but it asks a fairly pertinent question and gives
337 * an accurate answer:
339 static GLboolean
viaIsTexMemLow( struct via_context
*vmesa
,
342 struct via_tex_buffer
*buf
= via_alloc_texture(vmesa
, 512 * 1024, heap
);
346 via_free_texture(vmesa
, buf
);
351 /* Speculatively move texture images which haven't been used in a
352 * while back to system memory.
354 * TODO: only do this when texture memory is low.
358 * TODO: keep the fb/agp version hanging around and use the local
359 * version as backing store, so re-upload might be avoided.
361 * TODO: do this properly in the kernel...
363 GLboolean
viaSwapOutWork( struct via_context
*vmesa
)
365 struct via_tex_buffer
*s
, *tmp
;
369 if (VIA_DEBUG
& DEBUG_TEXTURE
)
370 fprintf(stderr
, "%s VID %d AGP %d SYS %d\n", __FUNCTION__
,
371 vmesa
->total_alloc
[VIA_MEM_VIDEO
],
372 vmesa
->total_alloc
[VIA_MEM_AGP
],
373 vmesa
->total_alloc
[VIA_MEM_SYSTEM
]);
376 for (heap
= VIA_MEM_VIDEO
; heap
<= VIA_MEM_AGP
; heap
++) {
377 GLuint nr
= 0, sz
= 0;
379 if (vmesa
->thrashing
) {
380 if (VIA_DEBUG
& DEBUG_TEXTURE
)
381 fprintf(stderr
, "Heap %d: trash flag\n", heap
);
382 target
= 1*1024*1024;
384 else if (viaIsTexMemLow(vmesa
, heap
)) {
385 if (VIA_DEBUG
& DEBUG_TEXTURE
)
386 fprintf(stderr
, "Heap %d: low memory\n", heap
);
390 if (VIA_DEBUG
& DEBUG_TEXTURE
)
391 fprintf(stderr
, "Heap %d: nothing to do\n", heap
);
395 foreach_s( s
, tmp
, &vmesa
->tex_image_list
[heap
] ) {
396 if (s
->lastUsed
< vmesa
->lastSwap
[1]) {
397 struct via_texture_object
*viaObj
=
398 (struct via_texture_object
*) s
->image
->image
.TexObject
;
400 if (VIA_DEBUG
& DEBUG_TEXTURE
)
402 "back copy tex sz %d, lastUsed %d lastSwap %d\n",
403 s
->size
, s
->lastUsed
, vmesa
->lastSwap
[1]);
405 if (viaMoveTexBuffers( vmesa
, &s
, 1, VIA_MEM_SYSTEM
)) {
406 viaObj
->memType
= VIA_MEM_MIXED
;
410 if (VIA_DEBUG
& DEBUG_TEXTURE
)
411 fprintf(stderr
, "Failed to back copy texture!\n");
421 vmesa
->thrashing
= GL_FALSE
; /* might not get set otherwise? */
426 assert(sz
== vmesa
->total_alloc
[heap
]);
428 if (VIA_DEBUG
& DEBUG_TEXTURE
)
429 fprintf(stderr
, "Heap %d: nr %d tot sz %d\n", heap
, nr
, sz
);
438 /* Basically, just collect the image dimensions and addresses for each
439 * image and update the texture object state accordingly.
441 static GLboolean
viaSetTexImages(GLcontext
*ctx
,
442 struct gl_texture_object
*texObj
)
444 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
445 struct via_texture_object
*viaObj
= (struct via_texture_object
*)texObj
;
446 const struct via_texture_image
*baseImage
=
447 (struct via_texture_image
*)texObj
->Image
[0][texObj
->BaseLevel
];
448 GLint firstLevel
, lastLevel
, numLevels
;
451 GLint i
, j
= 0, k
= 0, l
= 0, m
= 0;
455 GLuint heightExp
= 0;
457 switch (baseImage
->image
.TexFormat
) {
458 case MESA_FORMAT_ARGB8888
:
459 texFormat
= HC_HTXnFM_ARGB8888
;
461 case MESA_FORMAT_ARGB4444
:
462 texFormat
= HC_HTXnFM_ARGB4444
;
464 case MESA_FORMAT_RGB565
:
465 texFormat
= HC_HTXnFM_RGB565
;
467 case MESA_FORMAT_ARGB1555
:
468 texFormat
= HC_HTXnFM_ARGB1555
;
470 case MESA_FORMAT_RGB888
:
471 texFormat
= HC_HTXnFM_ARGB0888
;
474 texFormat
= HC_HTXnFM_L8
;
477 texFormat
= HC_HTXnFM_T8
;
479 case MESA_FORMAT_CI8
:
480 texFormat
= HC_HTXnFM_Index8
;
482 case MESA_FORMAT_AL88
:
483 texFormat
= HC_HTXnFM_AL88
;
486 texFormat
= HC_HTXnFM_A8
;
489 _mesa_problem(vmesa
->glCtx
, "Bad texture format in viaSetTexImages");
493 /* Compute which mipmap levels we really want to send to the hardware.
494 * This depends on the base image size, GL_TEXTURE_MIN_LOD,
495 * GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL, and GL_TEXTURE_MAX_LEVEL.
496 * Yes, this looks overly complicated, but it's all needed.
498 if (texObj
->MinFilter
== GL_LINEAR
|| texObj
->MinFilter
== GL_NEAREST
) {
499 firstLevel
= lastLevel
= texObj
->BaseLevel
;
502 firstLevel
= texObj
->BaseLevel
+ (GLint
)(texObj
->MinLod
+ 0.5);
503 firstLevel
= MAX2(firstLevel
, texObj
->BaseLevel
);
504 lastLevel
= texObj
->BaseLevel
+ (GLint
)(texObj
->MaxLod
+ 0.5);
505 lastLevel
= MAX2(lastLevel
, texObj
->BaseLevel
);
506 lastLevel
= MIN2(lastLevel
, texObj
->BaseLevel
+ baseImage
->image
.MaxLog2
);
507 lastLevel
= MIN2(lastLevel
, texObj
->MaxLevel
);
508 lastLevel
= MAX2(firstLevel
, lastLevel
); /* need at least one level */
511 numLevels
= lastLevel
- firstLevel
+ 1;
513 /* The hardware supports only 10 mipmap levels; ignore higher levels.
515 if ((numLevels
> 10) && (ctx
->Const
.MaxTextureLevels
> 10)) {
516 lastLevel
-= numLevels
- 10;
520 /* save these values, check if they effect the residency of the
523 if (viaObj
->firstLevel
!= firstLevel
||
524 viaObj
->lastLevel
!= lastLevel
) {
525 viaObj
->firstLevel
= firstLevel
;
526 viaObj
->lastLevel
= lastLevel
;
527 viaObj
->memType
= VIA_MEM_MIXED
;
530 if (VIA_DEBUG
& DEBUG_TEXTURE
& 0)
531 fprintf(stderr
, "%s, current memType: %s\n",
533 get_memtype_name(viaObj
->memType
));
536 if (viaObj
->memType
== VIA_MEM_MIXED
||
537 viaObj
->memType
== VIA_MEM_SYSTEM
) {
538 if (!viaSwapInTexObject(vmesa
, viaObj
)) {
539 if (VIA_DEBUG
& DEBUG_TEXTURE
)
540 if (!vmesa
->thrashing
)
541 fprintf(stderr
, "Thrashing flag set for frame %d\n",
543 vmesa
->thrashing
= GL_TRUE
;
548 if (viaObj
->memType
== VIA_MEM_AGP
)
549 viaObj
->regTexFM
= (HC_SubA_HTXnFM
<< 24) | HC_HTXnLoc_AGP
| texFormat
;
551 viaObj
->regTexFM
= (HC_SubA_HTXnFM
<< 24) | HC_HTXnLoc_Local
| texFormat
;
554 for (i
= 0; i
< numLevels
; i
++) {
555 struct via_texture_image
*viaImage
=
556 (struct via_texture_image
*)texObj
->Image
[0][firstLevel
+ i
];
558 w
= viaImage
->image
.WidthLog2
;
559 h
= viaImage
->image
.HeightLog2
;
560 p
= viaImage
->pitchLog2
;
562 assert(viaImage
->texMem
->memType
== viaObj
->memType
);
564 texBase
= viaImage
->texMem
->texBase
;
566 if (VIA_DEBUG
& DEBUG_TEXTURE
)
567 fprintf(stderr
, "%s: no texBase[%d]\n", __FUNCTION__
, i
);
571 /* Image has to remain resident until the coming fence is retired.
573 move_to_head( &vmesa
->tex_image_list
[viaImage
->texMem
->memType
],
575 viaImage
->texMem
->lastUsed
= vmesa
->lastBreadcrumbWrite
;
578 viaObj
->regTexBaseAndPitch
[i
].baseL
=
579 ((HC_SubA_HTXnL0BasL
+ i
) << 24) | (texBase
& 0xFFFFFF);
581 viaObj
->regTexBaseAndPitch
[i
].pitchLog2
=
582 ((HC_SubA_HTXnL0Pit
+ i
) << 24) | (p
<< 20);
585 /* The base high bytes for each 3 levels are packed
586 * together into one register:
590 basH
|= ((texBase
& 0xFF000000) >> (k
<< 3));
592 viaObj
->regTexBaseH
[j
] = ((j
+ HC_SubA_HTXnL012BasH
) << 24) | basH
;
596 /* Likewise, sets of 6 log2width and log2height values are
597 * packed into individual registers:
601 widthExp
|= (((GLuint
)w
& 0xF) << (m
<< 2));
602 heightExp
|= (((GLuint
)h
& 0xF) << (m
<< 2));
604 viaObj
->regTexWidthLog2
[l
] =
605 (l
+ HC_SubA_HTXnL0_5WE
) << 24 | widthExp
;
606 viaObj
->regTexHeightLog2
[l
] =
607 (l
+ HC_SubA_HTXnL0_5HE
) << 24 | heightExp
;
617 viaObj
->regTexBaseH
[j
] = ((j
+ HC_SubA_HTXnL012BasH
) << 24) | basH
;
620 viaObj
->regTexWidthLog2
[l
] = (l
+ HC_SubA_HTXnL0_5WE
) << 24 | widthExp
;
621 viaObj
->regTexHeightLog2
[l
] = (l
+ HC_SubA_HTXnL0_5HE
) << 24 | heightExp
;
628 GLboolean
viaUpdateTextureState( GLcontext
*ctx
)
630 struct gl_texture_unit
*texUnit
= ctx
->Texture
.Unit
;
633 for (i
= 0; i
< 2; i
++) {
634 if (texUnit
[i
]._ReallyEnabled
== TEXTURE_2D_BIT
||
635 texUnit
[i
]._ReallyEnabled
== TEXTURE_1D_BIT
) {
637 if (!viaSetTexImages(ctx
, texUnit
[i
]._Current
))
640 else if (texUnit
[i
]._ReallyEnabled
) {
655 static void viaTexImage(GLcontext
*ctx
,
657 GLenum target
, GLint level
,
658 GLint internalFormat
,
659 GLint width
, GLint height
, GLint border
,
660 GLenum format
, GLenum type
, const void *pixels
,
661 const struct gl_pixelstore_attrib
*packing
,
662 struct gl_texture_object
*texObj
,
663 struct gl_texture_image
*texImage
)
665 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
666 GLint texelBytes
, sizeInBytes
;
667 struct via_texture_object
*viaObj
= (struct via_texture_object
*)texObj
;
668 struct via_texture_image
*viaImage
= (struct via_texture_image
*)texImage
;
669 int heaps
[3], nheaps
, i
;
671 if (!is_empty_list(&vmesa
->freed_tex_buffers
)) {
672 viaCheckBreadcrumb(vmesa
, 0);
673 via_release_pending_textures(vmesa
);
676 /* choose the texture format */
677 texImage
->TexFormat
= viaChooseTexFormat(ctx
, internalFormat
,
680 assert(texImage
->TexFormat
);
682 texelBytes
= _mesa_get_format_bytes(texImage
->TexFormat
);
684 /* Minimum pitch of 32 bytes */
685 if (width
* texelBytes
< 32) {
686 width
= 32 / texelBytes
;
687 texImage
->RowStride
= width
;
690 assert(texImage
->RowStride
== width
);
691 viaImage
->pitchLog2
= logbase2(width
* texelBytes
);
693 /* allocate memory */
694 if (_mesa_is_format_compressed(texImage
->TexFormat
))
695 sizeInBytes
= _mesa_format_image_size(texImage
->TexFormat
,
700 sizeInBytes
= width
* height
* texelBytes
;
703 /* Attempt to allocate texture memory directly, otherwise use main
704 * memory and this texture will always be a fallback. FIXME!
706 * TODO: make room in agp if this fails.
707 * TODO: use fb ram for textures as well.
711 switch (viaObj
->memType
) {
712 case VIA_MEM_UNKNOWN
:
713 heaps
[0] = VIA_MEM_AGP
;
714 heaps
[1] = VIA_MEM_VIDEO
;
715 heaps
[2] = VIA_MEM_SYSTEM
;
720 heaps
[0] = viaObj
->memType
;
721 heaps
[1] = VIA_MEM_SYSTEM
;
727 heaps
[0] = VIA_MEM_SYSTEM
;
732 for (i
= 0; i
< nheaps
&& !viaImage
->texMem
; i
++) {
733 if (VIA_DEBUG
& DEBUG_TEXTURE
)
734 fprintf(stderr
, "try %s (obj %s)\n", get_memtype_name(heaps
[i
]),
735 get_memtype_name(viaObj
->memType
));
736 viaImage
->texMem
= via_alloc_texture(vmesa
, sizeInBytes
, heaps
[i
]);
739 if (!viaImage
->texMem
) {
740 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
744 if (VIA_DEBUG
& DEBUG_TEXTURE
)
745 fprintf(stderr
, "upload %d bytes to %s\n", sizeInBytes
,
746 get_memtype_name(viaImage
->texMem
->memType
));
748 viaImage
->texMem
->image
= viaImage
;
749 texImage
->Data
= viaImage
->texMem
->bufAddr
;
751 if (viaObj
->memType
== VIA_MEM_UNKNOWN
)
752 viaObj
->memType
= viaImage
->texMem
->memType
;
753 else if (viaObj
->memType
!= viaImage
->texMem
->memType
)
754 viaObj
->memType
= VIA_MEM_MIXED
;
756 if (VIA_DEBUG
& DEBUG_TEXTURE
)
757 fprintf(stderr
, "%s, obj %s, image : %s\n",
759 get_memtype_name(viaObj
->memType
),
760 get_memtype_name(viaImage
->texMem
->memType
));
762 vmesa
->clearTexCache
= 1;
764 pixels
= _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, 1,
766 pixels
, packing
, "glTexImage");
768 /* Note: we check for a NULL image pointer here, _after_ we allocated
769 * memory for the texture. That's what the GL spec calls for.
777 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
778 dstRowStride
= _mesa_format_row_stride(texImage
->TexFormat
, width
);
781 dstRowStride
= width
* _mesa_get_format_bytes(texImage
->TexFormat
);
783 success
= _mesa_texstore(ctx
, dims
,
784 texImage
->_BaseFormat
,
787 0, 0, 0, /* dstX/Y/Zoffset */
789 texImage
->ImageOffsets
,
791 format
, type
, pixels
, packing
);
793 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
797 _mesa_unmap_teximage_pbo(ctx
, packing
);
800 static void viaTexImage2D(GLcontext
*ctx
,
801 GLenum target
, GLint level
,
802 GLint internalFormat
,
803 GLint width
, GLint height
, GLint border
,
804 GLenum format
, GLenum type
, const void *pixels
,
805 const struct gl_pixelstore_attrib
*packing
,
806 struct gl_texture_object
*texObj
,
807 struct gl_texture_image
*texImage
)
809 viaTexImage( ctx
, 2, target
, level
,
810 internalFormat
, width
, height
, border
,
811 format
, type
, pixels
,
812 packing
, texObj
, texImage
);
815 static void viaTexSubImage2D(GLcontext
*ctx
,
818 GLint xoffset
, GLint yoffset
,
819 GLsizei width
, GLsizei height
,
820 GLenum format
, GLenum type
,
821 const GLvoid
*pixels
,
822 const struct gl_pixelstore_attrib
*packing
,
823 struct gl_texture_object
*texObj
,
824 struct gl_texture_image
*texImage
)
826 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
828 viaWaitIdle(vmesa
, GL_TRUE
);
829 vmesa
->clearTexCache
= 1;
831 _mesa_store_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
, width
,
832 height
, format
, type
, pixels
, packing
, texObj
,
836 static void viaTexImage1D(GLcontext
*ctx
,
837 GLenum target
, GLint level
,
838 GLint internalFormat
,
839 GLint width
, GLint border
,
840 GLenum format
, GLenum type
, const void *pixels
,
841 const struct gl_pixelstore_attrib
*packing
,
842 struct gl_texture_object
*texObj
,
843 struct gl_texture_image
*texImage
)
845 viaTexImage( ctx
, 1, target
, level
,
846 internalFormat
, width
, 1, border
,
847 format
, type
, pixels
,
848 packing
, texObj
, texImage
);
851 static void viaTexSubImage1D(GLcontext
*ctx
,
856 GLenum format
, GLenum type
,
857 const GLvoid
*pixels
,
858 const struct gl_pixelstore_attrib
*packing
,
859 struct gl_texture_object
*texObj
,
860 struct gl_texture_image
*texImage
)
862 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
864 viaWaitIdle(vmesa
, GL_TRUE
);
865 vmesa
->clearTexCache
= 1;
867 _mesa_store_texsubimage1d(ctx
, target
, level
, xoffset
, width
,
868 format
, type
, pixels
, packing
, texObj
,
874 static GLboolean
viaIsTextureResident(GLcontext
*ctx
,
875 struct gl_texture_object
*texObj
)
877 struct via_texture_object
*viaObj
=
878 (struct via_texture_object
*)texObj
;
880 return (viaObj
->memType
== VIA_MEM_AGP
||
881 viaObj
->memType
== VIA_MEM_VIDEO
);
886 static struct gl_texture_image
*viaNewTextureImage( GLcontext
*ctx
)
889 return (struct gl_texture_image
*)CALLOC_STRUCT(via_texture_image
);
893 static struct gl_texture_object
*viaNewTextureObject( GLcontext
*ctx
,
897 struct via_texture_object
*obj
= CALLOC_STRUCT(via_texture_object
);
899 _mesa_initialize_texture_object(&obj
->obj
, name
, target
);
902 obj
->memType
= VIA_MEM_UNKNOWN
;
908 static void viaFreeTextureImageData( GLcontext
*ctx
,
909 struct gl_texture_image
*texImage
)
911 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
912 struct via_texture_image
*image
= (struct via_texture_image
*)texImage
;
915 via_free_texture(vmesa
, image
->texMem
);
916 image
->texMem
= NULL
;
919 texImage
->Data
= NULL
;
925 void viaInitTextureFuncs(struct dd_function_table
* functions
)
927 functions
->ChooseTextureFormat
= viaChooseTexFormat
;
928 functions
->TexImage1D
= viaTexImage1D
;
929 functions
->TexImage2D
= viaTexImage2D
;
930 functions
->TexSubImage1D
= viaTexSubImage1D
;
931 functions
->TexSubImage2D
= viaTexSubImage2D
;
933 functions
->NewTextureObject
= viaNewTextureObject
;
934 functions
->NewTextureImage
= viaNewTextureImage
;
935 functions
->DeleteTexture
= _mesa_delete_texture_object
;
936 functions
->FreeTexImageData
= viaFreeTextureImageData
;
938 #if 0 && defined( USE_SSE_ASM )
940 * XXX this code is disabled for now because the via_sse_memcpy()
941 * routine causes segfaults with flightgear.
942 * See Mesa3d-dev mail list messages from 7/15/2005 for details.
943 * Note that this function is currently disabled in via_tris.c too.
945 if (getenv("VIA_NO_SSE"))
946 functions
->TextureMemCpy
= memcpy
;
948 functions
->TextureMemCpy
= via_sse_memcpy
;
950 functions
->TextureMemCpy
= memcpy
;
953 functions
->UpdateTexturePalette
= 0;
954 functions
->IsTextureResident
= viaIsTextureResident
;