Merge branch 'mesa_7_5_branch'
[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 };
64
65 struct rc_constant {
66 unsigned Type:2; /**< RC_CONSTANT_xxx */
67 unsigned Size:3;
68
69 union {
70 unsigned External;
71 float Immediate[4];
72 unsigned State[2];
73 } u;
74 };
75
76 struct rc_constant_list {
77 struct rc_constant * Constants;
78 unsigned Count;
79
80 unsigned _Reserved;
81 };
82
83 void rc_constants_init(struct rc_constant_list * c);
84 void rc_constants_copy(struct rc_constant_list * dst, struct rc_constant_list * src);
85 void rc_constants_destroy(struct rc_constant_list * c);
86 unsigned rc_constants_add(struct rc_constant_list * c, struct rc_constant * constant);
87 unsigned rc_constants_add_state(struct rc_constant_list * c, unsigned state1, unsigned state2);
88 unsigned rc_constants_add_immediate_vec4(struct rc_constant_list * c, const float * data);
89 unsigned rc_constants_add_immediate_scalar(struct rc_constant_list * c, float data, unsigned * swizzle);
90
91 /**
92 * Stores state that influences the compilation of a fragment program.
93 */
94 struct r300_fragment_program_external_state {
95 struct {
96 /**
97 * If the sampler is used as a shadow sampler,
98 * this field is:
99 * 0 - GL_LUMINANCE
100 * 1 - GL_INTENSITY
101 * 2 - GL_ALPHA
102 * depending on the depth texture mode.
103 */
104 unsigned depth_texture_mode : 2;
105
106 /**
107 * If the sampler is used as a shadow sampler,
108 * this field is (texture_compare_func - GL_NEVER).
109 * [e.g. if compare function is GL_LEQUAL, this field is 3]
110 *
111 * Otherwise, this field is 0.
112 */
113 unsigned texture_compare_func : 3;
114 } unit[16];
115 };
116
117
118
119 struct r300_fragment_program_node {
120 int tex_offset; /**< first tex instruction */
121 int tex_end; /**< last tex instruction, relative to tex_offset */
122 int alu_offset; /**< first ALU instruction */
123 int alu_end; /**< last ALU instruction, relative to alu_offset */
124 int flags;
125 };
126
127 /**
128 * Stores an R300 fragment program in its compiled-to-hardware form.
129 */
130 struct r300_fragment_program_code {
131 struct {
132 int length; /**< total # of texture instructions used */
133 uint32_t inst[R300_PFS_MAX_TEX_INST];
134 } tex;
135
136 struct {
137 int length; /**< total # of ALU instructions used */
138 struct {
139 uint32_t inst0;
140 uint32_t inst1;
141 uint32_t inst2;
142 uint32_t inst3;
143 } inst[R300_PFS_MAX_ALU_INST];
144 } alu;
145
146 struct r300_fragment_program_node node[4];
147 int cur_node;
148 int first_node_has_tex;
149
150 int max_temp_idx;
151 };
152
153
154 struct r500_fragment_program_code {
155 struct {
156 uint32_t inst0;
157 uint32_t inst1;
158 uint32_t inst2;
159 uint32_t inst3;
160 uint32_t inst4;
161 uint32_t inst5;
162 } inst[R500_PFS_MAX_INST];
163
164 int inst_offset;
165 int inst_end;
166
167 int max_temp_idx;
168 };
169
170 struct rX00_fragment_program_code {
171 union {
172 struct r300_fragment_program_code r300;
173 struct r500_fragment_program_code r500;
174 } code;
175
176 unsigned writes_depth:1;
177
178 struct rc_constant_list constants;
179 };
180
181
182 #define VSF_MAX_FRAGMENT_LENGTH (255*4)
183 #define VSF_MAX_FRAGMENT_TEMPS (14)
184
185 #define VSF_MAX_INPUTS 32
186 #define VSF_MAX_OUTPUTS 32
187
188 struct r300_vertex_program_code {
189 int length;
190 union {
191 uint32_t d[VSF_MAX_FRAGMENT_LENGTH];
192 float f[VSF_MAX_FRAGMENT_LENGTH];
193 } body;
194
195 int pos_end;
196 int num_temporaries; /* Number of temp vars used by program */
197 int inputs[VSF_MAX_INPUTS];
198 int outputs[VSF_MAX_OUTPUTS];
199
200 struct rc_constant_list constants;
201
202 uint32_t InputsRead;
203 uint32_t OutputsWritten;
204 };
205
206 void r300_vertex_program_dump(struct r300_vertex_program_code * vs);
207
208 #endif /* RADEON_CODE_H */