• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
25 
26 #include <stdint.h>
27 #include "elk_cfg.h"
28 #include "elk_compiler.h"
29 #include "compiler/nir/nir.h"
30 
31 #ifdef __cplusplus
32 #include "elk_ir_analysis.h"
33 #include "elk_ir_allocator.h"
34 
35 enum instruction_scheduler_mode {
36    SCHEDULE_PRE,
37    SCHEDULE_PRE_NON_LIFO,
38    SCHEDULE_PRE_LIFO,
39    SCHEDULE_POST,
40    SCHEDULE_NONE,
41 };
42 
43 #define UBO_START ((1 << 16) - 4)
44 
45 struct elk_backend_shader {
46 protected:
47 
48    elk_backend_shader(const struct elk_compiler *compiler,
49                   const struct elk_compile_params *params,
50                   const nir_shader *shader,
51                   struct elk_stage_prog_data *stage_prog_data,
52                   bool debug_enabled);
53 
54 public:
55    virtual ~elk_backend_shader();
56 
57    const struct elk_compiler *compiler;
58    void *log_data; /* Passed to compiler->*_log functions */
59 
60    const struct intel_device_info * const devinfo;
61    const nir_shader *nir;
62    struct elk_stage_prog_data * const stage_prog_data;
63 
64    /** ralloc context for temporary data used during compile */
65    void *mem_ctx;
66 
67    /**
68     * List of either elk_fs_inst or vec4_instruction (inheriting from
69     * elk_backend_instruction)
70     */
71    exec_list instructions;
72 
73    elk_cfg_t *cfg;
74    elk_analysis<elk::idom_tree, elk_backend_shader> idom_analysis;
75 
76    gl_shader_stage stage;
77    bool debug_enabled;
78 
79    elk::simple_allocator alloc;
80 
81    virtual void dump_instruction_to_file(const elk_backend_instruction *inst, FILE *file) const = 0;
82    virtual void dump_instructions_to_file(FILE *file) const;
83 
84    /* Convenience functions based on the above. */
85    void dump_instruction(const elk_backend_instruction *inst, FILE *file = stderr) const {
86       dump_instruction_to_file(inst, file);
87    }
88    void dump_instructions(const char *name = nullptr) const;
89 
90    void calculate_cfg();
91 
92    virtual void invalidate_analysis(elk::analysis_dependency_class c);
93 };
94 
95 #else
96 struct elk_backend_shader;
97 #endif /* __cplusplus */
98 
99 enum elk_reg_type elk_type_for_base_type(const struct glsl_type *type);
100 uint32_t elk_math_function(enum elk_opcode op);
101 const char *elk_instruction_name(const struct elk_isa_info *isa,
102                                  enum elk_opcode op);
103 bool elk_saturate_immediate(enum elk_reg_type type, struct elk_reg *reg);
104 bool elk_negate_immediate(enum elk_reg_type type, struct elk_reg *reg);
105 bool elk_abs_immediate(enum elk_reg_type type, struct elk_reg *reg);
106 
107 bool elk_opt_predicated_break(struct elk_backend_shader *s);
108 
109 #ifdef __cplusplus
110 extern "C" {
111 #endif
112 
113 /* elk_fs_reg_allocate.cpp */
114 void elk_fs_alloc_reg_sets(struct elk_compiler *compiler);
115 
116 /* elk_vec4_reg_allocate.cpp */
117 void elk_vec4_alloc_reg_set(struct elk_compiler *compiler);
118 
119 /* elk_disasm.c */
120 extern const char *const elk_conditional_modifier[16];
121 extern const char *const elk_pred_ctrl_align16[16];
122 
123 /* Per-thread scratch space is a power-of-two multiple of 1KB. */
124 static inline unsigned
elk_get_scratch_size(int size)125 elk_get_scratch_size(int size)
126 {
127    return MAX2(1024, util_next_power_of_two(size));
128 }
129 
130 
131 static inline nir_variable_mode
elk_nir_no_indirect_mask(const struct elk_compiler * compiler,gl_shader_stage stage)132 elk_nir_no_indirect_mask(const struct elk_compiler *compiler,
133                          gl_shader_stage stage)
134 {
135    const struct intel_device_info *devinfo = compiler->devinfo;
136    const bool is_scalar = compiler->scalar_stage[stage];
137    nir_variable_mode indirect_mask = (nir_variable_mode) 0;
138 
139    switch (stage) {
140    case MESA_SHADER_VERTEX:
141    case MESA_SHADER_FRAGMENT:
142       indirect_mask |= nir_var_shader_in;
143       break;
144 
145    case MESA_SHADER_GEOMETRY:
146       if (!is_scalar)
147          indirect_mask |= nir_var_shader_in;
148       break;
149 
150    default:
151       /* Everything else can handle indirect inputs */
152       break;
153    }
154 
155    if (is_scalar && stage != MESA_SHADER_TESS_CTRL)
156       indirect_mask |= nir_var_shader_out;
157 
158    /* On HSW+, we allow indirects in scalar shaders.  They get implemented
159     * using nir_lower_vars_to_explicit_types and nir_lower_explicit_io in
160     * elk_postprocess_nir.
161     *
162     * We haven't plumbed through the indirect scratch messages on gfx6 or
163     * earlier so doing indirects via scratch doesn't work there. On gfx7 and
164     * earlier the scratch space size is limited to 12kB.  If we allowed
165     * indirects as scratch all the time, we may easily exceed this limit
166     * without having any fallback.
167     */
168    if (is_scalar && devinfo->verx10 <= 70)
169       indirect_mask |= nir_var_function_temp;
170 
171    return indirect_mask;
172 }
173 
174 bool elk_texture_offset(const nir_tex_instr *tex, unsigned src,
175                         uint32_t *offset_bits);
176 
177 /**
178  * Scratch data used when compiling a GLSL geometry shader.
179  */
180 struct elk_gs_compile
181 {
182    struct elk_gs_prog_key key;
183    struct intel_vue_map input_vue_map;
184 
185    unsigned control_data_bits_per_vertex;
186    unsigned control_data_header_size_bits;
187 };
188 
189 #ifdef __cplusplus
190 }
191 #endif
192