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 **************************************************************************/
32 * @author Jose Fonseca <jfonseca@vmware.com>
35 #ifndef LP_BLD_SAMPLE_H
36 #define LP_BLD_SAMPLE_H
39 #include "pipe/p_format.h"
40 #include "util/u_debug.h"
41 #include "gallivm/lp_bld.h"
42 #include "gallivm/lp_bld_type.h"
43 #include "gallivm/lp_bld_swizzle.h"
47 struct pipe_sampler_view
;
48 struct pipe_sampler_state
;
49 struct util_format_description
;
51 struct lp_build_context
;
55 * Helper struct holding all derivatives needed for sampling
59 LLVMValueRef ddx_ddy
[2];
64 * Sampler static state.
66 * These are the bits of state from pipe_resource and pipe_sampler_state that
67 * are embedded in the generated code.
69 struct lp_sampler_static_state
71 /* pipe_sampler_view's state */
72 enum pipe_format format
;
73 unsigned swizzle_r
:3; /**< PIPE_SWIZZLE_* */
78 /* pipe_texture's state */
79 unsigned target
:3; /**< PIPE_TEXTURE_* */
80 unsigned pot_width
:1; /**< is the width a power of two? */
81 unsigned pot_height
:1;
84 /* pipe_sampler_state's state */
88 unsigned min_img_filter
:2;
89 unsigned min_mip_filter
:2;
90 unsigned mag_img_filter
:2;
91 unsigned compare_mode
:1;
92 unsigned compare_func
:3;
93 unsigned normalized_coords
:1;
94 unsigned min_max_lod_equal
:1; /**< min_lod == max_lod ? */
95 unsigned lod_bias_non_zero
:1;
96 unsigned apply_min_lod
:1; /**< min_lod > 0 ? */
97 unsigned apply_max_lod
:1; /**< max_lod < last_level ? */
100 unsigned force_nearest_s
:1;
101 unsigned force_nearest_t
:1;
106 * Sampler dynamic state.
108 * These are the bits of state from pipe_resource and pipe_sampler_state that
109 * are computed in runtime.
111 * There are obtained through callbacks, as we don't want to tie the texture
112 * sampling code generation logic to any particular texture layout or pipe
115 struct lp_sampler_dynamic_state
118 /** Obtain the base texture width (returns int32) */
120 (*width
)( const struct lp_sampler_dynamic_state
*state
,
121 struct gallivm_state
*gallivm
,
124 /** Obtain the base texture height (returns int32) */
126 (*height
)( const struct lp_sampler_dynamic_state
*state
,
127 struct gallivm_state
*gallivm
,
130 /** Obtain the base texture depth (returns int32) */
132 (*depth
)( const struct lp_sampler_dynamic_state
*state
,
133 struct gallivm_state
*gallivm
,
136 /** Obtain the first mipmap level (base level) (returns int32) */
138 (*first_level
)( const struct lp_sampler_dynamic_state
*state
,
139 struct gallivm_state
*gallivm
,
142 /** Obtain the number of mipmap levels minus one (returns int32) */
144 (*last_level
)( const struct lp_sampler_dynamic_state
*state
,
145 struct gallivm_state
*gallivm
,
148 /** Obtain stride in bytes between image rows/blocks (returns int32) */
150 (*row_stride
)( const struct lp_sampler_dynamic_state
*state
,
151 struct gallivm_state
*gallivm
,
154 /** Obtain stride in bytes between image slices (returns int32) */
156 (*img_stride
)( const struct lp_sampler_dynamic_state
*state
,
157 struct gallivm_state
*gallivm
,
160 /** Obtain pointer to array of pointers to mimpap levels */
162 (*data_ptr
)( const struct lp_sampler_dynamic_state
*state
,
163 struct gallivm_state
*gallivm
,
166 /** Obtain texture min lod (returns float) */
168 (*min_lod
)(const struct lp_sampler_dynamic_state
*state
,
169 struct gallivm_state
*gallivm
, unsigned unit
);
171 /** Obtain texture max lod (returns float) */
173 (*max_lod
)(const struct lp_sampler_dynamic_state
*state
,
174 struct gallivm_state
*gallivm
, unsigned unit
);
176 /** Obtain texture lod bias (returns float) */
178 (*lod_bias
)(const struct lp_sampler_dynamic_state
*state
,
179 struct gallivm_state
*gallivm
, unsigned unit
);
181 /** Obtain texture border color (returns ptr to float[4]) */
183 (*border_color
)(const struct lp_sampler_dynamic_state
*state
,
184 struct gallivm_state
*gallivm
, unsigned unit
);
189 * Keep all information for sampling code generation in a single place.
191 struct lp_build_sample_context
193 struct gallivm_state
*gallivm
;
195 const struct lp_sampler_static_state
*static_state
;
197 struct lp_sampler_dynamic_state
*dynamic_state
;
199 const struct util_format_description
*format_desc
;
201 /* See texture_dims() */
204 /** SIMD vector width */
205 unsigned vector_width
;
207 /** regular scalar float type */
208 struct lp_type float_type
;
209 struct lp_build_context float_bld
;
211 /** float vector type */
212 struct lp_build_context float_vec_bld
;
214 /** regular scalar int type */
215 struct lp_type int_type
;
216 struct lp_build_context int_bld
;
218 /** Incoming coordinates type and build context */
219 struct lp_type coord_type
;
220 struct lp_build_context coord_bld
;
222 /** Signed integer coordinates */
223 struct lp_type int_coord_type
;
224 struct lp_build_context int_coord_bld
;
226 /** Unsigned integer texture size */
227 struct lp_type int_size_type
;
228 struct lp_build_context int_size_bld
;
230 /** Unsigned integer texture size */
231 struct lp_type float_size_type
;
232 struct lp_build_context float_size_bld
;
234 /** Output texels type and build context */
235 struct lp_type texel_type
;
236 struct lp_build_context texel_bld
;
238 /** Float per-quad type */
239 struct lp_type perquadf_type
;
240 struct lp_build_context perquadf_bld
;
242 /** Int per-quad type */
243 struct lp_type perquadi_type
;
244 struct lp_build_context perquadi_bld
;
246 /* Common dynamic state values */
247 LLVMValueRef row_stride_array
;
248 LLVMValueRef img_stride_array
;
249 LLVMValueRef data_array
;
251 /** Integer vector with texture width, height, depth */
252 LLVMValueRef int_size
;
258 * We only support a few wrap modes in lp_build_sample_wrap_linear_int() at
259 * this time. Return whether the given mode is supported by that function.
261 static INLINE boolean
262 lp_is_simple_wrap_mode(unsigned mode
)
265 case PIPE_TEX_WRAP_REPEAT
:
266 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
275 apply_sampler_swizzle(struct lp_build_sample_context
*bld
,
278 unsigned char swizzles
[4];
280 swizzles
[0] = bld
->static_state
->swizzle_r
;
281 swizzles
[1] = bld
->static_state
->swizzle_g
;
282 swizzles
[2] = bld
->static_state
->swizzle_b
;
283 swizzles
[3] = bld
->static_state
->swizzle_a
;
285 lp_build_swizzle_soa_inplace(&bld
->texel_bld
, texel
, swizzles
);
289 static INLINE
unsigned
290 texture_dims(enum pipe_texture_target tex
)
293 case PIPE_TEXTURE_1D
:
295 case PIPE_TEXTURE_2D
:
296 case PIPE_TEXTURE_RECT
:
297 case PIPE_TEXTURE_CUBE
:
299 case PIPE_TEXTURE_3D
:
302 assert(0 && "bad texture target in texture_dims()");
309 lp_sampler_wrap_mode_uses_border_color(unsigned mode
,
310 unsigned min_img_filter
,
311 unsigned mag_img_filter
);
314 * Derive the sampler static state.
317 lp_sampler_static_state(struct lp_sampler_static_state
*state
,
318 const struct pipe_sampler_view
*view
,
319 const struct pipe_sampler_state
*sampler
);
323 lp_build_lod_selector(struct lp_build_sample_context
*bld
,
325 const struct lp_derivatives
*derivs
,
326 LLVMValueRef lod_bias
, /* optional */
327 LLVMValueRef explicit_lod
, /* optional */
329 LLVMValueRef
*out_lod_ipart
,
330 LLVMValueRef
*out_lod_fpart
);
333 lp_build_nearest_mip_level(struct lp_build_sample_context
*bld
,
336 LLVMValueRef
*level_out
);
339 lp_build_linear_mip_levels(struct lp_build_sample_context
*bld
,
341 LLVMValueRef lod_ipart
,
342 LLVMValueRef
*lod_fpart_inout
,
343 LLVMValueRef
*level0_out
,
344 LLVMValueRef
*level1_out
);
347 lp_build_get_mipmap_level(struct lp_build_sample_context
*bld
,
352 lp_build_mipmap_level_sizes(struct lp_build_sample_context
*bld
,
354 LLVMValueRef
*out_size_vec
,
355 LLVMValueRef
*row_stride_vec
,
356 LLVMValueRef
*img_stride_vec
);
360 lp_build_extract_image_sizes(struct lp_build_sample_context
*bld
,
361 struct lp_type size_type
,
362 struct lp_type coord_type
,
364 LLVMValueRef
*out_width
,
365 LLVMValueRef
*out_height
,
366 LLVMValueRef
*out_depth
);
370 lp_build_unnormalized_coords(struct lp_build_sample_context
*bld
,
371 LLVMValueRef flt_size
,
378 lp_build_cube_lookup(struct lp_build_sample_context
*bld
,
383 LLVMValueRef
*face_s
,
384 LLVMValueRef
*face_t
);
388 lp_build_sample_partial_offset(struct lp_build_context
*bld
,
389 unsigned block_length
,
392 LLVMValueRef
*out_offset
,
393 LLVMValueRef
*out_i
);
397 lp_build_sample_offset(struct lp_build_context
*bld
,
398 const struct util_format_description
*format_desc
,
402 LLVMValueRef y_stride
,
403 LLVMValueRef z_stride
,
404 LLVMValueRef
*out_offset
,
406 LLVMValueRef
*out_j
);
410 lp_build_sample_soa(struct gallivm_state
*gallivm
,
411 const struct lp_sampler_static_state
*static_state
,
412 struct lp_sampler_dynamic_state
*dynamic_state
,
413 struct lp_type fp_type
,
416 const LLVMValueRef
*coords
,
417 const struct lp_derivatives
*derivs
,
418 LLVMValueRef lod_bias
,
419 LLVMValueRef explicit_lod
,
420 LLVMValueRef texel_out
[4]);
424 lp_build_coord_repeat_npot_linear(struct lp_build_sample_context
*bld
,
425 LLVMValueRef coord_f
,
426 LLVMValueRef length_i
,
427 LLVMValueRef length_f
,
428 LLVMValueRef
*coord0_i
,
429 LLVMValueRef
*weight_f
);
433 lp_build_size_query_soa(struct gallivm_state
*gallivm
,
434 const struct lp_sampler_static_state
*static_state
,
435 struct lp_sampler_dynamic_state
*dynamic_state
,
436 struct lp_type int_type
,
438 LLVMValueRef explicit_lod
,
439 LLVMValueRef
*sizes_out
);
442 lp_build_sample_nop(struct gallivm_state
*gallivm
,
445 const LLVMValueRef
*coords
,
446 LLVMValueRef texel_out
[4]);
450 lp_build_minify(struct lp_build_context
*bld
,
451 LLVMValueRef base_size
,
455 #endif /* LP_BLD_SAMPLE_H */