OSDN Git Service

radeonsi: get rid of no_{prolog,epilog}
[android-x86/external-mesa.git] / src / gallium / drivers / radeonsi / si_shader_internal.h
1 /*
2  * Copyright 2016 Advanced Micro Devices, Inc.
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  * on the rights to use, copy, modify, merge, publish, distribute, sub
8  * license, and/or sell copies of the Software, and to permit persons to whom
9  * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21  * USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23
24 #ifndef SI_SHADER_PRIVATE_H
25 #define SI_SHADER_PRIVATE_H
26
27 #include "si_shader.h"
28 #include "gallivm/lp_bld_init.h"
29 #include "gallivm/lp_bld_tgsi.h"
30 #include "tgsi/tgsi_parse.h"
31
32 #include <llvm-c/Core.h>
33 #include <llvm-c/TargetMachine.h>
34
35 struct pipe_debug_callback;
36 struct radeon_shader_binary;
37
38 #define RADEON_LLVM_MAX_INPUT_SLOTS 32
39 #define RADEON_LLVM_MAX_INPUTS 32 * 4
40 #define RADEON_LLVM_MAX_OUTPUTS 32 * 4
41
42 #define RADEON_LLVM_INITIAL_CF_DEPTH 4
43
44 #define RADEON_LLVM_MAX_SYSTEM_VALUES 4
45
46 struct si_llvm_flow;
47
48 struct si_shader_context {
49         struct lp_build_tgsi_soa_context soa;
50         struct gallivm_state gallivm;
51         struct si_shader *shader;
52         struct si_screen *screen;
53
54         unsigned type; /* PIPE_SHADER_* specifies the type of shader. */
55         bool is_gs_copy_shader;
56
57         /* Whether the prolog will be compiled separately. */
58         bool separate_prolog;
59
60         /** This function is responsible for initilizing the inputs array and will be
61           * called once for each input declared in the TGSI shader.
62           */
63         void (*load_input)(struct si_shader_context *,
64                            unsigned input_index,
65                            const struct tgsi_full_declaration *decl,
66                            LLVMValueRef out[4]);
67
68         void (*load_system_value)(struct si_shader_context *,
69                                   unsigned index,
70                                   const struct tgsi_full_declaration *decl);
71
72         void (*declare_memory_region)(struct si_shader_context *,
73                                       const struct tgsi_full_declaration *decl);
74
75         /** This array contains the input values for the shader.  Typically these
76           * values will be in the form of a target intrinsic that will inform the
77           * backend how to load the actual inputs to the shader.
78           */
79         struct tgsi_full_declaration input_decls[RADEON_LLVM_MAX_INPUT_SLOTS];
80         LLVMValueRef inputs[RADEON_LLVM_MAX_INPUTS];
81         LLVMValueRef outputs[RADEON_LLVM_MAX_OUTPUTS][TGSI_NUM_CHANNELS];
82
83         /** This pointer is used to contain the temporary values.
84           * The amount of temporary used in tgsi can't be bound to a max value and
85           * thus we must allocate this array at runtime.
86           */
87         LLVMValueRef *temps;
88         unsigned temps_count;
89         LLVMValueRef system_values[RADEON_LLVM_MAX_SYSTEM_VALUES];
90
91         struct si_llvm_flow *flow;
92         unsigned flow_depth;
93         unsigned flow_depth_max;
94
95         struct tgsi_array_info *temp_arrays;
96         LLVMValueRef *temp_array_allocas;
97
98         LLVMValueRef undef_alloca;
99
100         LLVMValueRef main_fn;
101         LLVMTypeRef return_type;
102
103         int param_streamout_config;
104         int param_streamout_write_index;
105         int param_streamout_offset[4];
106         int param_vertex_id;
107         int param_rel_auto_id;
108         int param_vs_prim_id;
109         int param_instance_id;
110         int param_vertex_index0;
111         int param_tes_u;
112         int param_tes_v;
113         int param_tes_rel_patch_id;
114         int param_tes_patch_id;
115         int param_es2gs_offset;
116         int param_oc_lds;
117
118         /* Sets a bit if the dynamic HS control word was 0x80000000. The bit is
119          * 0x800000 for VS, 0x1 for ES.
120          */
121         int param_tess_offchip;
122
123         LLVMTargetMachineRef tm;
124
125         unsigned invariant_load_md_kind;
126         unsigned range_md_kind;
127         unsigned uniform_md_kind;
128         unsigned fpmath_md_kind;
129         LLVMValueRef fpmath_md_2p5_ulp;
130         LLVMValueRef empty_md;
131
132         /* Preloaded descriptors. */
133         LLVMValueRef esgs_ring;
134         LLVMValueRef gsvs_ring[4];
135
136         LLVMValueRef lds;
137         LLVMValueRef gs_next_vertex[4];
138         LLVMValueRef return_value;
139
140         LLVMTypeRef voidt;
141         LLVMTypeRef i1;
142         LLVMTypeRef i8;
143         LLVMTypeRef i32;
144         LLVMTypeRef i64;
145         LLVMTypeRef i128;
146         LLVMTypeRef f32;
147         LLVMTypeRef v16i8;
148         LLVMTypeRef v2i32;
149         LLVMTypeRef v4i32;
150         LLVMTypeRef v4f32;
151         LLVMTypeRef v8i32;
152
153         LLVMValueRef shared_memory;
154 };
155
156 static inline struct si_shader_context *
157 si_shader_context(struct lp_build_tgsi_context *bld_base)
158 {
159         return (struct si_shader_context*)bld_base;
160 }
161
162 void si_llvm_add_attribute(LLVMValueRef F, const char *name, int value);
163 void si_llvm_shader_type(LLVMValueRef F, unsigned type);
164
165 LLVMTargetRef si_llvm_get_amdgpu_target(const char *triple);
166
167 unsigned si_llvm_compile(LLVMModuleRef M, struct radeon_shader_binary *binary,
168                          LLVMTargetMachineRef tm,
169                          struct pipe_debug_callback *debug);
170
171 LLVMTypeRef tgsi2llvmtype(struct lp_build_tgsi_context *bld_base,
172                           enum tgsi_opcode_type type);
173
174 LLVMValueRef bitcast(struct lp_build_tgsi_context *bld_base,
175                      enum tgsi_opcode_type type, LLVMValueRef value);
176
177 LLVMValueRef si_llvm_bound_index(struct si_shader_context *ctx,
178                                  LLVMValueRef index,
179                                  unsigned num);
180
181 void si_llvm_context_init(struct si_shader_context *ctx,
182                           const char *triple,
183                           const struct tgsi_shader_info *info,
184                           const struct tgsi_token *tokens);
185
186 void si_llvm_create_func(struct si_shader_context *ctx,
187                          const char *name,
188                          LLVMTypeRef *return_types, unsigned num_return_elems,
189                          LLVMTypeRef *ParamTypes, unsigned ParamCount);
190
191 void si_llvm_dispose(struct si_shader_context *ctx);
192
193 void si_llvm_finalize_module(struct si_shader_context *ctx,
194                              bool run_verifier);
195
196 LLVMValueRef si_llvm_emit_fetch_64bit(struct lp_build_tgsi_context *bld_base,
197                                       enum tgsi_opcode_type type,
198                                       LLVMValueRef ptr,
199                                       LLVMValueRef ptr2);
200
201 LLVMValueRef si_llvm_saturate(struct lp_build_tgsi_context *bld_base,
202                               LLVMValueRef value);
203
204 LLVMValueRef si_llvm_emit_fetch(struct lp_build_tgsi_context *bld_base,
205                                 const struct tgsi_full_src_register *reg,
206                                 enum tgsi_opcode_type type,
207                                 unsigned swizzle);
208
209 void si_llvm_emit_store(struct lp_build_tgsi_context *bld_base,
210                         const struct tgsi_full_instruction *inst,
211                         const struct tgsi_opcode_info *info,
212                         LLVMValueRef dst[4]);
213
214 void si_shader_context_init_alu(struct lp_build_tgsi_context *bld_base);
215 void si_prepare_cube_coords(struct lp_build_tgsi_context *bld_base,
216                             struct lp_build_emit_data *emit_data,
217                             LLVMValueRef *coords_arg,
218                             LLVMValueRef *derivs_arg);
219
220 #endif