1 /**************************************************************************
3 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
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:
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * Kevin E. Martin <kevin@precisioninsight.com>
34 #ifndef _GAMMA_MACROS_H_
35 #define _GAMMA_MACROS_H_
39 #define DEBUG_COMMANDS_NOT
40 #define DEBUG_VERBOSE_NOT
41 #define DEBUG_VERBOSE_EXTRA_NOT
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
55 #define GAMMA_DMA_BUFFER_SIZE 4096
58 #define GAMMA_DMA_SEND_FLAGS DRM_DMA_PRIORITY
59 #define GAMMA_DMA_SEND_FLAGS DRM_DMA_BLOCK
61 /* MUST use non-blocking dma flags for drawable lock routines */
62 #define GAMMA_DMA_SEND_FLAGS 0
66 #define GAMMA_DMA_GET_FLAGS \
67 (DRM_DMA_SMALLER_OK | DRM_DMA_LARGER_OK | DRM_DMA_WAIT)
69 #define GAMMA_DMA_GET_FLAGS DRM_DMA_WAIT
72 #if defined(DEBUG_DRMDMA) || defined(DEBUG_COMMANDS) || defined(DEBUG_VERBOSE)
76 /* Note: The argument to DEBUG_GLCMDS() _must_ be enclosed in parenthesis */
78 #define DEBUG_GLCMDS(s) printf s
80 #define DEBUG_GLCMDS(s)
83 /* Note: The argument to DEBUG_DMACMDS() _must_ be enclosed in parenthesis */
85 #define DEBUG_DMACMDS(s) printf s
87 #define DEBUG_DMACMDS(s)
90 /* Note: The argument to DEBUG_WRITE() _must_ be enclosed in parenthesis */
92 #define DEBUG_WRITE(s) printf s
94 #define DEBUG_WRITE(s)
97 /* Note: The argument to DEBUG_ERROR() _must_ be enclosed in parenthesis */
99 #define DEBUG_ERROR(s) printf s
101 #define DEBUG_ERROR(s)
104 #define WRITEV(buf,val1,val2,val3,val4) \
106 buf++->i = 0x9C008300; \
113 #define WRITE(buf,reg,val) \
115 buf++->i = Glint##reg##Tag; \
117 DEBUG_WRITE(("WRITE(buf, %s, 0x%08x);\n", #reg, (int)val)); \
120 #define WRITEF(buf,reg,val) \
122 buf++->i = Glint##reg##Tag; \
124 DEBUG_WRITE(("WRITEF(buf, %s, %f);\n", #reg, (float)val)); \
127 #define CHECK_WC_DMA_BUFFER(gcp,n) \
129 (gcp)->WCbufCount += (n<<1); \
132 #define CHECK_DMA_BUFFER(gcp,n) \
134 if ((gcp)->bufCount+(n<<1) >= (gcp)->bufSize) \
135 PROCESS_DMA_BUFFER(gcp); \
136 (gcp)->bufCount += (n<<1); \
139 #define CHECK_DMA_BUFFER2(gcp,n) \
141 if ((gcp)->bufCount+n >= (gcp)->bufSize) \
142 PROCESS_DMA_BUFFER(gcp); \
143 (gcp)->bufCount += n; \
146 #define FLUSH_DMA_BUFFER(gcp) \
149 PROCESS_DMA_BUFFER(gcp); \
153 #define GET_DMA(fd, hHWCtx, n, idx, size)
154 #define SEND_DMA(fd, hHWCtx,n, idx, cnt)
156 #define GET_DMA(fd, hHWCtx, n, idx, size) \
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); \
172 if ((retcode = drmDMA((fd), &dma))) { \
173 DEBUG_DMACMDS(("drmDMA returned %d\n", retcode)); \
175 } while (!(dma).granted_count); \
177 for (i = 0; i < (n); i++) { \
178 (size)[i] >>= 2; /* Convert from bytes to words */ \
182 #define SEND_DMA(fd, hHWCtx, n, idx, cnt) \
187 for (i = 0; i < (n); i++) { \
188 (cnt)[i] <<= 2; /* Convert from words to bytes */ \
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; \
201 if ((retcode = drmDMA((fd), &dma))) { \
202 DEBUG_DMACMDS(("drmDMA returned %d\n", retcode)); \
205 for (i = 0; i < (n); i++) { \
211 #define GET_FIRST_DMA(fd, hHWCtx, n, idx, size, buf, cnt, gPriv) \
215 GET_DMA(fd, hHWCtx, n, idx, size); \
217 for (i = 0; i < (n); i++) { \
218 (buf)[i] = (dmaBuf)(gPriv)->bufs->list[(idx)[i]].address; \
223 #define PROCESS_DMA_BUFFER_TOP_HALF(gcp) \
225 SEND_DMA((gcp)->driFd, \
226 (gcp)->hHWContext, 1, &(gcp)->bufIndex, &(gcp)->bufCount); \
229 #define PROCESS_DMA_BUFFER_BOTTOM_HALF(gcp) \
231 GET_DMA((gcp)->driFd, \
232 (gcp)->hHWContext, 1, &(gcp)->bufIndex, &(gcp)->bufSize); \
235 (dmaBuf)(gcp)->gammaScreen->bufs->list[(gcp)->bufIndex].address; \
238 #define PROCESS_DMA_BUFFER(gcp) \
240 VALIDATE_DRAWABLE_INFO(gcp); \
241 PROCESS_DMA_BUFFER_TOP_HALF(gcp); \
242 PROCESS_DMA_BUFFER_BOTTOM_HALF(gcp); \
246 #define VALIDATE_DRAWABLE_INFO_NO_LOCK(gcp) \
248 /*__DRIscreenPrivate *psp = gcp->driScreen;*/ \
249 __DRIdrawablePrivate *pdp = gcp->driDrawable; \
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); \
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));\
263 gammaUpdateViewportOffset( gcp->glCtx); \
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; \
274 CHECK_WC_DMA_BUFFER(gcp, 1); \
275 WRITE(gcp->WCbuf, Rectangle2DControl, 1); \
276 gcp->NotClipped = GL_FALSE; \
278 gcp->WindowChanged = GL_TRUE; \
280 if (gcp->WCbufCount) { \
281 SEND_DMA((gcp)->gammaScreen->driScreen->fd, \
282 (gcp)->hHWContext, 1, &(gcp)->WCbufIndex, \
283 &(gcp)->WCbufCount); \
284 (gcp)->WCbufIndex = -1; \
289 #define VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gcp) \
291 if ((gcp)->WCbufIndex < 0) { \
292 GET_DMA((gcp)->gammaScreen->driScreen->fd, \
293 (gcp)->hHWContext, 1, &(gcp)->WCbufIndex, \
294 &(gcp)->WCbufSize); \
297 (dmaBuf)(gcp)->gammaScreen->bufs-> \
298 list[(gcp)->WCbufIndex].address; \
302 #define VALIDATE_DRAWABLE_INFO(gcp) \
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); \
313 #define VALIDATE_DRAWABLE_INFO(gcp)
316 #define CALC_LOG2(l2,s) \
320 while (__s > 1) { ++l2; __s >>= 1; } \
323 #endif /* _GAMMA_MACROS_H_ */