Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright © 2010 Intel Corporation
  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.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8.  * and/or sell copies of the Software, and to permit persons to whom the
  9.  * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
  18.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21.  * IN THE SOFTWARE.
  22.  */
  23.  
  24. #include <stdint.h>
  25. #include "brw_reg.h"
  26. #include "brw_defines.h"
  27. #include "main/compiler.h"
  28. #include "glsl/ir.h"
  29.  
  30. #ifdef __cplusplus
  31. #include "brw_ir_allocator.h"
  32. #endif
  33.  
  34. #pragma once
  35.  
  36. #define MAX_SAMPLER_MESSAGE_SIZE 11
  37. #define MAX_VGRF_SIZE 16
  38.  
  39. struct brw_compiler {
  40.    const struct brw_device_info *devinfo;
  41.  
  42.    struct {
  43.       struct ra_regs *regs;
  44.  
  45.       /**
  46.        * Array of the ra classes for the unaligned contiguous register
  47.        * block sizes used.
  48.        */
  49.       int *classes;
  50.  
  51.       /**
  52.        * Mapping for register-allocated objects in *regs to the first
  53.        * GRF for that object.
  54.        */
  55.       uint8_t *ra_reg_to_grf;
  56.    } vec4_reg_set;
  57.  
  58.    struct {
  59.       struct ra_regs *regs;
  60.  
  61.       /**
  62.        * Array of the ra classes for the unaligned contiguous register
  63.        * block sizes used, indexed by register size.
  64.        */
  65.       int classes[16];
  66.  
  67.       /**
  68.        * Mapping from classes to ra_reg ranges.  Each of the per-size
  69.        * classes corresponds to a range of ra_reg nodes.  This array stores
  70.        * those ranges in the form of first ra_reg in each class and the
  71.        * total number of ra_reg elements in the last array element.  This
  72.        * way the range of the i'th class is given by:
  73.        * [ class_to_ra_reg_range[i], class_to_ra_reg_range[i+1] )
  74.        */
  75.       int class_to_ra_reg_range[17];
  76.  
  77.       /**
  78.        * Mapping for register-allocated objects in *regs to the first
  79.        * GRF for that object.
  80.        */
  81.       uint8_t *ra_reg_to_grf;
  82.  
  83.       /**
  84.        * ra class for the aligned pairs we use for PLN, which doesn't
  85.        * appear in *classes.
  86.        */
  87.       int aligned_pairs_class;
  88.    } fs_reg_sets[2];
  89. };
  90.  
  91. enum PACKED register_file {
  92.    BAD_FILE,
  93.    GRF,
  94.    MRF,
  95.    IMM,
  96.    HW_REG, /* a struct brw_reg */
  97.    ATTR,
  98.    UNIFORM, /* prog_data->params[reg] */
  99. };
  100.  
  101. struct backend_reg
  102. {
  103. #ifdef __cplusplus
  104.    bool is_zero() const;
  105.    bool is_one() const;
  106.    bool is_negative_one() const;
  107.    bool is_null() const;
  108.    bool is_accumulator() const;
  109.    bool in_range(const backend_reg &r, unsigned n) const;
  110. #endif
  111.  
  112.    enum register_file file; /**< Register file: GRF, MRF, IMM. */
  113.    enum brw_reg_type type;  /**< Register type: BRW_REGISTER_TYPE_* */
  114.  
  115.    /**
  116.     * Register number.
  117.     *
  118.     * For GRF, it's a virtual register number until register allocation.
  119.     *
  120.     * For MRF, it's the hardware register.
  121.     */
  122.    uint16_t reg;
  123.  
  124.    /**
  125.     * Offset within the virtual register.
  126.     *
  127.     * In the scalar backend, this is in units of a float per pixel for pre-
  128.     * register allocation registers (i.e., one register in SIMD8 mode and two
  129.     * registers in SIMD16 mode).
  130.     *
  131.     * For uniforms, this is in units of 1 float.
  132.     */
  133.    uint16_t reg_offset;
  134.  
  135.    struct brw_reg fixed_hw_reg;
  136.  
  137.    bool negate;
  138.    bool abs;
  139. };
  140.  
  141. struct cfg_t;
  142. struct bblock_t;
  143.  
  144. #ifdef __cplusplus
  145. struct backend_instruction : public exec_node {
  146.    bool is_3src() const;
  147.    bool is_tex() const;
  148.    bool is_math() const;
  149.    bool is_control_flow() const;
  150.    bool is_commutative() const;
  151.    bool can_do_source_mods() const;
  152.    bool can_do_saturate() const;
  153.    bool can_do_cmod() const;
  154.    bool reads_accumulator_implicitly() const;
  155.    bool writes_accumulator_implicitly(const struct brw_device_info *devinfo) const;
  156.  
  157.    void remove(bblock_t *block);
  158.    void insert_after(bblock_t *block, backend_instruction *inst);
  159.    void insert_before(bblock_t *block, backend_instruction *inst);
  160.    void insert_before(bblock_t *block, exec_list *list);
  161.  
  162.    /**
  163.     * True if the instruction has side effects other than writing to
  164.     * its destination registers.  You are expected not to reorder or
  165.     * optimize these out unless you know what you are doing.
  166.     */
  167.    bool has_side_effects() const;
  168. #else
  169. struct backend_instruction {
  170.    struct exec_node link;
  171. #endif
  172.    /** @{
  173.     * Annotation for the generated IR.  One of the two can be set.
  174.     */
  175.    const void *ir;
  176.    const char *annotation;
  177.    /** @} */
  178.  
  179.    uint32_t offset; /**< spill/unspill offset or texture offset bitfield */
  180.    uint8_t mlen; /**< SEND message length */
  181.    int8_t base_mrf; /**< First MRF in the SEND message, if mlen is nonzero. */
  182.    uint8_t target; /**< MRT target. */
  183.    uint8_t regs_written; /**< Number of registers written by the instruction. */
  184.  
  185.    enum opcode opcode; /* BRW_OPCODE_* or FS_OPCODE_* */
  186.    enum brw_conditional_mod conditional_mod; /**< BRW_CONDITIONAL_* */
  187.    enum brw_predicate predicate;
  188.    bool predicate_inverse:1;
  189.    bool writes_accumulator:1; /**< instruction implicitly writes accumulator */
  190.    bool force_writemask_all:1;
  191.    bool no_dd_clear:1;
  192.    bool no_dd_check:1;
  193.    bool saturate:1;
  194.    bool shadow_compare:1;
  195.  
  196.    /* Chooses which flag subregister (f0.0 or f0.1) is used for conditional
  197.     * mod and predication.
  198.     */
  199.    unsigned flag_subreg:1;
  200.  
  201.    /** The number of hardware registers used for a message header. */
  202.    uint8_t header_size;
  203. };
  204.  
  205. #ifdef __cplusplus
  206.  
  207. enum instruction_scheduler_mode {
  208.    SCHEDULE_PRE,
  209.    SCHEDULE_PRE_NON_LIFO,
  210.    SCHEDULE_PRE_LIFO,
  211.    SCHEDULE_POST,
  212. };
  213.  
  214. class backend_visitor : public ir_visitor {
  215. protected:
  216.  
  217.    backend_visitor(struct brw_context *brw,
  218.                    struct gl_shader_program *shader_prog,
  219.                    struct gl_program *prog,
  220.                    struct brw_stage_prog_data *stage_prog_data,
  221.                    gl_shader_stage stage);
  222.  
  223. public:
  224.  
  225.    struct brw_context * const brw;
  226.    const struct brw_device_info * const devinfo;
  227.    struct gl_context * const ctx;
  228.    struct brw_shader * const shader;
  229.    struct gl_shader_program * const shader_prog;
  230.    struct gl_program * const prog;
  231.    struct brw_stage_prog_data * const stage_prog_data;
  232.  
  233.    /** ralloc context for temporary data used during compile */
  234.    void *mem_ctx;
  235.  
  236.    /**
  237.     * List of either fs_inst or vec4_instruction (inheriting from
  238.     * backend_instruction)
  239.     */
  240.    exec_list instructions;
  241.  
  242.    cfg_t *cfg;
  243.  
  244.    gl_shader_stage stage;
  245.    bool debug_enabled;
  246.    const char *stage_name;
  247.    const char *stage_abbrev;
  248.  
  249.    brw::simple_allocator alloc;
  250.  
  251.    virtual void dump_instruction(backend_instruction *inst) = 0;
  252.    virtual void dump_instruction(backend_instruction *inst, FILE *file) = 0;
  253.    virtual void dump_instructions();
  254.    virtual void dump_instructions(const char *name);
  255.  
  256.    void calculate_cfg();
  257.    void invalidate_cfg();
  258.  
  259.    void assign_common_binding_table_offsets(uint32_t next_binding_table_offset);
  260.  
  261.    virtual void invalidate_live_intervals() = 0;
  262. };
  263.  
  264. uint32_t brw_texture_offset(int *offsets, unsigned num_components);
  265.  
  266. #endif /* __cplusplus */
  267.  
  268. enum brw_reg_type brw_type_for_base_type(const struct glsl_type *type);
  269. enum brw_conditional_mod brw_conditional_for_comparison(unsigned int op);
  270. uint32_t brw_math_function(enum opcode op);
  271. const char *brw_instruction_name(enum opcode op);
  272. bool brw_saturate_immediate(enum brw_reg_type type, struct brw_reg *reg);
  273. bool brw_negate_immediate(enum brw_reg_type type, struct brw_reg *reg);
  274. bool brw_abs_immediate(enum brw_reg_type type, struct brw_reg *reg);
  275.  
  276. #ifdef __cplusplus
  277. extern "C" {
  278. #endif
  279.  
  280. struct brw_compiler *
  281. brw_compiler_create(void *mem_ctx, const struct brw_device_info *devinfo);
  282.  
  283. bool brw_vs_precompile(struct gl_context *ctx,
  284.                        struct gl_shader_program *shader_prog,
  285.                        struct gl_program *prog);
  286. bool brw_gs_precompile(struct gl_context *ctx,
  287.                        struct gl_shader_program *shader_prog,
  288.                        struct gl_program *prog);
  289. bool brw_fs_precompile(struct gl_context *ctx,
  290.                        struct gl_shader_program *shader_prog,
  291.                        struct gl_program *prog);
  292. bool brw_cs_precompile(struct gl_context *ctx,
  293.                        struct gl_shader_program *shader_prog,
  294.                        struct gl_program *prog);
  295.  
  296. #ifdef __cplusplus
  297. }
  298. #endif
  299.