Path: blob/21.2-virgl/src/gallium/drivers/r300/compiler/radeon_compiler.h
4574 views
/*1* Copyright 2009 Nicolai Hähnle <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE. */2122#ifndef RADEON_COMPILER_H23#define RADEON_COMPILER_H2425#include "memory_pool.h"26#include "radeon_code.h"27#include "radeon_program.h"28#include "radeon_emulate_loops.h"2930#define RC_DBG_LOG (1 << 0)31#define RC_DBG_STATS (1 << 1)3233struct rc_swizzle_caps;3435enum rc_program_type {36RC_VERTEX_PROGRAM,37RC_FRAGMENT_PROGRAM,38RC_NUM_PROGRAM_TYPES39};4041struct radeon_compiler {42struct memory_pool Pool;43struct rc_program Program;44const struct rc_regalloc_state *regalloc_state;45enum rc_program_type type;46unsigned Debug:2;47unsigned Error:1;48char * ErrorMsg;4950/* Hardware specification. */51unsigned is_r400:1;52unsigned is_r500:1;53unsigned has_half_swizzles:1;54unsigned has_presub:1;55unsigned has_omod:1;56unsigned disable_optimizations:1;57unsigned max_temp_regs;58unsigned max_constants;59int max_alu_insts;60unsigned max_tex_insts;6162/* Whether to remove unused constants and empty holes in constant space. */63unsigned remove_unused_constants:1;6465/**66* Variables used internally, not be touched by callers67* of the compiler68*/69/*@{*/70struct rc_swizzle_caps * SwizzleCaps;71/*@}*/7273struct emulate_loop_state loop_state;7475unsigned initial_num_insts; /* Number of instructions at start. */76};7778void rc_init(struct radeon_compiler * c, const struct rc_regalloc_state *rs);79void rc_destroy(struct radeon_compiler * c);8081void rc_debug(struct radeon_compiler * c, const char * fmt, ...);82void rc_error(struct radeon_compiler * c, const char * fmt, ...);8384int rc_if_fail_helper(struct radeon_compiler * c, const char * file, int line, const char * assertion);8586/**87* This macro acts like an if-statement that can be used to implement88* non-aborting assertions in the compiler.89*90* It checks whether \p cond is true. If not, an internal compiler error is91* flagged and the if-clause is run.92*93* A typical use-case would be:94*95* if (rc_assert(c, condition-that-must-be-true))96* return;97*/98#define rc_assert(c, cond) \99(!(cond) && rc_if_fail_helper(c, __FILE__, __LINE__, #cond))100101void rc_calculate_inputs_outputs(struct radeon_compiler * c);102103void rc_move_input(struct radeon_compiler * c, unsigned input, struct rc_src_register new_input);104void rc_move_output(struct radeon_compiler * c, unsigned output, unsigned new_output, unsigned writemask);105void rc_copy_output(struct radeon_compiler * c, unsigned output, unsigned dup_output);106void rc_transform_fragment_wpos(struct radeon_compiler * c, unsigned wpos, unsigned new_input,107int full_vtransform);108void rc_transform_fragment_face(struct radeon_compiler *c, unsigned face);109110struct r300_fragment_program_compiler {111struct radeon_compiler Base;112struct rX00_fragment_program_code *code;113/* Optional transformations and features. */114struct r300_fragment_program_external_state state;115/* Register corresponding to the depthbuffer. */116unsigned OutputDepth;117/* Registers corresponding to the four colorbuffers. */118unsigned OutputColor[4];119120void * UserData;121void (*AllocateHwInputs)(122struct r300_fragment_program_compiler * c,123void (*allocate)(void * data, unsigned input, unsigned hwreg),124void * mydata);125};126127void r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c);128129struct r300_vertex_program_compiler {130struct radeon_compiler Base;131struct r300_vertex_program_code *code;132uint32_t RequiredOutputs;133134void * UserData;135void (*SetHwInputOutput)(struct r300_vertex_program_compiler * c);136137};138139void r3xx_compile_vertex_program(struct r300_vertex_program_compiler* c);140void rc_vert_fc(struct radeon_compiler *compiler, void *user);141void r300_vertex_program_dump(struct radeon_compiler *compiler, void *user);142143struct radeon_compiler_pass {144const char *name; /* Name of the pass. */145int dump; /* Dump the program if Debug == 1? */146int predicate; /* Run this pass? */147void (*run)(struct radeon_compiler *c, void *user); /* The main entrypoint. */148void *user; /* Optional parameter which is passed to the run function. */149};150151struct rc_program_stats {152unsigned num_insts;153unsigned num_fc_insts;154unsigned num_tex_insts;155unsigned num_rgb_insts;156unsigned num_alpha_insts;157unsigned num_presub_ops;158unsigned num_temp_regs;159unsigned num_omod_ops;160unsigned num_inline_literals;161};162163void rc_get_stats(struct radeon_compiler *c, struct rc_program_stats *s);164165/* Executes a list of compiler passes given in the parameter 'list'. */166void rc_run_compiler_passes(struct radeon_compiler *c, struct radeon_compiler_pass *list);167void rc_run_compiler(struct radeon_compiler *c, struct radeon_compiler_pass *list);168void rc_validate_final_shader(struct radeon_compiler *c, void *user);169170#endif /* RADEON_COMPILER_H */171172173