r300/fragprog: Move wpos_attr and fog_attr where they belong
[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 #define R300_PFS_MAX_ALU_INST 64
27 #define R300_PFS_MAX_TEX_INST 32
28 #define R300_PFS_MAX_TEX_INDIRECT 4
29 #define R300_PFS_NUM_TEMP_REGS 32
30 #define R300_PFS_NUM_CONST_REGS 32
31
32 #define R500_PFS_MAX_INST 512
33 #define R500_PFS_NUM_TEMP_REGS 128
34 #define R500_PFS_NUM_CONST_REGS 256
35
36
37 #define STATE_R300_WINDOW_DIMENSION (STATE_INTERNAL_DRIVER+0)
38
39 enum {
40 /**
41 * External constants are constants whose meaning is unknown to this
42 * compiler. For example, a Mesa gl_program's constants are turned
43 * into external constants.
44 */
45 RC_CONSTANT_EXTERNAL = 0,
46
47 RC_CONSTANT_IMMEDIATE,
48
49 /**
50 * Constant referring to state that is known by this compiler,
51 * see RC_STATE_xxx, i.e. *not* arbitrary Mesa (or other) state.
52 */
53 RC_CONSTANT_STATE
54 };
55
56 enum {
57 RC_STATE_SHADOW_AMBIENT = 0,
58
59 RC_STATE_R300_WINDOW_DIMENSION,
60 RC_STATE_R300_TEXRECT_FACTOR
61 };
62
63 struct rc_constant {
64 unsigned Type:2; /**< RC_CONSTANT_xxx */
65 unsigned Size:3;
66
67 union {
68 unsigned External;
69 float Immediate[4];
70 unsigned State[2];
71 } u;
72 };
73
74 struct rc_constant_list {
75 struct rc_constant * Constants;
76 unsigned Count;
77
78 unsigned _Reserved;
79 };
80
81 void rc_constants_init(struct rc_constant_list * c);
82 void rc_constants_copy(struct rc_constant_list * dst, struct rc_constant_list * src);
83 void rc_constants_destroy(struct rc_constant_list * c);
84 unsigned rc_constants_add(struct rc_constant_list * c, struct rc_constant * constant);
85 unsigned rc_constants_add_state(struct rc_constant_list * c, unsigned state1, unsigned state2);
86 unsigned rc_constants_add_immediate_vec4(struct rc_constant_list * c, const float * data);
87 unsigned rc_constants_add_immediate_scalar(struct rc_constant_list * c, float data, unsigned * swizzle);
88
89 /**
90 * Stores state that influences the compilation of a fragment program.
91 */
92 struct r300_fragment_program_external_state {
93 struct {
94 /**
95 * If the sampler is used as a shadow sampler,
96 * this field is:
97 * 0 - GL_LUMINANCE
98 * 1 - GL_INTENSITY
99 * 2 - GL_ALPHA
100 * depending on the depth texture mode.
101 */
102 GLuint depth_texture_mode : 2;
103
104 /**
105 * If the sampler is used as a shadow sampler,
106 * this field is (texture_compare_func - GL_NEVER).
107 * [e.g. if compare function is GL_LEQUAL, this field is 3]
108 *
109 * Otherwise, this field is 0.
110 */
111 GLuint texture_compare_func : 3;
112 } unit[16];
113 };
114
115
116
117 struct r300_fragment_program_node {
118 int tex_offset; /**< first tex instruction */
119 int tex_end; /**< last tex instruction, relative to tex_offset */
120 int alu_offset; /**< first ALU instruction */
121 int alu_end; /**< last ALU instruction, relative to alu_offset */
122 int flags;
123 };
124
125 /**
126 * Stores an R300 fragment program in its compiled-to-hardware form.
127 */
128 struct r300_fragment_program_code {
129 struct {
130 int length; /**< total # of texture instructions used */
131 GLuint inst[R300_PFS_MAX_TEX_INST];
132 } tex;
133
134 struct {
135 int length; /**< total # of ALU instructions used */
136 struct {
137 GLuint inst0;
138 GLuint inst1;
139 GLuint inst2;
140 GLuint inst3;
141 } inst[R300_PFS_MAX_ALU_INST];
142 } alu;
143
144 struct r300_fragment_program_node node[4];
145 int cur_node;
146 int first_node_has_tex;
147
148 int max_temp_idx;
149 };
150
151
152 struct r500_fragment_program_code {
153 struct {
154 GLuint inst0;
155 GLuint inst1;
156 GLuint inst2;
157 GLuint inst3;
158 GLuint inst4;
159 GLuint inst5;
160 } inst[R500_PFS_MAX_INST];
161
162 int inst_offset;
163 int inst_end;
164
165 int max_temp_idx;
166 };
167
168 struct rX00_fragment_program_code {
169 union {
170 struct r300_fragment_program_code r300;
171 struct r500_fragment_program_code r500;
172 } code;
173
174 GLboolean writes_depth;
175
176 struct rc_constant_list constants;
177 };
178
179
180 #define VSF_MAX_FRAGMENT_LENGTH (255*4)
181 #define VSF_MAX_FRAGMENT_TEMPS (14)
182
183 struct r300_vertex_program_code {
184 int length;
185 union {
186 GLuint d[VSF_MAX_FRAGMENT_LENGTH];
187 float f[VSF_MAX_FRAGMENT_LENGTH];
188 } body;
189
190 int pos_end;
191 int num_temporaries; /* Number of temp vars used by program */
192 int inputs[VERT_ATTRIB_MAX];
193 int outputs[VERT_RESULT_MAX];
194
195 struct rc_constant_list constants;
196
197 GLbitfield InputsRead;
198 GLbitfield OutputsWritten;
199 };
200
201 #endif /* RADEON_CODE_H */