(Stephane Marchesin, me) add hyperz support to radeon and r200 drivers. Only fast...
[mesa.git] / src / mesa / drivers / dri / r300 / r300_context.h
1 /*
2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
3
4 The Weather Channel (TM) funded Tungsten Graphics to develop the
5 initial release of the Radeon 8500 driver under the XFree86 license.
6 This notice must be preserved.
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 * Keith Whitwell <keith@tungstengraphics.com>
33 * Nicolai Haehnle <prefect_@gmx.net>
34 */
35
36 #ifndef __R300_CONTEXT_H__
37 #define __R300_CONTEXT_H__
38
39 #include "tnl/t_vertex.h"
40 #include "drm.h"
41 #include "radeon_drm.h"
42 #include "dri_util.h"
43 #include "texmem.h"
44
45 #include "macros.h"
46 #include "mtypes.h"
47 #include "colormac.h"
48 #include "radeon_context.h"
49
50 struct r300_context;
51 typedef struct r300_context r300ContextRec;
52 typedef struct r300_context *r300ContextPtr;
53
54 #include "radeon_lock.h"
55 #include "mm.h"
56
57
58 static __inline__ uint32_t r300PackFloat32(float fl)
59 {
60 union { float fl; uint32_t u; } u;
61
62 u.fl = fl;
63 return u.u;
64 }
65
66 /**
67 * A block of hardware state.
68 *
69 * When check returns non-zero, the returned number of dwords must be
70 * copied verbatim into the command buffer in order to update a state atom
71 * when it is dirty.
72 */
73 struct r300_state_atom {
74 struct r300_state_atom *next, *prev;
75 const char* name; /* for debug */
76 int cmd_size; /* maximum size in dwords */
77 GLuint idx; /* index in an array (e.g. textures) */
78 uint32_t* cmd;
79 GLboolean dirty;
80
81 int (*check)(r300ContextPtr, struct r300_state_atom* atom);
82 };
83
84
85 #define R300_VPT_CMD_0 0
86 #define R300_VPT_XSCALE 1
87 #define R300_VPT_XOFFSET 2
88 #define R300_VPT_YSCALE 3
89 #define R300_VPT_YOFFSET 4
90 #define R300_VPT_ZSCALE 5
91 #define R300_VPT_ZOFFSET 6
92 #define R300_VPT_CMDSIZE 7
93
94 #define R300_OVF_CMD_0 0
95 #define R300_OVF_FMT_0 1
96 #define R300_OVF_FMT_1 2
97 #define R300_OVF_CMDSIZE 3
98
99 #define R300_VIR_CMD_0 0 /* vir is variable size (at least 1) */
100 #define R300_VIR_CNTL_0 1
101 #define R300_VIR_CNTL_1 2
102 #define R300_VIR_CNTL_2 3
103 #define R300_VIR_CNTL_3 4
104 #define R300_VIR_CNTL_4 5
105 #define R300_VIR_CNTL_5 6
106 #define R300_VIR_CNTL_6 7
107 #define R300_VIR_CNTL_7 8
108 #define R300_VIR_CMDSIZE 9
109
110 #define R300_VIC_CMD_0 0
111 #define R300_VIC_CNTL_0 1
112 #define R300_VIC_CNTL_1 2
113 #define R300_VIC_CMDSIZE 3
114
115 #define R300_PVS_CMD_0 0
116 #define R300_PVS_CNTL_1 1
117 #define R300_PVS_CNTL_2 2
118 #define R300_PVS_CNTL_3 3
119 #define R300_PVS_CMDSIZE 4
120
121 #define R300_TXE_CMD_0 0
122 #define R300_TXE_ENABLE 1
123 #define R300_TXE_CMDSIZE 2
124
125 #define R300_PS_CMD_0 0
126 #define R300_PS_POINTSIZE 1
127 #define R300_PS_CMDSIZE 2
128
129 #define R300_CUL_CMD_0 0
130 #define R300_CUL_CULL 1
131 #define R300_CUL_CMDSIZE 2
132
133 #define R300_RC_CMD_0 0
134 #define R300_RC_CNTL_0 1
135 #define R300_RC_CNTL_1 2
136 #define R300_RC_CMDSIZE 3
137
138 #define R300_RI_CMD_0 0
139 #define R300_RI_INTERP_0 1
140 #define R300_RI_INTERP_1 2
141 #define R300_RI_INTERP_2 3
142 #define R300_RI_INTERP_3 4
143 #define R300_RI_INTERP_4 5
144 #define R300_RI_INTERP_5 6
145 #define R300_RI_INTERP_6 7
146 #define R300_RI_INTERP_7 8
147 #define R300_RI_CMDSIZE 9
148
149 #define R300_RR_CMD_0 0 /* rr is variable size (at least 1) */
150 #define R300_RR_ROUTE_0 1
151 #define R300_RR_ROUTE_1 2
152 #define R300_RR_ROUTE_2 3
153 #define R300_RR_ROUTE_3 4
154 #define R300_RR_ROUTE_4 5
155 #define R300_RR_ROUTE_5 6
156 #define R300_RR_ROUTE_6 7
157 #define R300_RR_ROUTE_7 8
158 #define R300_RR_CMDSIZE 9
159
160 #define R300_FP_CMD_0 0
161 #define R300_FP_CNTL0 1
162 #define R300_FP_CNTL1 2
163 #define R300_FP_CNTL2 3
164 #define R300_FP_CMD_1 4
165 #define R300_FP_NODE0 5
166 #define R300_FP_NODE1 6
167 #define R300_FP_NODE2 7
168 #define R300_FP_NODE3 8
169 #define R300_FP_CMDSIZE 9
170
171 #define R300_FPI_CMD_0 0
172 #define R300_FPI_INSTR_0 1
173 #define R300_FPI_CMDSIZE 65
174
175 #define R300_AT_CMD_0 0
176 #define R300_AT_ALPHA_TEST 1
177 #define R300_AT_CMDSIZE 2
178
179 #define R300_BLD_CMD_0 0
180 #define R300_BLD_CBLEND 1
181 #define R300_BLD_ABLEND 2
182 #define R300_BLD_CMDSIZE 3
183
184 #define R300_CMK_CMD_0 0
185 #define R300_CMK_COLORMASK 1
186 #define R300_CMK_CMDSIZE 2
187
188 #define R300_CB_CMD_0 0
189 #define R300_CB_OFFSET 1
190 #define R300_CB_CMD_1 2
191 #define R300_CB_PITCH 3
192 #define R300_CB_CMDSIZE 4
193
194 #define R300_ZC_CMD_0 0
195 #define R300_ZC_CNTL_0 1
196 #define R300_ZC_CNTL_1 2
197 #define R300_ZC_CMDSIZE 3
198
199 #define R300_ZB_CMD_0 0
200 #define R300_ZB_OFFSET 1
201 #define R300_ZB_PITCH 2
202 #define R300_ZB_CMDSIZE 3
203
204 #define R300_VPI_CMD_0 0
205 #define R300_VPI_INSTR_0 1
206 #define R300_VPI_CMDSIZE 1025 /* 256 16 byte instructions */
207
208 #define R300_VPP_CMD_0 0
209 #define R300_VPP_PARAM_0 1
210 #define R300_VPP_CMDSIZE 1025 /* 256 4-component parameters */
211
212 #define R300_VPS_CMD_0 0
213 #define R300_VPS_ZERO_0 1
214 #define R300_VPS_ZERO_1 2
215 #define R300_VPS_POINTSIZE 3
216 #define R300_VPS_ZERO_3 4
217 #define R300_VPS_CMDSIZE 5
218
219 /**
220 * Cache for hardware register state.
221 */
222 struct r300_hw_state {
223 struct r300_state_atom atomlist;
224
225 GLboolean is_dirty;
226 GLboolean all_dirty;
227 int max_state_size; /* in dwords */
228
229 struct r300_state_atom vpt; /* viewport (1D98) */
230 struct r300_state_atom unk2080; /* (2080) */
231 struct r300_state_atom ovf; /* output vertex format (2090) */
232 struct r300_state_atom unk20B0; /* (20B0) */
233 struct r300_state_atom unk2134; /* (2134) */
234 struct r300_state_atom unk2140; /* (2140) */
235 struct r300_state_atom vir[2]; /* vap input route (2150/21E0) */
236 struct r300_state_atom vic; /* vap input control (2180) */
237 struct r300_state_atom unk21DC; /* (21DC) */
238 struct r300_state_atom unk221C; /* (221C) */
239 struct r300_state_atom unk2220; /* (2220) */
240 struct r300_state_atom unk2288; /* (2288) */
241 struct r300_state_atom pvs; /* pvs_cntl (22D0) */
242 struct r300_state_atom unk4008; /* (4008) */
243 struct r300_state_atom unk4010; /* (4010) */
244 struct r300_state_atom txe; /* tex enable (4104) */
245 struct r300_state_atom unk4200; /* (4200) */
246 struct r300_state_atom unk4214; /* (4214) */
247 struct r300_state_atom ps; /* pointsize (421C) */
248 struct r300_state_atom unk4230; /* (4230) */
249 struct r300_state_atom unk4260; /* (4260) */
250 struct r300_state_atom unk4274; /* (4274) */
251 struct r300_state_atom unk4288; /* (4288) */
252 struct r300_state_atom unk42A0; /* (42A0) */
253 struct r300_state_atom unk42B4; /* (42B4) */
254 struct r300_state_atom cul; /* cull cntl (42B8) */
255 struct r300_state_atom unk42C0; /* (42C0) */
256 struct r300_state_atom rc; /* rs control (4300) */
257 struct r300_state_atom ri; /* rs interpolators (4310) */
258 struct r300_state_atom rr; /* rs route (4330) */
259 struct r300_state_atom unk43A4; /* (43A4) */
260 struct r300_state_atom unk43E8; /* (43E8) */
261 struct r300_state_atom fp; /* fragment program cntl + nodes (4600) */
262 struct r300_state_atom unk46A4; /* (46A4) */
263 struct r300_state_atom fpi[4]; /* fp instructions (46C0/47C0/48C0/49C0) */
264 struct r300_state_atom unk4BC0; /* (4BC0) */
265 struct r300_state_atom unk4BC8; /* (4BC8) */
266 struct r300_state_atom at; /* alpha test (4BD4) */
267 struct r300_state_atom unk4BD8; /* (4BD8) */
268 struct r300_state_atom unk4E00; /* (4E00) */
269 struct r300_state_atom bld; /* blending (4E04) */
270 struct r300_state_atom cmk; /* colormask (4E0C) */
271 struct r300_state_atom unk4E10; /* (4E10) */
272 struct r300_state_atom cb; /* colorbuffer (4E28) */
273 struct r300_state_atom unk4E50; /* (4E50) */
274 struct r300_state_atom unk4E88; /* (4E88) */
275 struct r300_state_atom zc; /* z control (4F00) */
276 struct r300_state_atom unk4F08; /* (4F08) */
277 struct r300_state_atom unk4F10; /* (4F10) */
278 struct r300_state_atom zb; /* z buffer (4F20) */
279 struct r300_state_atom unk4F28; /* (4F28) */
280 struct r300_state_atom unk4F30; /* (4F30) */
281 struct r300_state_atom unk4F44; /* (4F44) */
282 struct r300_state_atom unk4F54; /* (4F54) */
283
284 struct r300_state_atom vpi; /* vp instructions */
285 struct r300_state_atom vpp; /* vp parameters */
286 struct r300_state_atom vps; /* vertex point size (?) */
287 };
288
289
290 /**
291 * This structure holds the command buffer while it is being constructed.
292 *
293 * The first batch of commands in the buffer is always the state that needs
294 * to be re-emitted when the context is lost. This batch can be skipped
295 * otherwise.
296 */
297 struct r300_cmdbuf {
298 int size; /* DWORDs allocated for buffer */
299 uint32_t* cmd_buf;
300 int count_used; /* DWORDs filled so far */
301 int count_reemit; /* size of re-emission batch */
302 };
303
304
305 /**
306 * State cache
307 */
308 struct r300_state {
309 };
310
311
312 /**
313 * R300 context structure.
314 */
315 struct r300_context {
316 struct radeon_context radeon; /* parent class, must be first */
317
318 struct r300_hw_state hw;
319 struct r300_cmdbuf cmdbuf;
320 struct r300_state state;
321 };
322
323 #define R300_CONTEXT(ctx) ((r300ContextPtr)(ctx->DriverCtx))
324
325 extern void r300DestroyContext(__DRIcontextPrivate * driContextPriv);
326 extern GLboolean r300CreateContext(const __GLcontextModes * glVisual,
327 __DRIcontextPrivate * driContextPriv,
328 void *sharedContextPrivate);
329
330 #endif /* __R300_CONTEXT_H__ */