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. */
72 * Command buffer setup.
76 CB_DEBUG(int cs_count = 0;) \
77 uint32_t *cs_ptr = NULL; \
78 CB_DEBUG((void) cs_count;) (void) cs_ptr;
80 #define NEW_CB(ptr, size) do { \
81 assert(sizeof(*ptr) == sizeof(uint32_t)); \
82 cs_ptr = (ptr) = (uint32_t*)malloc((size) * sizeof(uint32_t)); \
83 CB_DEBUG(cs_count = size;) \
86 #define BEGIN_CB(ptr, size) do { \
87 assert(sizeof(*ptr) == sizeof(uint32_t)); \
89 CB_DEBUG(cs_count = size;) \
93 CB_DEBUG(if (cs_count != 0) \
94 debug_printf("r300: Warning: cs_count off by %d at (%s, %s:%i)\n", \
95 cs_count, __FUNCTION__, __FILE__, __LINE__);) \
100 * Storing pure DWORDs.
103 #define OUT_CB(value) do { \
106 CB_DEBUG(cs_count--;) \
109 #define OUT_CB_TABLE(values, count) do { \
110 memcpy(cs_ptr, values, count * sizeof(uint32_t)); \
112 CB_DEBUG(cs_count -= count;) \
115 #define OUT_CB_32F(value) \
118 #define OUT_CB_REG(register, value) do { \
120 OUT_CB(CP_PACKET0(register, 0)); \
124 /* Note: This expects count to be the number of registers,
125 * not the actual packet0 count! */
126 #define OUT_CB_REG_SEQ(register, count) do { \
128 OUT_CB(CP_PACKET0(register, (count) - 1)); \
131 #define OUT_CB_ONE_REG(register, count) do { \
133 OUT_CB(CP_PACKET0(register, (count) - 1) | RADEON_ONE_REG_WR); \
136 #define OUT_CB_PKT3(op, count) \
137 OUT_CB(CP_PACKET3(op, count))
139 #endif /* R300_CB_H */