xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/r300/r300_cs.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2008 Corbin Simpson <[email protected]>
3  * SPDX-License-Identifier: MIT
4  */
5 
6 /**
7  * This file contains macros for immediate command submission.
8  */
9 
10 #ifndef R300_CS_H
11 #define R300_CS_H
12 
13 #include "r300_reg.h"
14 #include "r300_context.h"
15 
16 /* Yes, I know macros are ugly. However, they are much prettier than the code
17  * that they neatly hide away, and don't have the cost of function setup,so
18  * we're going to use them. */
19 
20 /**
21  * Command submission setup.
22  */
23 
24 #define CS_LOCALS(context) \
25     struct radeon_cmdbuf *cs_copy = &(context)->cs; \
26     struct radeon_winsys *cs_winsys = (context)->rws; \
27     int cs_count = 0; (void) cs_count; (void) cs_winsys;
28 
29 #if MESA_DEBUG
30 
31 #define BEGIN_CS(size) do { \
32     assert(size <= (cs_copy->current.max_dw - cs_copy->current.cdw)); \
33     cs_count = size; \
34 } while (0)
35 
36 #define END_CS do { \
37     if (cs_count != 0) \
38         debug_printf("r300: Warning: cs_count off by %d at (%s, %s:%i)\n", \
39                      cs_count, __func__, __FILE__, __LINE__); \
40     cs_count = 0; \
41 } while (0)
42 
43 #define CS_USED_DW(x) cs_count -= (x)
44 
45 #else
46 
47 #define BEGIN_CS(size)
48 #define END_CS
49 #define CS_USED_DW(x)
50 
51 #endif
52 
53 /**
54  * Writing pure DWORDs.
55  */
56 
57 #define OUT_CS(value) do { \
58     cs_copy->current.buf[cs_copy->current.cdw++] = (value); \
59     CS_USED_DW(1); \
60 } while (0)
61 
62 #define OUT_CS_32F(value) \
63     OUT_CS(fui(value))
64 
65 #define OUT_CS_REG(register, value) do { \
66     OUT_CS(CP_PACKET0(register, 0)); \
67     OUT_CS(value); \
68 } while (0)
69 
70 /* Note: This expects count to be the number of registers,
71  * not the actual packet0 count! */
72 #define OUT_CS_REG_SEQ(register, count) \
73     OUT_CS(CP_PACKET0((register), ((count) - 1)))
74 
75 #define OUT_CS_ONE_REG(register, count) \
76     OUT_CS(CP_PACKET0((register), ((count) - 1)) | RADEON_ONE_REG_WR)
77 
78 #define OUT_CS_PKT3(op, count) \
79     OUT_CS(CP_PACKET3(op, count))
80 
81 #define OUT_CS_TABLE(values, count) do { \
82     memcpy(cs_copy->current.buf + cs_copy->current.cdw, (values), (count) * 4); \
83     cs_copy->current.cdw += (count); \
84     CS_USED_DW(count); \
85 } while (0)
86 
87 
88 /**
89  * Writing buffers.
90  */
91 
92 #define OUT_CS_RELOC(r) do { \
93     assert((r)); \
94     assert((r)->buf); \
95     OUT_CS(0xc0001000); /* PKT3_NOP */ \
96     OUT_CS(cs_winsys->cs_lookup_buffer(cs_copy, (r)->buf) * 4); \
97 } while (0)
98 
99 
100 /**
101  * Command buffer emission.
102  */
103 
104 #define WRITE_CS_TABLE(values, count) do { \
105     assert(cs_count == 0); \
106     memcpy(cs_copy->current.buf + cs_copy->current.cdw, (values), (count) * 4); \
107     cs_copy->current.cdw += (count); \
108 } while (0)
109 
110 #endif /* R300_CS_H */
111