Merge commit 'origin/gallium-0.1' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / r300 / r300_cmdbuf.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 * \file
32 *
33 * \author Nicolai Haehnle <prefect_@gmx.net>
34 */
35
36 #ifndef __R300_CMDBUF_H__
37 #define __R300_CMDBUF_H__
38
39 #include "r300_context.h"
40
41 extern int r300FlushCmdBufLocked(r300ContextPtr r300, const char *caller);
42 extern int r300FlushCmdBuf(r300ContextPtr r300, const char *caller);
43
44 extern void r300EmitState(r300ContextPtr r300);
45
46 extern void r300InitCmdBuf(r300ContextPtr r300);
47 extern void r300DestroyCmdBuf(r300ContextPtr r300);
48
49 /**
50 * Make sure that enough space is available in the command buffer
51 * by flushing if necessary.
52 *
53 * \param dwords The number of dwords we need to be free on the command buffer
54 */
55 static INLINE void r300EnsureCmdBufSpace(r300ContextPtr r300,
56 int dwords, const char *caller)
57 {
58 assert(dwords < r300->cmdbuf.size);
59
60 if (r300->cmdbuf.count_used + dwords > r300->cmdbuf.size)
61 r300FlushCmdBuf(r300, caller);
62 }
63
64 /**
65 * Allocate the given number of dwords in the command buffer and return
66 * a pointer to the allocated area.
67 * When necessary, these functions cause a flush. r300AllocCmdBuf() also
68 * causes state reemission after a flush. This is necessary to ensure
69 * correct hardware state after an unlock.
70 */
71 static INLINE uint32_t *r300RawAllocCmdBuf(r300ContextPtr r300,
72 int dwords, const char *caller)
73 {
74 uint32_t *ptr;
75
76 r300EnsureCmdBufSpace(r300, dwords, caller);
77
78 ptr = &r300->cmdbuf.cmd_buf[r300->cmdbuf.count_used];
79 r300->cmdbuf.count_used += dwords;
80 return ptr;
81 }
82
83 static INLINE uint32_t *r300AllocCmdBuf(r300ContextPtr r300,
84 int dwords, const char *caller)
85 {
86 uint32_t *ptr;
87
88 r300EnsureCmdBufSpace(r300, dwords, caller);
89
90 if (!r300->cmdbuf.count_used) {
91 if (RADEON_DEBUG & DEBUG_IOCTL)
92 fprintf(stderr,
93 "Reemit state after flush (from %s)\n", caller);
94 r300EmitState(r300);
95 }
96
97 ptr = &r300->cmdbuf.cmd_buf[r300->cmdbuf.count_used];
98 r300->cmdbuf.count_used += dwords;
99 return ptr;
100 }
101
102 extern void r300EmitBlit(r300ContextPtr rmesa,
103 GLuint color_fmt,
104 GLuint src_pitch,
105 GLuint src_offset,
106 GLuint dst_pitch,
107 GLuint dst_offset,
108 GLint srcx, GLint srcy,
109 GLint dstx, GLint dsty, GLuint w, GLuint h);
110
111 extern void r300EmitWait(r300ContextPtr rmesa, GLuint flags);
112 extern void r300EmitLOAD_VBPNTR(r300ContextPtr rmesa, int start);
113 extern void r300EmitVertexShader(r300ContextPtr rmesa);
114 extern void r300EmitPixelShader(r300ContextPtr rmesa);
115
116 #endif /* __R300_CMDBUF_H__ */