radeon/r200: flush vertices when data in cmdbuf.
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_ioctl.h
1 /**************************************************************************
2
3 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
4 VA Linux Systems Inc., Fremont, California.
5
6 All Rights Reserved.
7
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
15
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 **************************************************************************/
29
30 /*
31 * Authors:
32 * Kevin E. Martin <martin@valinux.com>
33 * Gareth Hughes <gareth@valinux.com>
34 */
35
36 #ifndef __RADEON_IOCTL_H__
37 #define __RADEON_IOCTL_H__
38
39 #include "main/simple_list.h"
40 #include "radeon_lock.h"
41 #include "radeon_cs_legacy.h"
42
43 extern void radeonEmitState( r100ContextPtr rmesa );
44 extern void radeonEmitVertexAOS( r100ContextPtr rmesa,
45 GLuint vertex_size,
46 struct radeon_bo *bo,
47 GLuint offset );
48
49 extern void radeonEmitVbufPrim( r100ContextPtr rmesa,
50 GLuint vertex_format,
51 GLuint primitive,
52 GLuint vertex_nr );
53
54 extern void radeonFlushElts( GLcontext *ctx );
55
56
57 extern GLushort *radeonAllocEltsOpenEnded( r100ContextPtr rmesa,
58 GLuint vertex_format,
59 GLuint primitive,
60 GLuint min_nr );
61
62
63 extern void radeonEmitAOS( r100ContextPtr rmesa,
64 GLuint n,
65 GLuint offset );
66
67 extern void radeonEmitBlit( r100ContextPtr rmesa,
68 GLuint color_fmt,
69 GLuint src_pitch,
70 GLuint src_offset,
71 GLuint dst_pitch,
72 GLuint dst_offset,
73 GLint srcx, GLint srcy,
74 GLint dstx, GLint dsty,
75 GLuint w, GLuint h );
76
77 extern void radeonEmitWait( r100ContextPtr rmesa, GLuint flags );
78
79 extern void radeonFlushCmdBuf( r100ContextPtr rmesa, const char * );
80
81 extern void radeonFlush( GLcontext *ctx );
82 extern void radeonFinish( GLcontext *ctx );
83 extern void radeonInitIoctlFuncs( GLcontext *ctx );
84 extern void radeonGetAllParams( r100ContextPtr rmesa );
85 extern void radeonSetUpAtomList( r100ContextPtr rmesa );
86
87 /* ================================================================
88 * Helper macros:
89 */
90
91 /* Close off the last primitive, if it exists.
92 */
93 #define RADEON_NEWPRIM( rmesa ) \
94 do { \
95 if ( rmesa->radeon.dma.flush ) \
96 rmesa->radeon.dma.flush( rmesa->radeon.glCtx ); \
97 } while (0)
98
99 /* Can accomodate several state changes and primitive changes without
100 * actually firing the buffer.
101 */
102
103 #define RADEON_STATECHANGE( rmesa, ATOM ) \
104 do { \
105 RADEON_NEWPRIM( rmesa ); \
106 rmesa->hw.ATOM.dirty = GL_TRUE; \
107 rmesa->hw.is_dirty = GL_TRUE; \
108 } while (0)
109
110 #define RADEON_DB_STATE( ATOM ) \
111 memcpy( rmesa->hw.ATOM.lastcmd, rmesa->hw.ATOM.cmd, \
112 rmesa->hw.ATOM.cmd_size * 4)
113
114 static INLINE int RADEON_DB_STATECHANGE(r100ContextPtr rmesa,
115 struct radeon_state_atom *atom )
116 {
117 if (memcmp(atom->cmd, atom->lastcmd, atom->cmd_size*4)) {
118 GLuint *tmp;
119 RADEON_NEWPRIM( rmesa );
120 atom->dirty = GL_TRUE;
121 rmesa->hw.is_dirty = GL_TRUE;
122 tmp = atom->cmd;
123 atom->cmd = atom->lastcmd;
124 atom->lastcmd = tmp;
125 return 1;
126 }
127 else
128 return 0;
129 }
130
131 /* Fire the buffered vertices no matter what.
132 */
133 #define RADEON_FIREVERTICES( rmesa ) \
134 do { \
135 if (rmesa->radeon.cmdbuf.cs->cdw || rmesa->radeon.dma.flush ) { \
136 radeonFlush( rmesa->radeon.glCtx ); \
137 } \
138 } while (0)
139
140 /* Command lengths. Note that any time you ensure ELTS_BUFSZ or VBUF_BUFSZ
141 * are available, you will also be adding an rmesa->state.max_state_size because
142 * r200EmitState is called from within r200EmitVbufPrim and r200FlushElts.
143 */
144 #if RADEON_OLD_PACKETS
145 #define AOS_BUFSZ(nr) ((3 + ((nr / 2) * 3) + ((nr & 1) * 2)) * sizeof(int))
146 #define VERT_AOS_BUFSZ (0)
147 #define ELTS_BUFSZ(nr) (24 + nr * 2)
148 #define VBUF_BUFSZ (6 * sizeof(int))
149 #else
150 #define AOS_BUFSZ(nr) ((3 + ((nr / 2) * 3) + ((nr & 1) * 2)) * sizeof(int))
151 #define VERT_AOS_BUFSZ (5 * sizeof(int))
152 #define ELTS_BUFSZ(nr) (16 + nr * 2)
153 #define VBUF_BUFSZ (4 * sizeof(int))
154 #endif
155
156
157 static inline uint32_t cmdpacket3(int cmd_type)
158 {
159 drm_radeon_cmd_header_t cmd;
160
161 cmd.i = 0;
162 cmd.header.cmd_type = cmd_type;
163
164 return (uint32_t)cmd.i;
165
166 }
167
168 #define OUT_BATCH_PACKET3(packet, num_extra) do { \
169 if (!b_l_rmesa->radeonScreen->kernel_mm) { \
170 OUT_BATCH(cmdpacket3(RADEON_CMD_PACKET3)); \
171 OUT_BATCH(CP_PACKET3((packet), (num_extra))); \
172 } else { \
173 OUT_BATCH(CP_PACKET2); \
174 OUT_BATCH(CP_PACKET3((packet), (num_extra))); \
175 } \
176 } while(0)
177
178 #define OUT_BATCH_PACKET3_CLIP(packet, num_extra) do { \
179 if (!b_l_rmesa->radeonScreen->kernel_mm) { \
180 OUT_BATCH(cmdpacket3(RADEON_CMD_PACKET3_CLIP)); \
181 OUT_BATCH(CP_PACKET3((packet), (num_extra))); \
182 } else { \
183 OUT_BATCH(CP_PACKET2); \
184 OUT_BATCH(CP_PACKET3((packet), (num_extra))); \
185 } \
186 } while(0)
187
188
189 #endif /* __RADEON_IOCTL_H__ */