r300: release bo from pixmap
[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 #include "radeon_cs.h"
41
42 extern int r300FlushCmdBufLocked(r300ContextPtr r300, const char *caller);
43 extern int r300FlushCmdBuf(r300ContextPtr r300, const char *caller);
44
45 extern void r300EmitState(r300ContextPtr r300);
46
47 extern void r300InitCmdBuf(r300ContextPtr r300);
48 extern void r300DestroyCmdBuf(r300ContextPtr r300);
49 extern void r300EnsureCmdBufSpace(r300ContextPtr r300, int dwords, const char *caller);
50
51 void r300BeginBatch(r300ContextPtr r300,
52 int n,
53 int dostate,
54 const char *file,
55 const char *function,
56 int line);
57
58 /**
59 * Every function writing to the command buffer needs to declare this
60 * to get the necessary local variables.
61 */
62 #define BATCH_LOCALS(r300) \
63 const r300ContextPtr b_l_r300 = r300
64
65 /**
66 * Prepare writing n dwords to the command buffer,
67 * including producing any necessary state emits on buffer wraparound.
68 */
69 #define BEGIN_BATCH(n) r300BeginBatch(b_l_r300, n, 1, __FILE__, __FUNCTION__, __LINE__)
70
71 /**
72 * Same as BEGIN_BATCH, but do not cause automatic state emits.
73 */
74 #define BEGIN_BATCH_NO_AUTOSTATE(n) r300BeginBatch(b_l_r300, n, 0, __FILE__, __FUNCTION__, __LINE__)
75
76 /**
77 * Write one dword to the command buffer.
78 */
79 #define OUT_BATCH(data) \
80 do { \
81 radeon_cs_write_dword(b_l_r300->cmdbuf.cs, data);\
82 } while(0)
83
84 /**
85 * Write a relocated dword to the command buffer.
86 */
87 #define OUT_BATCH_RELOC(data, bo, offset, rd, wd, flags) \
88 do { \
89 if (offset) {\
90 fprintf(stderr, "(%s:%s:%d) offset : %d\n",\
91 __FILE__, __FUNCTION__, __LINE__, offset);\
92 }\
93 radeon_cs_write_dword(b_l_r300->cmdbuf.cs, offset);\
94 radeon_cs_write_reloc(b_l_r300->cmdbuf.cs, \
95 bo, \
96 offset, \
97 (bo)->size, \
98 rd, \
99 wd, \
100 flags);\
101 } while(0)
102
103 /**
104 * Write n dwords from ptr to the command buffer.
105 */
106 #define OUT_BATCH_TABLE(ptr,n) \
107 do { \
108 int _i; \
109 for (_i=0; _i < n; _i++) {\
110 radeon_cs_write_dword(b_l_r300->cmdbuf.cs, ptr[_i]);\
111 }\
112 } while(0)
113
114 /**
115 * Finish writing dwords to the command buffer.
116 * The number of (direct or indirect) OUT_BATCH calls between the previous
117 * BEGIN_BATCH and END_BATCH must match the number specified at BEGIN_BATCH time.
118 */
119 #define END_BATCH() \
120 do { \
121 radeon_cs_end(b_l_r300->cmdbuf.cs, __FILE__, __FUNCTION__, __LINE__);\
122 } while(0)
123
124 /**
125 * After the last END_BATCH() of rendering, this indicates that flushing
126 * the command buffer now is okay.
127 */
128 #define COMMIT_BATCH() \
129 do { \
130 } while(0)
131
132 void emit_vpu(r300ContextPtr r300, struct r300_state_atom * atom);
133 int check_vpu(r300ContextPtr r300, struct r300_state_atom *atom);
134
135 #endif /* __R300_CMDBUF_H__ */