1 /**************************************************************************
3 Copyright 2001 2d3d Inc., Delray Beach, FL
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ATI, VA LINUX SYSTEMS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 /* $XFree86: xc/lib/GL/mesa/src/drv/i830/i830_texmem.c,v 1.3 2002/12/10 01:26:53 dawes Exp $ */
32 * Jeff Hartmann <jhartmann@2d3d.com>
34 * Heavily based on the I810 driver, which was written by:
35 * Keith Whitwell <keithw@tungstengraphics.com>
41 #include "simple_list.h"
43 #include "texformat.h"
45 #include "i830_screen.h"
48 #include "i830_context.h"
50 #include "i830_state.h"
51 #include "i830_ioctl.h"
54 void i830DestroyTexObj(i830ContextPtr imesa
, i830TextureObjectPtr t
)
59 /* See if it was the driver's current object.
61 if ( imesa
!= NULL
) {
62 for ( i
= 0 ; i
< imesa
->glCtx
->Const
.MaxTextureUnits
; i
++ ) {
63 if ( t
== imesa
->CurrentTexObj
[ i
] ) {
64 imesa
->CurrentTexObj
[ i
] = NULL
;
65 imesa
->dirty
&= ~I830_UPLOAD_TEX_N( i
);
71 #if defined(i386) || defined(__i386__)
72 /* From linux kernel i386 header files, copes with odd sizes better
73 * than COPY_DWORDS would:
75 static __inline__
void * __memcpy(void * to
, const void * from
, size_t n
)
83 "1:\ttestb $1,%b4\n\t"
87 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
88 :"0" (n
/4), "q" (n
),"1" ((long) to
),"2" ((long) from
)
93 /* Allow compilation on other architectures */
94 #define __memcpy memcpy
97 /* Upload an image from mesa's internal copy.
99 static void i830UploadTexLevel( i830ContextPtr imesa
,
100 i830TextureObjectPtr t
, int hwlevel
)
102 const struct gl_texture_image
*image
= t
->image
[0][hwlevel
].image
;
105 if (!image
|| !image
->Data
)
108 if (image
->IsCompressed
) {
109 GLubyte
*dst
= (GLubyte
*)(t
->BufAddr
+ t
->image
[0][hwlevel
].offset
);
110 GLubyte
*src
= (GLubyte
*)image
->Data
;
112 if ((t
->Setup
[I830_TEXREG_TM0S1
] & TM0S1_MT_FORMAT_MASK
)==MT_COMPRESS_FXT1
)
114 for (j
= 0 ; j
< image
->Height
/4 ; j
++, dst
+= (t
->Pitch
)) {
115 __memcpy(dst
, src
, (image
->Width
*2) );
116 src
+= image
->Width
*2;
119 else if ((t
->Setup
[I830_TEXREG_TM0S1
] & TM0S1_MT_FORMAT_MASK
)==MT_COMPRESS_DXT1
)
121 for (j
= 0 ; j
< image
->Height
/4 ; j
++, dst
+= (t
->Pitch
)) {
122 __memcpy(dst
, src
, (image
->Width
*2) );
123 src
+= image
->Width
*2;
126 else if (((t
->Setup
[I830_TEXREG_TM0S1
] & TM0S1_MT_FORMAT_MASK
)==MT_COMPRESS_DXT2_3
) || ((t
->Setup
[I830_TEXREG_TM0S1
] & TM0S1_MT_FORMAT_MASK
)==MT_COMPRESS_DXT4_5
))
128 for (j
= 0 ; j
< image
->Height
/4 ; j
++, dst
+= (t
->Pitch
)) {
129 __memcpy(dst
, src
, (image
->Width
*4) );
130 src
+= image
->Width
*4;
134 else if (image
->Width
* image
->TexFormat
->TexelBytes
== t
->Pitch
) {
135 GLubyte
*dst
= (GLubyte
*)(t
->BufAddr
+ t
->image
[0][hwlevel
].offset
);
136 GLubyte
*src
= (GLubyte
*)image
->Data
;
138 memcpy( dst
, src
, t
->Pitch
* image
->Height
);
140 else switch (image
->TexFormat
->TexelBytes
) {
143 GLubyte
*dst
= (GLubyte
*)(t
->BufAddr
+ t
->image
[0][hwlevel
].offset
);
144 GLubyte
*src
= (GLubyte
*)image
->Data
;
146 for (j
= 0 ; j
< image
->Height
; j
++, dst
+= t
->Pitch
) {
147 __memcpy(dst
, src
, image
->Width
);
155 GLushort
*dst
= (GLushort
*)(t
->BufAddr
+ t
->image
[0][hwlevel
].offset
);
156 GLushort
*src
= (GLushort
*)image
->Data
;
158 for (j
= 0 ; j
< image
->Height
; j
++, dst
+= (t
->Pitch
/2)) {
159 __memcpy(dst
, src
, image
->Width
* 2 );
167 GLuint
*dst
= (GLuint
*)(t
->BufAddr
+ t
->image
[0][hwlevel
].offset
);
168 GLuint
*src
= (GLuint
*)image
->Data
;
170 for (j
= 0 ; j
< image
->Height
; j
++, dst
+= (t
->Pitch
/4)) {
171 __memcpy(dst
, src
, image
->Width
* 4 );
178 fprintf(stderr
, "%s: Not supported texel size %d\n",
179 __FUNCTION__
, image
->TexFormat
->TexelBytes
);
184 /* This is called with the lock held. May have to eject our own and/or
185 * other client's texture objects to make room for the upload.
188 int i830UploadTexImagesLocked( i830ContextPtr imesa
, i830TextureObjectPtr t
)
193 if ( t
->base
.memBlock
== NULL
) {
196 heap
= driAllocateTexture( imesa
->texture_heaps
, imesa
->nr_heaps
,
197 (driTextureObject
*) t
);
202 /* Set the base offset of the texture image */
203 ofs
= t
->base
.memBlock
->ofs
;
204 t
->BufAddr
= imesa
->i830Screen
->tex
.map
+ ofs
;
205 t
->Setup
[I830_TEXREG_TM0S0
] = (TM0S0_USE_FENCE
|
206 (imesa
->i830Screen
->textureOffset
+ ofs
));
208 for ( i
= 0 ; i
< imesa
->glCtx
->Const
.MaxTextureUnits
; i
++ ) {
209 if (t
== imesa
->CurrentTexObj
[i
]) {
210 imesa
->dirty
|= I830_UPLOAD_TEX_N( i
);
216 /* Let the world know we've used this memory recently.
218 driUpdateTextureLRU( (driTextureObject
*) t
);
220 if (imesa
->texture_heaps
[0]->timestamp
>= GET_DISPATCH_AGE(imesa
))
221 i830WaitAgeLocked( imesa
, imesa
->texture_heaps
[0]->timestamp
);
223 /* Upload any images that are new */
224 if (t
->base
.dirty_images
[0]) {
225 const int numLevels
= t
->base
.lastLevel
- t
->base
.firstLevel
+ 1;
227 for (i
= 0 ; i
< numLevels
; i
++) {
228 if ( (t
->base
.dirty_images
[0] & (1 << (i
+t
->base
.firstLevel
))) != 0 ) {
229 i830UploadTexLevel( imesa
, t
, i
);
232 t
->base
.dirty_images
[0] = 0;
233 imesa
->sarea
->perf_boxes
|= I830_BOX_TEXTURE_LOAD
;