GL_(UN)PACK_SKIP_IMAGES should only be applied to 3D texture pack/unpacking
[mesa.git] / src / mesa / drivers / dri / r200 / r200_ioctl.h
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_ioctl.h,v 1.1 2002/10/30 12:51:52 alanh Exp $ */
2 /*
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4
5 The Weather Channel (TM) funded Tungsten Graphics to develop the
6 initial release of the Radeon 8500 driver under the XFree86 license.
7 This notice must be preserved.
8
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 **************************************************************************/
30
31 /*
32 * Authors:
33 * Keith Whitwell <keith@tungstengraphics.com>
34 */
35
36 #ifndef __R200_IOCTL_H__
37 #define __R200_IOCTL_H__
38
39 #ifdef GLX_DIRECT_RENDERING
40
41 #include "simple_list.h"
42 #include "radeon_dri.h"
43 #include "r200_lock.h"
44
45 #include "xf86drm.h"
46 #include "drm.h"
47 #include "radeon_drm.h"
48
49 extern void r200EmitState( r200ContextPtr rmesa );
50 extern void r200EmitVertexAOS( r200ContextPtr rmesa,
51 GLuint vertex_size,
52 GLuint offset );
53
54 extern void r200EmitVbufPrim( r200ContextPtr rmesa,
55 GLuint primitive,
56 GLuint vertex_nr );
57
58 extern void r200FlushElts( r200ContextPtr rmesa );
59
60 extern GLushort *r200AllocEltsOpenEnded( r200ContextPtr rmesa,
61 GLuint primitive,
62 GLuint min_nr );
63
64 extern void r200EmitAOS( r200ContextPtr rmesa,
65 struct r200_dma_region **regions,
66 GLuint n,
67 GLuint offset );
68
69 extern void r200EmitBlit( r200ContextPtr rmesa,
70 GLuint color_fmt,
71 GLuint src_pitch,
72 GLuint src_offset,
73 GLuint dst_pitch,
74 GLuint dst_offset,
75 GLint srcx, GLint srcy,
76 GLint dstx, GLint dsty,
77 GLuint w, GLuint h );
78
79 extern void r200EmitWait( r200ContextPtr rmesa, GLuint flags );
80
81 extern void r200FlushCmdBuf( r200ContextPtr rmesa, const char * );
82 extern int r200FlushCmdBufLocked( r200ContextPtr rmesa, const char * caller );
83
84 extern void r200RefillCurrentDmaRegion( r200ContextPtr rmesa );
85
86 extern void r200AllocDmaRegion( r200ContextPtr rmesa,
87 struct r200_dma_region *region,
88 int bytes,
89 int alignment );
90
91 extern void r200AllocDmaRegionVerts( r200ContextPtr rmesa,
92 struct r200_dma_region *region,
93 int numverts,
94 int vertsize,
95 int alignment );
96
97 extern void r200ReleaseDmaRegion( r200ContextPtr rmesa,
98 struct r200_dma_region *region,
99 const char *caller );
100
101 extern void r200CopyBuffer( const __DRIdrawablePrivate *drawable );
102 extern void r200PageFlip( const __DRIdrawablePrivate *drawable );
103 extern void r200Flush( GLcontext *ctx );
104 extern void r200Finish( GLcontext *ctx );
105 extern void r200WaitForIdleLocked( r200ContextPtr rmesa );
106 extern void r200WaitForVBlank( r200ContextPtr rmesa );
107 extern void r200InitIoctlFuncs( struct dd_function_table *functions );
108
109 extern void *r200AllocateMemoryMESA( __DRInativeDisplay *dpy, int scrn, GLsizei size, GLfloat readfreq,
110 GLfloat writefreq, GLfloat priority );
111 extern void r200FreeMemoryMESA( __DRInativeDisplay *dpy, int scrn, GLvoid *pointer );
112 extern GLuint r200GetMemoryOffsetMESA( __DRInativeDisplay *dpy, int scrn, const GLvoid *pointer );
113
114 extern GLboolean r200IsGartMemory( r200ContextPtr rmesa, const GLvoid *pointer,
115 GLint size );
116
117 extern GLuint r200GartOffsetFromVirtual( r200ContextPtr rmesa,
118 const GLvoid *pointer );
119
120 void r200SetUpAtomList( r200ContextPtr rmesa );
121
122 /* ================================================================
123 * Helper macros:
124 */
125
126 /* Close off the last primitive, if it exists.
127 */
128 #define R200_NEWPRIM( rmesa ) \
129 do { \
130 if ( rmesa->dma.flush ) \
131 rmesa->dma.flush( rmesa ); \
132 } while (0)
133
134 /* Can accomodate several state changes and primitive changes without
135 * actually firing the buffer.
136 */
137 #define R200_STATECHANGE( rmesa, ATOM ) \
138 do { \
139 R200_NEWPRIM( rmesa ); \
140 rmesa->hw.ATOM.dirty = GL_TRUE; \
141 rmesa->hw.is_dirty = GL_TRUE; \
142 } while (0)
143
144 #define R200_DB_STATE( ATOM ) \
145 memcpy( rmesa->hw.ATOM.lastcmd, rmesa->hw.ATOM.cmd, \
146 rmesa->hw.ATOM.cmd_size * 4)
147
148 static __inline int R200_DB_STATECHANGE(
149 r200ContextPtr rmesa,
150 struct r200_state_atom *atom )
151 {
152 if (memcmp(atom->cmd, atom->lastcmd, atom->cmd_size*4)) {
153 int *tmp;
154 R200_NEWPRIM( rmesa );
155 atom->dirty = GL_TRUE;
156 rmesa->hw.is_dirty = GL_TRUE;
157 tmp = atom->cmd;
158 atom->cmd = atom->lastcmd;
159 atom->lastcmd = tmp;
160 return 1;
161 }
162 else
163 return 0;
164 }
165
166
167 /* Fire the buffered vertices no matter what.
168 */
169 #define R200_FIREVERTICES( rmesa ) \
170 do { \
171 if ( rmesa->store.cmd_used || rmesa->dma.flush ) { \
172 r200Flush( rmesa->glCtx ); \
173 } \
174 } while (0)
175
176 /* Command lengths. Note that any time you ensure ELTS_BUFSZ or VBUF_BUFSZ
177 * are available, you will also be adding an rmesa->state.max_state_size because
178 * r200EmitState is called from within r200EmitVbufPrim and r200FlushElts.
179 */
180 #define AOS_BUFSZ(nr) ((3 + ((nr / 2) * 3) + ((nr & 1) * 2)) * sizeof(int))
181 #define VERT_AOS_BUFSZ (5 * sizeof(int))
182 #define ELTS_BUFSZ(nr) (12 + nr * 2)
183 #define VBUF_BUFSZ (3 * sizeof(int))
184
185 /* Ensure that a minimum amount of space is available in the command buffer.
186 * This is used to ensure atomicity of state updates with the rendering requests
187 * that rely on them.
188 *
189 * An alternative would be to implement a "soft lock" such that when the buffer
190 * wraps at an inopportune time, we grab the lock, flush the current buffer,
191 * and hang on to the lock until the critical section is finished and we flush
192 * the buffer again and unlock.
193 */
194 static __inline void r200EnsureCmdBufSpace( r200ContextPtr rmesa, int bytes )
195 {
196 if (rmesa->store.cmd_used + bytes > R200_CMD_BUF_SZ)
197 r200FlushCmdBuf( rmesa, __FUNCTION__ );
198 assert( bytes <= R200_CMD_BUF_SZ );
199 }
200
201 /* Alloc space in the command buffer
202 */
203 static __inline char *r200AllocCmdBuf( r200ContextPtr rmesa,
204 int bytes, const char *where )
205 {
206 char * head;
207
208 if (rmesa->store.cmd_used + bytes > R200_CMD_BUF_SZ)
209 r200FlushCmdBuf( rmesa, where );
210
211 head = rmesa->store.cmd_buf + rmesa->store.cmd_used;
212 rmesa->store.cmd_used += bytes;
213 assert( rmesa->store.cmd_used <= R200_CMD_BUF_SZ );
214 return head;
215 }
216
217
218
219
220 #endif
221 #endif /* __R200_IOCTL_H__ */