2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
26 #ifndef SAVAGE_IOCTL_H
27 #define SAVAGE_IOCTL_H
29 #include "savagecontext.h"
31 void savageFlushVertices( savageContextPtr mmesa
);
33 unsigned int savageEmitEventLocked( savageContextPtr imesa
, unsigned int flags
);
34 unsigned int savageEmitEvent( savageContextPtr imesa
, unsigned int flags
);
35 void savageWaitEvent( savageContextPtr imesa
, unsigned int event
);
37 void savageFlushCmdBufLocked( savageContextPtr imesa
, GLboolean discard
);
38 void savageFlushCmdBuf( savageContextPtr imesa
, GLboolean discard
);
40 void savageDDInitIoctlFuncs( GLcontext
*ctx
);
42 void savageSwapBuffers( __DRIdrawable
*dPriv
);
44 #define WAIT_IDLE_EMPTY(imesa) do { \
45 if (SAVAGE_DEBUG & DEBUG_VERBOSE_MSG) \
46 fprintf (stderr, "WAIT_IDLE_EMPTY in %s\n", __FUNCTION__); \
47 savageWaitEvent(imesa, \
48 savageEmitEvent(imesa, SAVAGE_WAIT_2D|SAVAGE_WAIT_3D)); \
51 #define WAIT_IDLE_EMPTY_LOCKED(imesa) do { \
52 if (SAVAGE_DEBUG & DEBUG_VERBOSE_MSG) \
53 fprintf (stderr, "WAIT_IDLE_EMPTY_LOCKED in %s\n", __FUNCTION__); \
54 savageWaitEvent(imesa, savageEmitEventLocked( \
55 imesa, SAVAGE_WAIT_2D|SAVAGE_WAIT_3D)); \
58 #define FLUSH_BATCH(imesa) do { \
59 if (SAVAGE_DEBUG & DEBUG_VERBOSE_MSG) \
60 fprintf (stderr, "FLUSH_BATCH in %s\n", __FUNCTION__); \
61 savageFlushVertices(imesa); \
62 savageFlushCmdBuf(imesa, GL_FALSE); \
65 extern void savageGetDMABuffer( savageContextPtr imesa
);
68 void savageReleaseIndexedVerts( savageContextPtr imesa
)
74 GLboolean
savageHaveIndexedVerts( savageContextPtr imesa
)
76 return (imesa
->firstElt
!= -1);
80 uint32_t *savageAllocVtxBuf( savageContextPtr imesa
, GLuint words
)
82 struct savage_vtxbuf_t
*buffer
= imesa
->vtxBuf
;
85 if (buffer
== &imesa
->dmaVtxBuf
) {
88 savageGetDMABuffer(imesa
);
89 UNLOCK_HARDWARE(imesa
);
90 } else if (buffer
->used
+ words
> buffer
->total
) {
91 if (SAVAGE_DEBUG
& DEBUG_VERBOSE_MSG
)
92 fprintf (stderr
, "... flushing DMA buffer in %s\n",
94 savageReleaseIndexedVerts(imesa
);
95 savageFlushVertices(imesa
);
97 savageFlushCmdBufLocked(imesa
, GL_TRUE
); /* discard DMA buffer */
98 savageGetDMABuffer(imesa
);
99 UNLOCK_HARDWARE(imesa
);
101 } else if (buffer
->used
+ words
> buffer
->total
) {
102 if (SAVAGE_DEBUG
& DEBUG_VERBOSE_MSG
)
103 fprintf (stderr
, "... flushing client vertex buffer in %s\n",
105 savageReleaseIndexedVerts(imesa
);
106 savageFlushVertices(imesa
);
107 LOCK_HARDWARE(imesa
);
108 savageFlushCmdBufLocked(imesa
, GL_FALSE
); /* free clientVtxBuf */
109 UNLOCK_HARDWARE(imesa
);
112 head
= &buffer
->buf
[buffer
->used
];
114 buffer
->used
+= words
;
119 uint32_t *savageAllocIndexedVerts( savageContextPtr imesa
, GLuint n
)
122 savageFlushVertices(imesa
);
123 ret
= savageAllocVtxBuf(imesa
, n
*imesa
->HwVertexSize
);
124 imesa
->firstElt
= imesa
->vtxBuf
->flushed
/ imesa
->HwVertexSize
;
125 imesa
->vtxBuf
->flushed
= imesa
->vtxBuf
->used
;
130 * - Complete the drawing command with the correct number of indices.
131 * - Actually allocate entries for the indices in the command buffer.
132 * (This allocation must succeed without wrapping the cmd buffer!)
135 void savageFlushElts( savageContextPtr imesa
)
137 if (imesa
->elts
.cmd
) {
138 GLuint qwords
= (imesa
->elts
.n
+ 3) >> 2;
139 assert(imesa
->cmdBuf
.write
- imesa
->cmdBuf
.base
+ qwords
140 <= imesa
->cmdBuf
.size
);
141 imesa
->cmdBuf
.write
+= qwords
;
143 imesa
->elts
.cmd
->idx
.count
= imesa
->elts
.n
;
144 imesa
->elts
.cmd
= NULL
;
148 /* Allocate a command buffer entry with <bytes> bytes of arguments:
149 * - implies savageFlushElts
152 drm_savage_cmd_header_t
*savageAllocCmdBuf( savageContextPtr imesa
, GLuint bytes
)
154 drm_savage_cmd_header_t
*ret
;
155 GLuint qwords
= ((bytes
+ 7) >> 3) + 1; /* round up */
156 assert (qwords
< imesa
->cmdBuf
.size
);
158 savageFlushElts(imesa
);
160 if (imesa
->cmdBuf
.write
- imesa
->cmdBuf
.base
+ qwords
> imesa
->cmdBuf
.size
)
161 savageFlushCmdBuf(imesa
, GL_FALSE
);
163 ret
= (drm_savage_cmd_header_t
*)imesa
->cmdBuf
.write
;
164 imesa
->cmdBuf
.write
+= qwords
;
169 * - if it doesn't fit, flush the cmd buffer first
170 * - allocates the drawing command on the cmd buffer if there is no
171 * incomplete indexed drawing command yet
172 * - increments the number of elts. Final allocation is done in savageFlushElts
175 uint16_t *savageAllocElts( savageContextPtr imesa
, GLuint n
)
179 assert (savageHaveIndexedVerts(imesa
));
182 qwords
= (imesa
->elts
.n
+ n
+ 3) >> 2;
184 qwords
= ((n
+ 3) >> 2) + 1;
185 if (imesa
->cmdBuf
.write
- imesa
->cmdBuf
.base
+ qwords
> imesa
->cmdBuf
.size
)
186 savageFlushCmdBuf(imesa
, GL_FALSE
); /* implies savageFlushElts */
188 if (!imesa
->elts
.cmd
) {
189 savageFlushVertices(imesa
);
190 imesa
->elts
.cmd
= savageAllocCmdBuf(imesa
, 0);
191 imesa
->elts
.cmd
->idx
.cmd
= (imesa
->vtxBuf
== &imesa
->dmaVtxBuf
) ?
192 SAVAGE_CMD_DMA_IDX
: SAVAGE_CMD_VB_IDX
;
193 imesa
->elts
.cmd
->idx
.prim
= imesa
->HwPrim
;
194 imesa
->elts
.cmd
->idx
.skip
= imesa
->skip
;
198 ret
= (uint16_t *)(imesa
->elts
.cmd
+1) + imesa
->elts
.n
;