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
;
51 enum lp_build_tex_modifier
{
52 LP_BLD_TEX_MODIFIER_NONE
= 0,
53 LP_BLD_TEX_MODIFIER_PROJECTED
,
54 LP_BLD_TEX_MODIFIER_LOD_BIAS
,
55 LP_BLD_TEX_MODIFIER_EXPLICIT_LOD
,
56 LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV
61 * Describe a channel of a register.
64 * - immediate value (i.e. derived from a IMM register)
67 * - undetermined (when .file == TGSI_FILE_NULL)
69 * This is one of the analysis results, and is used to described
70 * the output color in terms of inputs.
72 struct lp_tgsi_channel_info
74 unsigned file
:4; /* TGSI_FILE_* */
75 unsigned swizzle
:3; /* PIPE_SWIZZLE_x */
78 float value
; /* for TGSI_FILE_IMMEDIATE */
84 * Describe a texture sampler interpolator.
86 * The interpolation is described in terms of regular inputs.
88 struct lp_tgsi_texture_info
90 struct lp_tgsi_channel_info coord
[4];
91 unsigned target
:8; /* TGSI_TEXTURE_* */
92 unsigned unit
:8; /* Sampler unit */
93 unsigned modifier
:8; /* LP_BLD_TEX_MODIFIER_* */
99 struct tgsi_shader_info base
;
102 * Whether any of the texture opcodes access a register file other than
105 * We could also handle TGSI_FILE_CONST/IMMEDIATE here, but there is little
108 unsigned indirect_textures
:1;
111 * Texture opcode description. Aimed at detecting and described direct
115 struct lp_tgsi_texture_info tex
[PIPE_MAX_SAMPLERS
];
118 * Output description. Aimed at detecting and describing simple blit
121 struct lp_tgsi_channel_info output
[PIPE_MAX_SHADER_OUTPUTS
][4];
124 * Shortcut pointers into the above (for fragment shaders).
126 const struct lp_tgsi_channel_info
*cbuf
[PIPE_MAX_COLOR_BUFS
];
130 * Sampler code generation interface.
132 * Although texture sampling is a requirement for TGSI translation, it is
133 * a very different problem with several different approaches to it. This
134 * structure establishes an interface for texture sampling code generation, so
135 * that we can easily use different texture sampling strategies.
137 struct lp_build_sampler_soa
140 (*destroy
)( struct lp_build_sampler_soa
*sampler
);
143 (*emit_fetch_texel
)( const struct lp_build_sampler_soa
*sampler
,
144 LLVMBuilderRef builder
,
148 const LLVMValueRef
*coords
,
149 const LLVMValueRef
*ddx
,
150 const LLVMValueRef
*ddy
,
151 LLVMValueRef lod_bias
, /* optional */
152 LLVMValueRef explicit_lod
, /* optional */
153 LLVMValueRef
*texel
);
157 struct lp_build_sampler_aos
160 (*emit_fetch_texel
)( struct lp_build_sampler_aos
*sampler
,
161 struct lp_build_context
*bld
,
162 unsigned target
, /* TGSI_TEXTURE_* */
167 enum lp_build_tex_modifier modifier
);
172 lp_build_tgsi_info(const struct tgsi_token
*tokens
,
173 struct lp_tgsi_info
*info
);
177 lp_build_tgsi_soa(LLVMBuilderRef builder
,
178 const struct tgsi_token
*tokens
,
180 struct lp_build_mask_context
*mask
,
181 LLVMValueRef consts_ptr
,
182 const LLVMValueRef
*pos
,
183 const LLVMValueRef (*inputs
)[4],
184 LLVMValueRef (*outputs
)[4],
185 struct lp_build_sampler_soa
*sampler
,
186 const struct tgsi_shader_info
*info
);
190 lp_build_tgsi_aos(LLVMBuilderRef builder
,
191 const struct tgsi_token
*tokens
,
193 const unsigned char swizzles
[4],
194 LLVMValueRef consts_ptr
,
195 const LLVMValueRef
*inputs
,
196 LLVMValueRef
*outputs
,
197 struct lp_build_sampler_aos
*sampler
,
198 const struct tgsi_shader_info
*info
);
201 #endif /* LP_BLD_TGSI_H */