xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/r300/compiler/radeon_code.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2009 Nicolai Hähnle <[email protected]>
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #ifndef RADEON_CODE_H
7 #define RADEON_CODE_H
8 
9 #include <stdint.h>
10 
11 #define R300_PFS_MAX_ALU_INST     64
12 #define R300_PFS_MAX_TEX_INST     32
13 #define R300_PFS_MAX_TEX_INDIRECT 4
14 #define R300_PFS_NUM_TEMP_REGS    32
15 #define R300_PFS_NUM_CONST_REGS   32
16 
17 #define R400_PFS_MAX_ALU_INST     512
18 #define R400_PFS_MAX_TEX_INST     512
19 
20 #define R500_PFS_MAX_INST         512
21 #define R500_PFS_NUM_TEMP_REGS    128
22 #define R500_PFS_NUM_CONST_REGS   256
23 #define R500_PFS_MAX_BRANCH_DEPTH_FULL 32
24 #define R500_PFS_MAX_BRANCH_DEPTH_PARTIAL 4
25 
26 /* The r500 maximum depth is not just for loops, but any combination of loops
27  * and subroutine jumps. */
28 #define R500_PVS_MAX_LOOP_DEPTH 8
29 
30 #define STATE_R300_WINDOW_DIMENSION (STATE_INTERNAL_DRIVER+0)
31 
32 enum {
33 	/**
34 	 * External constants are constants whose meaning is unknown to this
35 	 * compiler. For example, a Mesa gl_program's constants are turned
36 	 * into external constants.
37 	 */
38 	RC_CONSTANT_EXTERNAL = 0,
39 
40 	RC_CONSTANT_IMMEDIATE,
41 
42 	/**
43 	 * Constant referring to state that is known by this compiler,
44 	 * see RC_STATE_xxx, i.e. *not* arbitrary Mesa (or other) state.
45 	 */
46 	RC_CONSTANT_STATE
47 };
48 
49 enum {
50 	RC_STATE_SHADOW_AMBIENT = 0,
51 
52 	RC_STATE_R300_WINDOW_DIMENSION,
53 	RC_STATE_R300_TEXRECT_FACTOR,
54 	RC_STATE_R300_TEXSCALE_FACTOR,
55 	RC_STATE_R300_VIEWPORT_SCALE,
56 	RC_STATE_R300_VIEWPORT_OFFSET
57 };
58 
59 struct rc_constant {
60 	unsigned Type:2; /**< RC_CONSTANT_xxx */
61 	unsigned UseMask:4;
62 
63 	union {
64 		unsigned External;
65 		float Immediate[4];
66 		unsigned State[2];
67 	} u;
68 };
69 
70 struct rc_constant_list {
71 	struct rc_constant * Constants;
72 	unsigned Count;
73 
74 	unsigned _Reserved;
75 };
76 
77 struct const_remap {
78         int index[4];
79         uint8_t swizzle[4];
80 };
81 
82 void rc_constants_init(struct rc_constant_list * c);
83 void rc_constants_copy(struct rc_constant_list * dst, struct rc_constant_list * src);
84 void rc_constants_destroy(struct rc_constant_list * c);
85 unsigned rc_constants_add(struct rc_constant_list * c, struct rc_constant * constant);
86 unsigned rc_constants_add_state(struct rc_constant_list * c, unsigned state1, unsigned state2);
87 unsigned rc_constants_add_immediate_vec4(struct rc_constant_list * c, const float * data);
88 unsigned rc_constants_add_immediate_scalar(struct rc_constant_list * c, float data, unsigned * swizzle);
89 void rc_constants_print(struct rc_constant_list *c, struct const_remap *r);
90 
91 /**
92  * Compare functions.
93  *
94  * \note By design, RC_COMPARE_FUNC_xxx + GL_NEVER gives you
95  * the correct GL compare function.
96  */
97 typedef enum {
98 	RC_COMPARE_FUNC_NEVER = 0,
99 	RC_COMPARE_FUNC_LESS,
100 	RC_COMPARE_FUNC_EQUAL,
101 	RC_COMPARE_FUNC_LEQUAL,
102 	RC_COMPARE_FUNC_GREATER,
103 	RC_COMPARE_FUNC_NOTEQUAL,
104 	RC_COMPARE_FUNC_GEQUAL,
105 	RC_COMPARE_FUNC_ALWAYS
106 } rc_compare_func;
107 
108 /**
109  * Coordinate wrapping modes.
110  *
111  * These are not quite the same as their GL counterparts yet.
112  */
113 typedef enum {
114 	RC_WRAP_NONE = 0,
115 	RC_WRAP_REPEAT,
116 	RC_WRAP_MIRRORED_REPEAT,
117 	RC_WRAP_MIRRORED_CLAMP
118 } rc_wrap_mode;
119 
120 /**
121  * Stores state that influences the compilation of a fragment program.
122  */
123 struct r300_fragment_program_external_state {
124 	struct {
125 		/**
126 		 * This field contains swizzle for some lowering passes
127 		 * (shadow comparison, unorm->snorm conversion)
128 		 */
129 		unsigned texture_swizzle:12;
130 
131 		/**
132 		 * If the sampler is used as a shadow sampler,
133 		 * this field specifies the compare function.
134 		 *
135 		 * Otherwise, this field is \ref RC_COMPARE_FUNC_NEVER (aka 0).
136 		 * \sa rc_compare_func
137 		 */
138 		unsigned texture_compare_func : 3;
139 
140 		/**
141 		 * No matter what the sampler type is,
142 		 * this field turns it into a shadow sampler.
143 		 */
144 		unsigned compare_mode_enabled : 1;
145 
146 		/**
147 		 * This field specifies wrapping modes for the sampler.
148 		 *
149 		 * If this field is \ref RC_WRAP_NONE (aka 0), no wrapping maths
150 		 * will be performed on the coordinates.
151 		 */
152 		unsigned wrap_mode : 3;
153 
154 		/**
155 		 * The coords are scaled after applying the wrap mode emulation
156 		 * and right before texture fetch. The scaling factor is given by
157 		 * RC_STATE_R300_TEXSCALE_FACTOR. */
158 		unsigned clamp_and_scale_before_fetch : 1;
159 	} unit[16];
160 
161 	unsigned alpha_to_one:1;
162 };
163 
164 
165 
166 struct r300_fragment_program_node {
167 	int tex_offset; /**< first tex instruction */
168 	int tex_end; /**< last tex instruction, relative to tex_offset */
169 	int alu_offset; /**< first ALU instruction */
170 	int alu_end; /**< last ALU instruction, relative to alu_offset */
171 	int flags;
172 };
173 
174 /**
175  * Stores an R300 fragment program in its compiled-to-hardware form.
176  */
177 struct r300_fragment_program_code {
178 	struct {
179 		unsigned int length; /**< total # of texture instructions used */
180 		uint32_t inst[R400_PFS_MAX_TEX_INST];
181 	} tex;
182 
183 	struct {
184 		unsigned int length; /**< total # of ALU instructions used */
185 		struct {
186 			uint32_t rgb_inst;
187 			uint32_t rgb_addr;
188 			uint32_t alpha_inst;
189 			uint32_t alpha_addr;
190 			uint32_t r400_ext_addr;
191 		} inst[R400_PFS_MAX_ALU_INST];
192 	} alu;
193 
194 	uint32_t config; /* US_CONFIG */
195 	uint32_t pixsize; /* US_PIXSIZE */
196 	uint32_t code_offset; /* US_CODE_OFFSET */
197 	uint32_t r400_code_offset_ext; /* US_CODE_EXT */
198 	uint32_t code_addr[4]; /* US_CODE_ADDR */
199 	/*US_CODE_BANK.R390_MODE: Enables 512 instructions and 64 temporaries
200 	 * for r400 cards */
201 	unsigned int r390_mode:1;
202 };
203 
204 
205 struct r500_fragment_program_code {
206 	struct {
207 		uint32_t inst0;
208 		uint32_t inst1;
209 		uint32_t inst2;
210 		uint32_t inst3;
211 		uint32_t inst4;
212 		uint32_t inst5;
213 	} inst[R500_PFS_MAX_INST];
214 
215 	int inst_end; /* Number of instructions - 1; also, last instruction to be executed */
216 
217 	int max_temp_idx;
218 
219 	uint32_t us_fc_ctrl;
220 
221 	uint32_t int_constants[32];
222 	uint32_t int_constant_count;
223 };
224 
225 struct rX00_fragment_program_code {
226 	union {
227 		struct r300_fragment_program_code r300;
228 		struct r500_fragment_program_code r500;
229 	} code;
230 
231 	unsigned writes_depth:1;
232 
233 	struct rc_constant_list constants;
234 	struct const_remap *constants_remap_table;
235 };
236 
237 
238 #define R300_VS_MAX_ALU		256
239 #define R300_VS_MAX_ALU_DWORDS  (R300_VS_MAX_ALU * 4)
240 #define R500_VS_MAX_ALU	        1024
241 #define R500_VS_MAX_ALU_DWORDS  (R500_VS_MAX_ALU * 4)
242 #define R300_VS_MAX_TEMPS	32
243 /* This is the max for all chipsets (r300-r500) */
244 #define R300_VS_MAX_FC_OPS 16
245 #define R300_VS_MAX_LOOP_DEPTH 1
246 
247 #define VSF_MAX_INPUTS 32
248 #define VSF_MAX_OUTPUTS 32
249 
250 struct r300_vertex_program_code {
251 	int length;
252 	union {
253 		uint32_t d[R500_VS_MAX_ALU_DWORDS];
254 		float f[R500_VS_MAX_ALU_DWORDS];
255 	} body;
256 
257 	int pos_end;
258 	int num_temporaries;	/* Number of temp vars used by program */
259 	int inputs[VSF_MAX_INPUTS];
260 	int outputs[VSF_MAX_OUTPUTS];
261 	unsigned last_input_read;
262 	unsigned last_pos_write;
263 
264 	struct rc_constant_list constants;
265 	struct const_remap *constants_remap_table;
266 
267 	uint32_t InputsRead;
268 	uint32_t OutputsWritten;
269 
270 	unsigned int num_fc_ops;
271 	uint32_t fc_ops;
272 	union {
273 	        uint32_t r300[R300_VS_MAX_FC_OPS];
274 		struct {
275 			uint32_t lw;
276 			uint32_t uw;
277 		} r500[R300_VS_MAX_FC_OPS];
278 	} fc_op_addrs;
279 	int32_t fc_loop_index[R300_VS_MAX_FC_OPS];
280 };
281 
282 #endif /* RADEON_CODE_H */
283 
284