Path: blob/21.2-virgl/src/gallium/drivers/r300/r300_cb.h
4570 views
/*1* Copyright 2008 Corbin Simpson <[email protected]>2* Copyright 2010 Marek Olšák <[email protected]>3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* on the rights to use, copy, modify, merge, publish, distribute, sub8* license, and/or sell copies of the Software, and to permit persons to whom9* the Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL18* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,19* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR20* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE21* USE OR OTHER DEALINGS IN THE SOFTWARE. */2223/**24* This file contains macros for building command buffers in memory.25*26* Use NEW_CB for buffers with a varying size and it will also allocate27* the buffer.28* Use BEGIN_CB for arrays with a static size.29*30* Example:31*32* uint32_t cb[3];33* CB_LOCALS;34*35* BEGIN_CB(cb, 3);36* OUT_CB_REG_SEQ(R500_RB3D_CONSTANT_COLOR_AR, 2);37* OUT_CB(blend_color_red_alpha);38* OUT_CB(blend_color_green_blue);39* END_CB;40*41* And later:42*43* CS_LOCALS;44* WRITE_CS_TABLE(cb, 3);45*46* Or using a little slower variant:47*48* CS_LOCALS;49* BEGIN_CS(cb, 3);50* OUT_CS_TABLE(cb, 3);51* END_CS;52*/5354#ifndef R300_CB_H55#define R300_CB_H5657#include "r300_reg.h"5859/* Yes, I know macros are ugly. However, they are much prettier than the code60* that they neatly hide away, and don't have the cost of function setup, so61* we're going to use them. */6263/**64* Command buffer setup.65*/6667#ifdef DEBUG6869#define CB_LOCALS \70int cs_count = 0; \71uint32_t *cs_ptr = NULL; \72(void) cs_count; (void) cs_ptr7374#define BEGIN_CB(ptr, size) do { \75assert(sizeof(*(ptr)) == sizeof(uint32_t)); \76cs_count = (size); \77cs_ptr = (ptr); \78} while (0)7980#define NEW_CB(ptr, size) \81do { \82assert(sizeof(*(ptr)) == sizeof(uint32_t)); \83cs_count = (size); \84cs_ptr = (ptr) = malloc((size) * sizeof(uint32_t)); \85} while (0)8687#define END_CB do { \88if (cs_count != 0) \89debug_printf("r300: Warning: cs_count off by %d at (%s, %s:%i)\n", \90cs_count, __FUNCTION__, __FILE__, __LINE__); \91} while (0)9293#define CB_USED_DW(x) cs_count -= x9495#else9697#define CB_LOCALS \98uint32_t *cs_ptr = NULL; (void) cs_ptr99100#define NEW_CB(ptr, size) \101cs_ptr = (ptr) = malloc((size) * sizeof(uint32_t))102103#define BEGIN_CB(ptr, size) cs_ptr = (ptr)104#define END_CB105#define CB_USED_DW(x)106107#endif108109110/**111* Storing pure DWORDs.112*/113114#define OUT_CB(value) do { \115*cs_ptr = (value); \116cs_ptr++; \117CB_USED_DW(1); \118} while (0)119120#define OUT_CB_TABLE(values, count) do { \121memcpy(cs_ptr, values, count * sizeof(uint32_t)); \122cs_ptr += count; \123CB_USED_DW(count); \124} while (0)125126#define OUT_CB_32F(value) \127OUT_CB(fui(value));128129#define OUT_CB_REG(register, value) do { \130assert(register); \131OUT_CB(CP_PACKET0(register, 0)); \132OUT_CB(value); \133} while (0)134135/* Note: This expects count to be the number of registers,136* not the actual packet0 count! */137#define OUT_CB_REG_SEQ(register, count) do { \138assert(register); \139OUT_CB(CP_PACKET0(register, (count) - 1)); \140} while (0)141142#define OUT_CB_ONE_REG(register, count) do { \143assert(register); \144OUT_CB(CP_PACKET0(register, (count) - 1) | RADEON_ONE_REG_WR); \145} while (0)146147#define OUT_CB_PKT3(op, count) \148OUT_CB(CP_PACKET3(op, count))149150#endif /* R300_CB_H */151152153