91e5dee0b0146c394b107340516b5e98302bb862
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. */
24 * This file contains macros for immediate command submission.
31 #include "r300_context.h"
32 #include "r300_winsys.h"
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. */
45 * Command submission setup.
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;)
53 #define BEGIN_CS(size) do { \
54 assert(r300_check_cs(cs_context_copy, (size))); \
55 cs_winsys->begin_cs(cs_winsys, (size), \
56 __FILE__, __FUNCTION__, __LINE__); \
57 CS_DEBUG(cs_count = size;) \
61 CS_DEBUG(if (cs_count != 0) \
62 debug_printf("r300: Warning: cs_count off by %d\n", cs_count);) \
63 cs_winsys->end_cs(cs_winsys, __FILE__, __FUNCTION__, __LINE__); \
64 CS_DEBUG(cs_count = 0;) \
69 * Writing pure DWORDs.
72 #define OUT_CS(value) do { \
73 cs_winsys->write_cs_dword(cs_winsys, (value)); \
74 CS_DEBUG(cs_count--;) \
77 #define OUT_CS_32F(value) do { \
78 cs_winsys->write_cs_dword(cs_winsys, fui(value)); \
79 CS_DEBUG(cs_count--;) \
82 #define OUT_CS_REG(register, value) do { \
84 cs_winsys->write_cs_dword(cs_winsys, CP_PACKET0(register, 0)); \
85 cs_winsys->write_cs_dword(cs_winsys, value); \
86 CS_DEBUG(cs_count -= 2;) \
89 /* Note: This expects count to be the number of registers,
90 * not the actual packet0 count! */
91 #define OUT_CS_REG_SEQ(register, count) do { \
93 cs_winsys->write_cs_dword(cs_winsys, CP_PACKET0((register), ((count) - 1))); \
94 CS_DEBUG(cs_count--;) \
97 #define OUT_CS_TABLE(values, count) do { \
98 cs_winsys->write_cs_table(cs_winsys, values, count); \
99 CS_DEBUG(cs_count -= count;) \
102 #define OUT_CS_ONE_REG(register, count) do { \
104 cs_winsys->write_cs_dword(cs_winsys, CP_PACKET0((register), ((count) - 1)) | RADEON_ONE_REG_WR); \
105 CS_DEBUG(cs_count--;) \
108 #define OUT_CS_PKT3(op, count) do { \
109 cs_winsys->write_cs_dword(cs_winsys, CP_PACKET3(op, count)); \
110 CS_DEBUG(cs_count--;) \
115 * Writing relocations.
118 #define OUT_CS_BUF_RELOC(bo, offset, rd, wd, flags) do { \
120 cs_winsys->write_cs_dword(cs_winsys, offset); \
121 r300_buffer_write_reloc(cs_winsys, r300_buffer(bo), rd, wd, flags); \
122 CS_DEBUG(cs_count -= 3;) \
125 #define OUT_CS_TEX_RELOC(tex, offset, rd, wd, flags) do { \
127 cs_winsys->write_cs_dword(cs_winsys, offset); \
128 r300_texture_write_reloc(cs_winsys, tex, rd, wd, flags); \
129 CS_DEBUG(cs_count -= 3;) \
132 #define OUT_CS_BUF_RELOC_NO_OFFSET(bo, rd, wd, flags) do { \
134 r300_buffer_write_reloc(cs_winsys, r300_buffer(bo), rd, wd, flags); \
135 CS_DEBUG(cs_count -= 2;) \
138 #define OUT_CS_INDEX_RELOC(bo, offset, count, rd, wd, flags) do { \
140 cs_winsys->write_cs_dword(cs_winsys, offset); \
141 cs_winsys->write_cs_dword(cs_winsys, count); \
142 cs_winsys->write_cs_reloc(cs_winsys, bo, rd, wd, flags); \
143 CS_DEBUG(cs_count -= 4;) \
148 * Command buffer emission.
151 /* It's recommended not to call begin_cs/end_cs before/after this macro. */
152 #define WRITE_CS_TABLE(values, count) do { \
153 CS_DEBUG(assert(cs_count == 0);) \
154 cs_winsys->write_cs_table(cs_winsys, values, count); \
157 #endif /* R300_CS_H */