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/texcompress.h"
41 #include "main/texobj.h"
42 #include "main/texstore.h"
44 #include "via_context.h"
47 #include "via_state.h"
48 #include "via_ioctl.h"
49 #include "via_3d_reg.h"
52 viaChooseTexFormat( GLcontext
*ctx
, GLint internalFormat
,
53 GLenum format
, GLenum type
)
55 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
56 const GLboolean do32bpt
= ( vmesa
->viaScreen
->bitsPerPixel
== 32
57 /* && vmesa->viaScreen->textureSize > 4*1024*1024 */
61 switch ( internalFormat
) {
64 case GL_COMPRESSED_RGBA
:
65 if ( format
== GL_BGRA
) {
66 if ( type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
67 type
== GL_UNSIGNED_BYTE
) {
68 return MESA_FORMAT_ARGB8888
;
70 else if ( type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
71 return MESA_FORMAT_ARGB4444
;
73 else if ( type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
74 return MESA_FORMAT_ARGB1555
;
77 else if ( type
== GL_UNSIGNED_BYTE
||
78 type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
79 type
== GL_UNSIGNED_INT_8_8_8_8
) {
80 return MESA_FORMAT_ARGB8888
;
82 return do32bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB4444
;
86 case GL_COMPRESSED_RGB
:
87 if ( format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) {
88 return MESA_FORMAT_RGB565
;
90 else if ( type
== GL_UNSIGNED_BYTE
) {
91 return MESA_FORMAT_ARGB8888
;
93 return do32bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_RGB565
;
99 return MESA_FORMAT_ARGB8888
;
103 return MESA_FORMAT_ARGB4444
;
106 return MESA_FORMAT_ARGB1555
;
112 return MESA_FORMAT_ARGB8888
;
117 return MESA_FORMAT_RGB565
;
124 case GL_COMPRESSED_ALPHA
:
125 return MESA_FORMAT_A8
;
133 case GL_COMPRESSED_LUMINANCE
:
134 return MESA_FORMAT_L8
;
137 case GL_LUMINANCE_ALPHA
:
138 case GL_LUMINANCE4_ALPHA4
:
139 case GL_LUMINANCE6_ALPHA2
:
140 case GL_LUMINANCE8_ALPHA8
:
141 case GL_LUMINANCE12_ALPHA4
:
142 case GL_LUMINANCE12_ALPHA12
:
143 case GL_LUMINANCE16_ALPHA16
:
144 case GL_COMPRESSED_LUMINANCE_ALPHA
:
145 return MESA_FORMAT_AL88
;
152 case GL_COMPRESSED_INTENSITY
:
153 return MESA_FORMAT_I8
;
156 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
157 type
== GL_UNSIGNED_BYTE
)
158 return MESA_FORMAT_YCBCR
;
160 return MESA_FORMAT_YCBCR_REV
;
162 case GL_COMPRESSED_RGB_FXT1_3DFX
:
163 return MESA_FORMAT_RGB_FXT1
;
164 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
165 return MESA_FORMAT_RGBA_FXT1
;
169 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
170 return MESA_FORMAT_RGB_DXT1
;
172 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
173 return MESA_FORMAT_RGBA_DXT1
;
177 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
178 return MESA_FORMAT_RGBA_DXT3
;
180 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
181 return MESA_FORMAT_RGBA_DXT5
;
184 case GL_COLOR_INDEX1_EXT
:
185 case GL_COLOR_INDEX2_EXT
:
186 case GL_COLOR_INDEX4_EXT
:
187 case GL_COLOR_INDEX8_EXT
:
188 case GL_COLOR_INDEX12_EXT
:
189 case GL_COLOR_INDEX16_EXT
:
190 return MESA_FORMAT_CI8
;
193 fprintf(stderr
, "unexpected texture format %s in %s\n",
194 _mesa_lookup_enum_by_nr(internalFormat
),
196 return MESA_FORMAT_NONE
;
199 return MESA_FORMAT_NONE
; /* never get here */
202 static int logbase2(int n
)
215 static const char *get_memtype_name( GLint memType
)
217 static const char *names
[] = {
225 return names
[memType
];
229 static GLboolean
viaMoveTexBuffers( struct via_context
*vmesa
,
230 struct via_tex_buffer
**buffers
,
234 struct via_tex_buffer
*newTexBuf
[VIA_MAX_TEXLEVELS
];
237 if (VIA_DEBUG
& DEBUG_TEXTURE
)
238 fprintf(stderr
, "%s to %s\n",
240 get_memtype_name(newMemType
));
242 memset(newTexBuf
, 0, sizeof(newTexBuf
));
244 /* First do all the allocations (or fail):
246 for (i
= 0; i
< nr
; i
++) {
247 if (buffers
[i
]->memType
!= newMemType
) {
249 /* Don't allow uploads in a thrash state. Should try and
250 * catch this earlier.
252 if (vmesa
->thrashing
&& newMemType
!= VIA_MEM_SYSTEM
)
255 newTexBuf
[i
] = via_alloc_texture(vmesa
,
264 /* Now copy all the image data and free the old texture memory.
266 for (i
= 0; i
< nr
; i
++) {
268 memcpy(newTexBuf
[i
]->bufAddr
,
272 newTexBuf
[i
]->image
= buffers
[i
]->image
;
273 newTexBuf
[i
]->image
->texMem
= newTexBuf
[i
];
274 newTexBuf
[i
]->image
->image
.Data
= newTexBuf
[i
]->bufAddr
;
275 via_free_texture(vmesa
, buffers
[i
]);
279 if (VIA_DEBUG
& DEBUG_TEXTURE
)
280 fprintf(stderr
, "%s - success\n", __FUNCTION__
);
285 /* Release any allocations made prior to failure:
287 if (VIA_DEBUG
& DEBUG_TEXTURE
)
288 fprintf(stderr
, "%s - failed\n", __FUNCTION__
);
290 for (i
= 0; i
< nr
; i
++) {
292 via_free_texture(vmesa
, newTexBuf
[i
]);
300 static GLboolean
viaMoveTexObject( struct via_context
*vmesa
,
301 struct via_texture_object
*viaObj
,
304 struct via_texture_image
**viaImage
=
305 (struct via_texture_image
**)&viaObj
->obj
.Image
[0][0];
306 struct via_tex_buffer
*buffers
[VIA_MAX_TEXLEVELS
];
309 for (i
= viaObj
->firstLevel
; i
<= viaObj
->lastLevel
; i
++)
310 buffers
[nr
++] = viaImage
[i
]->texMem
;
312 if (viaMoveTexBuffers( vmesa
, &buffers
[0], nr
, newMemType
)) {
313 viaObj
->memType
= newMemType
;
322 static GLboolean
viaSwapInTexObject( struct via_context
*vmesa
,
323 struct via_texture_object
*viaObj
)
325 const struct via_texture_image
*baseImage
=
326 (struct via_texture_image
*)viaObj
->obj
.Image
[0][viaObj
->obj
.BaseLevel
];
328 if (VIA_DEBUG
& DEBUG_TEXTURE
)
329 fprintf(stderr
, "%s\n", __FUNCTION__
);
331 if (baseImage
->texMem
->memType
!= VIA_MEM_SYSTEM
)
332 return viaMoveTexObject( vmesa
, viaObj
, baseImage
->texMem
->memType
);
334 return (viaMoveTexObject( vmesa
, viaObj
, VIA_MEM_AGP
) ||
335 viaMoveTexObject( vmesa
, viaObj
, VIA_MEM_VIDEO
));
339 /* This seems crude, but it asks a fairly pertinent question and gives
340 * an accurate answer:
342 static GLboolean
viaIsTexMemLow( struct via_context
*vmesa
,
345 struct via_tex_buffer
*buf
= via_alloc_texture(vmesa
, 512 * 1024, heap
);
349 via_free_texture(vmesa
, buf
);
354 /* Speculatively move texture images which haven't been used in a
355 * while back to system memory.
357 * TODO: only do this when texture memory is low.
361 * TODO: keep the fb/agp version hanging around and use the local
362 * version as backing store, so re-upload might be avoided.
364 * TODO: do this properly in the kernel...
366 GLboolean
viaSwapOutWork( struct via_context
*vmesa
)
368 struct via_tex_buffer
*s
, *tmp
;
372 if (VIA_DEBUG
& DEBUG_TEXTURE
)
373 fprintf(stderr
, "%s VID %d AGP %d SYS %d\n", __FUNCTION__
,
374 vmesa
->total_alloc
[VIA_MEM_VIDEO
],
375 vmesa
->total_alloc
[VIA_MEM_AGP
],
376 vmesa
->total_alloc
[VIA_MEM_SYSTEM
]);
379 for (heap
= VIA_MEM_VIDEO
; heap
<= VIA_MEM_AGP
; heap
++) {
380 GLuint nr
= 0, sz
= 0;
382 if (vmesa
->thrashing
) {
383 if (VIA_DEBUG
& DEBUG_TEXTURE
)
384 fprintf(stderr
, "Heap %d: trash flag\n", heap
);
385 target
= 1*1024*1024;
387 else if (viaIsTexMemLow(vmesa
, heap
)) {
388 if (VIA_DEBUG
& DEBUG_TEXTURE
)
389 fprintf(stderr
, "Heap %d: low memory\n", heap
);
393 if (VIA_DEBUG
& DEBUG_TEXTURE
)
394 fprintf(stderr
, "Heap %d: nothing to do\n", heap
);
398 foreach_s( s
, tmp
, &vmesa
->tex_image_list
[heap
] ) {
399 if (s
->lastUsed
< vmesa
->lastSwap
[1]) {
400 struct via_texture_object
*viaObj
=
401 (struct via_texture_object
*) s
->image
->image
.TexObject
;
403 if (VIA_DEBUG
& DEBUG_TEXTURE
)
405 "back copy tex sz %d, lastUsed %d lastSwap %d\n",
406 s
->size
, s
->lastUsed
, vmesa
->lastSwap
[1]);
408 if (viaMoveTexBuffers( vmesa
, &s
, 1, VIA_MEM_SYSTEM
)) {
409 viaObj
->memType
= VIA_MEM_MIXED
;
413 if (VIA_DEBUG
& DEBUG_TEXTURE
)
414 fprintf(stderr
, "Failed to back copy texture!\n");
424 vmesa
->thrashing
= GL_FALSE
; /* might not get set otherwise? */
429 assert(sz
== vmesa
->total_alloc
[heap
]);
431 if (VIA_DEBUG
& DEBUG_TEXTURE
)
432 fprintf(stderr
, "Heap %d: nr %d tot sz %d\n", heap
, nr
, sz
);
441 /* Basically, just collect the image dimensions and addresses for each
442 * image and update the texture object state accordingly.
444 static GLboolean
viaSetTexImages(GLcontext
*ctx
,
445 struct gl_texture_object
*texObj
)
447 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
448 struct via_texture_object
*viaObj
= (struct via_texture_object
*)texObj
;
449 const struct via_texture_image
*baseImage
=
450 (struct via_texture_image
*)texObj
->Image
[0][texObj
->BaseLevel
];
451 GLint firstLevel
, lastLevel
, numLevels
;
454 GLint i
, j
= 0, k
= 0, l
= 0, m
= 0;
458 GLuint heightExp
= 0;
460 switch (baseImage
->image
.TexFormat
) {
461 case MESA_FORMAT_ARGB8888
:
462 texFormat
= HC_HTXnFM_ARGB8888
;
464 case MESA_FORMAT_ARGB4444
:
465 texFormat
= HC_HTXnFM_ARGB4444
;
467 case MESA_FORMAT_RGB565
:
468 texFormat
= HC_HTXnFM_RGB565
;
470 case MESA_FORMAT_ARGB1555
:
471 texFormat
= HC_HTXnFM_ARGB1555
;
473 case MESA_FORMAT_RGB888
:
474 texFormat
= HC_HTXnFM_ARGB0888
;
477 texFormat
= HC_HTXnFM_L8
;
480 texFormat
= HC_HTXnFM_T8
;
482 case MESA_FORMAT_CI8
:
483 texFormat
= HC_HTXnFM_Index8
;
485 case MESA_FORMAT_AL88
:
486 texFormat
= HC_HTXnFM_AL88
;
489 texFormat
= HC_HTXnFM_A8
;
492 _mesa_problem(vmesa
->glCtx
, "Bad texture format in viaSetTexImages");
496 /* Compute which mipmap levels we really want to send to the hardware.
497 * This depends on the base image size, GL_TEXTURE_MIN_LOD,
498 * GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL, and GL_TEXTURE_MAX_LEVEL.
499 * Yes, this looks overly complicated, but it's all needed.
501 if (texObj
->MinFilter
== GL_LINEAR
|| texObj
->MinFilter
== GL_NEAREST
) {
502 firstLevel
= lastLevel
= texObj
->BaseLevel
;
505 firstLevel
= texObj
->BaseLevel
+ (GLint
)(texObj
->MinLod
+ 0.5);
506 firstLevel
= MAX2(firstLevel
, texObj
->BaseLevel
);
507 lastLevel
= texObj
->BaseLevel
+ (GLint
)(texObj
->MaxLod
+ 0.5);
508 lastLevel
= MAX2(lastLevel
, texObj
->BaseLevel
);
509 lastLevel
= MIN2(lastLevel
, texObj
->BaseLevel
+ baseImage
->image
.MaxLog2
);
510 lastLevel
= MIN2(lastLevel
, texObj
->MaxLevel
);
511 lastLevel
= MAX2(firstLevel
, lastLevel
); /* need at least one level */
514 numLevels
= lastLevel
- firstLevel
+ 1;
516 /* The hardware supports only 10 mipmap levels; ignore higher levels.
518 if ((numLevels
> 10) && (ctx
->Const
.MaxTextureLevels
> 10)) {
519 lastLevel
-= numLevels
- 10;
523 /* save these values, check if they effect the residency of the
526 if (viaObj
->firstLevel
!= firstLevel
||
527 viaObj
->lastLevel
!= lastLevel
) {
528 viaObj
->firstLevel
= firstLevel
;
529 viaObj
->lastLevel
= lastLevel
;
530 viaObj
->memType
= VIA_MEM_MIXED
;
533 if (VIA_DEBUG
& DEBUG_TEXTURE
& 0)
534 fprintf(stderr
, "%s, current memType: %s\n",
536 get_memtype_name(viaObj
->memType
));
539 if (viaObj
->memType
== VIA_MEM_MIXED
||
540 viaObj
->memType
== VIA_MEM_SYSTEM
) {
541 if (!viaSwapInTexObject(vmesa
, viaObj
)) {
542 if (VIA_DEBUG
& DEBUG_TEXTURE
)
543 if (!vmesa
->thrashing
)
544 fprintf(stderr
, "Thrashing flag set for frame %d\n",
546 vmesa
->thrashing
= GL_TRUE
;
551 if (viaObj
->memType
== VIA_MEM_AGP
)
552 viaObj
->regTexFM
= (HC_SubA_HTXnFM
<< 24) | HC_HTXnLoc_AGP
| texFormat
;
554 viaObj
->regTexFM
= (HC_SubA_HTXnFM
<< 24) | HC_HTXnLoc_Local
| texFormat
;
557 for (i
= 0; i
< numLevels
; i
++) {
558 struct via_texture_image
*viaImage
=
559 (struct via_texture_image
*)texObj
->Image
[0][firstLevel
+ i
];
561 w
= viaImage
->image
.WidthLog2
;
562 h
= viaImage
->image
.HeightLog2
;
563 p
= viaImage
->pitchLog2
;
565 assert(viaImage
->texMem
->memType
== viaObj
->memType
);
567 texBase
= viaImage
->texMem
->texBase
;
569 if (VIA_DEBUG
& DEBUG_TEXTURE
)
570 fprintf(stderr
, "%s: no texBase[%d]\n", __FUNCTION__
, i
);
574 /* Image has to remain resident until the coming fence is retired.
576 move_to_head( &vmesa
->tex_image_list
[viaImage
->texMem
->memType
],
578 viaImage
->texMem
->lastUsed
= vmesa
->lastBreadcrumbWrite
;
581 viaObj
->regTexBaseAndPitch
[i
].baseL
=
582 ((HC_SubA_HTXnL0BasL
+ i
) << 24) | (texBase
& 0xFFFFFF);
584 viaObj
->regTexBaseAndPitch
[i
].pitchLog2
=
585 ((HC_SubA_HTXnL0Pit
+ i
) << 24) | (p
<< 20);
588 /* The base high bytes for each 3 levels are packed
589 * together into one register:
593 basH
|= ((texBase
& 0xFF000000) >> (k
<< 3));
595 viaObj
->regTexBaseH
[j
] = ((j
+ HC_SubA_HTXnL012BasH
) << 24) | basH
;
599 /* Likewise, sets of 6 log2width and log2height values are
600 * packed into individual registers:
604 widthExp
|= (((GLuint
)w
& 0xF) << (m
<< 2));
605 heightExp
|= (((GLuint
)h
& 0xF) << (m
<< 2));
607 viaObj
->regTexWidthLog2
[l
] =
608 (l
+ HC_SubA_HTXnL0_5WE
) << 24 | widthExp
;
609 viaObj
->regTexHeightLog2
[l
] =
610 (l
+ HC_SubA_HTXnL0_5HE
) << 24 | heightExp
;
620 viaObj
->regTexBaseH
[j
] = ((j
+ HC_SubA_HTXnL012BasH
) << 24) | basH
;
623 viaObj
->regTexWidthLog2
[l
] = (l
+ HC_SubA_HTXnL0_5WE
) << 24 | widthExp
;
624 viaObj
->regTexHeightLog2
[l
] = (l
+ HC_SubA_HTXnL0_5HE
) << 24 | heightExp
;
631 GLboolean
viaUpdateTextureState( GLcontext
*ctx
)
633 struct gl_texture_unit
*texUnit
= ctx
->Texture
.Unit
;
636 for (i
= 0; i
< 2; i
++) {
637 if (texUnit
[i
]._ReallyEnabled
== TEXTURE_2D_BIT
||
638 texUnit
[i
]._ReallyEnabled
== TEXTURE_1D_BIT
) {
640 if (!viaSetTexImages(ctx
, texUnit
[i
]._Current
))
643 else if (texUnit
[i
]._ReallyEnabled
) {
658 static void viaTexImage(GLcontext
*ctx
,
660 GLenum target
, GLint level
,
661 GLint internalFormat
,
662 GLint width
, GLint height
, GLint border
,
663 GLenum format
, GLenum type
, const void *pixels
,
664 const struct gl_pixelstore_attrib
*packing
,
665 struct gl_texture_object
*texObj
,
666 struct gl_texture_image
*texImage
)
668 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
669 GLint postConvWidth
= width
;
670 GLint postConvHeight
= height
;
671 GLint texelBytes
, sizeInBytes
;
672 struct via_texture_object
*viaObj
= (struct via_texture_object
*)texObj
;
673 struct via_texture_image
*viaImage
= (struct via_texture_image
*)texImage
;
674 int heaps
[3], nheaps
, i
;
676 if (!is_empty_list(&vmesa
->freed_tex_buffers
)) {
677 viaCheckBreadcrumb(vmesa
, 0);
678 via_release_pending_textures(vmesa
);
681 if (ctx
->_ImageTransferState
& IMAGE_CONVOLUTION_BIT
) {
682 _mesa_adjust_image_for_convolution(ctx
, dims
, &postConvWidth
,
686 /* choose the texture format */
687 texImage
->TexFormat
= viaChooseTexFormat(ctx
, internalFormat
,
690 assert(texImage
->TexFormat
);
692 texelBytes
= _mesa_get_format_bytes(texImage
->TexFormat
);
694 /* Minimum pitch of 32 bytes */
695 if (postConvWidth
* texelBytes
< 32) {
696 postConvWidth
= 32 / texelBytes
;
697 texImage
->RowStride
= postConvWidth
;
700 assert(texImage
->RowStride
== postConvWidth
);
701 viaImage
->pitchLog2
= logbase2(postConvWidth
* texelBytes
);
703 /* allocate memory */
704 if (_mesa_is_format_compressed(texImage
->TexFormat
))
705 sizeInBytes
= _mesa_format_image_size(texImage
->TexFormat
,
710 sizeInBytes
= postConvWidth
* postConvHeight
* texelBytes
;
713 /* Attempt to allocate texture memory directly, otherwise use main
714 * memory and this texture will always be a fallback. FIXME!
716 * TODO: make room in agp if this fails.
717 * TODO: use fb ram for textures as well.
721 switch (viaObj
->memType
) {
722 case VIA_MEM_UNKNOWN
:
723 heaps
[0] = VIA_MEM_AGP
;
724 heaps
[1] = VIA_MEM_VIDEO
;
725 heaps
[2] = VIA_MEM_SYSTEM
;
730 heaps
[0] = viaObj
->memType
;
731 heaps
[1] = VIA_MEM_SYSTEM
;
737 heaps
[0] = VIA_MEM_SYSTEM
;
742 for (i
= 0; i
< nheaps
&& !viaImage
->texMem
; i
++) {
743 if (VIA_DEBUG
& DEBUG_TEXTURE
)
744 fprintf(stderr
, "try %s (obj %s)\n", get_memtype_name(heaps
[i
]),
745 get_memtype_name(viaObj
->memType
));
746 viaImage
->texMem
= via_alloc_texture(vmesa
, sizeInBytes
, heaps
[i
]);
749 if (!viaImage
->texMem
) {
750 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
754 if (VIA_DEBUG
& DEBUG_TEXTURE
)
755 fprintf(stderr
, "upload %d bytes to %s\n", sizeInBytes
,
756 get_memtype_name(viaImage
->texMem
->memType
));
758 viaImage
->texMem
->image
= viaImage
;
759 texImage
->Data
= viaImage
->texMem
->bufAddr
;
761 if (viaObj
->memType
== VIA_MEM_UNKNOWN
)
762 viaObj
->memType
= viaImage
->texMem
->memType
;
763 else if (viaObj
->memType
!= viaImage
->texMem
->memType
)
764 viaObj
->memType
= VIA_MEM_MIXED
;
766 if (VIA_DEBUG
& DEBUG_TEXTURE
)
767 fprintf(stderr
, "%s, obj %s, image : %s\n",
769 get_memtype_name(viaObj
->memType
),
770 get_memtype_name(viaImage
->texMem
->memType
));
772 vmesa
->clearTexCache
= 1;
774 pixels
= _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, 1,
776 pixels
, packing
, "glTexImage");
778 /* Note: we check for a NULL image pointer here, _after_ we allocated
779 * memory for the texture. That's what the GL spec calls for.
787 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
788 dstRowStride
= _mesa_format_row_stride(texImage
->TexFormat
, width
);
791 dstRowStride
= postConvWidth
* _mesa_get_format_bytes(texImage
->TexFormat
);
793 success
= _mesa_texstore(ctx
, dims
,
794 texImage
->_BaseFormat
,
797 0, 0, 0, /* dstX/Y/Zoffset */
799 texImage
->ImageOffsets
,
801 format
, type
, pixels
, packing
);
803 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
807 _mesa_unmap_teximage_pbo(ctx
, packing
);
810 static void viaTexImage2D(GLcontext
*ctx
,
811 GLenum target
, GLint level
,
812 GLint internalFormat
,
813 GLint width
, GLint height
, GLint border
,
814 GLenum format
, GLenum type
, const void *pixels
,
815 const struct gl_pixelstore_attrib
*packing
,
816 struct gl_texture_object
*texObj
,
817 struct gl_texture_image
*texImage
)
819 viaTexImage( ctx
, 2, target
, level
,
820 internalFormat
, width
, height
, border
,
821 format
, type
, pixels
,
822 packing
, texObj
, texImage
);
825 static void viaTexSubImage2D(GLcontext
*ctx
,
828 GLint xoffset
, GLint yoffset
,
829 GLsizei width
, GLsizei height
,
830 GLenum format
, GLenum type
,
831 const GLvoid
*pixels
,
832 const struct gl_pixelstore_attrib
*packing
,
833 struct gl_texture_object
*texObj
,
834 struct gl_texture_image
*texImage
)
836 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
838 viaWaitIdle(vmesa
, GL_TRUE
);
839 vmesa
->clearTexCache
= 1;
841 _mesa_store_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
, width
,
842 height
, format
, type
, pixels
, packing
, texObj
,
846 static void viaTexImage1D(GLcontext
*ctx
,
847 GLenum target
, GLint level
,
848 GLint internalFormat
,
849 GLint width
, GLint border
,
850 GLenum format
, GLenum type
, const void *pixels
,
851 const struct gl_pixelstore_attrib
*packing
,
852 struct gl_texture_object
*texObj
,
853 struct gl_texture_image
*texImage
)
855 viaTexImage( ctx
, 1, target
, level
,
856 internalFormat
, width
, 1, border
,
857 format
, type
, pixels
,
858 packing
, texObj
, texImage
);
861 static void viaTexSubImage1D(GLcontext
*ctx
,
866 GLenum format
, GLenum type
,
867 const GLvoid
*pixels
,
868 const struct gl_pixelstore_attrib
*packing
,
869 struct gl_texture_object
*texObj
,
870 struct gl_texture_image
*texImage
)
872 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
874 viaWaitIdle(vmesa
, GL_TRUE
);
875 vmesa
->clearTexCache
= 1;
877 _mesa_store_texsubimage1d(ctx
, target
, level
, xoffset
, width
,
878 format
, type
, pixels
, packing
, texObj
,
884 static GLboolean
viaIsTextureResident(GLcontext
*ctx
,
885 struct gl_texture_object
*texObj
)
887 struct via_texture_object
*viaObj
=
888 (struct via_texture_object
*)texObj
;
890 return (viaObj
->memType
== VIA_MEM_AGP
||
891 viaObj
->memType
== VIA_MEM_VIDEO
);
896 static struct gl_texture_image
*viaNewTextureImage( GLcontext
*ctx
)
899 return (struct gl_texture_image
*)CALLOC_STRUCT(via_texture_image
);
903 static struct gl_texture_object
*viaNewTextureObject( GLcontext
*ctx
,
907 struct via_texture_object
*obj
= CALLOC_STRUCT(via_texture_object
);
909 _mesa_initialize_texture_object(&obj
->obj
, name
, target
);
912 obj
->memType
= VIA_MEM_UNKNOWN
;
918 static void viaFreeTextureImageData( GLcontext
*ctx
,
919 struct gl_texture_image
*texImage
)
921 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
922 struct via_texture_image
*image
= (struct via_texture_image
*)texImage
;
925 via_free_texture(vmesa
, image
->texMem
);
926 image
->texMem
= NULL
;
929 texImage
->Data
= NULL
;
935 void viaInitTextureFuncs(struct dd_function_table
* functions
)
937 functions
->ChooseTextureFormat
= viaChooseTexFormat
;
938 functions
->TexImage1D
= viaTexImage1D
;
939 functions
->TexImage2D
= viaTexImage2D
;
940 functions
->TexSubImage1D
= viaTexSubImage1D
;
941 functions
->TexSubImage2D
= viaTexSubImage2D
;
943 functions
->NewTextureObject
= viaNewTextureObject
;
944 functions
->NewTextureImage
= viaNewTextureImage
;
945 functions
->DeleteTexture
= _mesa_delete_texture_object
;
946 functions
->FreeTexImageData
= viaFreeTextureImageData
;
948 #if 0 && defined( USE_SSE_ASM )
950 * XXX this code is disabled for now because the via_sse_memcpy()
951 * routine causes segfaults with flightgear.
952 * See Mesa3d-dev mail list messages from 7/15/2005 for details.
953 * Note that this function is currently disabled in via_tris.c too.
955 if (getenv("VIA_NO_SSE"))
956 functions
->TextureMemCpy
= _mesa_memcpy
;
958 functions
->TextureMemCpy
= via_sse_memcpy
;
960 functions
->TextureMemCpy
= _mesa_memcpy
;
963 functions
->UpdateTexturePalette
= 0;
964 functions
->IsTextureResident
= viaIsTextureResident
;