1db7da642bd89af4027acf30766f8a44b1c06b36
[mesa.git] / src / gallium / drivers / r300 / r300_cs.h
1 /*
2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 /**
24 * This file contains macros for immediate command submission.
25 */
26
27 #ifndef R300_CS_H
28 #define R300_CS_H
29
30 #include "r300_reg.h"
31 #include "r300_context.h"
32 #include "r300_winsys.h"
33
34 /* Yes, I know macros are ugly. However, they are much prettier than the code
35 * that they neatly hide away, and don't have the cost of function setup,so
36 * we're going to use them. */
37
38 #ifdef DEBUG
39 #define CS_DEBUG(x) x
40 #else
41 #define CS_DEBUG(x)
42 #endif
43
44 /**
45 * Command submission setup.
46 */
47
48 #define CS_LOCALS(context) \
49 struct r300_context* const cs_context_copy = (context); \
50 struct r300_winsys_screen *cs_winsys = cs_context_copy->rws; \
51 CS_DEBUG(int cs_count = 0; (void) cs_count;)
52
53 #define BEGIN_CS(size) do { \
54 assert(r300_check_cs(cs_context_copy, (size))); \
55 CS_DEBUG(cs_count = size;) \
56 } while (0)
57
58 #ifdef DEBUG
59 #define END_CS do { \
60 if (cs_count != 0) \
61 debug_printf("r300: Warning: cs_count off by %d at (%s, %s:%i)\n", \
62 cs_count, __FUNCTION__, __FILE__, __LINE__); \
63 cs_count = 0; \
64 } while (0)
65 #else
66 #define END_CS
67 #endif
68
69 /**
70 * Writing pure DWORDs.
71 */
72
73 #define OUT_CS(value) do { \
74 cs_winsys->write_cs_dword(cs_winsys, (value)); \
75 CS_DEBUG(cs_count--;) \
76 } while (0)
77
78 #define OUT_CS_32F(value) do { \
79 cs_winsys->write_cs_dword(cs_winsys, fui(value)); \
80 CS_DEBUG(cs_count--;) \
81 } while (0)
82
83 #define OUT_CS_REG(register, value) do { \
84 assert(register); \
85 cs_winsys->write_cs_dword(cs_winsys, CP_PACKET0(register, 0)); \
86 cs_winsys->write_cs_dword(cs_winsys, value); \
87 CS_DEBUG(cs_count -= 2;) \
88 } while (0)
89
90 /* Note: This expects count to be the number of registers,
91 * not the actual packet0 count! */
92 #define OUT_CS_REG_SEQ(register, count) do { \
93 assert(register); \
94 cs_winsys->write_cs_dword(cs_winsys, CP_PACKET0((register), ((count) - 1))); \
95 CS_DEBUG(cs_count--;) \
96 } while (0)
97
98 #define OUT_CS_TABLE(values, count) do { \
99 cs_winsys->write_cs_table(cs_winsys, values, count); \
100 CS_DEBUG(cs_count -= count;) \
101 } while (0)
102
103 #define OUT_CS_ONE_REG(register, count) do { \
104 assert(register); \
105 cs_winsys->write_cs_dword(cs_winsys, CP_PACKET0((register), ((count) - 1)) | RADEON_ONE_REG_WR); \
106 CS_DEBUG(cs_count--;) \
107 } while (0)
108
109 #define OUT_CS_PKT3(op, count) do { \
110 cs_winsys->write_cs_dword(cs_winsys, CP_PACKET3(op, count)); \
111 CS_DEBUG(cs_count--;) \
112 } while (0)
113
114
115 /**
116 * Writing relocations.
117 */
118
119 #define OUT_CS_RELOC(bo, offset, rd, wd, flags) do { \
120 assert(bo); \
121 cs_winsys->write_cs_dword(cs_winsys, offset); \
122 cs_winsys->write_cs_reloc(cs_winsys, bo, rd, wd, flags); \
123 CS_DEBUG(cs_count -= 3;) \
124 } while (0)
125
126 #define OUT_CS_BUF_RELOC(bo, offset, rd, wd, flags) do { \
127 assert(bo); \
128 OUT_CS_RELOC(r300_buffer(bo)->buf, offset, rd, wd, flags); \
129 } while (0)
130
131 #define OUT_CS_TEX_RELOC(tex, offset, rd, wd, flags) do { \
132 assert(tex); \
133 OUT_CS_RELOC(tex->buffer, offset, rd, wd, flags); \
134 } while (0)
135
136 #define OUT_CS_BUF_RELOC_NO_OFFSET(bo, rd, wd, flags) do { \
137 assert(bo); \
138 cs_winsys->write_cs_reloc(cs_winsys, r300_buffer(bo)->buf, rd, wd, flags); \
139 CS_DEBUG(cs_count -= 2;) \
140 } while (0)
141
142
143 /**
144 * Command buffer emission.
145 */
146
147 #define WRITE_CS_TABLE(values, count) do { \
148 CS_DEBUG(assert(cs_count == 0);) \
149 cs_winsys->write_cs_table(cs_winsys, values, count); \
150 } while (0)
151
152 #endif /* R300_CS_H */