2 * Copyright 2016 Advanced Micro Devices, Inc.
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:
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
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.
24 #ifndef SI_SHADER_PRIVATE_H
25 #define SI_SHADER_PRIVATE_H
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"
32 #include <llvm-c/Core.h>
33 #include <llvm-c/TargetMachine.h>
35 struct pipe_debug_callback
;
36 struct radeon_shader_binary
;
38 #define RADEON_LLVM_MAX_INPUT_SLOTS 32
39 #define RADEON_LLVM_MAX_INPUTS 32 * 4
40 #define RADEON_LLVM_MAX_OUTPUTS 32 * 4
42 #define RADEON_LLVM_INITIAL_CF_DEPTH 4
44 #define RADEON_LLVM_MAX_SYSTEM_VALUES 4
46 struct radeon_llvm_flow
;
48 struct radeon_llvm_context
{
49 struct lp_build_tgsi_soa_context soa
;
51 /*=== Front end configuration ===*/
53 /* Instructions that are not described by any of the TGSI opcodes. */
55 /** This function is responsible for initilizing the inputs array and will be
56 * called once for each input declared in the TGSI shader.
58 void (*load_input
)(struct radeon_llvm_context
*,
60 const struct tgsi_full_declaration
*decl
,
63 void (*load_system_value
)(struct radeon_llvm_context
*,
65 const struct tgsi_full_declaration
*decl
);
67 void (*declare_memory_region
)(struct radeon_llvm_context
*,
68 const struct tgsi_full_declaration
*decl
);
70 /** This array contains the input values for the shader. Typically these
71 * values will be in the form of a target intrinsic that will inform the
72 * backend how to load the actual inputs to the shader.
74 struct tgsi_full_declaration input_decls
[RADEON_LLVM_MAX_INPUT_SLOTS
];
75 LLVMValueRef inputs
[RADEON_LLVM_MAX_INPUTS
];
76 LLVMValueRef outputs
[RADEON_LLVM_MAX_OUTPUTS
][TGSI_NUM_CHANNELS
];
78 /** This pointer is used to contain the temporary values.
79 * The amount of temporary used in tgsi can't be bound to a max value and
80 * thus we must allocate this array at runtime.
84 LLVMValueRef system_values
[RADEON_LLVM_MAX_SYSTEM_VALUES
];
86 /*=== Private Members ===*/
88 struct radeon_llvm_flow
*flow
;
90 unsigned flow_depth_max
;
92 struct tgsi_array_info
*temp_arrays
;
93 LLVMValueRef
*temp_array_allocas
;
95 LLVMValueRef undef_alloca
;
98 LLVMTypeRef return_type
;
100 unsigned fpmath_md_kind
;
101 LLVMValueRef fpmath_md_2p5_ulp
;
103 struct gallivm_state gallivm
;
106 static inline struct radeon_llvm_context
*
107 radeon_llvm_context(struct lp_build_tgsi_context
*bld_base
)
109 return (struct radeon_llvm_context
*)bld_base
;
112 void radeon_llvm_add_attribute(LLVMValueRef F
, const char *name
, int value
);
113 void radeon_llvm_shader_type(LLVMValueRef F
, unsigned type
);
115 LLVMTargetRef
radeon_llvm_get_r600_target(const char *triple
);
117 unsigned radeon_llvm_compile(LLVMModuleRef M
, struct radeon_shader_binary
*binary
,
118 LLVMTargetMachineRef tm
,
119 struct pipe_debug_callback
*debug
);
121 LLVMTypeRef
tgsi2llvmtype(struct lp_build_tgsi_context
*bld_base
,
122 enum tgsi_opcode_type type
);
124 LLVMValueRef
bitcast(struct lp_build_tgsi_context
*bld_base
,
125 enum tgsi_opcode_type type
, LLVMValueRef value
);
127 LLVMValueRef
radeon_llvm_bound_index(struct radeon_llvm_context
*ctx
,
131 void radeon_llvm_context_init(struct radeon_llvm_context
*ctx
,
133 const struct tgsi_shader_info
*info
,
134 const struct tgsi_token
*tokens
);
136 void radeon_llvm_create_func(struct radeon_llvm_context
*ctx
,
137 LLVMTypeRef
*return_types
, unsigned num_return_elems
,
138 LLVMTypeRef
*ParamTypes
, unsigned ParamCount
);
140 void radeon_llvm_dispose(struct radeon_llvm_context
*ctx
);
142 void radeon_llvm_finalize_module(struct radeon_llvm_context
*ctx
,
145 LLVMValueRef
radeon_llvm_emit_fetch_64bit(struct lp_build_tgsi_context
*bld_base
,
146 enum tgsi_opcode_type type
,
150 LLVMValueRef
radeon_llvm_saturate(struct lp_build_tgsi_context
*bld_base
,
153 LLVMValueRef
radeon_llvm_emit_fetch(struct lp_build_tgsi_context
*bld_base
,
154 const struct tgsi_full_src_register
*reg
,
155 enum tgsi_opcode_type type
,
158 void radeon_llvm_emit_store(struct lp_build_tgsi_context
*bld_base
,
159 const struct tgsi_full_instruction
*inst
,
160 const struct tgsi_opcode_info
*info
,
161 LLVMValueRef dst
[4]);
163 void si_shader_context_init_alu(struct lp_build_tgsi_context
*bld_base
);
164 void si_prepare_cube_coords(struct lp_build_tgsi_context
*bld_base
,
165 struct lp_build_emit_data
*emit_data
,
166 LLVMValueRef
*coords_arg
,
167 LLVMValueRef
*derivs_arg
);