Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / gallium / auxiliary / gallivm / lp_bld_tgsi.h
1 /**************************************************************************
2  *
3  * Copyright 2009 VMware, Inc.
4  * All Rights Reserved.
5  *
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:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
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.
25  *
26  **************************************************************************/
27
28 /**
29  * @file
30  * TGSI to LLVM IR translation.
31  *
32  * @author Jose Fonseca <jfonseca@vmware.com>
33  */
34
35 #ifndef LP_BLD_TGSI_H
36 #define LP_BLD_TGSI_H
37
38 #include "gallivm/lp_bld.h"
39 #include "pipe/p_compiler.h"
40 #include "pipe/p_state.h"
41 #include "tgsi/tgsi_scan.h"
42
43
44 struct tgsi_token;
45 struct tgsi_shader_info;
46 struct lp_type;
47 struct lp_build_context;
48 struct lp_build_mask_context;
49 struct gallivm_state;
50
51
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
58 };
59
60
61 /**
62  * Describe a channel of a register.
63  *
64  * The value can be a:
65  * - immediate value (i.e. derived from a IMM register)
66  * - CONST[n].x/y/z/w
67  * - IN[n].x/y/z/w
68  * - undetermined (when .file == TGSI_FILE_NULL)
69  *
70  * This is one of the analysis results, and is used to described
71  * the output color in terms of inputs.
72  */
73 struct lp_tgsi_channel_info
74 {
75    unsigned file:4; /* TGSI_FILE_* */
76    unsigned swizzle:3; /* PIPE_SWIZZLE_x */
77    union {
78       uint32_t index;
79       float value; /* for TGSI_FILE_IMMEDIATE */
80    } u;
81 };
82
83
84 /**
85  * Describe a texture sampler interpolator.
86  *
87  * The interpolation is described in terms of regular inputs.
88  */
89 struct lp_tgsi_texture_info
90 {
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_* */
95 };
96
97
98 struct lp_tgsi_info
99 {
100    struct tgsi_shader_info base;
101
102    /*
103     * Whether any of the texture opcodes access a register file other than
104     * TGSI_FILE_INPUT.
105     *
106     * We could also handle TGSI_FILE_CONST/IMMEDIATE here, but there is little
107     * benefit.
108     */
109    unsigned indirect_textures:1;
110
111    /*
112     * Texture opcode description. Aimed at detecting and described direct
113     * texture opcodes.
114     */
115    unsigned num_texs;
116    struct lp_tgsi_texture_info tex[PIPE_MAX_SAMPLERS];
117
118    /*
119     * Output description. Aimed at detecting and describing simple blit
120     * shaders.
121     */
122    struct lp_tgsi_channel_info output[PIPE_MAX_SHADER_OUTPUTS][4];
123
124    /*
125     * Shortcut pointers into the above (for fragment shaders).
126     */
127    const struct lp_tgsi_channel_info *cbuf[PIPE_MAX_COLOR_BUFS];
128 };
129
130 /**
131  * Sampler code generation interface.
132  *
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.
137  */
138 struct lp_build_sampler_soa
139 {
140    void
141    (*destroy)( struct lp_build_sampler_soa *sampler );
142
143    void
144    (*emit_fetch_texel)( const struct lp_build_sampler_soa *sampler,
145                         struct gallivm_state *gallivm,
146                         struct lp_type type,
147                         unsigned unit,
148                         unsigned num_coords,
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);
155 };
156
157
158 struct lp_build_sampler_aos
159 {
160    LLVMValueRef
161    (*emit_fetch_texel)( struct lp_build_sampler_aos *sampler,
162                         struct lp_build_context *bld,
163                         unsigned target, /* TGSI_TEXTURE_* */
164                         unsigned unit,
165                         LLVMValueRef coords,
166                         LLVMValueRef ddx,
167                         LLVMValueRef ddy,
168                         enum lp_build_tex_modifier modifier);
169 };
170
171
172 void
173 lp_build_tgsi_info(const struct tgsi_token *tokens,
174                    struct lp_tgsi_info *info);
175
176
177 void
178 lp_build_tgsi_soa(struct gallivm_state *gallivm,
179                   const struct tgsi_token *tokens,
180                   struct lp_type type,
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);
189
190
191 void
192 lp_build_tgsi_aos(struct gallivm_state *gallivm,
193                   const struct tgsi_token *tokens,
194                   struct lp_type type,
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);
201
202
203 LLVMValueRef
204 lp_build_system_values_array(struct gallivm_state *gallivm,
205                              const struct tgsi_shader_info *info,
206                              LLVMValueRef instance_id,
207                              LLVMValueRef facing);
208
209
210 #endif /* LP_BLD_TGSI_H */