1 /* $XFree86: xc/lib/GL/mesa/src/drv/gamma/gamma_macros.h,v 1.5 2002/02/22 21:33:02 dawes Exp $ */
2 /**************************************************************************
4 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
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:
15 The above copyright notice and this permission notice (including the
16 next paragraph) shall be included in all copies or substantial portions
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.
27 **************************************************************************/
31 * Kevin E. Martin <kevin@precisioninsight.com>
35 #ifndef _GAMMA_MACROS_H_
36 #define _GAMMA_MACROS_H_
38 #ifdef GLX_DIRECT_RENDERING
42 #define DEBUG_COMMANDS_NOT
43 #define DEBUG_VERBOSE_NOT
44 #define DEBUG_VERBOSE_EXTRA_NOT
46 #define RANDOMIZE_COLORS_NOT
47 #define TURN_OFF_CLEARS_NOT
48 #define CULL_ALL_PRIMS_NOT
49 #define TURN_OFF_DEPTH_NOT
50 #define TURN_OFF_BLEND_NOT
51 #define FAST_CLEAR_4_NOT
52 #define FORCE_DEPTH32_NOT
53 #define DONT_SEND_DMA_NOT
54 #define TURN_OFF_FCP_NOT
55 #define TURN_OFF_TEXTURES_NOT
58 #define GAMMA_DMA_BUFFER_SIZE 4096
61 #define GAMMA_DMA_SEND_FLAGS DRM_DMA_PRIORITY
62 #define GAMMA_DMA_SEND_FLAGS DRM_DMA_BLOCK
64 /* MUST use non-blocking dma flags for drawable lock routines */
65 #define GAMMA_DMA_SEND_FLAGS 0
69 #define GAMMA_DMA_GET_FLAGS \
70 (DRM_DMA_SMALLER_OK | DRM_DMA_LARGER_OK | DRM_DMA_WAIT)
72 #define GAMMA_DMA_GET_FLAGS DRM_DMA_WAIT
75 #if defined(DEBUG_DRMDMA) || defined(DEBUG_COMMANDS) || defined(DEBUG_VERBOSE)
79 /* Note: The argument to DEBUG_GLCMDS() _must_ be enclosed in parenthesis */
81 #define DEBUG_GLCMDS(s) printf s
83 #define DEBUG_GLCMDS(s)
86 /* Note: The argument to DEBUG_DMACMDS() _must_ be enclosed in parenthesis */
88 #define DEBUG_DMACMDS(s) printf s
90 #define DEBUG_DMACMDS(s)
93 /* Note: The argument to DEBUG_WRITE() _must_ be enclosed in parenthesis */
95 #define DEBUG_WRITE(s) printf s
97 #define DEBUG_WRITE(s)
100 /* Note: The argument to DEBUG_ERROR() _must_ be enclosed in parenthesis */
102 #define DEBUG_ERROR(s) printf s
104 #define DEBUG_ERROR(s)
107 #define WRITEV(buf,val1,val2,val3,val4) \
109 buf++->i = 0x9C008300; \
116 #define WRITE(buf,reg,val) \
118 buf++->i = Glint##reg##Tag; \
120 DEBUG_WRITE(("WRITE(buf, %s, 0x%08x);\n", #reg, (int)val)); \
123 #define WRITEF(buf,reg,val) \
125 buf++->i = Glint##reg##Tag; \
127 DEBUG_WRITE(("WRITEF(buf, %s, %f);\n", #reg, (float)val)); \
130 #define CHECK_WC_DMA_BUFFER(gcp,n) \
132 (gcp)->WCbufCount += (n<<1); \
135 #define CHECK_DMA_BUFFER(gcp,n) \
137 if ((gcp)->bufCount+(n<<1) >= (gcp)->bufSize) \
138 PROCESS_DMA_BUFFER(gcp); \
139 (gcp)->bufCount += (n<<1); \
142 #define CHECK_DMA_BUFFER2(gcp,n) \
144 if ((gcp)->bufCount+n >= (gcp)->bufSize) \
145 PROCESS_DMA_BUFFER(gcp); \
146 (gcp)->bufCount += n; \
149 #define FLUSH_DMA_BUFFER(gcp) \
152 PROCESS_DMA_BUFFER(gcp); \
156 #define GET_DMA(fd, hHWCtx, n, idx, size)
157 #define SEND_DMA(fd, hHWCtx,n, idx, cnt)
159 #define GET_DMA(fd, hHWCtx, n, idx, size) \
164 dma.context = (hHWCtx); \
165 dma.send_count = 0; \
166 dma.send_list = NULL; \
167 dma.send_sizes = NULL; \
168 dma.flags = GAMMA_DMA_GET_FLAGS; \
169 dma.request_count = (n); \
170 dma.request_size = GAMMA_DMA_BUFFER_SIZE; \
171 dma.request_list = (idx); \
172 dma.request_sizes = (size); \
175 if ((retcode = drmDMA((fd), &dma))) { \
176 DEBUG_DMACMDS(("drmDMA returned %d\n", retcode)); \
178 } while (!(dma).granted_count); \
180 for (i = 0; i < (n); i++) { \
181 (size)[i] >>= 2; /* Convert from bytes to words */ \
185 #define SEND_DMA(fd, hHWCtx, n, idx, cnt) \
190 for (i = 0; i < (n); i++) { \
191 (cnt)[i] <<= 2; /* Convert from words to bytes */ \
194 dma.context = (hHWCtx); \
195 dma.send_count = 1; \
196 dma.send_list = (idx); \
197 dma.send_sizes = (cnt); \
198 dma.flags = GAMMA_DMA_SEND_FLAGS; \
199 dma.request_count = 0; \
200 dma.request_size = 0; \
201 dma.request_list = NULL; \
202 dma.request_sizes = NULL; \
204 if ((retcode = drmDMA((fd), &dma))) { \
205 DEBUG_DMACMDS(("drmDMA returned %d\n", retcode)); \
208 for (i = 0; i < (n); i++) { \
214 #define GET_FIRST_DMA(fd, hHWCtx, n, idx, size, buf, cnt, gPriv) \
218 GET_DMA(fd, hHWCtx, n, idx, size); \
220 for (i = 0; i < (n); i++) { \
221 (buf)[i] = (dmaBuf)(gPriv)->bufs->list[(idx)[i]].address; \
226 #define PROCESS_DMA_BUFFER_TOP_HALF(gcp) \
228 SEND_DMA((gcp)->driFd, \
229 (gcp)->hHWContext, 1, &(gcp)->bufIndex, &(gcp)->bufCount); \
232 #define PROCESS_DMA_BUFFER_BOTTOM_HALF(gcp) \
234 GET_DMA((gcp)->driFd, \
235 (gcp)->hHWContext, 1, &(gcp)->bufIndex, &(gcp)->bufSize); \
238 (dmaBuf)(gcp)->gammaScreen->bufs->list[(gcp)->bufIndex].address; \
241 #define PROCESS_DMA_BUFFER(gcp) \
243 VALIDATE_DRAWABLE_INFO(gcp); \
244 PROCESS_DMA_BUFFER_TOP_HALF(gcp); \
245 PROCESS_DMA_BUFFER_BOTTOM_HALF(gcp); \
249 #define VALIDATE_DRAWABLE_INFO_NO_LOCK(gcp) \
251 /*__DRIscreenPrivate *psp = gcp->driScreen;*/ \
252 __DRIdrawablePrivate *pdp = gcp->driDrawable; \
254 if (*(pdp->pStamp) != pdp->lastStamp) { \
255 int old_index = pdp->index; \
256 while (*(pdp->pStamp) != pdp->lastStamp) { \
257 DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
259 if (pdp->index != old_index) { \
260 gcp->Window &= ~W_GIDMask; \
261 gcp->Window |= (pdp->index << 5); \
262 CHECK_WC_DMA_BUFFER(gcp, 1); \
263 WRITE(gcp->WCbuf, GLINTWindow, gcp->Window|(gcp->FrameCount<<9));\
266 gammaUpdateViewportOffset( gcp->glCtx); \
268 if (pdp->numClipRects == 1 && \
269 pdp->pClipRects->x1 == pdp->x && \
270 pdp->pClipRects->x2 == (pdp->x+pdp->w) && \
271 pdp->pClipRects->y1 == pdp->y && \
272 pdp->pClipRects->y2 == (pdp->y+pdp->h)) { \
273 CHECK_WC_DMA_BUFFER(gcp, 1); \
274 WRITE(gcp->WCbuf, Rectangle2DControl, 0); \
275 gcp->NotClipped = GL_TRUE; \
277 CHECK_WC_DMA_BUFFER(gcp, 1); \
278 WRITE(gcp->WCbuf, Rectangle2DControl, 1); \
279 gcp->NotClipped = GL_FALSE; \
281 gcp->WindowChanged = GL_TRUE; \
283 if (gcp->WCbufCount) { \
284 SEND_DMA((gcp)->gammaScreen->driScreen->fd, \
285 (gcp)->hHWContext, 1, &(gcp)->WCbufIndex, \
286 &(gcp)->WCbufCount); \
287 (gcp)->WCbufIndex = -1; \
292 #define VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gcp) \
294 if ((gcp)->WCbufIndex < 0) { \
295 GET_DMA((gcp)->gammaScreen->driScreen->fd, \
296 (gcp)->hHWContext, 1, &(gcp)->WCbufIndex, \
297 &(gcp)->WCbufSize); \
300 (dmaBuf)(gcp)->gammaScreen->bufs-> \
301 list[(gcp)->WCbufIndex].address; \
305 #define VALIDATE_DRAWABLE_INFO(gcp) \
307 __DRIscreenPrivate *psp = gcp->driScreen; \
308 if (gcp->driDrawable) { \
309 DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
310 VALIDATE_DRAWABLE_INFO_NO_LOCK(gcp); \
311 DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
312 VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gcp); \
316 #define VALIDATE_DRAWABLE_INFO(gcp)
319 #define CALC_LOG2(l2,s) \
323 while (__s > 1) { ++l2; __s >>= 1; } \
328 #endif /* _GAMMA_MACROS_H_ */