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