r300g: drop DBG_CS
[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 #ifndef R300_CS_H
24 #define R300_CS_H
25
26 #include "util/u_math.h"
27
28 #include "r300_reg.h"
29 #include "r300_winsys.h"
30
31 /* Yes, I know macros are ugly. However, they are much prettier than the code
32 * that they neatly hide away, and don't have the cost of function setup,so
33 * we're going to use them. */
34
35 /* XXX stolen from radeon_reg.h */
36 #define RADEON_CP_PACKET0 0x0
37
38 #define CP_PACKET0(register, count) \
39 (RADEON_CP_PACKET0 | ((count) << 16) | ((register) >> 2))
40
41 #define CS_LOCALS(context) \
42 struct r300_context* const cs_context_copy = (context); \
43 struct r300_winsys_screen *cs_winsys = cs_context_copy->rws; \
44 int cs_count = 0; (void) cs_count;
45
46 #define BEGIN_CS(size) do { \
47 assert(r300_check_cs(cs_context_copy, (size))); \
48 cs_winsys->begin_cs(cs_winsys, (size), \
49 __FILE__, __FUNCTION__, __LINE__); \
50 cs_count = size; \
51 } while (0)
52
53 #define OUT_CS(value) do { \
54 cs_winsys->write_cs_dword(cs_winsys, (value)); \
55 cs_count--; \
56 } while (0)
57
58 #define OUT_CS_32F(value) do { \
59 cs_winsys->write_cs_dword(cs_winsys, fui(value)); \
60 cs_count--; \
61 } while (0)
62
63 #define OUT_CS_REG(register, value) do { \
64 assert(register); \
65 cs_winsys->write_cs_dword(cs_winsys, CP_PACKET0(register, 0)); \
66 cs_winsys->write_cs_dword(cs_winsys, value); \
67 cs_count -= 2; \
68 } while (0)
69
70 /* Note: This expects count to be the number of registers,
71 * not the actual packet0 count! */
72 #define OUT_CS_REG_SEQ(register, count) do { \
73 assert(register); \
74 cs_winsys->write_cs_dword(cs_winsys, CP_PACKET0((register), ((count) - 1))); \
75 cs_count--; \
76 } while (0)
77
78 #define OUT_CS_TABLE(values, count) do { \
79 cs_winsys->write_cs_table(cs_winsys, values, count); \
80 cs_count -= count; \
81 } while (0)
82
83 #define OUT_CS_BUF_RELOC(bo, offset, rd, wd, flags) do { \
84 assert(bo); \
85 cs_winsys->write_cs_dword(cs_winsys, offset); \
86 r300_buffer_write_reloc(cs_winsys, r300_buffer(bo), rd, wd, flags); \
87 cs_count -= 3; \
88 } while (0)
89
90
91 #define OUT_CS_TEX_RELOC(tex, offset, rd, wd, flags) do { \
92 assert(tex); \
93 cs_winsys->write_cs_dword(cs_winsys, offset); \
94 r300_texture_write_reloc(cs_winsys, tex, rd, wd, flags); \
95 cs_count -= 3; \
96 } while (0)
97
98
99 #define OUT_CS_BUF_RELOC_NO_OFFSET(bo, rd, wd, flags) do { \
100 assert(bo); \
101 r300_buffer_write_reloc(cs_winsys, r300_buffer(bo), rd, wd, flags); \
102 cs_count -= 2; \
103 } while (0)
104
105 #define END_CS do { \
106 if (cs_count != 0) \
107 debug_printf("r300: Warning: cs_count off by %d\n", cs_count); \
108 cs_winsys->end_cs(cs_winsys, __FILE__, __FUNCTION__, __LINE__); \
109 } while (0)
110
111 #define FLUSH_CS do { \
112 if (SCREEN_DBG_ON(r300->screen, DBG_STATS)) { \
113 r300->flush_counter++; \
114 } \
115 cs_winsys->flush_cs(cs_winsys); \
116 } while (0)
117
118 #define RADEON_ONE_REG_WR (1 << 15)
119
120 #define OUT_CS_ONE_REG(register, count) do { \
121 assert(register); \
122 cs_winsys->write_cs_dword(cs_winsys, CP_PACKET0((register), ((count) - 1)) | RADEON_ONE_REG_WR); \
123 cs_count--; \
124 } while (0)
125
126 #define CP_PACKET3(op, count) \
127 (RADEON_CP_PACKET3 | (op) | ((count) << 16))
128
129 #define OUT_CS_PKT3(op, count) do { \
130 cs_winsys->write_cs_dword(cs_winsys, CP_PACKET3(op, count)); \
131 cs_count--; \
132 } while (0)
133
134 #define OUT_CS_INDEX_RELOC(bo, offset, count, rd, wd, flags) do { \
135 assert(bo); \
136 cs_winsys->write_cs_dword(cs_winsys, offset); \
137 cs_winsys->write_cs_dword(cs_winsys, count); \
138 cs_winsys->write_cs_reloc(cs_winsys, bo, rd, wd, flags); \
139 cs_count -= 4; \
140 } while (0)
141
142 #endif /* R300_CS_H */