• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2009 Nicolai Hähnle <nhaehnle@gmail.com>
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #ifndef RADEON_COMPILER_H
7 #define RADEON_COMPILER_H
8 
9 #include <stdbool.h>
10 
11 #include "memory_pool.h"
12 #include "radeon_code.h"
13 #include "radeon_program.h"
14 
15 #define RC_DBG_LOG (1 << 0)
16 
17 #define RC_MATH_DX        0x00
18 #define RC_MATH_IEEE      0x01
19 #define RC_MATH_FF        0x02
20 
21 struct rc_swizzle_caps;
22 
23 enum rc_program_type { RC_VERTEX_PROGRAM, RC_FRAGMENT_PROGRAM, RC_NUM_PROGRAM_TYPES };
24 
25 struct radeon_compiler {
26    struct memory_pool Pool;
27    struct rc_program Program;
28    const struct rc_regalloc_state *regalloc_state;
29    struct util_debug_callback *debug;
30    enum rc_program_type type;
31    unsigned Debug : 2;
32    unsigned Error : 1;
33    char *ErrorMsg;
34 
35    /* Hardware specification. */
36    unsigned is_r400 : 1;
37    unsigned is_r500 : 1;
38    unsigned has_half_swizzles : 1;
39    unsigned has_presub : 1;
40    unsigned has_omod : 1;
41    unsigned disable_optimizations : 1;
42    unsigned max_temp_regs;
43    unsigned max_constants;
44    int max_alu_insts;
45    unsigned max_tex_insts;
46 
47    int max_temp_index;
48 
49    /* Whether to remove unused constants and empty holes in constant space. */
50    unsigned remove_unused_constants : 1;
51 
52    /* Math compatibility mode, for some PVS opcodes and for multiply by zero rules on R5xx */
53    unsigned math_rules : 2;
54 
55    /**
56     * Variables used internally, not be touched by callers
57     * of the compiler
58     */
59    /*@{*/
60    const struct rc_swizzle_caps *SwizzleCaps;
61    /*@}*/
62 };
63 
64 void rc_init(struct radeon_compiler *c, const struct rc_regalloc_state *rs);
65 void rc_destroy(struct radeon_compiler *c);
66 
67 void rc_debug(struct radeon_compiler *c, const char *fmt, ...);
68 void rc_error(struct radeon_compiler *c, const char *fmt, ...);
69 
70 int rc_if_fail_helper(struct radeon_compiler *c, const char *file, int line, const char *assertion);
71 
72 /**
73  * This macro acts like an if-statement that can be used to implement
74  * non-aborting assertions in the compiler.
75  *
76  * It checks whether \p cond is true. If not, an internal compiler error is
77  * flagged and the if-clause is run.
78  *
79  * A typical use-case would be:
80  *
81  *  if (rc_assert(c, condition-that-must-be-true))
82  *  	return;
83  */
84 #define rc_assert(c, cond) (!(cond) && rc_if_fail_helper(c, __FILE__, __LINE__, #cond))
85 
86 void rc_mark_unused_channels(struct radeon_compiler *c, void *user);
87 void rc_calculate_inputs_outputs(struct radeon_compiler *c);
88 void rc_copy_output(struct radeon_compiler *c, unsigned output, unsigned dup_output);
89 void rc_transform_fragment_wpos(struct radeon_compiler *c, unsigned wpos, unsigned new_input,
90                                 int full_vtransform);
91 void rc_transform_fragment_face(struct radeon_compiler *c, unsigned face);
92 
93 struct r300_fragment_program_compiler {
94    struct radeon_compiler Base;
95    struct rX00_fragment_program_code *code;
96    /* Optional transformations and features. */
97    struct r300_fragment_program_external_state state;
98    /* Register corresponding to the depthbuffer. */
99    unsigned OutputDepth;
100    /* Registers corresponding to the four colorbuffers. */
101    unsigned OutputColor[4];
102 
103    void *UserData;
104    void (*AllocateHwInputs)(struct r300_fragment_program_compiler *c,
105                             void (*allocate)(void *data, unsigned input, unsigned hwreg),
106                             void *mydata);
107 };
108 
109 void r3xx_compile_fragment_program(struct r300_fragment_program_compiler *c);
110 
111 struct r300_vertex_program_compiler {
112    struct radeon_compiler Base;
113    struct r300_vertex_program_code *code;
114    uint32_t RequiredOutputs;
115 
116    void *UserData;
117    void (*SetHwInputOutput)(struct r300_vertex_program_compiler *c);
118 };
119 
120 void r3xx_compile_vertex_program(struct r300_vertex_program_compiler *c);
121 void rc_vert_fc(struct radeon_compiler *compiler, void *user);
122 void r300_vertex_program_dump(struct radeon_compiler *compiler, void *user);
123 
124 struct radeon_compiler_pass {
125    const char *name;                                   /* Name of the pass. */
126    int dump;                                           /* Dump the program if Debug == 1? */
127    int predicate;                                      /* Run this pass? */
128    void (*run)(struct radeon_compiler *c, void *user); /* The main entrypoint. */
129    void *user; /* Optional parameter which is passed to the run function. */
130 };
131 
132 struct rc_program_stats {
133    unsigned num_cycles;
134    unsigned num_consts;
135    unsigned num_insts;
136    unsigned num_fc_insts;
137    unsigned num_tex_insts;
138    unsigned num_rgb_insts;
139    unsigned num_alpha_insts;
140    unsigned num_pred_insts;
141    unsigned num_presub_ops;
142    unsigned num_temp_regs;
143    unsigned num_omod_ops;
144    unsigned num_inline_literals;
145    unsigned num_loops;
146 };
147 
148 void rc_get_stats(struct radeon_compiler *c, struct rc_program_stats *s);
149 
150 /* Executes a list of compiler passes given in the parameter 'list'. */
151 bool rc_run_compiler_passes(struct radeon_compiler *c, struct radeon_compiler_pass *list);
152 void rc_run_compiler(struct radeon_compiler *c, struct radeon_compiler_pass *list);
153 void rc_validate_final_shader(struct radeon_compiler *c, void *user);
154 
155 #endif /* RADEON_COMPILER_H */
156