r300: cleanup some of the swtcl code
[mesa.git] / src / mesa / drivers / dri / r300 / r300_emit.h
1 /*
2 * Copyright (C) 2005 Vladimir Dergachev.
3 *
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a 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, sublicense, 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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 */
27
28 /*
29 * Authors:
30 * Vladimir Dergachev <volodya@mindspring.com>
31 * Nicolai Haehnle <prefect_@gmx.net>
32 * Aapo Tahkola <aet@rasterburn.org>
33 * Ben Skeggs <darktama@iinet.net.au>
34 * Jerome Glisse <j.glisse@gmail.com>
35 */
36
37 /* This files defines functions for accessing R300 hardware.
38 */
39 #ifndef __R300_EMIT_H__
40 #define __R300_EMIT_H__
41
42 #include "glheader.h"
43 #include "r300_context.h"
44 #include "r300_cmdbuf.h"
45 #include "radeon_reg.h"
46
47 /* TODO: move these defines (and the ones from DRM) into r300_reg.h and sync up
48 * with DRM */
49 #define CP_PACKET0(reg, n) (RADEON_CP_PACKET0 | ((n)<<16) | ((reg)>>2))
50 #define CP_PACKET3( pkt, n ) \
51 (RADEON_CP_PACKET3 | (pkt) | ((n) << 16))
52
53 static inline uint32_t cmdpacket0(int reg, int count)
54 {
55 drm_r300_cmd_header_t cmd;
56
57 cmd.packet0.cmd_type = R300_CMD_PACKET0;
58 cmd.packet0.count = count;
59 cmd.packet0.reghi = ((unsigned int)reg & 0xFF00) >> 8;
60 cmd.packet0.reglo = ((unsigned int)reg & 0x00FF);
61
62 return cmd.u;
63 }
64
65 static inline uint32_t cmdvpu(int addr, int count)
66 {
67 drm_r300_cmd_header_t cmd;
68
69 cmd.vpu.cmd_type = R300_CMD_VPU;
70 cmd.vpu.count = count;
71 cmd.vpu.adrhi = ((unsigned int)addr & 0xFF00) >> 8;
72 cmd.vpu.adrlo = ((unsigned int)addr & 0x00FF);
73
74 return cmd.u;
75 }
76
77 static inline uint32_t cmdpacket3(int packet)
78 {
79 drm_r300_cmd_header_t cmd;
80
81 cmd.packet3.cmd_type = R300_CMD_PACKET3;
82 cmd.packet3.packet = packet;
83
84 return cmd.u;
85 }
86
87 static inline uint32_t cmdcpdelay(unsigned short count)
88 {
89 drm_r300_cmd_header_t cmd;
90
91 cmd.delay.cmd_type = R300_CMD_CP_DELAY;
92 cmd.delay.count = count;
93
94 return cmd.u;
95 }
96
97 static inline uint32_t cmdwait(unsigned char flags)
98 {
99 drm_r300_cmd_header_t cmd;
100
101 cmd.wait.cmd_type = R300_CMD_WAIT;
102 cmd.wait.flags = flags;
103
104 return cmd.u;
105 }
106
107 static inline uint32_t cmdpacify(void)
108 {
109 drm_r300_cmd_header_t cmd;
110
111 cmd.header.cmd_type = R300_CMD_END3D;
112
113 return cmd.u;
114 }
115
116 /**
117 * Prepare to write a register value to register at address reg.
118 * If num_extra > 0 then the following extra values are written
119 * to registers with address +4, +8 and so on..
120 */
121 #define reg_start(reg, num_extra) \
122 do { \
123 int _n; \
124 _n=(num_extra); \
125 cmd = (drm_radeon_cmd_header_t*) \
126 r300AllocCmdBuf(rmesa, \
127 (_n+2), \
128 __FUNCTION__); \
129 cmd_reserved=_n+2; \
130 cmd_written=1; \
131 cmd[0].i=cmdpacket0((reg), _n+1); \
132 } while (0);
133
134 /**
135 * Emit GLuint freestyle
136 */
137 #define e32(dword) \
138 do { \
139 if(cmd_written<cmd_reserved) { \
140 cmd[cmd_written].i=(dword); \
141 cmd_written++; \
142 } else { \
143 fprintf(stderr, \
144 "e32 but no previous packet " \
145 "declaration.\n" \
146 "Aborting! in %s::%s at line %d, " \
147 "cmd_written=%d cmd_reserved=%d\n", \
148 __FILE__, __FUNCTION__, __LINE__, \
149 cmd_written, cmd_reserved); \
150 _mesa_exit(-1); \
151 } \
152 } while(0)
153
154 #define efloat(f) e32(r300PackFloat32(f))
155
156 #define vsf_start_fragment(dest, length) \
157 do { \
158 int _n; \
159 _n = (length); \
160 cmd = (drm_radeon_cmd_header_t*) \
161 r300AllocCmdBuf(rmesa, \
162 (_n+1), \
163 __FUNCTION__); \
164 cmd_reserved = _n+2; \
165 cmd_written =1; \
166 cmd[0].i = cmdvpu((dest), _n/4); \
167 } while (0);
168
169 #define start_packet3(packet, count) \
170 { \
171 int _n; \
172 GLuint _p; \
173 _n = (count); \
174 _p = (packet); \
175 cmd = (drm_radeon_cmd_header_t*) \
176 r300AllocCmdBuf(rmesa, \
177 (_n+3), \
178 __FUNCTION__); \
179 cmd_reserved = _n+3; \
180 cmd_written = 2; \
181 if(_n > 0x3fff) { \
182 fprintf(stderr,"Too big packet3 %08x: cannot " \
183 "store %d dwords\n", \
184 _p, _n); \
185 _mesa_exit(-1); \
186 } \
187 cmd[0].i = cmdpacket3(R300_CMD_PACKET3_RAW); \
188 cmd[1].i = _p | ((_n & 0x3fff)<<16); \
189 }
190
191 /**
192 * Must be sent to switch to 2d commands
193 */
194 void static inline end_3d(r300ContextPtr rmesa)
195 {
196 drm_radeon_cmd_header_t *cmd = NULL;
197
198 cmd =
199 (drm_radeon_cmd_header_t *) r300AllocCmdBuf(rmesa, 1, __FUNCTION__);
200 cmd[0].header.cmd_type = R300_CMD_END3D;
201 }
202
203 void static inline cp_delay(r300ContextPtr rmesa, unsigned short count)
204 {
205 drm_radeon_cmd_header_t *cmd = NULL;
206
207 cmd =
208 (drm_radeon_cmd_header_t *) r300AllocCmdBuf(rmesa, 1, __FUNCTION__);
209 cmd[0].i = cmdcpdelay(count);
210 }
211
212 void static inline cp_wait(r300ContextPtr rmesa, unsigned char flags)
213 {
214 drm_radeon_cmd_header_t *cmd = NULL;
215
216 cmd =
217 (drm_radeon_cmd_header_t *) r300AllocCmdBuf(rmesa, 1, __FUNCTION__);
218 cmd[0].i = cmdwait(flags);
219 }
220
221 extern int r300EmitArrays(GLcontext * ctx);
222
223 #ifdef USER_BUFFERS
224 void r300UseArrays(GLcontext * ctx);
225 #endif
226
227 extern void r300ReleaseArrays(GLcontext * ctx);
228 extern int r300PrimitiveType(r300ContextPtr rmesa, int prim);
229 extern int r300NumVerts(r300ContextPtr rmesa, int num_verts, int prim);
230
231 extern void r300EmitCacheFlush(r300ContextPtr rmesa);
232
233 extern GLuint r300VAPInputRoute1(uint32_t * dst, int swizzle[][4], GLuint nr);
234 extern GLuint r300VAPInputCntl0(GLcontext * ctx, GLuint InputsRead);
235 extern GLuint r300VAPInputCntl1(GLcontext * ctx, GLuint InputsRead);
236 extern GLuint r300VAPOutputCntl0(GLcontext * ctx, GLuint OutputsWritten);
237 extern GLuint r300VAPOutputCntl1(GLcontext * ctx, GLuint OutputsWritten);
238
239 #endif