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_
40
#define DEBUG_COMMANDS_NOT
41
#define DEBUG_VERBOSE_NOT
42
#define DEBUG_VERBOSE_EXTRA_NOT
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
56
#define GAMMA_DMA_BUFFER_SIZE 4096
59
#define GAMMA_DMA_SEND_FLAGS DRM_DMA_PRIORITY
60
#define GAMMA_DMA_SEND_FLAGS DRM_DMA_BLOCK
62
/* MUST use non-blocking dma flags for drawable lock routines */
63
#define GAMMA_DMA_SEND_FLAGS 0
67
#define GAMMA_DMA_GET_FLAGS \
68
(DRM_DMA_SMALLER_OK | DRM_DMA_LARGER_OK | DRM_DMA_WAIT)
70
#define GAMMA_DMA_GET_FLAGS DRM_DMA_WAIT
73
#if defined(DEBUG_DRMDMA) || defined(DEBUG_COMMANDS) || defined(DEBUG_VERBOSE)
77
/* Note: The argument to DEBUG_GLCMDS() _must_ be enclosed in parenthesis */
79
#define DEBUG_GLCMDS(s) printf s
81
#define DEBUG_GLCMDS(s)
84
/* Note: The argument to DEBUG_DMACMDS() _must_ be enclosed in parenthesis */
86
#define DEBUG_DMACMDS(s) printf s
88
#define DEBUG_DMACMDS(s)
91
/* Note: The argument to DEBUG_WRITE() _must_ be enclosed in parenthesis */
93
#define DEBUG_WRITE(s) printf s
95
#define DEBUG_WRITE(s)
98
/* Note: The argument to DEBUG_ERROR() _must_ be enclosed in parenthesis */
100
#define DEBUG_ERROR(s) printf s
102
#define DEBUG_ERROR(s)
105
#define WRITEV(buf,val1,val2,val3,val4) \
107
buf++->i = 0x9C008300; \
114
#define WRITE(buf,reg,val) \
116
buf++->i = Glint##reg##Tag; \
118
DEBUG_WRITE(("WRITE(buf, %s, 0x%08x);\n", #reg, (int)val)); \
121
#define WRITEF(buf,reg,val) \
123
buf++->i = Glint##reg##Tag; \
125
DEBUG_WRITE(("WRITEF(buf, %s, %f);\n", #reg, (float)val)); \
128
#define CHECK_WC_DMA_BUFFER(gcp,n) \
130
(gcp)->WCbufCount += (n<<1); \
133
#define CHECK_DMA_BUFFER(gcp,n) \
135
if ((gcp)->bufCount+(n<<1) >= (gcp)->bufSize) \
136
PROCESS_DMA_BUFFER(gcp); \
137
(gcp)->bufCount += (n<<1); \
140
#define CHECK_DMA_BUFFER2(gcp,n) \
142
if ((gcp)->bufCount+n >= (gcp)->bufSize) \
143
PROCESS_DMA_BUFFER(gcp); \
144
(gcp)->bufCount += n; \
147
#define FLUSH_DMA_BUFFER(gcp) \
150
PROCESS_DMA_BUFFER(gcp); \
154
#define GET_DMA(fd, hHWCtx, n, idx, size)
155
#define SEND_DMA(fd, hHWCtx,n, idx, cnt)
157
#define GET_DMA(fd, hHWCtx, n, idx, size) \
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); \
173
if ((retcode = drmDMA((fd), &dma))) { \
174
DEBUG_DMACMDS(("drmDMA returned %d\n", retcode)); \
176
} while (!(dma).granted_count); \
178
for (i = 0; i < (n); i++) { \
179
(size)[i] >>= 2; /* Convert from bytes to words */ \
183
#define SEND_DMA(fd, hHWCtx, n, idx, cnt) \
188
for (i = 0; i < (n); i++) { \
189
(cnt)[i] <<= 2; /* Convert from words to bytes */ \
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; \
202
if ((retcode = drmDMA((fd), &dma))) { \
203
DEBUG_DMACMDS(("drmDMA returned %d\n", retcode)); \
206
for (i = 0; i < (n); i++) { \
212
#define GET_FIRST_DMA(fd, hHWCtx, n, idx, size, buf, cnt, gPriv) \
216
GET_DMA(fd, hHWCtx, n, idx, size); \
218
for (i = 0; i < (n); i++) { \
219
(buf)[i] = (dmaBuf)(gPriv)->bufs->list[(idx)[i]].address; \
224
#define PROCESS_DMA_BUFFER_TOP_HALF(gcp) \
226
SEND_DMA((gcp)->driFd, \
227
(gcp)->hHWContext, 1, &(gcp)->bufIndex, &(gcp)->bufCount); \
230
#define PROCESS_DMA_BUFFER_BOTTOM_HALF(gcp) \
232
GET_DMA((gcp)->driFd, \
233
(gcp)->hHWContext, 1, &(gcp)->bufIndex, &(gcp)->bufSize); \
236
(dmaBuf)(gcp)->gammaScreen->bufs->list[(gcp)->bufIndex].address; \
239
#define PROCESS_DMA_BUFFER(gcp) \
241
VALIDATE_DRAWABLE_INFO(gcp); \
242
PROCESS_DMA_BUFFER_TOP_HALF(gcp); \
243
PROCESS_DMA_BUFFER_BOTTOM_HALF(gcp); \
247
#define VALIDATE_DRAWABLE_INFO_NO_LOCK(gcp) \
249
/*__DRIscreenPrivate *psp = gcp->driScreen;*/ \
250
__DRIdrawablePrivate *pdp = gcp->driDrawable; \
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); \
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));\
264
gammaUpdateViewportOffset( gcp->glCtx); \
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; \
275
CHECK_WC_DMA_BUFFER(gcp, 1); \
276
WRITE(gcp->WCbuf, Rectangle2DControl, 1); \
277
gcp->NotClipped = GL_FALSE; \
279
gcp->WindowChanged = GL_TRUE; \
281
if (gcp->WCbufCount) { \
282
SEND_DMA((gcp)->gammaScreen->driScreen->fd, \
283
(gcp)->hHWContext, 1, &(gcp)->WCbufIndex, \
284
&(gcp)->WCbufCount); \
285
(gcp)->WCbufIndex = -1; \
290
#define VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gcp) \
292
if ((gcp)->WCbufIndex < 0) { \
293
GET_DMA((gcp)->gammaScreen->driScreen->fd, \
294
(gcp)->hHWContext, 1, &(gcp)->WCbufIndex, \
295
&(gcp)->WCbufSize); \
298
(dmaBuf)(gcp)->gammaScreen->bufs-> \
299
list[(gcp)->WCbufIndex].address; \
303
#define VALIDATE_DRAWABLE_INFO(gcp) \
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); \
314
#define VALIDATE_DRAWABLE_INFO(gcp)
317
#define CALC_LOG2(l2,s) \
321
while (__s > 1) { ++l2; __s >>= 1; } \
324
#endif /* _GAMMA_MACROS_H_ */