• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    int sampler_state_count;
165 };
166 
167 struct r300_fragment_program_node {
168    int tex_offset; /**< first tex instruction */
169    int tex_end;    /**< last tex instruction, relative to tex_offset */
170    int alu_offset; /**< first ALU instruction */
171    int alu_end;    /**< last ALU instruction, relative to alu_offset */
172    int flags;
173 };
174 
175 /**
176  * Stores an R300 fragment program in its compiled-to-hardware form.
177  */
178 struct r300_fragment_program_code {
179    struct {
180       unsigned int length; /**< total # of texture instructions used */
181       uint32_t inst[R400_PFS_MAX_TEX_INST];
182    } tex;
183 
184    struct {
185       unsigned int length; /**< total # of ALU instructions used */
186       struct {
187          uint32_t rgb_inst;
188          uint32_t rgb_addr;
189          uint32_t alpha_inst;
190          uint32_t alpha_addr;
191          uint32_t r400_ext_addr;
192       } inst[R400_PFS_MAX_ALU_INST];
193    } alu;
194 
195    uint32_t config;               /* US_CONFIG */
196    uint32_t pixsize;              /* US_PIXSIZE */
197    uint32_t code_offset;          /* US_CODE_OFFSET */
198    uint32_t r400_code_offset_ext; /* US_CODE_EXT */
199    uint32_t code_addr[4];         /* US_CODE_ADDR */
200    /*US_CODE_BANK.R390_MODE: Enables 512 instructions and 64 temporaries
201     * for r400 cards */
202    unsigned int r390_mode : 1;
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 #define R300_VS_MAX_ALU        256
238 #define R300_VS_MAX_ALU_DWORDS (R300_VS_MAX_ALU * 4)
239 #define R500_VS_MAX_ALU        1024
240 #define R500_VS_MAX_ALU_DWORDS (R500_VS_MAX_ALU * 4)
241 #define R300_VS_MAX_TEMPS      32
242 /* This is the max for all chipsets (r300-r500) */
243 #define R300_VS_MAX_FC_OPS     16
244 #define R300_VS_MAX_LOOP_DEPTH 1
245 
246 #define VSF_MAX_INPUTS  32
247 #define VSF_MAX_OUTPUTS 32
248 
249 struct r300_vertex_program_code {
250    int length;
251    union {
252       uint32_t d[R500_VS_MAX_ALU_DWORDS];
253       float f[R500_VS_MAX_ALU_DWORDS];
254    } body;
255 
256    int pos_end;
257    int num_temporaries; /* Number of temp vars used by program */
258    int inputs[VSF_MAX_INPUTS];
259    int outputs[VSF_MAX_OUTPUTS];
260    unsigned last_input_read;
261    unsigned last_pos_write;
262 
263    struct rc_constant_list constants;
264    struct const_remap *constants_remap_table;
265 
266    uint32_t InputsRead;
267    uint32_t OutputsWritten;
268 
269    unsigned int num_fc_ops;
270    uint32_t fc_ops;
271    union {
272       uint32_t r300[R300_VS_MAX_FC_OPS];
273       struct {
274          uint32_t lw;
275          uint32_t uw;
276       } r500[R300_VS_MAX_FC_OPS];
277    } fc_op_addrs;
278    int32_t fc_loop_index[R300_VS_MAX_FC_OPS];
279 };
280 
281 #endif /* RADEON_CODE_H */
282