92f3c57435a137a368d72dc457f99a99e2e5b4ef
[profile/ivi/mesa.git] / src / gallium / auxiliary / gallivm / lp_bld_sample.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  * Texture sampling.
31  *
32  * @author Jose Fonseca <jfonseca@vmware.com>
33  */
34
35 #ifndef LP_BLD_SAMPLE_H
36 #define LP_BLD_SAMPLE_H
37
38
39 #include "gallivm/lp_bld.h"
40
41 struct pipe_texture;
42 struct pipe_sampler_state;
43 struct util_format_description;
44 struct lp_type;
45 struct lp_build_context;
46
47
48 /**
49  * Sampler static state.
50  *
51  * These are the bits of state from pipe_texture and pipe_sampler_state that
52  * are embedded in the generated code.
53  */
54 struct lp_sampler_static_state
55 {
56    /* pipe_texture's state */
57    enum pipe_format format;
58    unsigned target:2;
59    unsigned pot_width:1;
60    unsigned pot_height:1;
61    unsigned pot_depth:1;
62
63    /* pipe_sampler_state's state */
64    unsigned wrap_s:3;
65    unsigned wrap_t:3;
66    unsigned wrap_r:3;
67    unsigned min_img_filter:2;
68    unsigned min_mip_filter:2;
69    unsigned mag_img_filter:2;
70    unsigned compare_mode:1;
71    unsigned compare_func:3;
72    unsigned normalized_coords:1;
73    float lod_bias, min_lod, max_lod;
74    float border_color[4];
75 };
76
77
78 /**
79  * Sampler dynamic state.
80  *
81  * These are the bits of state from pipe_texture and pipe_sampler_state that
82  * are computed in runtime.
83  *
84  * There are obtained through callbacks, as we don't want to tie the texture
85  * sampling code generation logic to any particular texture layout or pipe
86  * driver.
87  */
88 struct lp_sampler_dynamic_state
89 {
90
91    /** Obtain the base texture width. */
92    LLVMValueRef
93    (*width)( struct lp_sampler_dynamic_state *state,
94              LLVMBuilderRef builder,
95              unsigned unit);
96
97    /** Obtain the base texture height. */
98    LLVMValueRef
99    (*height)( struct lp_sampler_dynamic_state *state,
100               LLVMBuilderRef builder,
101               unsigned unit);
102
103    /** Obtain the base texture depth. */
104    LLVMValueRef
105    (*depth)( struct lp_sampler_dynamic_state *state,
106              LLVMBuilderRef builder,
107              unsigned unit);
108
109    /** Obtain the number of mipmap levels (minus one). */
110    LLVMValueRef
111    (*last_level)( struct lp_sampler_dynamic_state *state,
112                   LLVMBuilderRef builder,
113                   unsigned unit);
114
115    LLVMValueRef
116    (*row_stride)( struct lp_sampler_dynamic_state *state,
117                   LLVMBuilderRef builder,
118                   unsigned unit);
119
120    LLVMValueRef
121    (*data_ptr)( struct lp_sampler_dynamic_state *state,
122                 LLVMBuilderRef builder,
123                 unsigned unit);
124
125 };
126
127
128 /**
129  * Derive the sampler static state.
130  */
131 void
132 lp_sampler_static_state(struct lp_sampler_static_state *state,
133                         const struct pipe_texture *texture,
134                         const struct pipe_sampler_state *sampler);
135
136
137 LLVMValueRef
138 lp_build_gather(LLVMBuilderRef builder,
139                 unsigned length,
140                 unsigned src_width,
141                 unsigned dst_width,
142                 LLVMValueRef base_ptr,
143                 LLVMValueRef offsets);
144
145
146 LLVMValueRef
147 lp_build_sample_offset(struct lp_build_context *bld,
148                        const struct util_format_description *format_desc,
149                        LLVMValueRef x,
150                        LLVMValueRef y,
151                        LLVMValueRef z,
152                        LLVMValueRef y_stride,
153                        LLVMValueRef z_stride);
154
155
156 void
157 lp_build_sample_soa(LLVMBuilderRef builder,
158                     const struct lp_sampler_static_state *static_state,
159                     struct lp_sampler_dynamic_state *dynamic_state,
160                     struct lp_type fp_type,
161                     unsigned unit,
162                     unsigned num_coords,
163                     const LLVMValueRef *coords,
164                     LLVMValueRef lodbias,
165                     LLVMValueRef *texel);
166
167
168
169 #endif /* LP_BLD_SAMPLE_H */