Merge remote branch 'origin/master' into radeon-rewrite
[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 #define MAX_CS_SIZE 64 * 1024 / 4
36
37 #define VERY_VERBOSE_REGISTERS 0
38
39 /* XXX stolen from radeon_drm.h */
40 #define RADEON_GEM_DOMAIN_CPU 0x1
41 #define RADEON_GEM_DOMAIN_GTT 0x2
42 #define RADEON_GEM_DOMAIN_VRAM 0x4
43
44 /* XXX stolen from radeon_reg.h */
45 #define RADEON_CP_PACKET0 0x0
46
47 #define CP_PACKET0(register, count) \
48 (RADEON_CP_PACKET0 | ((count) << 16) | ((register) >> 2))
49
50 #define CS_LOCALS(context) \
51 struct r300_winsys* cs_winsys = context->winsys; \
52 struct radeon_cs* cs = cs_winsys->cs; \
53 int cs_count = 0;
54
55 #define CHECK_CS(size) \
56 cs_winsys->check_cs(cs, (size))
57
58 #define BEGIN_CS(size) do { \
59 CHECK_CS(size); \
60 debug_printf("r300: BEGIN_CS, count %d, in %s (%s:%d)\n", \
61 size, __FUNCTION__, __FILE__, __LINE__); \
62 cs_winsys->begin_cs(cs, (size), __FILE__, __FUNCTION__, __LINE__); \
63 cs_count = size; \
64 } while (0)
65
66 #define OUT_CS(value) do { \
67 cs_winsys->write_cs_dword(cs, (value)); \
68 cs_count--; \
69 } while (0)
70
71 #define OUT_CS_32F(value) do { \
72 cs_winsys->write_cs_dword(cs, fui(value)); \
73 cs_count--; \
74 } while (0)
75
76 #define OUT_CS_REG(register, value) do { \
77 if (VERY_VERBOSE_REGISTERS) \
78 debug_printf("r300: writing 0x%08X to register 0x%04X\n", \
79 value, register); \
80 assert(register); \
81 OUT_CS(CP_PACKET0(register, 0)); \
82 OUT_CS(value); \
83 } while (0)
84
85 /* Note: This expects count to be the number of registers,
86 * not the actual packet0 count! */
87 #define OUT_CS_REG_SEQ(register, count) do { \
88 if (VERY_VERBOSE_REGISTERS) \
89 debug_printf("r300: writing register sequence of %d to 0x%04X\n", \
90 count, register); \
91 assert(register); \
92 OUT_CS(CP_PACKET0(register, ((count) - 1))); \
93 } while (0)
94
95 #define OUT_CS_RELOC(bo, offset, rd, wd, flags) do { \
96 debug_printf("r300: writing relocation for buffer %p, offset %d\n", \
97 bo, offset); \
98 assert(bo); \
99 OUT_CS(offset); \
100 cs_winsys->write_cs_reloc(cs, bo, rd, wd, flags); \
101 cs_count -= 2; \
102 } while (0)
103
104 #define END_CS do { \
105 debug_printf("r300: END_CS in %s (%s:%d)\n", __FUNCTION__, __FILE__, \
106 __LINE__); \
107 if (cs_count != 0) \
108 debug_printf("r300: Warning: cs_count off by %d\n", cs_count); \
109 cs_winsys->end_cs(cs, __FILE__, __FUNCTION__, __LINE__); \
110 } while (0)
111
112 #define FLUSH_CS do { \
113 debug_printf("r300: FLUSH_CS in %s (%s:%d)\n\n", __FUNCTION__, __FILE__, \
114 __LINE__); \
115 cs_winsys->flush_cs(cs); \
116 } while (0)
117
118 #define RADEON_ONE_REG_WR (1 << 15)
119
120 #define OUT_CS_ONE_REG(register, count) do { \
121 if (VERY_VERBOSE_REGISTERS) \
122 debug_printf("r300: writing data sequence of %d to 0x%04X\n", \
123 count, register); \
124 assert(register); \
125 OUT_CS(CP_PACKET0(register, ((count) - 1)) | RADEON_ONE_REG_WR); \
126 } while (0)
127
128 #define CP_PACKET3(op, count) \
129 (RADEON_CP_PACKET3 | (op) | ((count) << 16))
130
131 #define OUT_CS_PKT3(op, count) do { \
132 OUT_CS(CP_PACKET3(op, count)); \
133 } while (0)
134
135 #define OUT_CS_INDEX_RELOC(bo, offset, count, rd, wd, flags) do { \
136 debug_printf("r300: writing relocation for index buffer %p," \
137 "offset %d\n", bo, offset); \
138 assert(bo); \
139 OUT_CS(offset); \
140 OUT_CS(count); \
141 cs_winsys->write_cs_reloc(cs, bo, rd, wd, flags); \
142 cs_count -= 2; \
143 } while (0)
144
145 #endif /* R300_CS_H */