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/context.h"
35 #include "main/mipmap.h"
37 #include "main/simple_list.h"
38 #include "main/texobj.h"
39 #include "main/texstore.h"
41 #include "via_context.h"
44 #include "via_ioctl.h"
45 #include "via_3d_reg.h"
48 viaChooseTexFormat( GLcontext
*ctx
, GLint internalFormat
,
49 GLenum format
, GLenum type
)
51 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
52 const GLboolean do32bpt
= ( vmesa
->viaScreen
->bitsPerPixel
== 32
53 /* && vmesa->viaScreen->textureSize > 4*1024*1024 */
57 switch ( internalFormat
) {
60 case GL_COMPRESSED_RGBA
:
61 if ( format
== GL_BGRA
) {
62 if ( type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
63 type
== GL_UNSIGNED_BYTE
) {
64 return MESA_FORMAT_ARGB8888
;
66 else if ( type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
67 return MESA_FORMAT_ARGB4444
;
69 else if ( type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
70 return MESA_FORMAT_ARGB1555
;
73 else if ( type
== GL_UNSIGNED_BYTE
||
74 type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
75 type
== GL_UNSIGNED_INT_8_8_8_8
) {
76 return MESA_FORMAT_ARGB8888
;
78 return do32bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB4444
;
82 case GL_COMPRESSED_RGB
:
83 if ( format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) {
84 return MESA_FORMAT_RGB565
;
86 else if ( type
== GL_UNSIGNED_BYTE
) {
87 return MESA_FORMAT_ARGB8888
;
89 return do32bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_RGB565
;
95 return MESA_FORMAT_ARGB8888
;
99 return MESA_FORMAT_ARGB4444
;
102 return MESA_FORMAT_ARGB1555
;
108 return MESA_FORMAT_ARGB8888
;
113 return MESA_FORMAT_RGB565
;
120 case GL_COMPRESSED_ALPHA
:
121 return MESA_FORMAT_A8
;
129 case GL_COMPRESSED_LUMINANCE
:
130 return MESA_FORMAT_L8
;
133 case GL_LUMINANCE_ALPHA
:
134 case GL_LUMINANCE4_ALPHA4
:
135 case GL_LUMINANCE6_ALPHA2
:
136 case GL_LUMINANCE8_ALPHA8
:
137 case GL_LUMINANCE12_ALPHA4
:
138 case GL_LUMINANCE12_ALPHA12
:
139 case GL_LUMINANCE16_ALPHA16
:
140 case GL_COMPRESSED_LUMINANCE_ALPHA
:
141 return MESA_FORMAT_AL88
;
148 case GL_COMPRESSED_INTENSITY
:
149 return MESA_FORMAT_I8
;
152 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
153 type
== GL_UNSIGNED_BYTE
)
154 return MESA_FORMAT_YCBCR
;
156 return MESA_FORMAT_YCBCR_REV
;
158 case GL_COMPRESSED_RGB_FXT1_3DFX
:
159 return MESA_FORMAT_RGB_FXT1
;
160 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
161 return MESA_FORMAT_RGBA_FXT1
;
165 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
166 return MESA_FORMAT_RGB_DXT1
;
168 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
169 return MESA_FORMAT_RGBA_DXT1
;
173 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
174 return MESA_FORMAT_RGBA_DXT3
;
176 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
177 return MESA_FORMAT_RGBA_DXT5
;
180 case GL_COLOR_INDEX1_EXT
:
181 case GL_COLOR_INDEX2_EXT
:
182 case GL_COLOR_INDEX4_EXT
:
183 case GL_COLOR_INDEX8_EXT
:
184 case GL_COLOR_INDEX12_EXT
:
185 case GL_COLOR_INDEX16_EXT
:
186 return MESA_FORMAT_CI8
;
189 fprintf(stderr
, "unexpected texture format %s in %s\n",
190 _mesa_lookup_enum_by_nr(internalFormat
),
192 return MESA_FORMAT_NONE
;
195 return MESA_FORMAT_NONE
; /* never get here */
198 static int logbase2(int n
)
211 static const char *get_memtype_name( GLint memType
)
213 static const char *names
[] = {
221 return names
[memType
];
225 static GLboolean
viaMoveTexBuffers( struct via_context
*vmesa
,
226 struct via_tex_buffer
**buffers
,
230 struct via_tex_buffer
*newTexBuf
[VIA_MAX_TEXLEVELS
];
233 if (VIA_DEBUG
& DEBUG_TEXTURE
)
234 fprintf(stderr
, "%s to %s\n",
236 get_memtype_name(newMemType
));
238 memset(newTexBuf
, 0, sizeof(newTexBuf
));
240 /* First do all the allocations (or fail):
242 for (i
= 0; i
< nr
; i
++) {
243 if (buffers
[i
]->memType
!= newMemType
) {
245 /* Don't allow uploads in a thrash state. Should try and
246 * catch this earlier.
248 if (vmesa
->thrashing
&& newMemType
!= VIA_MEM_SYSTEM
)
251 newTexBuf
[i
] = via_alloc_texture(vmesa
,
260 /* Now copy all the image data and free the old texture memory.
262 for (i
= 0; i
< nr
; i
++) {
264 memcpy(newTexBuf
[i
]->bufAddr
,
268 newTexBuf
[i
]->image
= buffers
[i
]->image
;
269 newTexBuf
[i
]->image
->texMem
= newTexBuf
[i
];
270 newTexBuf
[i
]->image
->image
.Data
= newTexBuf
[i
]->bufAddr
;
271 via_free_texture(vmesa
, buffers
[i
]);
275 if (VIA_DEBUG
& DEBUG_TEXTURE
)
276 fprintf(stderr
, "%s - success\n", __FUNCTION__
);
281 /* Release any allocations made prior to failure:
283 if (VIA_DEBUG
& DEBUG_TEXTURE
)
284 fprintf(stderr
, "%s - failed\n", __FUNCTION__
);
286 for (i
= 0; i
< nr
; i
++) {
288 via_free_texture(vmesa
, newTexBuf
[i
]);
296 static GLboolean
viaMoveTexObject( struct via_context
*vmesa
,
297 struct via_texture_object
*viaObj
,
300 struct via_texture_image
**viaImage
=
301 (struct via_texture_image
**)&viaObj
->obj
.Image
[0][0];
302 struct via_tex_buffer
*buffers
[VIA_MAX_TEXLEVELS
];
305 for (i
= viaObj
->firstLevel
; i
<= viaObj
->lastLevel
; i
++)
306 buffers
[nr
++] = viaImage
[i
]->texMem
;
308 if (viaMoveTexBuffers( vmesa
, &buffers
[0], nr
, newMemType
)) {
309 viaObj
->memType
= newMemType
;
318 static GLboolean
viaSwapInTexObject( struct via_context
*vmesa
,
319 struct via_texture_object
*viaObj
)
321 const struct via_texture_image
*baseImage
=
322 (struct via_texture_image
*)viaObj
->obj
.Image
[0][viaObj
->obj
.BaseLevel
];
324 if (VIA_DEBUG
& DEBUG_TEXTURE
)
325 fprintf(stderr
, "%s\n", __FUNCTION__
);
327 if (baseImage
->texMem
->memType
!= VIA_MEM_SYSTEM
)
328 return viaMoveTexObject( vmesa
, viaObj
, baseImage
->texMem
->memType
);
330 return (viaMoveTexObject( vmesa
, viaObj
, VIA_MEM_AGP
) ||
331 viaMoveTexObject( vmesa
, viaObj
, VIA_MEM_VIDEO
));
335 /* This seems crude, but it asks a fairly pertinent question and gives
336 * an accurate answer:
338 static GLboolean
viaIsTexMemLow( struct via_context
*vmesa
,
341 struct via_tex_buffer
*buf
= via_alloc_texture(vmesa
, 512 * 1024, heap
);
345 via_free_texture(vmesa
, buf
);
350 /* Speculatively move texture images which haven't been used in a
351 * while back to system memory.
353 * TODO: only do this when texture memory is low.
357 * TODO: keep the fb/agp version hanging around and use the local
358 * version as backing store, so re-upload might be avoided.
360 * TODO: do this properly in the kernel...
362 GLboolean
viaSwapOutWork( struct via_context
*vmesa
)
364 struct via_tex_buffer
*s
, *tmp
;
368 if (VIA_DEBUG
& DEBUG_TEXTURE
)
369 fprintf(stderr
, "%s VID %d AGP %d SYS %d\n", __FUNCTION__
,
370 vmesa
->total_alloc
[VIA_MEM_VIDEO
],
371 vmesa
->total_alloc
[VIA_MEM_AGP
],
372 vmesa
->total_alloc
[VIA_MEM_SYSTEM
]);
375 for (heap
= VIA_MEM_VIDEO
; heap
<= VIA_MEM_AGP
; heap
++) {
376 GLuint nr
= 0, sz
= 0;
378 if (vmesa
->thrashing
) {
379 if (VIA_DEBUG
& DEBUG_TEXTURE
)
380 fprintf(stderr
, "Heap %d: trash flag\n", heap
);
381 target
= 1*1024*1024;
383 else if (viaIsTexMemLow(vmesa
, heap
)) {
384 if (VIA_DEBUG
& DEBUG_TEXTURE
)
385 fprintf(stderr
, "Heap %d: low memory\n", heap
);
389 if (VIA_DEBUG
& DEBUG_TEXTURE
)
390 fprintf(stderr
, "Heap %d: nothing to do\n", heap
);
394 foreach_s( s
, tmp
, &vmesa
->tex_image_list
[heap
] ) {
395 if (s
->lastUsed
< vmesa
->lastSwap
[1]) {
396 struct via_texture_object
*viaObj
=
397 (struct via_texture_object
*) s
->image
->image
.TexObject
;
399 if (VIA_DEBUG
& DEBUG_TEXTURE
)
401 "back copy tex sz %d, lastUsed %d lastSwap %d\n",
402 s
->size
, s
->lastUsed
, vmesa
->lastSwap
[1]);
404 if (viaMoveTexBuffers( vmesa
, &s
, 1, VIA_MEM_SYSTEM
)) {
405 viaObj
->memType
= VIA_MEM_MIXED
;
409 if (VIA_DEBUG
& DEBUG_TEXTURE
)
410 fprintf(stderr
, "Failed to back copy texture!\n");
420 vmesa
->thrashing
= GL_FALSE
; /* might not get set otherwise? */
425 assert(sz
== vmesa
->total_alloc
[heap
]);
427 if (VIA_DEBUG
& DEBUG_TEXTURE
)
428 fprintf(stderr
, "Heap %d: nr %d tot sz %d\n", heap
, nr
, sz
);
437 /* Basically, just collect the image dimensions and addresses for each
438 * image and update the texture object state accordingly.
440 static GLboolean
viaSetTexImages(GLcontext
*ctx
,
441 struct gl_texture_object
*texObj
)
443 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
444 struct via_texture_object
*viaObj
= (struct via_texture_object
*)texObj
;
445 const struct via_texture_image
*baseImage
=
446 (struct via_texture_image
*)texObj
->Image
[0][texObj
->BaseLevel
];
447 GLint firstLevel
, lastLevel
, numLevels
;
450 GLint i
, j
= 0, k
= 0, l
= 0, m
= 0;
454 GLuint heightExp
= 0;
456 switch (baseImage
->image
.TexFormat
) {
457 case MESA_FORMAT_ARGB8888
:
458 texFormat
= HC_HTXnFM_ARGB8888
;
460 case MESA_FORMAT_ARGB4444
:
461 texFormat
= HC_HTXnFM_ARGB4444
;
463 case MESA_FORMAT_RGB565
:
464 texFormat
= HC_HTXnFM_RGB565
;
466 case MESA_FORMAT_ARGB1555
:
467 texFormat
= HC_HTXnFM_ARGB1555
;
469 case MESA_FORMAT_RGB888
:
470 texFormat
= HC_HTXnFM_ARGB0888
;
473 texFormat
= HC_HTXnFM_L8
;
476 texFormat
= HC_HTXnFM_T8
;
478 case MESA_FORMAT_CI8
:
479 texFormat
= HC_HTXnFM_Index8
;
481 case MESA_FORMAT_AL88
:
482 texFormat
= HC_HTXnFM_AL88
;
485 texFormat
= HC_HTXnFM_A8
;
488 _mesa_problem(vmesa
->glCtx
, "Bad texture format in viaSetTexImages");
492 /* Compute which mipmap levels we really want to send to the hardware.
493 * This depends on the base image size, GL_TEXTURE_MIN_LOD,
494 * GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL, and GL_TEXTURE_MAX_LEVEL.
495 * Yes, this looks overly complicated, but it's all needed.
497 if (texObj
->MinFilter
== GL_LINEAR
|| texObj
->MinFilter
== GL_NEAREST
) {
498 firstLevel
= lastLevel
= texObj
->BaseLevel
;
501 firstLevel
= texObj
->BaseLevel
+ (GLint
)(texObj
->MinLod
+ 0.5);
502 firstLevel
= MAX2(firstLevel
, texObj
->BaseLevel
);
503 lastLevel
= texObj
->BaseLevel
+ (GLint
)(texObj
->MaxLod
+ 0.5);
504 lastLevel
= MAX2(lastLevel
, texObj
->BaseLevel
);
505 lastLevel
= MIN2(lastLevel
, texObj
->BaseLevel
+ baseImage
->image
.MaxLog2
);
506 lastLevel
= MIN2(lastLevel
, texObj
->MaxLevel
);
507 lastLevel
= MAX2(firstLevel
, lastLevel
); /* need at least one level */
510 numLevels
= lastLevel
- firstLevel
+ 1;
512 /* The hardware supports only 10 mipmap levels; ignore higher levels.
514 if ((numLevels
> 10) && (ctx
->Const
.MaxTextureLevels
> 10)) {
515 lastLevel
-= numLevels
- 10;
519 /* save these values, check if they effect the residency of the
522 if (viaObj
->firstLevel
!= firstLevel
||
523 viaObj
->lastLevel
!= lastLevel
) {
524 viaObj
->firstLevel
= firstLevel
;
525 viaObj
->lastLevel
= lastLevel
;
526 viaObj
->memType
= VIA_MEM_MIXED
;
529 if (VIA_DEBUG
& DEBUG_TEXTURE
& 0)
530 fprintf(stderr
, "%s, current memType: %s\n",
532 get_memtype_name(viaObj
->memType
));
535 if (viaObj
->memType
== VIA_MEM_MIXED
||
536 viaObj
->memType
== VIA_MEM_SYSTEM
) {
537 if (!viaSwapInTexObject(vmesa
, viaObj
)) {
538 if (VIA_DEBUG
& DEBUG_TEXTURE
)
539 if (!vmesa
->thrashing
)
540 fprintf(stderr
, "Thrashing flag set for frame %d\n",
542 vmesa
->thrashing
= GL_TRUE
;
547 if (viaObj
->memType
== VIA_MEM_AGP
)
548 viaObj
->regTexFM
= (HC_SubA_HTXnFM
<< 24) | HC_HTXnLoc_AGP
| texFormat
;
550 viaObj
->regTexFM
= (HC_SubA_HTXnFM
<< 24) | HC_HTXnLoc_Local
| texFormat
;
553 for (i
= 0; i
< numLevels
; i
++) {
554 struct via_texture_image
*viaImage
=
555 (struct via_texture_image
*)texObj
->Image
[0][firstLevel
+ i
];
557 w
= viaImage
->image
.WidthLog2
;
558 h
= viaImage
->image
.HeightLog2
;
559 p
= viaImage
->pitchLog2
;
561 assert(viaImage
->texMem
->memType
== viaObj
->memType
);
563 texBase
= viaImage
->texMem
->texBase
;
565 if (VIA_DEBUG
& DEBUG_TEXTURE
)
566 fprintf(stderr
, "%s: no texBase[%d]\n", __FUNCTION__
, i
);
570 /* Image has to remain resident until the coming fence is retired.
572 move_to_head( &vmesa
->tex_image_list
[viaImage
->texMem
->memType
],
574 viaImage
->texMem
->lastUsed
= vmesa
->lastBreadcrumbWrite
;
577 viaObj
->regTexBaseAndPitch
[i
].baseL
=
578 ((HC_SubA_HTXnL0BasL
+ i
) << 24) | (texBase
& 0xFFFFFF);
580 viaObj
->regTexBaseAndPitch
[i
].pitchLog2
=
581 ((HC_SubA_HTXnL0Pit
+ i
) << 24) | (p
<< 20);
584 /* The base high bytes for each 3 levels are packed
585 * together into one register:
589 basH
|= ((texBase
& 0xFF000000) >> (k
<< 3));
591 viaObj
->regTexBaseH
[j
] = ((j
+ HC_SubA_HTXnL012BasH
) << 24) | basH
;
595 /* Likewise, sets of 6 log2width and log2height values are
596 * packed into individual registers:
600 widthExp
|= (((GLuint
)w
& 0xF) << (m
<< 2));
601 heightExp
|= (((GLuint
)h
& 0xF) << (m
<< 2));
603 viaObj
->regTexWidthLog2
[l
] =
604 (l
+ HC_SubA_HTXnL0_5WE
) << 24 | widthExp
;
605 viaObj
->regTexHeightLog2
[l
] =
606 (l
+ HC_SubA_HTXnL0_5HE
) << 24 | heightExp
;
616 viaObj
->regTexBaseH
[j
] = ((j
+ HC_SubA_HTXnL012BasH
) << 24) | basH
;
619 viaObj
->regTexWidthLog2
[l
] = (l
+ HC_SubA_HTXnL0_5WE
) << 24 | widthExp
;
620 viaObj
->regTexHeightLog2
[l
] = (l
+ HC_SubA_HTXnL0_5HE
) << 24 | heightExp
;
627 GLboolean
viaUpdateTextureState( GLcontext
*ctx
)
629 struct gl_texture_unit
*texUnit
= ctx
->Texture
.Unit
;
632 for (i
= 0; i
< 2; i
++) {
633 if (texUnit
[i
]._ReallyEnabled
== TEXTURE_2D_BIT
||
634 texUnit
[i
]._ReallyEnabled
== TEXTURE_1D_BIT
) {
636 if (!viaSetTexImages(ctx
, texUnit
[i
]._Current
))
639 else if (texUnit
[i
]._ReallyEnabled
) {
654 static void viaTexImage(GLcontext
*ctx
,
656 GLenum target
, GLint level
,
657 GLint internalFormat
,
658 GLint width
, GLint height
, GLint border
,
659 GLenum format
, GLenum type
, const void *pixels
,
660 const struct gl_pixelstore_attrib
*packing
,
661 struct gl_texture_object
*texObj
,
662 struct gl_texture_image
*texImage
)
664 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
665 GLint postConvWidth
= width
;
666 GLint postConvHeight
= height
;
667 GLint texelBytes
, sizeInBytes
;
668 struct via_texture_object
*viaObj
= (struct via_texture_object
*)texObj
;
669 struct via_texture_image
*viaImage
= (struct via_texture_image
*)texImage
;
670 int heaps
[3], nheaps
, i
;
672 if (!is_empty_list(&vmesa
->freed_tex_buffers
)) {
673 viaCheckBreadcrumb(vmesa
, 0);
674 via_release_pending_textures(vmesa
);
677 /* choose the texture format */
678 texImage
->TexFormat
= viaChooseTexFormat(ctx
, internalFormat
,
681 assert(texImage
->TexFormat
);
683 texelBytes
= _mesa_get_format_bytes(texImage
->TexFormat
);
685 /* Minimum pitch of 32 bytes */
686 if (postConvWidth
* texelBytes
< 32) {
687 postConvWidth
= 32 / texelBytes
;
688 texImage
->RowStride
= postConvWidth
;
691 assert(texImage
->RowStride
== postConvWidth
);
692 viaImage
->pitchLog2
= logbase2(postConvWidth
* texelBytes
);
694 /* allocate memory */
695 if (_mesa_is_format_compressed(texImage
->TexFormat
))
696 sizeInBytes
= _mesa_format_image_size(texImage
->TexFormat
,
701 sizeInBytes
= postConvWidth
* postConvHeight
* texelBytes
;
704 /* Attempt to allocate texture memory directly, otherwise use main
705 * memory and this texture will always be a fallback. FIXME!
707 * TODO: make room in agp if this fails.
708 * TODO: use fb ram for textures as well.
712 switch (viaObj
->memType
) {
713 case VIA_MEM_UNKNOWN
:
714 heaps
[0] = VIA_MEM_AGP
;
715 heaps
[1] = VIA_MEM_VIDEO
;
716 heaps
[2] = VIA_MEM_SYSTEM
;
721 heaps
[0] = viaObj
->memType
;
722 heaps
[1] = VIA_MEM_SYSTEM
;
728 heaps
[0] = VIA_MEM_SYSTEM
;
733 for (i
= 0; i
< nheaps
&& !viaImage
->texMem
; i
++) {
734 if (VIA_DEBUG
& DEBUG_TEXTURE
)
735 fprintf(stderr
, "try %s (obj %s)\n", get_memtype_name(heaps
[i
]),
736 get_memtype_name(viaObj
->memType
));
737 viaImage
->texMem
= via_alloc_texture(vmesa
, sizeInBytes
, heaps
[i
]);
740 if (!viaImage
->texMem
) {
741 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
745 if (VIA_DEBUG
& DEBUG_TEXTURE
)
746 fprintf(stderr
, "upload %d bytes to %s\n", sizeInBytes
,
747 get_memtype_name(viaImage
->texMem
->memType
));
749 viaImage
->texMem
->image
= viaImage
;
750 texImage
->Data
= viaImage
->texMem
->bufAddr
;
752 if (viaObj
->memType
== VIA_MEM_UNKNOWN
)
753 viaObj
->memType
= viaImage
->texMem
->memType
;
754 else if (viaObj
->memType
!= viaImage
->texMem
->memType
)
755 viaObj
->memType
= VIA_MEM_MIXED
;
757 if (VIA_DEBUG
& DEBUG_TEXTURE
)
758 fprintf(stderr
, "%s, obj %s, image : %s\n",
760 get_memtype_name(viaObj
->memType
),
761 get_memtype_name(viaImage
->texMem
->memType
));
763 vmesa
->clearTexCache
= 1;
765 pixels
= _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, 1,
767 pixels
, packing
, "glTexImage");
769 /* Note: we check for a NULL image pointer here, _after_ we allocated
770 * memory for the texture. That's what the GL spec calls for.
778 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
779 dstRowStride
= _mesa_format_row_stride(texImage
->TexFormat
, width
);
782 dstRowStride
= postConvWidth
* _mesa_get_format_bytes(texImage
->TexFormat
);
784 success
= _mesa_texstore(ctx
, dims
,
785 texImage
->_BaseFormat
,
788 0, 0, 0, /* dstX/Y/Zoffset */
790 texImage
->ImageOffsets
,
792 format
, type
, pixels
, packing
);
794 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
798 _mesa_unmap_teximage_pbo(ctx
, packing
);
801 static void viaTexImage2D(GLcontext
*ctx
,
802 GLenum target
, GLint level
,
803 GLint internalFormat
,
804 GLint width
, GLint height
, GLint border
,
805 GLenum format
, GLenum type
, const void *pixels
,
806 const struct gl_pixelstore_attrib
*packing
,
807 struct gl_texture_object
*texObj
,
808 struct gl_texture_image
*texImage
)
810 viaTexImage( ctx
, 2, target
, level
,
811 internalFormat
, width
, height
, border
,
812 format
, type
, pixels
,
813 packing
, texObj
, texImage
);
816 static void viaTexSubImage2D(GLcontext
*ctx
,
819 GLint xoffset
, GLint yoffset
,
820 GLsizei width
, GLsizei height
,
821 GLenum format
, GLenum type
,
822 const GLvoid
*pixels
,
823 const struct gl_pixelstore_attrib
*packing
,
824 struct gl_texture_object
*texObj
,
825 struct gl_texture_image
*texImage
)
827 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
829 viaWaitIdle(vmesa
, GL_TRUE
);
830 vmesa
->clearTexCache
= 1;
832 _mesa_store_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
, width
,
833 height
, format
, type
, pixels
, packing
, texObj
,
837 static void viaTexImage1D(GLcontext
*ctx
,
838 GLenum target
, GLint level
,
839 GLint internalFormat
,
840 GLint width
, GLint border
,
841 GLenum format
, GLenum type
, const void *pixels
,
842 const struct gl_pixelstore_attrib
*packing
,
843 struct gl_texture_object
*texObj
,
844 struct gl_texture_image
*texImage
)
846 viaTexImage( ctx
, 1, target
, level
,
847 internalFormat
, width
, 1, border
,
848 format
, type
, pixels
,
849 packing
, texObj
, texImage
);
852 static void viaTexSubImage1D(GLcontext
*ctx
,
857 GLenum format
, GLenum type
,
858 const GLvoid
*pixels
,
859 const struct gl_pixelstore_attrib
*packing
,
860 struct gl_texture_object
*texObj
,
861 struct gl_texture_image
*texImage
)
863 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
865 viaWaitIdle(vmesa
, GL_TRUE
);
866 vmesa
->clearTexCache
= 1;
868 _mesa_store_texsubimage1d(ctx
, target
, level
, xoffset
, width
,
869 format
, type
, pixels
, packing
, texObj
,
875 static GLboolean
viaIsTextureResident(GLcontext
*ctx
,
876 struct gl_texture_object
*texObj
)
878 struct via_texture_object
*viaObj
=
879 (struct via_texture_object
*)texObj
;
881 return (viaObj
->memType
== VIA_MEM_AGP
||
882 viaObj
->memType
== VIA_MEM_VIDEO
);
887 static struct gl_texture_image
*viaNewTextureImage( GLcontext
*ctx
)
890 return (struct gl_texture_image
*)CALLOC_STRUCT(via_texture_image
);
894 static struct gl_texture_object
*viaNewTextureObject( GLcontext
*ctx
,
898 struct via_texture_object
*obj
= CALLOC_STRUCT(via_texture_object
);
900 _mesa_initialize_texture_object(&obj
->obj
, name
, target
);
903 obj
->memType
= VIA_MEM_UNKNOWN
;
909 static void viaFreeTextureImageData( GLcontext
*ctx
,
910 struct gl_texture_image
*texImage
)
912 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
913 struct via_texture_image
*image
= (struct via_texture_image
*)texImage
;
916 via_free_texture(vmesa
, image
->texMem
);
917 image
->texMem
= NULL
;
920 texImage
->Data
= NULL
;
926 void viaInitTextureFuncs(struct dd_function_table
* functions
)
928 functions
->ChooseTextureFormat
= viaChooseTexFormat
;
929 functions
->TexImage1D
= viaTexImage1D
;
930 functions
->TexImage2D
= viaTexImage2D
;
931 functions
->TexSubImage1D
= viaTexSubImage1D
;
932 functions
->TexSubImage2D
= viaTexSubImage2D
;
934 functions
->NewTextureObject
= viaNewTextureObject
;
935 functions
->NewTextureImage
= viaNewTextureImage
;
936 functions
->DeleteTexture
= _mesa_delete_texture_object
;
937 functions
->FreeTexImageData
= viaFreeTextureImageData
;
939 #if 0 && defined( USE_SSE_ASM )
941 * XXX this code is disabled for now because the via_sse_memcpy()
942 * routine causes segfaults with flightgear.
943 * See Mesa3d-dev mail list messages from 7/15/2005 for details.
944 * Note that this function is currently disabled in via_tris.c too.
946 if (getenv("VIA_NO_SSE"))
947 functions
->TextureMemCpy
= memcpy
;
949 functions
->TextureMemCpy
= via_sse_memcpy
;
951 functions
->TextureMemCpy
= memcpy
;
954 functions
->IsTextureResident
= viaIsTextureResident
;