2 * Copyright 2009 Nicolai Hähnle <nhaehnle@gmail.com>
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:
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
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. */
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
34 #define R400_PFS_MAX_ALU_INST 512
35 #define R400_PFS_MAX_TEX_INST 512
37 #define R500_PFS_MAX_INST 512
38 #define R500_PFS_NUM_TEMP_REGS 128
39 #define R500_PFS_NUM_CONST_REGS 256
40 #define R500_PFS_MAX_BRANCH_DEPTH_FULL 32
41 #define R500_PFS_MAX_BRANCH_DEPTH_PARTIAL 4
43 /* The r500 maximum depth is not just for loops, but any combination of loops
44 * and subroutine jumps. */
45 #define R500_PVS_MAX_LOOP_DEPTH 8
47 #define STATE_R300_WINDOW_DIMENSION (STATE_INTERNAL_DRIVER+0)
51 * External constants are constants whose meaning is unknown to this
52 * compiler. For example, a Mesa gl_program's constants are turned
53 * into external constants.
55 RC_CONSTANT_EXTERNAL
= 0,
57 RC_CONSTANT_IMMEDIATE
,
60 * Constant referring to state that is known by this compiler,
61 * see RC_STATE_xxx, i.e. *not* arbitrary Mesa (or other) state.
67 RC_STATE_SHADOW_AMBIENT
= 0,
69 RC_STATE_R300_WINDOW_DIMENSION
,
70 RC_STATE_R300_TEXRECT_FACTOR
,
71 RC_STATE_R300_TEXSCALE_FACTOR
,
72 RC_STATE_R300_VIEWPORT_SCALE
,
73 RC_STATE_R300_VIEWPORT_OFFSET
77 unsigned Type
:2; /**< RC_CONSTANT_xxx */
87 struct rc_constant_list
{
88 struct rc_constant
* Constants
;
94 void rc_constants_init(struct rc_constant_list
* c
);
95 void rc_constants_copy(struct rc_constant_list
* dst
, struct rc_constant_list
* src
);
96 void rc_constants_destroy(struct rc_constant_list
* c
);
97 unsigned rc_constants_add(struct rc_constant_list
* c
, struct rc_constant
* constant
);
98 unsigned rc_constants_add_state(struct rc_constant_list
* c
, unsigned state1
, unsigned state2
);
99 unsigned rc_constants_add_immediate_vec4(struct rc_constant_list
* c
, const float * data
);
100 unsigned rc_constants_add_immediate_scalar(struct rc_constant_list
* c
, float data
, unsigned * swizzle
);
101 void rc_constants_print(struct rc_constant_list
* c
);
106 * \note By design, RC_COMPARE_FUNC_xxx + GL_NEVER gives you
107 * the correct GL compare function.
110 RC_COMPARE_FUNC_NEVER
= 0,
111 RC_COMPARE_FUNC_LESS
,
112 RC_COMPARE_FUNC_EQUAL
,
113 RC_COMPARE_FUNC_LEQUAL
,
114 RC_COMPARE_FUNC_GREATER
,
115 RC_COMPARE_FUNC_NOTEQUAL
,
116 RC_COMPARE_FUNC_GEQUAL
,
117 RC_COMPARE_FUNC_ALWAYS
121 * Coordinate wrapping modes.
123 * These are not quite the same as their GL counterparts yet.
128 RC_WRAP_MIRRORED_REPEAT
,
129 RC_WRAP_MIRRORED_CLAMP
133 * Stores state that influences the compilation of a fragment program.
135 struct r300_fragment_program_external_state
{
138 * This field contains swizzle for some lowering passes
139 * (shadow comparison, unorm->snorm conversion)
141 unsigned texture_swizzle
:12;
144 * If the sampler is used as a shadow sampler,
145 * this field specifies the compare function.
147 * Otherwise, this field is \ref RC_COMPARE_FUNC_NEVER (aka 0).
148 * \sa rc_compare_func
150 unsigned texture_compare_func
: 3;
153 * No matter what the sampler type is,
154 * this field turns it into a shadow sampler.
156 unsigned compare_mode_enabled
: 1;
159 * If the sampler will receive non-normalized coords,
160 * this field is set. The scaling factor is given by
161 * RC_STATE_R300_TEXRECT_FACTOR.
163 unsigned non_normalized_coords
: 1;
166 * This field specifies wrapping modes for the sampler.
168 * If this field is \ref RC_WRAP_NONE (aka 0), no wrapping maths
169 * will be performed on the coordinates.
171 unsigned wrap_mode
: 3;
174 * The coords are scaled after applying the wrap mode emulation
175 * and right before texture fetch. The scaling factor is given by
176 * RC_STATE_R300_TEXSCALE_FACTOR. */
177 unsigned clamp_and_scale_before_fetch
: 1;
180 unsigned alpha_to_one
:1;
185 struct r300_fragment_program_node
{
186 int tex_offset
; /**< first tex instruction */
187 int tex_end
; /**< last tex instruction, relative to tex_offset */
188 int alu_offset
; /**< first ALU instruction */
189 int alu_end
; /**< last ALU instruction, relative to alu_offset */
194 * Stores an R300 fragment program in its compiled-to-hardware form.
196 struct r300_fragment_program_code
{
198 unsigned int length
; /**< total # of texture instructions used */
199 uint32_t inst
[R400_PFS_MAX_TEX_INST
];
203 unsigned int length
; /**< total # of ALU instructions used */
209 uint32_t r400_ext_addr
;
210 } inst
[R400_PFS_MAX_ALU_INST
];
213 uint32_t config
; /* US_CONFIG */
214 uint32_t pixsize
; /* US_PIXSIZE */
215 uint32_t code_offset
; /* US_CODE_OFFSET */
216 uint32_t r400_code_offset_ext
; /* US_CODE_EXT */
217 uint32_t code_addr
[4]; /* US_CODE_ADDR */
218 /*US_CODE_BANK.R390_MODE: Enables 512 instructions and 64 temporaries
220 unsigned int r390_mode
:1;
224 struct r500_fragment_program_code
{
232 } inst
[R500_PFS_MAX_INST
];
234 int inst_end
; /* Number of instructions - 1; also, last instruction to be executed */
240 uint32_t int_constants
[32];
241 uint32_t int_constant_count
;
244 struct rX00_fragment_program_code
{
246 struct r300_fragment_program_code r300
;
247 struct r500_fragment_program_code r500
;
250 unsigned writes_depth
:1;
252 struct rc_constant_list constants
;
253 unsigned *constants_remap_table
;
257 #define R300_VS_MAX_ALU 256
258 #define R300_VS_MAX_ALU_DWORDS (R300_VS_MAX_ALU * 4)
259 #define R500_VS_MAX_ALU 1024
260 #define R500_VS_MAX_ALU_DWORDS (R500_VS_MAX_ALU * 4)
261 #define R300_VS_MAX_TEMPS 32
262 /* This is the max for all chipsets (r300-r500) */
263 #define R300_VS_MAX_FC_OPS 16
264 #define R300_VS_MAX_LOOP_DEPTH 1
266 #define VSF_MAX_INPUTS 32
267 #define VSF_MAX_OUTPUTS 32
269 struct r300_vertex_program_code
{
272 uint32_t d
[R500_VS_MAX_ALU_DWORDS
];
273 float f
[R500_VS_MAX_ALU_DWORDS
];
277 int num_temporaries
; /* Number of temp vars used by program */
278 int inputs
[VSF_MAX_INPUTS
];
279 int outputs
[VSF_MAX_OUTPUTS
];
281 struct rc_constant_list constants
;
282 unsigned *constants_remap_table
;
285 uint32_t OutputsWritten
;
287 unsigned int num_fc_ops
;
290 uint32_t r300
[R300_VS_MAX_FC_OPS
];
294 } r500
[R300_VS_MAX_FC_OPS
];
296 int32_t fc_loop_index
[R300_VS_MAX_FC_OPS
];
299 #endif /* RADEON_CODE_H */