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. */
23 #ifndef RADEON_COMPILER_H
24 #define RADEON_COMPILER_H
26 #include "main/compiler.h"
28 #include "memory_pool.h"
29 #include "radeon_code.h"
30 #include "radeon_program.h"
31 #include "radeon_emulate_loops.h"
33 #define RC_DBG_LOG (1 << 0)
34 #define RC_DBG_STATS (1 << 1)
36 struct rc_swizzle_caps
;
38 enum rc_program_type
{
44 struct radeon_compiler
{
45 struct memory_pool Pool
;
46 struct rc_program Program
;
47 enum rc_program_type type
;
52 /* Hardware specification. */
55 unsigned has_half_swizzles
:1;
56 unsigned has_presub
:1;
58 unsigned disable_optimizations
:1;
59 unsigned max_temp_regs
;
60 unsigned max_constants
;
62 unsigned max_tex_insts
;
64 /* Whether to remove unused constants and empty holes in constant space. */
65 unsigned remove_unused_constants
:1;
68 * Variables used internally, not be touched by callers
72 struct rc_swizzle_caps
* SwizzleCaps
;
75 struct emulate_loop_state loop_state
;
77 unsigned initial_num_insts
; /* Number of instructions at start. */
80 void rc_init(struct radeon_compiler
* c
);
81 void rc_destroy(struct radeon_compiler
* c
);
83 void rc_debug(struct radeon_compiler
* c
, const char * fmt
, ...);
84 void rc_error(struct radeon_compiler
* c
, const char * fmt
, ...);
86 int rc_if_fail_helper(struct radeon_compiler
* c
, const char * file
, int line
, const char * assertion
);
89 * This macro acts like an if-statement that can be used to implement
90 * non-aborting assertions in the compiler.
92 * It checks whether \p cond is true. If not, an internal compiler error is
93 * flagged and the if-clause is run.
95 * A typical use-case would be:
97 * if (rc_assert(c, condition-that-must-be-true))
100 #define rc_assert(c, cond) \
101 (!(cond) && rc_if_fail_helper(c, __FILE__, __LINE__, #cond))
103 void rc_calculate_inputs_outputs(struct radeon_compiler
* c
);
105 void rc_move_input(struct radeon_compiler
* c
, unsigned input
, struct rc_src_register new_input
);
106 void rc_move_output(struct radeon_compiler
* c
, unsigned output
, unsigned new_output
, unsigned writemask
);
107 void rc_copy_output(struct radeon_compiler
* c
, unsigned output
, unsigned dup_output
);
108 void rc_transform_fragment_wpos(struct radeon_compiler
* c
, unsigned wpos
, unsigned new_input
,
109 int full_vtransform
);
110 void rc_transform_fragment_face(struct radeon_compiler
*c
, unsigned face
);
112 struct r300_fragment_program_compiler
{
113 struct radeon_compiler Base
;
114 struct rX00_fragment_program_code
*code
;
115 /* Optional transformations and features. */
116 struct r300_fragment_program_external_state state
;
117 unsigned enable_shadow_ambient
;
118 /* Register corresponding to the depthbuffer. */
119 unsigned OutputDepth
;
120 /* Registers corresponding to the four colorbuffers. */
121 unsigned OutputColor
[4];
124 void (*AllocateHwInputs
)(
125 struct r300_fragment_program_compiler
* c
,
126 void (*allocate
)(void * data
, unsigned input
, unsigned hwreg
),
130 void r3xx_compile_fragment_program(struct r300_fragment_program_compiler
* c
);
132 struct r300_vertex_program_compiler
{
133 struct radeon_compiler Base
;
134 struct r300_vertex_program_code
*code
;
135 uint32_t RequiredOutputs
;
138 void (*SetHwInputOutput
)(struct r300_vertex_program_compiler
* c
);
142 void r3xx_compile_vertex_program(struct r300_vertex_program_compiler
* c
);
143 void rc_vert_fc(struct radeon_compiler
*compiler
, void *user
);
144 void r300_vertex_program_dump(struct radeon_compiler
*compiler
, void *user
);
146 struct radeon_compiler_pass
{
147 const char *name
; /* Name of the pass. */
148 int dump
; /* Dump the program if Debug == 1? */
149 int predicate
; /* Run this pass? */
150 void (*run
)(struct radeon_compiler
*c
, void *user
); /* The main entrypoint. */
151 void *user
; /* Optional parameter which is passed to the run function. */
154 struct rc_program_stats
{
156 unsigned num_fc_insts
;
157 unsigned num_tex_insts
;
158 unsigned num_rgb_insts
;
159 unsigned num_alpha_insts
;
160 unsigned num_presub_ops
;
161 unsigned num_temp_regs
;
162 unsigned num_omod_ops
;
163 unsigned num_inline_literals
;
166 void rc_get_stats(struct radeon_compiler
*c
, struct rc_program_stats
*s
);
168 /* Executes a list of compiler passes given in the parameter 'list'. */
169 void rc_run_compiler_passes(struct radeon_compiler
*c
, struct radeon_compiler_pass
*list
);
170 void rc_run_compiler(struct radeon_compiler
*c
, struct radeon_compiler_pass
*list
);
171 void rc_validate_final_shader(struct radeon_compiler
*c
, void *user
);
173 #endif /* RADEON_COMPILER_H */