util: Include missing header in u_draw.h.
[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 "pipe/p_format.h"
40
41 #include "gallivm/lp_bld.h"
42
43 struct pipe_resource;
44 struct pipe_sampler_view;
45 struct pipe_sampler_state;
46 struct util_format_description;
47 struct lp_type;
48 struct lp_build_context;
49
50
51 /**
52 * Sampler static state.
53 *
54 * These are the bits of state from pipe_resource and pipe_sampler_state that
55 * are embedded in the generated code.
56 */
57 struct lp_sampler_static_state
58 {
59 /* pipe_sampler_view's state */
60 enum pipe_format format;
61 unsigned swizzle_r:3; /**< PIPE_SWIZZLE_* */
62 unsigned swizzle_g:3;
63 unsigned swizzle_b:3;
64 unsigned swizzle_a:3;
65
66 /* pipe_texture's state */
67 unsigned target:3; /**< PIPE_TEXTURE_* */
68 unsigned pot_width:1; /**< is the width a power of two? */
69 unsigned pot_height:1;
70 unsigned pot_depth:1;
71
72 /* pipe_sampler_state's state */
73 unsigned wrap_s:3;
74 unsigned wrap_t:3;
75 unsigned wrap_r:3;
76 unsigned min_img_filter:2;
77 unsigned min_mip_filter:2;
78 unsigned mag_img_filter:2;
79 unsigned compare_mode:1;
80 unsigned compare_func:3;
81 unsigned normalized_coords:1;
82 float lod_bias, min_lod, max_lod;
83 float border_color[4];
84 };
85
86
87 /**
88 * Sampler dynamic state.
89 *
90 * These are the bits of state from pipe_resource and pipe_sampler_state that
91 * are computed in runtime.
92 *
93 * There are obtained through callbacks, as we don't want to tie the texture
94 * sampling code generation logic to any particular texture layout or pipe
95 * driver.
96 */
97 struct lp_sampler_dynamic_state
98 {
99
100 /** Obtain the base texture width. */
101 LLVMValueRef
102 (*width)( const struct lp_sampler_dynamic_state *state,
103 LLVMBuilderRef builder,
104 unsigned unit);
105
106 /** Obtain the base texture height. */
107 LLVMValueRef
108 (*height)( const struct lp_sampler_dynamic_state *state,
109 LLVMBuilderRef builder,
110 unsigned unit);
111
112 /** Obtain the base texture depth. */
113 LLVMValueRef
114 (*depth)( const struct lp_sampler_dynamic_state *state,
115 LLVMBuilderRef builder,
116 unsigned unit);
117
118 /** Obtain the number of mipmap levels (minus one). */
119 LLVMValueRef
120 (*last_level)( const struct lp_sampler_dynamic_state *state,
121 LLVMBuilderRef builder,
122 unsigned unit);
123
124 LLVMValueRef
125 (*row_stride)( const struct lp_sampler_dynamic_state *state,
126 LLVMBuilderRef builder,
127 unsigned unit);
128
129 LLVMValueRef
130 (*img_stride)( const struct lp_sampler_dynamic_state *state,
131 LLVMBuilderRef builder,
132 unsigned unit);
133
134 LLVMValueRef
135 (*data_ptr)( const struct lp_sampler_dynamic_state *state,
136 LLVMBuilderRef builder,
137 unsigned unit);
138
139 };
140
141
142 /**
143 * Derive the sampler static state.
144 */
145 void
146 lp_sampler_static_state(struct lp_sampler_static_state *state,
147 const struct pipe_sampler_view *view,
148 const struct pipe_sampler_state *sampler);
149
150
151 void
152 lp_build_sample_offset(struct lp_build_context *bld,
153 const struct util_format_description *format_desc,
154 LLVMValueRef x,
155 LLVMValueRef y,
156 LLVMValueRef z,
157 LLVMValueRef y_stride,
158 LLVMValueRef z_stride,
159 LLVMValueRef *out_offset,
160 LLVMValueRef *out_i,
161 LLVMValueRef *out_j);
162
163
164 void
165 lp_build_sample_soa(LLVMBuilderRef builder,
166 const struct lp_sampler_static_state *static_state,
167 struct lp_sampler_dynamic_state *dynamic_state,
168 struct lp_type fp_type,
169 unsigned unit,
170 unsigned num_coords,
171 const LLVMValueRef *coords,
172 const LLVMValueRef *ddx,
173 const LLVMValueRef *ddy,
174 LLVMValueRef lod_bias,
175 LLVMValueRef explicit_lod,
176 LLVMValueRef texel_out[4]);
177
178
179
180 #endif /* LP_BLD_SAMPLE_H */