1 /* 2 * Copyright 2009 Nicolai Hähnle <[email protected]> 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 struct rc_swizzle_caps; 18 19 enum rc_program_type { 20 RC_VERTEX_PROGRAM, 21 RC_FRAGMENT_PROGRAM, 22 RC_NUM_PROGRAM_TYPES 23 }; 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 /** 53 * Variables used internally, not be touched by callers 54 * of the compiler 55 */ 56 /*@{*/ 57 const struct rc_swizzle_caps * SwizzleCaps; 58 /*@}*/ 59 }; 60 61 void rc_init(struct radeon_compiler * c, const struct rc_regalloc_state *rs); 62 void rc_destroy(struct radeon_compiler * c); 63 64 void rc_debug(struct radeon_compiler * c, const char * fmt, ...); 65 void rc_error(struct radeon_compiler * c, const char * fmt, ...); 66 67 int rc_if_fail_helper(struct radeon_compiler * c, const char * file, int line, const char * assertion); 68 69 /** 70 * This macro acts like an if-statement that can be used to implement 71 * non-aborting assertions in the compiler. 72 * 73 * It checks whether \p cond is true. If not, an internal compiler error is 74 * flagged and the if-clause is run. 75 * 76 * A typical use-case would be: 77 * 78 * if (rc_assert(c, condition-that-must-be-true)) 79 * return; 80 */ 81 #define rc_assert(c, cond) \ 82 (!(cond) && rc_if_fail_helper(c, __FILE__, __LINE__, #cond)) 83 84 void rc_mark_unused_channels(struct radeon_compiler * c, void *user); 85 void rc_calculate_inputs_outputs(struct radeon_compiler * c); 86 void rc_copy_output(struct radeon_compiler * c, unsigned output, unsigned dup_output); 87 void rc_transform_fragment_wpos(struct radeon_compiler * c, unsigned wpos, unsigned new_input, 88 int full_vtransform); 89 void rc_transform_fragment_face(struct radeon_compiler *c, unsigned face); 90 91 struct r300_fragment_program_compiler { 92 struct radeon_compiler Base; 93 struct rX00_fragment_program_code *code; 94 /* Optional transformations and features. */ 95 struct r300_fragment_program_external_state state; 96 /* Register corresponding to the depthbuffer. */ 97 unsigned OutputDepth; 98 /* Registers corresponding to the four colorbuffers. */ 99 unsigned OutputColor[4]; 100 101 void * UserData; 102 void (*AllocateHwInputs)( 103 struct r300_fragment_program_compiler * c, 104 void (*allocate)(void * data, unsigned input, unsigned hwreg), 105 void * mydata); 106 }; 107 108 void r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c); 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 }; 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