r300/compiler: kill off RC_WRAP_CLAMP
[mesa.git] / src / mesa / drivers / dri / r300 / compiler / radeon_code.h
1 /*
2 * Copyright 2009 Nicolai Hähnle <nhaehnle@gmail.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #ifndef RADEON_CODE_H
24 #define RADEON_CODE_H
25
26 #include <stdint.h>
27
28 #define R300_PFS_MAX_ALU_INST 64
29 #define R300_PFS_MAX_TEX_INST 32
30 #define R300_PFS_MAX_TEX_INDIRECT 4
31 #define R300_PFS_NUM_TEMP_REGS 32
32 #define R300_PFS_NUM_CONST_REGS 32
33
34 #define R500_PFS_MAX_INST 512
35 #define R500_PFS_NUM_TEMP_REGS 128
36 #define R500_PFS_NUM_CONST_REGS 256
37
38
39 #define STATE_R300_WINDOW_DIMENSION (STATE_INTERNAL_DRIVER+0)
40
41 enum {
42 /**
43 * External constants are constants whose meaning is unknown to this
44 * compiler. For example, a Mesa gl_program's constants are turned
45 * into external constants.
46 */
47 RC_CONSTANT_EXTERNAL = 0,
48
49 RC_CONSTANT_IMMEDIATE,
50
51 /**
52 * Constant referring to state that is known by this compiler,
53 * see RC_STATE_xxx, i.e. *not* arbitrary Mesa (or other) state.
54 */
55 RC_CONSTANT_STATE
56 };
57
58 enum {
59 RC_STATE_SHADOW_AMBIENT = 0,
60
61 RC_STATE_R300_WINDOW_DIMENSION,
62 RC_STATE_R300_TEXRECT_FACTOR,
63 RC_STATE_R300_VIEWPORT_SCALE,
64 RC_STATE_R300_VIEWPORT_OFFSET
65 };
66
67 struct rc_constant {
68 unsigned Type:2; /**< RC_CONSTANT_xxx */
69 unsigned Size:3;
70
71 union {
72 unsigned External;
73 float Immediate[4];
74 unsigned State[2];
75 } u;
76 };
77
78 struct rc_constant_list {
79 struct rc_constant * Constants;
80 unsigned Count;
81
82 unsigned _Reserved;
83 };
84
85 void rc_constants_init(struct rc_constant_list * c);
86 void rc_constants_copy(struct rc_constant_list * dst, struct rc_constant_list * src);
87 void rc_constants_destroy(struct rc_constant_list * c);
88 unsigned rc_constants_add(struct rc_constant_list * c, struct rc_constant * constant);
89 unsigned rc_constants_add_state(struct rc_constant_list * c, unsigned state1, unsigned state2);
90 unsigned rc_constants_add_immediate_vec4(struct rc_constant_list * c, const float * data);
91 unsigned rc_constants_add_immediate_scalar(struct rc_constant_list * c, float data, unsigned * swizzle);
92
93 /**
94 * Compare functions.
95 *
96 * \note By design, RC_COMPARE_FUNC_xxx + GL_NEVER gives you
97 * the correct GL compare function.
98 */
99 typedef enum {
100 RC_COMPARE_FUNC_NEVER = 0,
101 RC_COMPARE_FUNC_LESS,
102 RC_COMPARE_FUNC_EQUAL,
103 RC_COMPARE_FUNC_LEQUAL,
104 RC_COMPARE_FUNC_GREATER,
105 RC_COMPARE_FUNC_NOTEQUAL,
106 RC_COMPARE_FUNC_GEQUAL,
107 RC_COMPARE_FUNC_ALWAYS
108 } rc_compare_func;
109
110 /**
111 * Coordinate wrapping modes.
112 *
113 * These are not quite the same as their GL counterparts yet.
114 */
115 typedef enum {
116 RC_WRAP_NONE = 0,
117 RC_WRAP_REPEAT,
118 RC_WRAP_MIRROR
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 * If the sampler is used as a shadow sampler,
128 * this field is:
129 * 0 - GL_LUMINANCE
130 * 1 - GL_INTENSITY
131 * 2 - GL_ALPHA
132 * depending on the depth texture mode.
133 */
134 unsigned depth_texture_mode : 2;
135
136 /**
137 * If the sampler is used as a shadow sampler,
138 * this field specifies the compare function.
139 *
140 * Otherwise, this field is \ref RC_COMPARE_FUNC_NEVER (aka 0).
141 * \sa rc_compare_func
142 */
143 unsigned texture_compare_func : 3;
144
145 /**
146 * If the sampler needs to fake NPOT, this field is set.
147 */
148 unsigned fake_npot : 1;
149
150 /**
151 * If the sampler will recieve non-normalized coords,
152 * this field is set.
153 */
154 unsigned non_normalized_coords : 1;
155
156 /**
157 * This field specifies wrapping modes for the sampler.
158 *
159 * If this field is \ref RC_WRAP_NONE (aka 0), no wrapping maths
160 * will be performed on the coordinates.
161 */
162 unsigned wrap_mode : 2;
163 } unit[16];
164 };
165
166
167
168 struct r300_fragment_program_node {
169 int tex_offset; /**< first tex instruction */
170 int tex_end; /**< last tex instruction, relative to tex_offset */
171 int alu_offset; /**< first ALU instruction */
172 int alu_end; /**< last ALU instruction, relative to alu_offset */
173 int flags;
174 };
175
176 /**
177 * Stores an R300 fragment program in its compiled-to-hardware form.
178 */
179 struct r300_fragment_program_code {
180 struct {
181 int length; /**< total # of texture instructions used */
182 uint32_t inst[R300_PFS_MAX_TEX_INST];
183 } tex;
184
185 struct {
186 int length; /**< total # of ALU instructions used */
187 struct {
188 uint32_t rgb_inst;
189 uint32_t rgb_addr;
190 uint32_t alpha_inst;
191 uint32_t alpha_addr;
192 } inst[R300_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 code_addr[4]; /* US_CODE_ADDR */
199 };
200
201
202 struct r500_fragment_program_code {
203 struct {
204 uint32_t inst0;
205 uint32_t inst1;
206 uint32_t inst2;
207 uint32_t inst3;
208 uint32_t inst4;
209 uint32_t inst5;
210 } inst[R500_PFS_MAX_INST];
211
212 int inst_end; /* Number of instructions - 1; also, last instruction to be executed */
213
214 int max_temp_idx;
215
216 uint32_t us_fc_ctrl;
217 };
218
219 struct rX00_fragment_program_code {
220 union {
221 struct r300_fragment_program_code r300;
222 struct r500_fragment_program_code r500;
223 } code;
224
225 unsigned writes_depth:1;
226
227 struct rc_constant_list constants;
228 };
229
230
231 #define VSF_MAX_FRAGMENT_LENGTH (255*4)
232 #define VSF_MAX_FRAGMENT_TEMPS (14)
233
234 #define VSF_MAX_INPUTS 32
235 #define VSF_MAX_OUTPUTS 32
236
237 struct r300_vertex_program_code {
238 int length;
239 union {
240 uint32_t d[VSF_MAX_FRAGMENT_LENGTH];
241 float f[VSF_MAX_FRAGMENT_LENGTH];
242 } body;
243
244 int pos_end;
245 int num_temporaries; /* Number of temp vars used by program */
246 int inputs[VSF_MAX_INPUTS];
247 int outputs[VSF_MAX_OUTPUTS];
248
249 struct rc_constant_list constants;
250
251 uint32_t InputsRead;
252 uint32_t OutputsWritten;
253 };
254
255 void r300_vertex_program_dump(struct r300_vertex_program_code * vs);
256
257 #endif /* RADEON_CODE_H */
258