2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4 The Weather Channel (TM) funded Tungsten Graphics to develop the
5 initial release of the Radeon 8500 driver under the XFree86 license.
6 This notice must be preserved.
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Keith Whitwell <keith@tungstengraphics.com>
38 #include "main/glheader.h"
39 #include "main/imports.h"
40 #include "main/macros.h"
41 #include "main/context.h"
42 #include "swrast/swrast.h"
46 #include "radeon_common.h"
47 #include "radeon_lock.h"
48 #include "r200_context.h"
49 #include "r200_ioctl.h"
50 #include "radeon_reg.h"
54 #define R200_TIMEOUT 512
55 #define R200_IDLE_RETRY 16
57 static void r200KernelClear(GLcontext
*ctx
, GLuint flags
)
59 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
60 __DRIdrawable
*dPriv
= radeon_get_drawable(&rmesa
->radeon
);
61 GLint cx
, cy
, cw
, ch
, ret
;
64 radeonEmitState(&rmesa
->radeon
);
66 LOCK_HARDWARE( &rmesa
->radeon
);
68 /* Throttle the number of clear ioctls we do.
71 drm_radeon_getparam_t gp
;
75 gp
.param
= RADEON_PARAM_LAST_CLEAR
;
76 gp
.value
= (int *)&clear
;
77 ret
= drmCommandWriteRead( rmesa
->radeon
.dri
.fd
,
78 DRM_RADEON_GETPARAM
, &gp
, sizeof(gp
) );
81 fprintf( stderr
, "%s: drmRadeonGetParam: %d\n", __FUNCTION__
, ret
);
85 /* Clear throttling needs more thought.
87 if ( rmesa
->radeon
.sarea
->last_clear
- clear
<= 25 ) {
91 if (rmesa
->radeon
.do_usleeps
) {
92 UNLOCK_HARDWARE( &rmesa
->radeon
);
94 LOCK_HARDWARE( &rmesa
->radeon
);
98 /* Send current state to the hardware */
99 rcommonFlushCmdBufLocked( &rmesa
->radeon
, __FUNCTION__
);
102 /* compute region after locking: */
103 cx
= ctx
->DrawBuffer
->_Xmin
;
104 cy
= ctx
->DrawBuffer
->_Ymin
;
105 cw
= ctx
->DrawBuffer
->_Xmax
- cx
;
106 ch
= ctx
->DrawBuffer
->_Ymax
- cy
;
108 /* Flip top to bottom */
110 cy
= dPriv
->y
+ dPriv
->h
- cy
- ch
;
111 for ( i
= 0 ; i
< dPriv
->numClipRects
; ) {
112 GLint nr
= MIN2( i
+ RADEON_NR_SAREA_CLIPRECTS
, dPriv
->numClipRects
);
113 drm_clip_rect_t
*box
= dPriv
->pClipRects
;
114 drm_clip_rect_t
*b
= rmesa
->radeon
.sarea
->boxes
;
115 drm_radeon_clear_t clear
;
116 drm_radeon_clear_rect_t depth_boxes
[RADEON_NR_SAREA_CLIPRECTS
];
119 if (cw
!= dPriv
->w
|| ch
!= dPriv
->h
) {
120 /* clear subregion */
121 for ( ; i
< nr
; i
++ ) {
124 GLint w
= box
[i
].x2
- x
;
125 GLint h
= box
[i
].y2
- y
;
127 if ( x
< cx
) w
-= cx
- x
, x
= cx
;
128 if ( y
< cy
) h
-= cy
- y
, y
= cy
;
129 if ( x
+ w
> cx
+ cw
) w
= cx
+ cw
- x
;
130 if ( y
+ h
> cy
+ ch
) h
= cy
+ ch
- y
;
131 if ( w
<= 0 ) continue;
132 if ( h
<= 0 ) continue;
142 /* clear whole window */
143 for ( ; i
< nr
; i
++ ) {
149 rmesa
->radeon
.sarea
->nbox
= n
;
152 clear
.clear_color
= rmesa
->radeon
.state
.color
.clear
;
153 clear
.clear_depth
= rmesa
->radeon
.state
.depth
.clear
; /* needed for hyperz */
154 clear
.color_mask
= rmesa
->hw
.msk
.cmd
[MSK_RB3D_PLANEMASK
];
155 clear
.depth_mask
= rmesa
->radeon
.state
.stencil
.clear
;
156 clear
.depth_boxes
= depth_boxes
;
159 b
= rmesa
->radeon
.sarea
->boxes
;
160 for ( ; n
>= 0 ; n
-- ) {
161 depth_boxes
[n
].f
[CLEAR_X1
] = (float)b
[n
].x1
;
162 depth_boxes
[n
].f
[CLEAR_Y1
] = (float)b
[n
].y1
;
163 depth_boxes
[n
].f
[CLEAR_X2
] = (float)b
[n
].x2
;
164 depth_boxes
[n
].f
[CLEAR_Y2
] = (float)b
[n
].y2
;
165 depth_boxes
[n
].f
[CLEAR_DEPTH
] = ctx
->Depth
.Clear
;
168 ret
= drmCommandWrite( rmesa
->radeon
.dri
.fd
, DRM_RADEON_CLEAR
,
169 &clear
, sizeof(clear
));
173 UNLOCK_HARDWARE( &rmesa
->radeon
);
174 fprintf( stderr
, "DRM_RADEON_CLEAR: return = %d\n", ret
);
178 UNLOCK_HARDWARE( &rmesa
->radeon
);
180 /* ================================================================
183 static void r200Clear( GLcontext
*ctx
, GLbitfield mask
)
185 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
186 __DRIdrawable
*dPriv
= radeon_get_drawable(&rmesa
->radeon
);
188 GLuint color_mask
= 0;
189 GLuint orig_mask
= mask
;
191 if ( R200_DEBUG
& RADEON_IOCTL
) {
192 if (rmesa
->radeon
.sarea
)
193 fprintf( stderr
, "r200Clear %x %d\n", mask
, rmesa
->radeon
.sarea
->pfCurrentPage
);
195 fprintf( stderr
, "r200Clear %x radeon->sarea is NULL\n", mask
);
199 LOCK_HARDWARE( &rmesa
->radeon
);
200 UNLOCK_HARDWARE( &rmesa
->radeon
);
201 if ( dPriv
->numClipRects
== 0 )
207 if ( mask
& BUFFER_BIT_FRONT_LEFT
) {
208 flags
|= RADEON_FRONT
;
209 color_mask
= rmesa
->hw
.msk
.cmd
[MSK_RB3D_PLANEMASK
];
210 mask
&= ~BUFFER_BIT_FRONT_LEFT
;
213 if ( mask
& BUFFER_BIT_BACK_LEFT
) {
214 flags
|= RADEON_BACK
;
215 color_mask
= rmesa
->hw
.msk
.cmd
[MSK_RB3D_PLANEMASK
];
216 mask
&= ~BUFFER_BIT_BACK_LEFT
;
219 if ( mask
& BUFFER_BIT_DEPTH
) {
220 flags
|= RADEON_DEPTH
;
221 mask
&= ~BUFFER_BIT_DEPTH
;
224 if ( (mask
& BUFFER_BIT_STENCIL
) ) {
225 flags
|= RADEON_STENCIL
;
226 mask
&= ~BUFFER_BIT_STENCIL
;
230 if (R200_DEBUG
& RADEON_FALLBACKS
)
231 fprintf(stderr
, "%s: swrast clear, mask: %x\n", __FUNCTION__
, mask
);
232 _swrast_Clear( ctx
, mask
);
238 if (rmesa
->using_hyperz
) {
239 flags
|= RADEON_USE_COMP_ZBUF
;
240 /* if (rmesa->radeon.radeonScreen->chip_family == CHIP_FAMILY_R200)
241 flags |= RADEON_USE_HIERZ; */
242 if (!((flags
& RADEON_DEPTH
) && (flags
& RADEON_STENCIL
) &&
243 ((rmesa
->radeon
.state
.stencil
.clear
& R200_STENCIL_WRITE_MASK
) == R200_STENCIL_WRITE_MASK
))) {
244 flags
|= RADEON_CLEAR_FASTZ
;
248 if (rmesa
->radeon
.radeonScreen
->kernel_mm
)
249 radeonUserClear(ctx
, orig_mask
);
251 r200KernelClear(ctx
, flags
);
252 rmesa
->radeon
.hw
.all_dirty
= GL_TRUE
;
256 GLboolean
r200IsGartMemory( r200ContextPtr rmesa
, const GLvoid
*pointer
,
259 ptrdiff_t offset
= (char *)pointer
- (char *)rmesa
->radeon
.radeonScreen
->gartTextures
.map
;
260 int valid
= (size
>= 0 &&
262 offset
+ size
< rmesa
->radeon
.radeonScreen
->gartTextures
.size
);
264 if (R200_DEBUG
& RADEON_IOCTL
)
265 fprintf(stderr
, "r200IsGartMemory( %p ) : %d\n", pointer
, valid
);
271 GLuint
r200GartOffsetFromVirtual( r200ContextPtr rmesa
, const GLvoid
*pointer
)
273 ptrdiff_t offset
= (char *)pointer
- (char *)rmesa
->radeon
.radeonScreen
->gartTextures
.map
;
275 if (offset
< 0 || offset
> rmesa
->radeon
.radeonScreen
->gartTextures
.size
)
278 return rmesa
->radeon
.radeonScreen
->gart_texture_offset
+ offset
;
283 void r200InitIoctlFuncs( struct dd_function_table
*functions
)
285 functions
->Clear
= r200Clear
;
286 functions
->Finish
= radeonFinish
;
287 functions
->Flush
= radeonFlush
;