1 /* 2 * Copyright 2009 Nicolai Hähnle <nhaehnle@gmail.com> 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, 89 unsigned *swizzle); 90 void rc_constants_print(struct rc_constant_list *c, struct const_remap *r); 91 92 /** 93 * Compare functions. 94 * 95 * \note By design, RC_COMPARE_FUNC_xxx + GL_NEVER gives you 96 * the correct GL compare function. 97 */ 98 typedef enum { 99 RC_COMPARE_FUNC_NEVER = 0, 100 RC_COMPARE_FUNC_LESS, 101 RC_COMPARE_FUNC_EQUAL, 102 RC_COMPARE_FUNC_LEQUAL, 103 RC_COMPARE_FUNC_GREATER, 104 RC_COMPARE_FUNC_NOTEQUAL, 105 RC_COMPARE_FUNC_GEQUAL, 106 RC_COMPARE_FUNC_ALWAYS 107 } rc_compare_func; 108 109 /** 110 * Coordinate wrapping modes. 111 * 112 * These are not quite the same as their GL counterparts yet. 113 */ 114 typedef enum { 115 RC_WRAP_NONE = 0, 116 RC_WRAP_REPEAT, 117 RC_WRAP_MIRRORED_REPEAT, 118 RC_WRAP_MIRRORED_CLAMP 119 } rc_wrap_mode; 120 121 /** 122 * Stores state that influences the compilation of a fragment program. 123 */ 124 struct r300_fragment_program_external_state { 125 struct { 126 /** 127 * This field contains swizzle for some lowering passes 128 * (shadow comparison, unorm->snorm conversion) 129 */ 130 unsigned texture_swizzle : 12; 131 132 /** 133 * If the sampler is used as a shadow sampler, 134 * this field specifies the compare function. 135 * 136 * Otherwise, this field is \ref RC_COMPARE_FUNC_NEVER (aka 0). 137 * \sa rc_compare_func 138 */ 139 unsigned texture_compare_func : 3; 140 141 /** 142 * No matter what the sampler type is, 143 * this field turns it into a shadow sampler. 144 */ 145 unsigned compare_mode_enabled : 1; 146 147 /** 148 * This field specifies wrapping modes for the sampler. 149 * 150 * If this field is \ref RC_WRAP_NONE (aka 0), no wrapping maths 151 * will be performed on the coordinates. 152 */ 153 unsigned wrap_mode : 3; 154 155 /** 156 * The coords are scaled after applying the wrap mode emulation 157 * and right before texture fetch. The scaling factor is given by 158 * RC_STATE_R300_TEXSCALE_FACTOR. */ 159 unsigned clamp_and_scale_before_fetch : 1; 160 } unit[16]; 161 162 unsigned alpha_to_one : 1; 163 }; 164 165 struct r300_fragment_program_node { 166 int tex_offset; /**< first tex instruction */ 167 int tex_end; /**< last tex instruction, relative to tex_offset */ 168 int alu_offset; /**< first ALU instruction */ 169 int alu_end; /**< last ALU instruction, relative to alu_offset */ 170 int flags; 171 }; 172 173 /** 174 * Stores an R300 fragment program in its compiled-to-hardware form. 175 */ 176 struct r300_fragment_program_code { 177 struct { 178 unsigned int length; /**< total # of texture instructions used */ 179 uint32_t inst[R400_PFS_MAX_TEX_INST]; 180 } tex; 181 182 struct { 183 unsigned int length; /**< total # of ALU instructions used */ 184 struct { 185 uint32_t rgb_inst; 186 uint32_t rgb_addr; 187 uint32_t alpha_inst; 188 uint32_t alpha_addr; 189 uint32_t r400_ext_addr; 190 } inst[R400_PFS_MAX_ALU_INST]; 191 } alu; 192 193 uint32_t config; /* US_CONFIG */ 194 uint32_t pixsize; /* US_PIXSIZE */ 195 uint32_t code_offset; /* US_CODE_OFFSET */ 196 uint32_t r400_code_offset_ext; /* US_CODE_EXT */ 197 uint32_t code_addr[4]; /* US_CODE_ADDR */ 198 /*US_CODE_BANK.R390_MODE: Enables 512 instructions and 64 temporaries 199 * for r400 cards */ 200 unsigned int r390_mode : 1; 201 }; 202 203 struct r500_fragment_program_code { 204 struct { 205 uint32_t inst0; 206 uint32_t inst1; 207 uint32_t inst2; 208 uint32_t inst3; 209 uint32_t inst4; 210 uint32_t inst5; 211 } inst[R500_PFS_MAX_INST]; 212 213 int inst_end; /* Number of instructions - 1; also, last instruction to be executed */ 214 215 int max_temp_idx; 216 217 uint32_t us_fc_ctrl; 218 219 uint32_t int_constants[32]; 220 uint32_t int_constant_count; 221 }; 222 223 struct rX00_fragment_program_code { 224 union { 225 struct r300_fragment_program_code r300; 226 struct r500_fragment_program_code r500; 227 } code; 228 229 unsigned writes_depth : 1; 230 231 struct rc_constant_list constants; 232 struct const_remap *constants_remap_table; 233 }; 234 235 #define R300_VS_MAX_ALU 256 236 #define R300_VS_MAX_ALU_DWORDS (R300_VS_MAX_ALU * 4) 237 #define R500_VS_MAX_ALU 1024 238 #define R500_VS_MAX_ALU_DWORDS (R500_VS_MAX_ALU * 4) 239 #define R300_VS_MAX_TEMPS 32 240 /* This is the max for all chipsets (r300-r500) */ 241 #define R300_VS_MAX_FC_OPS 16 242 #define R300_VS_MAX_LOOP_DEPTH 1 243 244 #define VSF_MAX_INPUTS 32 245 #define VSF_MAX_OUTPUTS 32 246 247 struct r300_vertex_program_code { 248 int length; 249 union { 250 uint32_t d[R500_VS_MAX_ALU_DWORDS]; 251 float f[R500_VS_MAX_ALU_DWORDS]; 252 } body; 253 254 int pos_end; 255 int num_temporaries; /* Number of temp vars used by program */ 256 int inputs[VSF_MAX_INPUTS]; 257 int outputs[VSF_MAX_OUTPUTS]; 258 unsigned last_input_read; 259 unsigned last_pos_write; 260 261 struct rc_constant_list constants; 262 struct const_remap *constants_remap_table; 263 264 uint32_t InputsRead; 265 uint32_t OutputsWritten; 266 267 unsigned int num_fc_ops; 268 uint32_t fc_ops; 269 union { 270 uint32_t r300[R300_VS_MAX_FC_OPS]; 271 struct { 272 uint32_t lw; 273 uint32_t uw; 274 } r500[R300_VS_MAX_FC_OPS]; 275 } fc_op_addrs; 276 int32_t fc_loop_index[R300_VS_MAX_FC_OPS]; 277 }; 278 279 #endif /* RADEON_CODE_H */ 280