Merge remote branch 'origin/master' into nv50-compiler
[mesa.git] / src / mesa / drivers / dri / r300 / compiler / radeon_compiler.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_COMPILER_H
24 #define RADEON_COMPILER_H
25
26 #include "../../../../main/compiler.h"
27
28 #include "memory_pool.h"
29 #include "radeon_code.h"
30 #include "radeon_program.h"
31
32 struct rc_swizzle_caps;
33
34 struct radeon_compiler {
35 struct memory_pool Pool;
36 struct rc_program Program;
37 unsigned Debug:1;
38 unsigned Error:1;
39 char * ErrorMsg;
40
41 /* Hardware specification. */
42 unsigned is_r500:1;
43 unsigned max_temp_regs;
44
45 /* Whether to remove unused constants and empty holes in constant space. */
46 unsigned remove_unused_constants:1;
47
48 /**
49 * Variables used internally, not be touched by callers
50 * of the compiler
51 */
52 /*@{*/
53 struct rc_swizzle_caps * SwizzleCaps;
54 /*@}*/
55 };
56
57 void rc_init(struct radeon_compiler * c);
58 void rc_destroy(struct radeon_compiler * c);
59
60 void rc_debug(struct radeon_compiler * c, const char * fmt, ...);
61 void rc_error(struct radeon_compiler * c, const char * fmt, ...);
62
63 int rc_if_fail_helper(struct radeon_compiler * c, const char * file, int line, const char * assertion);
64
65 /**
66 * This macro acts like an if-statement that can be used to implement
67 * non-aborting assertions in the compiler.
68 *
69 * It checks whether \p cond is true. If not, an internal compiler error is
70 * flagged and the if-clause is run.
71 *
72 * A typical use-case would be:
73 *
74 * if (rc_assert(c, condition-that-must-be-true))
75 * return;
76 */
77 #define rc_assert(c, cond) \
78 (!(cond) && rc_if_fail_helper(c, __FILE__, __LINE__, #cond))
79
80 void rc_calculate_inputs_outputs(struct radeon_compiler * c);
81
82 void rc_move_input(struct radeon_compiler * c, unsigned input, struct rc_src_register new_input);
83 void rc_move_output(struct radeon_compiler * c, unsigned output, unsigned new_output, unsigned writemask);
84 void rc_copy_output(struct radeon_compiler * c, unsigned output, unsigned dup_output);
85 void rc_transform_fragment_wpos(struct radeon_compiler * c, unsigned wpos, unsigned new_input,
86 int full_vtransform);
87 void rc_transform_fragment_face(struct radeon_compiler *c, unsigned face);
88
89 struct r300_fragment_program_compiler {
90 struct radeon_compiler Base;
91 struct rX00_fragment_program_code *code;
92 /* Optional transformations and features. */
93 struct r300_fragment_program_external_state state;
94 unsigned enable_shadow_ambient;
95 /* Register corresponding to the depthbuffer. */
96 unsigned OutputDepth;
97 /* Registers corresponding to the four colorbuffers. */
98 unsigned OutputColor[4];
99
100 void * UserData;
101 void (*AllocateHwInputs)(
102 struct r300_fragment_program_compiler * c,
103 void (*allocate)(void * data, unsigned input, unsigned hwreg),
104 void * mydata);
105 };
106
107 void r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c);
108
109
110 struct r300_vertex_program_compiler {
111 struct radeon_compiler Base;
112 struct r300_vertex_program_code *code;
113 uint32_t RequiredOutputs;
114
115 void * UserData;
116 void (*SetHwInputOutput)(struct r300_vertex_program_compiler * c);
117
118 int PredicateIndex;
119 unsigned int PredicateMask;
120 };
121
122 void r3xx_compile_vertex_program(struct r300_vertex_program_compiler* c);
123 void r300_vertex_program_dump(struct r300_vertex_program_compiler * c);
124
125 #endif /* RADEON_COMPILER_H */