1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * TGSI to LLVM IR translation.
32 * @author Jose Fonseca <jfonseca@vmware.com>
38 #include "gallivm/lp_bld.h"
39 #include "pipe/p_compiler.h"
40 #include "pipe/p_state.h"
41 #include "tgsi/tgsi_scan.h"
45 struct tgsi_shader_info
;
47 struct lp_build_context
;
48 struct lp_build_mask_context
;
52 enum lp_build_tex_modifier
{
53 LP_BLD_TEX_MODIFIER_NONE
= 0,
54 LP_BLD_TEX_MODIFIER_PROJECTED
,
55 LP_BLD_TEX_MODIFIER_LOD_BIAS
,
56 LP_BLD_TEX_MODIFIER_EXPLICIT_LOD
,
57 LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV
62 * Describe a channel of a register.
65 * - immediate value (i.e. derived from a IMM register)
68 * - undetermined (when .file == TGSI_FILE_NULL)
70 * This is one of the analysis results, and is used to described
71 * the output color in terms of inputs.
73 struct lp_tgsi_channel_info
75 unsigned file
:4; /* TGSI_FILE_* */
76 unsigned swizzle
:3; /* PIPE_SWIZZLE_x */
79 float value
; /* for TGSI_FILE_IMMEDIATE */
85 * Describe a texture sampler interpolator.
87 * The interpolation is described in terms of regular inputs.
89 struct lp_tgsi_texture_info
91 struct lp_tgsi_channel_info coord
[4];
92 unsigned target
:8; /* TGSI_TEXTURE_* */
93 unsigned unit
:8; /* Sampler unit */
94 unsigned modifier
:8; /* LP_BLD_TEX_MODIFIER_* */
100 struct tgsi_shader_info base
;
103 * Whether any of the texture opcodes access a register file other than
106 * We could also handle TGSI_FILE_CONST/IMMEDIATE here, but there is little
109 unsigned indirect_textures
:1;
112 * Texture opcode description. Aimed at detecting and described direct
116 struct lp_tgsi_texture_info tex
[PIPE_MAX_SAMPLERS
];
119 * Output description. Aimed at detecting and describing simple blit
122 struct lp_tgsi_channel_info output
[PIPE_MAX_SHADER_OUTPUTS
][4];
125 * Shortcut pointers into the above (for fragment shaders).
127 const struct lp_tgsi_channel_info
*cbuf
[PIPE_MAX_COLOR_BUFS
];
131 * Sampler code generation interface.
133 * Although texture sampling is a requirement for TGSI translation, it is
134 * a very different problem with several different approaches to it. This
135 * structure establishes an interface for texture sampling code generation, so
136 * that we can easily use different texture sampling strategies.
138 struct lp_build_sampler_soa
141 (*destroy
)( struct lp_build_sampler_soa
*sampler
);
144 (*emit_fetch_texel
)( const struct lp_build_sampler_soa
*sampler
,
145 struct gallivm_state
*gallivm
,
149 const LLVMValueRef
*coords
,
150 const LLVMValueRef
*ddx
,
151 const LLVMValueRef
*ddy
,
152 LLVMValueRef lod_bias
, /* optional */
153 LLVMValueRef explicit_lod
, /* optional */
154 LLVMValueRef
*texel
);
158 struct lp_build_sampler_aos
161 (*emit_fetch_texel
)( struct lp_build_sampler_aos
*sampler
,
162 struct lp_build_context
*bld
,
163 unsigned target
, /* TGSI_TEXTURE_* */
168 enum lp_build_tex_modifier modifier
);
173 lp_build_tgsi_info(const struct tgsi_token
*tokens
,
174 struct lp_tgsi_info
*info
);
178 lp_build_tgsi_soa(struct gallivm_state
*gallivm
,
179 const struct tgsi_token
*tokens
,
181 struct lp_build_mask_context
*mask
,
182 LLVMValueRef consts_ptr
,
183 LLVMValueRef system_values_array
,
184 const LLVMValueRef
*pos
,
185 const LLVMValueRef (*inputs
)[4],
186 LLVMValueRef (*outputs
)[4],
187 struct lp_build_sampler_soa
*sampler
,
188 const struct tgsi_shader_info
*info
);
192 lp_build_tgsi_aos(struct gallivm_state
*gallivm
,
193 const struct tgsi_token
*tokens
,
195 const unsigned char swizzles
[4],
196 LLVMValueRef consts_ptr
,
197 const LLVMValueRef
*inputs
,
198 LLVMValueRef
*outputs
,
199 struct lp_build_sampler_aos
*sampler
,
200 const struct tgsi_shader_info
*info
);
204 lp_build_system_values_array(struct gallivm_state
*gallivm
,
205 const struct tgsi_shader_info
*info
,
206 LLVMValueRef instance_id
,
207 LLVMValueRef facing
);
210 #endif /* LP_BLD_TGSI_H */