1 /**************************************************************************
3 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
4 VA Linux Systems Inc., Fremont, California.
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:
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.
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.
28 **************************************************************************/
32 * Kevin E. Martin <martin@valinux.com>
33 * Gareth Hughes <gareth@valinux.com>
34 * Keith Whitwell <keithw@vmware.com>
40 #include "main/attrib.h"
41 #include "main/bufferobj.h"
42 #include "swrast/swrast.h"
44 #include "main/glheader.h"
45 #include "util/simple_list.h"
47 #include "radeon_context.h"
48 #include "radeon_common.h"
49 #include "radeon_ioctl.h"
51 #define RADEON_TIMEOUT 512
52 #define RADEON_IDLE_RETRY 16
55 /* =============================================================
56 * Kernel command buffer handling
59 /* The state atoms will be emitted in the order they appear in the atom list,
60 * so this step is important.
62 void radeonSetUpAtomList( r100ContextPtr rmesa
)
64 int i
, mtu
= rmesa
->radeon
.glCtx
.Const
.MaxTextureUnits
;
66 make_empty_list(&rmesa
->radeon
.hw
.atomlist
);
67 rmesa
->radeon
.hw
.atomlist
.name
= "atom-list";
69 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.ctx
);
70 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.set
);
71 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.lin
);
72 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.msk
);
73 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.vpt
);
74 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.tcl
);
75 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.msc
);
76 for (i
= 0; i
< mtu
; ++i
) {
77 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.tex
[i
]);
78 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.txr
[i
]);
79 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.cube
[i
]);
81 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.zbs
);
82 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.mtl
);
83 for (i
= 0; i
< 3 + mtu
; ++i
)
84 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.mat
[i
]);
85 for (i
= 0; i
< 8; ++i
)
86 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.lit
[i
]);
87 for (i
= 0; i
< 6; ++i
)
88 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.ucp
[i
]);
89 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.stp
);
90 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.eye
);
91 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.grd
);
92 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.fog
);
93 insert_at_tail(&rmesa
->radeon
.hw
.atomlist
, &rmesa
->hw
.glt
);
96 static void radeonEmitScissor(r100ContextPtr rmesa
)
98 BATCH_LOCALS(&rmesa
->radeon
);
99 if (rmesa
->radeon
.state
.scissor
.enabled
) {
101 OUT_BATCH(CP_PACKET0(RADEON_PP_CNTL
, 0));
102 OUT_BATCH(rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] | RADEON_SCISSOR_ENABLE
);
103 OUT_BATCH(CP_PACKET0(RADEON_RE_TOP_LEFT
, 0));
104 OUT_BATCH((rmesa
->radeon
.state
.scissor
.rect
.y1
<< 16) |
105 rmesa
->radeon
.state
.scissor
.rect
.x1
);
106 OUT_BATCH(CP_PACKET0(RADEON_RE_WIDTH_HEIGHT
, 0));
107 OUT_BATCH(((rmesa
->radeon
.state
.scissor
.rect
.y2
) << 16) |
108 (rmesa
->radeon
.state
.scissor
.rect
.x2
));
112 OUT_BATCH(CP_PACKET0(RADEON_PP_CNTL
, 0));
113 OUT_BATCH(rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] & ~RADEON_SCISSOR_ENABLE
);
118 /* Fire a section of the retained (indexed_verts) buffer as a regular
121 extern void radeonEmitVbufPrim( r100ContextPtr rmesa
,
122 GLuint vertex_format
,
126 BATCH_LOCALS(&rmesa
->radeon
);
128 assert(!(primitive
& RADEON_CP_VC_CNTL_PRIM_WALK_IND
));
130 radeonEmitState(&rmesa
->radeon
);
131 radeonEmitScissor(rmesa
);
133 #if RADEON_OLD_PACKETS
135 OUT_BATCH_PACKET3_CLIP(RADEON_CP_PACKET3_3D_RNDR_GEN_INDX_PRIM
, 3);
136 OUT_BATCH(rmesa
->ioctl
.vertex_offset
);
138 OUT_BATCH(vertex_nr
);
139 OUT_BATCH(vertex_format
);
140 OUT_BATCH(primitive
| RADEON_CP_VC_CNTL_PRIM_WALK_LIST
|
141 RADEON_CP_VC_CNTL_COLOR_ORDER_RGBA
|
142 RADEON_CP_VC_CNTL_VTX_FMT_RADEON_MODE
|
143 (vertex_nr
<< RADEON_CP_VC_CNTL_NUM_SHIFT
));
145 radeon_cs_write_reloc(rmesa
->radeon
.cmdbuf
.cs
,
147 RADEON_GEM_DOMAIN_GTT
,
154 OUT_BATCH_PACKET3_CLIP(RADEON_CP_PACKET3_3D_DRAW_VBUF
, 1);
155 OUT_BATCH(vertex_format
);
156 OUT_BATCH(primitive
|
157 RADEON_CP_VC_CNTL_PRIM_WALK_LIST
|
158 RADEON_CP_VC_CNTL_COLOR_ORDER_RGBA
|
159 RADEON_CP_VC_CNTL_MAOS_ENABLE
|
160 RADEON_CP_VC_CNTL_VTX_FMT_RADEON_MODE
|
161 (vertex_nr
<< RADEON_CP_VC_CNTL_NUM_SHIFT
));
166 void radeonFlushElts( struct gl_context
*ctx
)
168 r100ContextPtr rmesa
= R100_CONTEXT(ctx
);
169 BATCH_LOCALS(&rmesa
->radeon
);
171 uint32_t *cmd
= (uint32_t *)(rmesa
->radeon
.cmdbuf
.cs
->packets
+ rmesa
->tcl
.elt_cmd_start
);
172 int dwords
= (rmesa
->radeon
.cmdbuf
.cs
->section_ndw
- rmesa
->radeon
.cmdbuf
.cs
->section_cdw
);
174 if (RADEON_DEBUG
& RADEON_IOCTL
)
175 fprintf(stderr
, "%s\n", __func__
);
177 assert( rmesa
->radeon
.dma
.flush
== radeonFlushElts
);
178 rmesa
->radeon
.dma
.flush
= NULL
;
180 nr
= rmesa
->tcl
.elt_used
;
182 #if RADEON_OLD_PACKETS
186 #if RADEON_OLD_PACKETS
187 cmd
[1] |= (dwords
+ 3) << 16;
188 cmd
[5] |= nr
<< RADEON_CP_VC_CNTL_NUM_SHIFT
;
190 cmd
[1] |= (dwords
+ 2) << 16;
191 cmd
[3] |= nr
<< RADEON_CP_VC_CNTL_NUM_SHIFT
;
194 rmesa
->radeon
.cmdbuf
.cs
->cdw
+= dwords
;
195 rmesa
->radeon
.cmdbuf
.cs
->section_cdw
+= dwords
;
197 #if RADEON_OLD_PACKETS
198 radeon_cs_write_reloc(rmesa
->radeon
.cmdbuf
.cs
,
200 RADEON_GEM_DOMAIN_GTT
,
206 if (RADEON_DEBUG
& RADEON_SYNC
) {
207 fprintf(stderr
, "%s: Syncing\n", __func__
);
208 radeonFinish( &rmesa
->radeon
.glCtx
);
213 GLushort
*radeonAllocEltsOpenEnded( r100ContextPtr rmesa
,
214 GLuint vertex_format
,
220 BATCH_LOCALS(&rmesa
->radeon
);
222 if (RADEON_DEBUG
& RADEON_IOCTL
)
223 fprintf(stderr
, "%s %d prim %x\n", __func__
, min_nr
, primitive
);
225 assert((primitive
& RADEON_CP_VC_CNTL_PRIM_WALK_IND
));
227 radeonEmitState(&rmesa
->radeon
);
228 radeonEmitScissor(rmesa
);
230 rmesa
->tcl
.elt_cmd_start
= rmesa
->radeon
.cmdbuf
.cs
->cdw
;
232 /* round up min_nr to align the state */
233 align_min_nr
= (min_nr
+ 1) & ~1;
235 #if RADEON_OLD_PACKETS
236 BEGIN_BATCH(2+ELTS_BUFSZ(align_min_nr
)/4);
237 OUT_BATCH_PACKET3_CLIP(RADEON_CP_PACKET3_3D_RNDR_GEN_INDX_PRIM
, 0);
238 OUT_BATCH(rmesa
->ioctl
.vertex_offset
);
239 OUT_BATCH(rmesa
->ioctl
.vertex_max
);
240 OUT_BATCH(vertex_format
);
241 OUT_BATCH(primitive
|
242 RADEON_CP_VC_CNTL_PRIM_WALK_IND
|
243 RADEON_CP_VC_CNTL_COLOR_ORDER_RGBA
|
244 RADEON_CP_VC_CNTL_VTX_FMT_RADEON_MODE
);
246 BEGIN_BATCH(ELTS_BUFSZ(align_min_nr
)/4);
247 OUT_BATCH_PACKET3_CLIP(RADEON_CP_PACKET3_DRAW_INDX
, 0);
248 OUT_BATCH(vertex_format
);
249 OUT_BATCH(primitive
|
250 RADEON_CP_VC_CNTL_PRIM_WALK_IND
|
251 RADEON_CP_VC_CNTL_COLOR_ORDER_RGBA
|
252 RADEON_CP_VC_CNTL_MAOS_ENABLE
|
253 RADEON_CP_VC_CNTL_VTX_FMT_RADEON_MODE
);
257 rmesa
->tcl
.elt_cmd_offset
= rmesa
->radeon
.cmdbuf
.cs
->cdw
;
258 rmesa
->tcl
.elt_used
= min_nr
;
260 retval
= (GLushort
*)(rmesa
->radeon
.cmdbuf
.cs
->packets
+ rmesa
->tcl
.elt_cmd_offset
);
262 if (RADEON_DEBUG
& RADEON_RENDER
)
263 fprintf(stderr
, "%s: header prim %x \n",
264 __func__
, primitive
);
266 assert(!rmesa
->radeon
.dma
.flush
);
267 rmesa
->radeon
.glCtx
.Driver
.NeedFlush
|= FLUSH_STORED_VERTICES
;
268 rmesa
->radeon
.dma
.flush
= radeonFlushElts
;
273 void radeonEmitVertexAOS( r100ContextPtr rmesa
,
275 struct radeon_bo
*bo
,
278 #if RADEON_OLD_PACKETS
279 rmesa
->ioctl
.vertex_offset
= offset
;
280 rmesa
->ioctl
.bo
= bo
;
282 BATCH_LOCALS(&rmesa
->radeon
);
284 if (RADEON_DEBUG
& (RADEON_PRIMS
|RADEON_IOCTL
))
285 fprintf(stderr
, "%s: vertex_size 0x%x offset 0x%x \n",
286 __func__
, vertex_size
, offset
);
289 OUT_BATCH_PACKET3(RADEON_CP_PACKET3_3D_LOAD_VBPNTR
, 2);
291 OUT_BATCH(vertex_size
| (vertex_size
<< 8));
292 OUT_BATCH_RELOC(bo
, offset
, RADEON_GEM_DOMAIN_GTT
, 0, 0);
299 void radeonEmitAOS( r100ContextPtr rmesa
,
303 #if RADEON_OLD_PACKETS
305 rmesa
->ioctl
.bo
= rmesa
->radeon
.tcl
.aos
[0].bo
;
306 rmesa
->ioctl
.vertex_offset
=
307 (rmesa
->radeon
.tcl
.aos
[0].offset
+ offset
* rmesa
->radeon
.tcl
.aos
[0].stride
* 4);
308 rmesa
->ioctl
.vertex_max
= rmesa
->radeon
.tcl
.aos
[0].count
;
310 BATCH_LOCALS(&rmesa
->radeon
);
312 // int sz = AOS_BUFSZ(nr);
313 int sz
= 1 + (nr
>> 1) * 3 + (nr
& 1) * 2;
316 if (RADEON_DEBUG
& RADEON_IOCTL
)
317 fprintf(stderr
, "%s\n", __func__
);
319 BEGIN_BATCH(sz
+2+(nr
* 2));
320 OUT_BATCH_PACKET3(RADEON_CP_PACKET3_3D_LOAD_VBPNTR
, sz
- 1);
324 for (i
= 0; i
+ 1 < nr
; i
+= 2) {
325 OUT_BATCH((rmesa
->radeon
.tcl
.aos
[i
].components
<< 0) |
326 (rmesa
->radeon
.tcl
.aos
[i
].stride
<< 8) |
327 (rmesa
->radeon
.tcl
.aos
[i
+ 1].components
<< 16) |
328 (rmesa
->radeon
.tcl
.aos
[i
+ 1].stride
<< 24));
330 voffset
= rmesa
->radeon
.tcl
.aos
[i
+ 0].offset
+
331 offset
* 4 * rmesa
->radeon
.tcl
.aos
[i
+ 0].stride
;
333 voffset
= rmesa
->radeon
.tcl
.aos
[i
+ 1].offset
+
334 offset
* 4 * rmesa
->radeon
.tcl
.aos
[i
+ 1].stride
;
339 OUT_BATCH((rmesa
->radeon
.tcl
.aos
[nr
- 1].components
<< 0) |
340 (rmesa
->radeon
.tcl
.aos
[nr
- 1].stride
<< 8));
341 voffset
= rmesa
->radeon
.tcl
.aos
[nr
- 1].offset
+
342 offset
* 4 * rmesa
->radeon
.tcl
.aos
[nr
- 1].stride
;
345 for (i
= 0; i
+ 1 < nr
; i
+= 2) {
346 voffset
= rmesa
->radeon
.tcl
.aos
[i
+ 0].offset
+
347 offset
* 4 * rmesa
->radeon
.tcl
.aos
[i
+ 0].stride
;
348 radeon_cs_write_reloc(rmesa
->radeon
.cmdbuf
.cs
,
349 rmesa
->radeon
.tcl
.aos
[i
+0].bo
,
350 RADEON_GEM_DOMAIN_GTT
,
352 voffset
= rmesa
->radeon
.tcl
.aos
[i
+ 1].offset
+
353 offset
* 4 * rmesa
->radeon
.tcl
.aos
[i
+ 1].stride
;
354 radeon_cs_write_reloc(rmesa
->radeon
.cmdbuf
.cs
,
355 rmesa
->radeon
.tcl
.aos
[i
+1].bo
,
356 RADEON_GEM_DOMAIN_GTT
,
360 voffset
= rmesa
->radeon
.tcl
.aos
[nr
- 1].offset
+
361 offset
* 4 * rmesa
->radeon
.tcl
.aos
[nr
- 1].stride
;
362 radeon_cs_write_reloc(rmesa
->radeon
.cmdbuf
.cs
,
363 rmesa
->radeon
.tcl
.aos
[nr
-1].bo
,
364 RADEON_GEM_DOMAIN_GTT
,
373 /* ================================================================
376 #define RADEON_MAX_CLEARS 256
378 static void radeonClear( struct gl_context
*ctx
, GLbitfield mask
)
380 r100ContextPtr rmesa
= R100_CONTEXT(ctx
);
381 GLuint hwmask
, swmask
;
382 GLuint hwbits
= BUFFER_BIT_FRONT_LEFT
| BUFFER_BIT_BACK_LEFT
|
383 BUFFER_BIT_DEPTH
| BUFFER_BIT_STENCIL
|
386 if (mask
& (BUFFER_BIT_FRONT_LEFT
| BUFFER_BIT_FRONT_RIGHT
)) {
387 rmesa
->radeon
.front_buffer_dirty
= GL_TRUE
;
390 if ( RADEON_DEBUG
& RADEON_IOCTL
) {
391 fprintf( stderr
, "radeonClear\n");
394 radeon_firevertices(&rmesa
->radeon
);
396 hwmask
= mask
& hwbits
;
397 swmask
= mask
& ~hwbits
;
400 if (RADEON_DEBUG
& RADEON_FALLBACKS
)
401 fprintf(stderr
, "%s: swrast clear, mask: %x\n", __func__
, swmask
);
402 _swrast_Clear( ctx
, swmask
);
408 radeonUserClear(ctx
, hwmask
);
411 void radeonInitIoctlFuncs( struct gl_context
*ctx
)
413 ctx
->Driver
.Clear
= radeonClear
;
414 ctx
->Driver
.Finish
= radeonFinish
;
415 ctx
->Driver
.Flush
= radeonFlush
;