2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 * Copyright 2010 Marek Olšák <maraeo@gmail.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
25 * This file contains macros for building command buffers in memory.
27 * Use NEW_CB for buffers with a varying size and it will also allocate
29 * Use BEGIN_CB for arrays with a static size.
37 * OUT_CB_REG_SEQ(R500_RB3D_CONSTANT_COLOR_AR, 2);
38 * OUT_CB(blend_color_red_alpha);
39 * OUT_CB(blend_color_green_blue);
45 * WRITE_CS_TABLE(cb, 3);
47 * Or using a little slower variant:
51 * OUT_CS_TABLE(cb, 3);
60 /* Yes, I know macros are ugly. However, they are much prettier than the code
61 * that they neatly hide away, and don't have the cost of function setup, so
62 * we're going to use them. */
65 * Command buffer setup.
72 uint32_t *cs_ptr = NULL; \
73 (void) cs_count; (void) cs_ptr
75 #define BEGIN_CB(ptr, size) do { \
76 assert(sizeof(*(ptr)) == sizeof(uint32_t)); \
81 #define NEW_CB(ptr, size) \
83 assert(sizeof(*(ptr)) == sizeof(uint32_t)); \
85 cs_ptr = (ptr) = malloc((size) * sizeof(uint32_t)); \
90 debug_printf("r300: Warning: cs_count off by %d at (%s, %s:%i)\n", \
91 cs_count, __FUNCTION__, __FILE__, __LINE__); \
94 #define CB_USED_DW(x) cs_count -= x
99 uint32_t *cs_ptr = NULL; (void) cs_ptr
101 #define NEW_CB(ptr, size) \
102 cs_ptr = (ptr) = malloc((size) * sizeof(uint32_t))
104 #define BEGIN_CB(ptr, size) cs_ptr = (ptr)
106 #define CB_USED_DW(x)
112 * Storing pure DWORDs.
115 #define OUT_CB(value) do { \
121 #define OUT_CB_TABLE(values, count) do { \
122 memcpy(cs_ptr, values, count * sizeof(uint32_t)); \
127 #define OUT_CB_32F(value) \
130 #define OUT_CB_REG(register, value) do { \
132 OUT_CB(CP_PACKET0(register, 0)); \
136 /* Note: This expects count to be the number of registers,
137 * not the actual packet0 count! */
138 #define OUT_CB_REG_SEQ(register, count) do { \
140 OUT_CB(CP_PACKET0(register, (count) - 1)); \
143 #define OUT_CB_ONE_REG(register, count) do { \
145 OUT_CB(CP_PACKET0(register, (count) - 1) | RADEON_ONE_REG_WR); \
148 #define OUT_CB_PKT3(op, count) \
149 OUT_CB(CP_PACKET3(op, count))
151 #endif /* R300_CB_H */