2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
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:
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
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. */
26 #include "util/u_math.h"
29 #include "r300_winsys.h"
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. */
35 #define MAX_CS_SIZE 64 * 1024 / 4
37 #define VERY_VERBOSE_CS 1
38 #define VERY_VERBOSE_REGISTERS 1
40 /* XXX stolen from radeon_reg.h */
41 #define RADEON_CP_PACKET0 0x0
43 #define CP_PACKET0(register, count) \
44 (RADEON_CP_PACKET0 | ((count) << 16) | ((register) >> 2))
46 #define CS_LOCALS(context) \
47 struct r300_context* const cs_context_copy = (context); \
48 struct r300_winsys_screen *cs_winsys = cs_context_copy->rws; \
49 int cs_count = 0; (void) cs_count;
51 #define CHECK_CS(size) \
52 assert(r300_check_cs(cs_context_copy, (size)))
54 #define BEGIN_CS(size) do { \
56 if (VERY_VERBOSE_CS) { \
57 DBG(cs_context_copy, DBG_CS, "r300: BEGIN_CS, count %d, in %s (%s:%d)\n", \
58 size, __FUNCTION__, __FILE__, __LINE__); \
60 cs_winsys->begin_cs(cs_winsys, (size), \
61 __FILE__, __FUNCTION__, __LINE__); \
65 #define OUT_CS(value) do { \
66 if (VERY_VERBOSE_CS || VERY_VERBOSE_REGISTERS) { \
67 DBG(cs_context_copy, DBG_CS, "r300: writing %08x\n", value); \
69 cs_winsys->write_cs_dword(cs_winsys, (value)); \
73 #define OUT_CS_32F(value) do { \
74 if (VERY_VERBOSE_CS || VERY_VERBOSE_REGISTERS) { \
75 DBG(cs_context_copy, DBG_CS, "r300: writing %f\n", value); \
77 cs_winsys->write_cs_dword(cs_winsys, fui(value)); \
81 #define OUT_CS_REG(register, value) do { \
82 if (VERY_VERBOSE_REGISTERS) \
83 DBG(cs_context_copy, DBG_CS, "r300: writing 0x%08X to register 0x%04X\n", \
86 cs_winsys->write_cs_dword(cs_winsys, CP_PACKET0(register, 0)); \
87 cs_winsys->write_cs_dword(cs_winsys, value); \
91 /* Note: This expects count to be the number of registers,
92 * not the actual packet0 count! */
93 #define OUT_CS_REG_SEQ(register, count) do { \
94 if (VERY_VERBOSE_REGISTERS) \
95 DBG(cs_context_copy, DBG_CS, "r300: writing register sequence of %d to 0x%04X\n", \
98 cs_winsys->write_cs_dword(cs_winsys, CP_PACKET0((register), ((count) - 1))); \
102 #define OUT_CS_TABLE(values, count) do { \
103 if (VERY_VERBOSE_REGISTERS) \
104 DBG(cs_context_copy, DBG_CS, "r300: writing table of %d dwords\n", count); \
105 cs_winsys->write_cs_table(cs_winsys, values, count); \
109 #define OUT_CS_BUF_RELOC(bo, offset, rd, wd, flags) do { \
110 DBG(cs_context_copy, DBG_CS, "r300: writing relocation for buffer %p, offset %d, " \
111 "domains (%d, %d, %d)\n", \
112 bo, offset, rd, wd, flags); \
114 cs_winsys->write_cs_dword(cs_winsys, offset); \
115 r300_buffer_write_reloc(cs_winsys, r300_buffer(bo), rd, wd, flags); \
120 #define OUT_CS_TEX_RELOC(tex, offset, rd, wd, flags) do { \
121 DBG(cs_context_copy, DBG_CS, "r300: writing relocation for texture %p, offset %d, " \
122 "domains (%d, %d, %d)\n", \
123 tex, offset, rd, wd, flags); \
125 cs_winsys->write_cs_dword(cs_winsys, offset); \
126 r300_texture_write_reloc(cs_winsys, tex, rd, wd, flags); \
131 #define OUT_CS_BUF_RELOC_NO_OFFSET(bo, rd, wd, flags) do { \
132 DBG(cs_context_copy, DBG_CS, "r300: writing relocation for buffer %p, " \
133 "domains (%d, %d, %d)\n", \
134 bo, rd, wd, flags); \
136 r300_buffer_write_reloc(cs_winsys, r300_buffer(bo), rd, wd, flags); \
140 #define END_CS do { \
141 if (VERY_VERBOSE_CS) { \
142 DBG(cs_context_copy, DBG_CS, "r300: END_CS in %s (%s:%d)\n", __FUNCTION__, \
143 __FILE__, __LINE__); \
146 debug_printf("r300: Warning: cs_count off by %d\n", cs_count); \
147 cs_winsys->end_cs(cs_winsys, __FILE__, __FUNCTION__, __LINE__); \
150 #define FLUSH_CS do { \
151 if (VERY_VERBOSE_CS) { \
152 DBG(cs_context_copy, DBG_CS, "r300: FLUSH_CS in %s (%s:%d)\n\n", __FUNCTION__, \
153 __FILE__, __LINE__); \
155 if (SCREEN_DBG_ON(r300->screen, DBG_STATS)) { \
156 r300->flush_counter++; \
158 cs_winsys->flush_cs(cs_winsys); \
161 #define RADEON_ONE_REG_WR (1 << 15)
163 #define OUT_CS_ONE_REG(register, count) do { \
164 if (VERY_VERBOSE_REGISTERS) \
165 DBG(cs_context_copy, DBG_CS, "r300: writing data sequence of %d to 0x%04X\n", \
168 cs_winsys->write_cs_dword(cs_winsys, CP_PACKET0((register), ((count) - 1)) | RADEON_ONE_REG_WR); \
172 #define CP_PACKET3(op, count) \
173 (RADEON_CP_PACKET3 | (op) | ((count) << 16))
175 #define OUT_CS_PKT3(op, count) do { \
176 cs_winsys->write_cs_dword(cs_winsys, CP_PACKET3(op, count)); \
180 #define OUT_CS_INDEX_RELOC(bo, offset, count, rd, wd, flags) do { \
181 DBG(cs_context_copy, DBG_CS, "r300: writing relocation for index buffer %p," \
182 "offset %d\n", bo, offset); \
184 cs_winsys->write_cs_dword(cs_winsys, offset); \
185 cs_winsys->write_cs_dword(cs_winsys, count); \
186 cs_winsys->write_cs_reloc(cs_winsys, bo, rd, wd, flags); \
190 #endif /* R300_CS_H */