fix up radeon span functions using latest r200 code from Brian,
[mesa.git] / src / mesa / drivers / dri / gamma / gamma_macros.h
1 /* $XFree86: xc/lib/GL/mesa/src/drv/gamma/gamma_macros.h,v 1.5 2002/02/22 21:33:02 dawes Exp $ */
2 /**************************************************************************
3
4 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
5 All Rights Reserved.
6
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sub license, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
14
15 The above copyright notice and this permission notice (including the
16 next paragraph) shall be included in all copies or substantial portions
17 of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
23 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
27 **************************************************************************/
28
29 /*
30 * Authors:
31 * Kevin E. Martin <kevin@precisioninsight.com>
32 *
33 */
34
35 #ifndef _GAMMA_MACROS_H_
36 #define _GAMMA_MACROS_H_
37
38 #define DEBUG_DRMDMA
39 #define DEBUG_ERRORS
40 #define DEBUG_COMMANDS_NOT
41 #define DEBUG_VERBOSE_NOT
42 #define DEBUG_VERBOSE_EXTRA_NOT
43
44 #define RANDOMIZE_COLORS_NOT
45 #define TURN_OFF_CLEARS_NOT
46 #define CULL_ALL_PRIMS_NOT
47 #define TURN_OFF_DEPTH_NOT
48 #define TURN_OFF_BLEND_NOT
49 #define FAST_CLEAR_4_NOT
50 #define FORCE_DEPTH32_NOT
51 #define DONT_SEND_DMA_NOT
52 #define TURN_OFF_FCP_NOT
53 #define TURN_OFF_TEXTURES_NOT
54 #define DO_VALIDATE
55
56 #define GAMMA_DMA_BUFFER_SIZE 4096
57
58 #if 0
59 #define GAMMA_DMA_SEND_FLAGS DRM_DMA_PRIORITY
60 #define GAMMA_DMA_SEND_FLAGS DRM_DMA_BLOCK
61 #else
62 /* MUST use non-blocking dma flags for drawable lock routines */
63 #define GAMMA_DMA_SEND_FLAGS 0
64 #endif
65
66 #if 0
67 #define GAMMA_DMA_GET_FLAGS \
68 (DRM_DMA_SMALLER_OK | DRM_DMA_LARGER_OK | DRM_DMA_WAIT)
69 #else
70 #define GAMMA_DMA_GET_FLAGS DRM_DMA_WAIT
71 #endif
72
73 #if defined(DEBUG_DRMDMA) || defined(DEBUG_COMMANDS) || defined(DEBUG_VERBOSE)
74 #include <stdio.h>
75 #endif
76
77 /* Note: The argument to DEBUG_GLCMDS() _must_ be enclosed in parenthesis */
78 #ifdef DEBUG_VERBOSE
79 #define DEBUG_GLCMDS(s) printf s
80 #else
81 #define DEBUG_GLCMDS(s)
82 #endif
83
84 /* Note: The argument to DEBUG_DMACMDS() _must_ be enclosed in parenthesis */
85 #ifdef DEBUG_DRMDMA
86 #define DEBUG_DMACMDS(s) printf s
87 #else
88 #define DEBUG_DMACMDS(s)
89 #endif
90
91 /* Note: The argument to DEBUG_WRITE() _must_ be enclosed in parenthesis */
92 #ifdef DEBUG_COMMANDS
93 #define DEBUG_WRITE(s) printf s
94 #else
95 #define DEBUG_WRITE(s)
96 #endif
97
98 /* Note: The argument to DEBUG_ERROR() _must_ be enclosed in parenthesis */
99 #ifdef DEBUG_ERRORS
100 #define DEBUG_ERROR(s) printf s
101 #else
102 #define DEBUG_ERROR(s)
103 #endif
104
105 #define WRITEV(buf,val1,val2,val3,val4) \
106 do { \
107 buf++->i = 0x9C008300; \
108 buf++->f = val1; \
109 buf++->f = val2; \
110 buf++->f = val3; \
111 buf++->f = val4; \
112 } while (0)
113
114 #define WRITE(buf,reg,val) \
115 do { \
116 buf++->i = Glint##reg##Tag; \
117 buf++->i = val; \
118 DEBUG_WRITE(("WRITE(buf, %s, 0x%08x);\n", #reg, (int)val)); \
119 } while (0)
120
121 #define WRITEF(buf,reg,val) \
122 do { \
123 buf++->i = Glint##reg##Tag; \
124 buf++->f = val; \
125 DEBUG_WRITE(("WRITEF(buf, %s, %f);\n", #reg, (float)val)); \
126 } while (0)
127
128 #define CHECK_WC_DMA_BUFFER(gcp,n) \
129 do { \
130 (gcp)->WCbufCount += (n<<1); \
131 } while (0)
132
133 #define CHECK_DMA_BUFFER(gcp,n) \
134 do { \
135 if ((gcp)->bufCount+(n<<1) >= (gcp)->bufSize) \
136 PROCESS_DMA_BUFFER(gcp); \
137 (gcp)->bufCount += (n<<1); \
138 } while (0)
139
140 #define CHECK_DMA_BUFFER2(gcp,n) \
141 do { \
142 if ((gcp)->bufCount+n >= (gcp)->bufSize) \
143 PROCESS_DMA_BUFFER(gcp); \
144 (gcp)->bufCount += n; \
145 } while (0)
146
147 #define FLUSH_DMA_BUFFER(gcp) \
148 do { \
149 if (gcp->bufCount) \
150 PROCESS_DMA_BUFFER(gcp); \
151 } while (0)
152
153 #ifdef DONT_SEND_DMA
154 #define GET_DMA(fd, hHWCtx, n, idx, size)
155 #define SEND_DMA(fd, hHWCtx,n, idx, cnt)
156 #else
157 #define GET_DMA(fd, hHWCtx, n, idx, size) \
158 do { \
159 drmDMAReq dma; \
160 int retcode, i; \
161 \
162 dma.context = (hHWCtx); \
163 dma.send_count = 0; \
164 dma.send_list = NULL; \
165 dma.send_sizes = NULL; \
166 dma.flags = GAMMA_DMA_GET_FLAGS; \
167 dma.request_count = (n); \
168 dma.request_size = GAMMA_DMA_BUFFER_SIZE; \
169 dma.request_list = (idx); \
170 dma.request_sizes = (size); \
171 \
172 do { \
173 if ((retcode = drmDMA((fd), &dma))) { \
174 DEBUG_DMACMDS(("drmDMA returned %d\n", retcode)); \
175 } \
176 } while (!(dma).granted_count); \
177 \
178 for (i = 0; i < (n); i++) { \
179 (size)[i] >>= 2; /* Convert from bytes to words */ \
180 } \
181 } while (0)
182
183 #define SEND_DMA(fd, hHWCtx, n, idx, cnt) \
184 do { \
185 drmDMAReq dma; \
186 int retcode, i; \
187 \
188 for (i = 0; i < (n); i++) { \
189 (cnt)[i] <<= 2; /* Convert from words to bytes */ \
190 } \
191 \
192 dma.context = (hHWCtx); \
193 dma.send_count = 1; \
194 dma.send_list = (idx); \
195 dma.send_sizes = (cnt); \
196 dma.flags = GAMMA_DMA_SEND_FLAGS; \
197 dma.request_count = 0; \
198 dma.request_size = 0; \
199 dma.request_list = NULL; \
200 dma.request_sizes = NULL; \
201 \
202 if ((retcode = drmDMA((fd), &dma))) { \
203 DEBUG_DMACMDS(("drmDMA returned %d\n", retcode)); \
204 } \
205 \
206 for (i = 0; i < (n); i++) { \
207 (cnt)[i] = 0; \
208 } \
209 } while (0)
210 #endif
211
212 #define GET_FIRST_DMA(fd, hHWCtx, n, idx, size, buf, cnt, gPriv) \
213 do { \
214 int i; \
215 \
216 GET_DMA(fd, hHWCtx, n, idx, size); \
217 \
218 for (i = 0; i < (n); i++) { \
219 (buf)[i] = (dmaBuf)(gPriv)->bufs->list[(idx)[i]].address; \
220 (cnt)[i] = 0; \
221 } \
222 } while (0)
223
224 #define PROCESS_DMA_BUFFER_TOP_HALF(gcp) \
225 do { \
226 SEND_DMA((gcp)->driFd, \
227 (gcp)->hHWContext, 1, &(gcp)->bufIndex, &(gcp)->bufCount); \
228 } while (0)
229
230 #define PROCESS_DMA_BUFFER_BOTTOM_HALF(gcp) \
231 do { \
232 GET_DMA((gcp)->driFd, \
233 (gcp)->hHWContext, 1, &(gcp)->bufIndex, &(gcp)->bufSize); \
234 \
235 (gcp)->buf = \
236 (dmaBuf)(gcp)->gammaScreen->bufs->list[(gcp)->bufIndex].address; \
237 } while (0)
238
239 #define PROCESS_DMA_BUFFER(gcp) \
240 do { \
241 VALIDATE_DRAWABLE_INFO(gcp); \
242 PROCESS_DMA_BUFFER_TOP_HALF(gcp); \
243 PROCESS_DMA_BUFFER_BOTTOM_HALF(gcp); \
244 } while (0)
245
246 #ifdef DO_VALIDATE
247 #define VALIDATE_DRAWABLE_INFO_NO_LOCK(gcp) \
248 do { \
249 /*__DRIscreenPrivate *psp = gcp->driScreen;*/ \
250 __DRIdrawablePrivate *pdp = gcp->driDrawable; \
251 \
252 if (*(pdp->pStamp) != pdp->lastStamp) { \
253 int old_index = pdp->index; \
254 while (*(pdp->pStamp) != pdp->lastStamp) { \
255 DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
256 } \
257 if (pdp->index != old_index) { \
258 gcp->Window &= ~W_GIDMask; \
259 gcp->Window |= (pdp->index << 5); \
260 CHECK_WC_DMA_BUFFER(gcp, 1); \
261 WRITE(gcp->WCbuf, GLINTWindow, gcp->Window|(gcp->FrameCount<<9));\
262 } \
263 \
264 gammaUpdateViewportOffset( gcp->glCtx); \
265 \
266 if (pdp->numClipRects == 1 && \
267 pdp->pClipRects->x1 == pdp->x && \
268 pdp->pClipRects->x2 == (pdp->x+pdp->w) && \
269 pdp->pClipRects->y1 == pdp->y && \
270 pdp->pClipRects->y2 == (pdp->y+pdp->h)) { \
271 CHECK_WC_DMA_BUFFER(gcp, 1); \
272 WRITE(gcp->WCbuf, Rectangle2DControl, 0); \
273 gcp->NotClipped = GL_TRUE; \
274 } else { \
275 CHECK_WC_DMA_BUFFER(gcp, 1); \
276 WRITE(gcp->WCbuf, Rectangle2DControl, 1); \
277 gcp->NotClipped = GL_FALSE; \
278 } \
279 gcp->WindowChanged = GL_TRUE; \
280 \
281 if (gcp->WCbufCount) { \
282 SEND_DMA((gcp)->gammaScreen->driScreen->fd, \
283 (gcp)->hHWContext, 1, &(gcp)->WCbufIndex, \
284 &(gcp)->WCbufCount); \
285 (gcp)->WCbufIndex = -1; \
286 } \
287 } \
288 } while (0)
289
290 #define VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gcp) \
291 do { \
292 if ((gcp)->WCbufIndex < 0) { \
293 GET_DMA((gcp)->gammaScreen->driScreen->fd, \
294 (gcp)->hHWContext, 1, &(gcp)->WCbufIndex, \
295 &(gcp)->WCbufSize); \
296 \
297 (gcp)->WCbuf = \
298 (dmaBuf)(gcp)->gammaScreen->bufs-> \
299 list[(gcp)->WCbufIndex].address; \
300 } \
301 } while (0)
302
303 #define VALIDATE_DRAWABLE_INFO(gcp) \
304 do { \
305 __DRIscreenPrivate *psp = gcp->driScreen; \
306 if (gcp->driDrawable) { \
307 DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
308 VALIDATE_DRAWABLE_INFO_NO_LOCK(gcp); \
309 DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
310 VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gcp); \
311 } \
312 } while (0)
313 #else
314 #define VALIDATE_DRAWABLE_INFO(gcp)
315 #endif
316
317 #define CALC_LOG2(l2,s) \
318 do { \
319 int __s = s; \
320 l2 = 0; \
321 while (__s > 1) { ++l2; __s >>= 1; } \
322 } while (0)
323
324 #endif /* _GAMMA_MACROS_H_ */