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_state.h"
40 #include "util/format/u_formats.h"
41 #include "util/u_debug.h"
42 #include "gallivm/lp_bld.h"
43 #include "gallivm/lp_bld_type.h"
44 #include "gallivm/lp_bld_swizzle.h"
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 #define LP_MAX_TEXEL_BUFFER_ELEMENTS 134217728
51
52 struct util_format_description;
53 struct lp_type;
54 struct lp_build_context;
55
56
57 /**
58 * Helper struct holding all derivatives needed for sampling
59 */
60 struct lp_derivatives
61 {
62 LLVMValueRef ddx[3];
63 LLVMValueRef ddy[3];
64 };
65
66
67 enum lp_sampler_lod_property {
68 LP_SAMPLER_LOD_SCALAR,
69 LP_SAMPLER_LOD_PER_ELEMENT,
70 LP_SAMPLER_LOD_PER_QUAD
71 };
72
73
74 enum lp_sampler_lod_control {
75 LP_SAMPLER_LOD_IMPLICIT,
76 LP_SAMPLER_LOD_BIAS,
77 LP_SAMPLER_LOD_EXPLICIT,
78 LP_SAMPLER_LOD_DERIVATIVES,
79 };
80
81
82 enum lp_sampler_op_type {
83 LP_SAMPLER_OP_TEXTURE,
84 LP_SAMPLER_OP_FETCH,
85 LP_SAMPLER_OP_GATHER,
86 LP_SAMPLER_OP_LODQ
87 };
88
89
90 #define LP_SAMPLER_SHADOW (1 << 0)
91 #define LP_SAMPLER_OFFSETS (1 << 1)
92 #define LP_SAMPLER_OP_TYPE_SHIFT 2
93 #define LP_SAMPLER_OP_TYPE_MASK (3 << 2)
94 #define LP_SAMPLER_LOD_CONTROL_SHIFT 4
95 #define LP_SAMPLER_LOD_CONTROL_MASK (3 << 4)
96 #define LP_SAMPLER_LOD_PROPERTY_SHIFT 6
97 #define LP_SAMPLER_LOD_PROPERTY_MASK (3 << 6)
98 #define LP_SAMPLER_GATHER_COMP_SHIFT 8
99 #define LP_SAMPLER_GATHER_COMP_MASK (3 << 8)
100 #define LP_SAMPLER_FETCH_MS (1 << 10)
101
102
103 /* Parameters used to handle TEX instructions */
104 struct lp_sampler_params
105 {
106 struct lp_type type;
107 unsigned texture_index;
108 unsigned sampler_index;
109 LLVMValueRef texture_index_offset;
110 unsigned sample_key;
111 LLVMTypeRef resources_type;
112 LLVMValueRef resources_ptr;
113 LLVMTypeRef thread_data_type;
114 LLVMValueRef thread_data_ptr;
115 const LLVMValueRef *coords;
116 const LLVMValueRef *offsets;
117 LLVMValueRef ms_index;
118 LLVMValueRef lod;
119 LLVMValueRef aniso_filter_table;
120 const struct lp_derivatives *derivs;
121 LLVMValueRef *texel;
122
123 LLVMValueRef texture_resource;
124 LLVMValueRef sampler_resource;
125 LLVMValueRef exec_mask;
126 };
127
128 /* Parameters used to handle sampler_size instructions */
129 struct lp_sampler_size_query_params
130 {
131 struct lp_type int_type;
132 unsigned texture_unit;
133 LLVMValueRef texture_unit_offset;
134 unsigned target;
135 LLVMTypeRef resources_type;
136 LLVMValueRef resources_ptr;
137 bool is_sviewinfo;
138 bool samples_only;
139 bool ms;
140 enum lp_sampler_lod_property lod_property;
141 LLVMValueRef explicit_lod;
142 LLVMValueRef *sizes_out;
143
144 LLVMValueRef resource;
145 LLVMValueRef exec_mask;
146 enum pipe_format format;
147 };
148
149 #define LP_IMG_LOAD 0
150 #define LP_IMG_STORE 1
151 #define LP_IMG_ATOMIC 2
152 #define LP_IMG_ATOMIC_CAS 3
153 #define LP_IMG_OP_COUNT 4
154
155 struct lp_img_params
156 {
157 struct lp_type type;
158 unsigned image_index;
159 LLVMValueRef image_index_offset;
160 unsigned img_op;
161 unsigned target;
162 LLVMAtomicRMWBinOp op;
163 LLVMValueRef exec_mask;
164 LLVMTypeRef resources_type;
165 LLVMValueRef resources_ptr;
166 LLVMTypeRef thread_data_type;
167 LLVMValueRef thread_data_ptr;
168 const LLVMValueRef *coords;
169 LLVMValueRef ms_index;
170 LLVMValueRef indata[4];
171 LLVMValueRef indata2[4];
172 LLVMValueRef *outdata;
173
174 LLVMValueRef resource;
175 enum pipe_format format;
176 };
177
178
179 /**
180 * Texture static state.
181 *
182 * These are the bits of state from pipe_resource/pipe_sampler_view that
183 * are embedded in the generated code.
184 */
185 struct lp_static_texture_state
186 {
187 /* pipe_sampler_view's state */
188 enum pipe_format format;
189 enum pipe_format res_format;
190 unsigned swizzle_r:3; /**< PIPE_SWIZZLE_* */
191 unsigned swizzle_g:3;
192 unsigned swizzle_b:3;
193 unsigned swizzle_a:3;
194
195 /* pipe_texture's state */
196 enum pipe_texture_target target:5; /**< PIPE_TEXTURE_* */
197 unsigned pot_width:1; /**< is the width a power of two? */
198 unsigned pot_height:1;
199 unsigned pot_depth:1;
200 unsigned level_zero_only:1;
201 };
202
203
204 /**
205 * Sampler static state.
206 *
207 * These are the bits of state from pipe_sampler_state that
208 * are embedded in the generated code.
209 */
210 struct lp_static_sampler_state
211 {
212 /* pipe_sampler_state's state */
213 unsigned wrap_s:3;
214 unsigned wrap_t:3;
215 unsigned wrap_r:3;
216 unsigned min_img_filter:2;
217 unsigned min_mip_filter:2;
218 unsigned mag_img_filter:2;
219 unsigned compare_mode:1;
220 unsigned compare_func:3;
221 unsigned normalized_coords:1;
222 unsigned min_max_lod_equal:1; /**< min_lod == max_lod ? */
223 unsigned lod_bias_non_zero:1;
224 unsigned max_lod_pos:1;
225 unsigned apply_min_lod:1; /**< min_lod > 0 ? */
226 unsigned apply_max_lod:1; /**< max_lod < last_level ? */
227 unsigned seamless_cube_map:1;
228 unsigned aniso:1;
229 unsigned reduction_mode:2;
230 };
231
232
233 /**
234 * Sampler dynamic state.
235 *
236 * These are the bits of state from pipe_resource/pipe_sampler_view
237 * as well as from sampler state that are computed at runtime.
238 *
239 * There are obtained through callbacks, as we don't want to tie the texture
240 * sampling code generation logic to any particular texture layout or pipe
241 * driver.
242 */
243 struct lp_sampler_dynamic_state
244 {
245 /* First callbacks for sampler view state */
246
247 /** Obtain the base texture width (or number of elements) (returns int32) */
248 LLVMValueRef
249 (*width)(struct gallivm_state *gallivm,
250 LLVMTypeRef resources_type,
251 LLVMValueRef resources_ptr,
252 unsigned texture_unit, LLVMValueRef texture_unit_offset);
253
254 /** Obtain the base texture height (returns int32) */
255 LLVMValueRef
256 (*height)(struct gallivm_state *gallivm,
257 LLVMTypeRef resources_type,
258 LLVMValueRef resources_ptr,
259 unsigned texture_unit, LLVMValueRef texture_unit_offset);
260
261 /** Obtain the base texture depth (or array size) (returns int32) */
262 LLVMValueRef
263 (*depth)(struct gallivm_state *gallivm,
264 LLVMTypeRef resources_type,
265 LLVMValueRef resources_ptr,
266 unsigned texture_unit, LLVMValueRef texture_unit_offset);
267
268 /** Obtain the first mipmap level (base level) (returns int32) */
269 LLVMValueRef
270 (*first_level)(struct gallivm_state *gallivm,
271 LLVMTypeRef resources_type,
272 LLVMValueRef resources_ptr,
273 unsigned texture_unit, LLVMValueRef texture_unit_offset);
274
275 /** Obtain the number of mipmap levels minus one (returns int32) */
276 LLVMValueRef
277 (*last_level)(struct gallivm_state *gallivm,
278 LLVMTypeRef resources_type,
279 LLVMValueRef resources_ptr,
280 unsigned texture_unit, LLVMValueRef texture_unit_offset);
281
282 /** Obtain stride in bytes between image rows/blocks (returns int32) */
283 LLVMValueRef
284 (*row_stride)(struct gallivm_state *gallivm,
285 LLVMTypeRef resources_type,
286 LLVMValueRef resources_ptr,
287 unsigned texture_unit, LLVMValueRef texture_unit_offset,
288 LLVMTypeRef *out_type);
289
290 /** Obtain stride in bytes between image slices (returns int32) */
291 LLVMValueRef
292 (*img_stride)(struct gallivm_state *gallivm,
293 LLVMTypeRef resources_type,
294 LLVMValueRef resources_ptr,
295 unsigned texture_unit, LLVMValueRef texture_unit_offset,\
296 LLVMTypeRef *out_type);
297
298 /** Obtain pointer to base of texture */
299 LLVMValueRef
300 (*base_ptr)(struct gallivm_state *gallivm,
301 LLVMTypeRef resources_type,
302 LLVMValueRef resources_ptr,
303 unsigned texture_unit, LLVMValueRef texture_unit_offset);
304
305 /** Obtain pointer to array of mipmap offsets */
306 LLVMValueRef
307 (*mip_offsets)(struct gallivm_state *gallivm,
308 LLVMTypeRef resources_type,
309 LLVMValueRef resources_ptr,
310 unsigned texture_unit, LLVMValueRef texture_unit_offset,
311 LLVMTypeRef *out_type);
312
313 /** Obtain number of samples (returns int32) */
314 LLVMValueRef
315 (*num_samples)(struct gallivm_state *gallivm,
316 LLVMTypeRef resources_type,
317 LLVMValueRef resources_ptr,
318 unsigned texture_unit, LLVMValueRef texture_unit_offset);
319
320 /** Obtain multisample stride (returns int32) */
321 LLVMValueRef
322 (*sample_stride)(struct gallivm_state *gallivm,
323 LLVMTypeRef resources_type,
324 LLVMValueRef resources_ptr,
325 unsigned texture_unit, LLVMValueRef texture_unit_offset);
326
327 /* These are callbacks for sampler state */
328
329 /** Obtain texture min lod (returns float) */
330 LLVMValueRef
331 (*min_lod)(struct gallivm_state *gallivm,
332 LLVMTypeRef resources_type,
333 LLVMValueRef resources_ptr,
334 unsigned sampler_unit);
335
336 /** Obtain texture max lod (returns float) */
337 LLVMValueRef
338 (*max_lod)(struct gallivm_state *gallivm,
339 LLVMTypeRef resources_type,
340 LLVMValueRef resources_ptr,
341 unsigned sampler_unit);
342
343 /** Obtain texture lod bias (returns float) */
344 LLVMValueRef
345 (*lod_bias)(struct gallivm_state *gallivm,
346 LLVMTypeRef resources_type,
347 LLVMValueRef resources_ptr,
348 unsigned sampler_unit);
349
350 /** Obtain texture border color (returns ptr to float[4]) */
351 LLVMValueRef
352 (*border_color)(struct gallivm_state *gallivm,
353 LLVMTypeRef resources_type,
354 LLVMValueRef resources_ptr,
355 unsigned sampler_unit);
356
357 /** Obtain maximum anisotropy */
358 LLVMValueRef
359 (*max_aniso)(struct gallivm_state *gallivm,
360 LLVMTypeRef resources_type,
361 LLVMValueRef resources_ptr,
362 unsigned sampler_unit);
363
364 /**
365 * Obtain texture cache (returns ptr to lp_build_format_cache).
366 *
367 * It's optional: no caching will be done if it's NULL.
368 */
369 LLVMValueRef
370 (*cache_ptr)(struct gallivm_state *gallivm,
371 LLVMTypeRef thread_data_type,
372 LLVMValueRef thread_data_ptr,
373 unsigned unit);
374 };
375
376
377 struct lp_build_sampler_soa;
378 struct lp_build_image_soa;
379
380 struct lp_sampler_dynamic_state *
381 lp_build_sampler_soa_dynamic_state(struct lp_build_sampler_soa *sampler);
382
383 struct lp_sampler_dynamic_state *
384 lp_build_image_soa_dynamic_state(struct lp_build_image_soa *_image);
385
386 /**
387 * Keep all information for sampling code generation in a single place.
388 */
389 struct lp_build_sample_context
390 {
391 struct gallivm_state *gallivm;
392
393 const struct lp_static_texture_state *static_texture_state;
394 const struct lp_static_sampler_state *static_sampler_state;
395
396 struct lp_sampler_dynamic_state *dynamic_state;
397
398 const struct util_format_description *format_desc;
399
400 /* See texture_dims() */
401 unsigned dims;
402
403 /** SIMD vector width */
404 unsigned vector_width;
405
406 /** number of mipmaps (valid are 1, length/4, length) */
407 unsigned num_mips;
408
409 /** number of lod values (valid are 1, length/4, length) */
410 unsigned num_lods;
411
412 unsigned gather_comp;
413 bool no_quad_lod;
414 bool no_brilinear;
415 bool no_rho_approx;
416 bool fetch_ms;
417
418 /** regular scalar float type */
419 struct lp_type float_type;
420 struct lp_build_context float_bld;
421
422 /** float vector type */
423 struct lp_build_context float_vec_bld;
424
425 /** regular scalar int type */
426 struct lp_type int_type;
427 struct lp_build_context int_bld;
428
429 /** Incoming coordinates type and build context */
430 struct lp_type coord_type;
431 struct lp_build_context coord_bld;
432
433 /** Signed integer coordinates */
434 struct lp_type int_coord_type;
435 struct lp_build_context int_coord_bld;
436
437 /** Unsigned integer texture size */
438 struct lp_type int_size_in_type;
439 struct lp_build_context int_size_in_bld;
440
441 /** Float incoming texture size */
442 struct lp_type float_size_in_type;
443 struct lp_build_context float_size_in_bld;
444
445 /** Unsigned integer texture size (might be per quad) */
446 struct lp_type int_size_type;
447 struct lp_build_context int_size_bld;
448
449 /** Float texture size (might be per quad) */
450 struct lp_type float_size_type;
451 struct lp_build_context float_size_bld;
452
453 /** Output texels type and build context */
454 struct lp_type texel_type;
455 struct lp_build_context texel_bld;
456
457 /** Float level type */
458 struct lp_type levelf_type;
459 struct lp_build_context levelf_bld;
460
461 /** Int level type */
462 struct lp_type leveli_type;
463 struct lp_build_context leveli_bld;
464
465 /** Float lod type */
466 struct lp_type lodf_type;
467 struct lp_build_context lodf_bld;
468
469 /** Int lod type */
470 struct lp_type lodi_type;
471 struct lp_build_context lodi_bld;
472
473 /* Common dynamic state values */
474 LLVMTypeRef row_stride_type;
475 LLVMValueRef row_stride_array;
476 LLVMTypeRef img_stride_type;
477 LLVMValueRef img_stride_array;
478 LLVMValueRef base_ptr;
479 LLVMTypeRef mip_offsets_type;
480 LLVMValueRef mip_offsets;
481 LLVMValueRef cache;
482
483 /** Integer vector with texture width, height, depth */
484 LLVMValueRef int_size;
485 LLVMValueRef int_tex_blocksize;
486 LLVMValueRef int_tex_blocksize_log2;
487 LLVMValueRef int_view_blocksize;
488
489 LLVMValueRef border_color_clamped;
490
491 LLVMTypeRef resources_type;
492 LLVMValueRef resources_ptr;
493
494 LLVMValueRef aniso_filter_table;
495 };
496
497 /*
498 * Indirect texture access context
499 *
500 * This is used to store info across building
501 * and indirect texture switch statement.
502 */
503 struct lp_build_sample_array_switch {
504 struct gallivm_state *gallivm;
505 struct lp_sampler_params params;
506 unsigned base, range;
507 LLVMValueRef switch_ref;
508 LLVMBasicBlockRef merge_ref;
509 LLVMValueRef phi;
510 };
511
512 struct lp_build_img_op_array_switch {
513 struct gallivm_state *gallivm;
514 struct lp_img_params params;
515 unsigned base, range;
516 LLVMValueRef switch_ref;
517 LLVMBasicBlockRef merge_ref;
518 LLVMValueRef phi[4];
519 };
520
521
522 /**
523 * We only support a few wrap modes in lp_build_sample_wrap_linear_int() at
524 * this time. Return whether the given mode is supported by that function.
525 */
526 static inline bool
lp_is_simple_wrap_mode(unsigned mode)527 lp_is_simple_wrap_mode(unsigned mode)
528 {
529 switch (mode) {
530 case PIPE_TEX_WRAP_REPEAT:
531 case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
532 return true;
533 default:
534 return false;
535 }
536 }
537
538
539 static inline void
apply_sampler_swizzle(struct lp_build_sample_context * bld,LLVMValueRef * texel)540 apply_sampler_swizzle(struct lp_build_sample_context *bld,
541 LLVMValueRef *texel)
542 {
543 unsigned char swizzles[4];
544
545 swizzles[0] = bld->static_texture_state->swizzle_r;
546 swizzles[1] = bld->static_texture_state->swizzle_g;
547 swizzles[2] = bld->static_texture_state->swizzle_b;
548 swizzles[3] = bld->static_texture_state->swizzle_a;
549
550 lp_build_swizzle_soa_inplace(&bld->texel_bld, texel, swizzles);
551 }
552
553 /*
554 * not really dimension as such, this indicates the amount of
555 * "normal" texture coords subject to minification, wrapping etc.
556 */
557 static inline unsigned
texture_dims(enum pipe_texture_target tex)558 texture_dims(enum pipe_texture_target tex)
559 {
560 switch (tex) {
561 case PIPE_TEXTURE_1D:
562 case PIPE_TEXTURE_1D_ARRAY:
563 case PIPE_BUFFER:
564 return 1;
565 case PIPE_TEXTURE_2D:
566 case PIPE_TEXTURE_2D_ARRAY:
567 case PIPE_TEXTURE_RECT:
568 case PIPE_TEXTURE_CUBE:
569 case PIPE_TEXTURE_CUBE_ARRAY:
570 return 2;
571 case PIPE_TEXTURE_3D:
572 return 3;
573 default:
574 assert(0 && "bad texture target in texture_dims()");
575 return 2;
576 }
577 }
578
579
580 static inline bool
has_layer_coord(enum pipe_texture_target tex)581 has_layer_coord(enum pipe_texture_target tex)
582 {
583 switch (tex) {
584 case PIPE_TEXTURE_1D_ARRAY:
585 case PIPE_TEXTURE_2D_ARRAY:
586 /* cube is not layered but 3rd coord (after cube mapping) behaves the same */
587 case PIPE_TEXTURE_CUBE:
588 case PIPE_TEXTURE_CUBE_ARRAY:
589 return true;
590 default:
591 return false;
592 }
593 }
594
595
596 bool
597 lp_sampler_wrap_mode_uses_border_color(enum pipe_tex_wrap mode,
598 enum pipe_tex_filter min_img_filter,
599 enum pipe_tex_filter mag_img_filter);
600
601 /**
602 * Derive the sampler static state.
603 */
604 void
605 lp_sampler_static_sampler_state(struct lp_static_sampler_state *state,
606 const struct pipe_sampler_state *sampler);
607
608
609 void
610 lp_sampler_static_texture_state(struct lp_static_texture_state *state,
611 const struct pipe_sampler_view *view);
612
613 void
614 lp_sampler_static_texture_state_image(struct lp_static_texture_state *state,
615 const struct pipe_image_view *view);
616
617 void
618 lp_build_lod_selector(struct lp_build_sample_context *bld,
619 bool is_lodq,
620 unsigned sampler_index,
621 LLVMValueRef first_level,
622 LLVMValueRef s,
623 LLVMValueRef t,
624 LLVMValueRef r,
625 const struct lp_derivatives *derivs,
626 LLVMValueRef lod_bias, /* optional */
627 LLVMValueRef explicit_lod, /* optional */
628 enum pipe_tex_mipfilter mip_filter,
629 LLVMValueRef max_aniso,
630 LLVMValueRef *out_lod,
631 LLVMValueRef *out_lod_ipart,
632 LLVMValueRef *out_lod_fpart,
633 LLVMValueRef *out_lod_positive);
634
635 void
636 lp_build_nearest_mip_level(struct lp_build_sample_context *bld,
637 LLVMValueRef first_level,
638 LLVMValueRef last_level,
639 LLVMValueRef lod,
640 LLVMValueRef *level_out,
641 LLVMValueRef *out_of_bounds);
642
643 void
644 lp_build_linear_mip_levels(struct lp_build_sample_context *bld,
645 unsigned texture_unit,
646 LLVMValueRef first_level,
647 LLVMValueRef last_level,
648 LLVMValueRef lod_ipart,
649 LLVMValueRef *lod_fpart_inout,
650 LLVMValueRef *level0_out,
651 LLVMValueRef *level1_out);
652
653 LLVMValueRef
654 lp_build_get_mipmap_level(struct lp_build_sample_context *bld,
655 LLVMValueRef level);
656
657
658 LLVMValueRef
659 lp_build_get_mip_offsets(struct lp_build_sample_context *bld,
660 LLVMValueRef level);
661
662
663 void
664 lp_build_mipmap_level_sizes(struct lp_build_sample_context *bld,
665 LLVMValueRef ilevel,
666 LLVMValueRef *out_size_vec,
667 LLVMValueRef *row_stride_vec,
668 LLVMValueRef *img_stride_vec);
669
670 LLVMValueRef
671 lp_build_scale_view_dims(struct lp_build_context *bld, LLVMValueRef size,
672 LLVMValueRef tex_blocksize,
673 LLVMValueRef tex_blocksize_log2,
674 LLVMValueRef view_blocksize);
675
676 LLVMValueRef
677 lp_build_scale_view_dim(struct gallivm_state *gallivm, LLVMValueRef size,
678 unsigned tex_blocksize, unsigned view_blocksize);
679
680 void
681 lp_build_extract_image_sizes(struct lp_build_sample_context *bld,
682 struct lp_build_context *size_bld,
683 struct lp_type coord_type,
684 LLVMValueRef size,
685 LLVMValueRef *out_width,
686 LLVMValueRef *out_height,
687 LLVMValueRef *out_depth);
688
689
690 void
691 lp_build_unnormalized_coords(struct lp_build_sample_context *bld,
692 LLVMValueRef flt_size,
693 LLVMValueRef *s,
694 LLVMValueRef *t,
695 LLVMValueRef *r);
696
697
698 void
699 lp_build_cube_lookup(struct lp_build_sample_context *bld,
700 LLVMValueRef *coords,
701 const struct lp_derivatives *derivs_in, /* optional */
702 struct lp_derivatives *derivs_out, /* optional */
703 bool need_derivs);
704
705
706 void
707 lp_build_cube_new_coords(struct lp_build_context *ivec_bld,
708 LLVMValueRef face,
709 LLVMValueRef x0,
710 LLVMValueRef x1,
711 LLVMValueRef y0,
712 LLVMValueRef y1,
713 LLVMValueRef max_coord,
714 LLVMValueRef new_faces[4],
715 LLVMValueRef new_xcoords[4][2],
716 LLVMValueRef new_ycoords[4][2]);
717
718
719 void
720 lp_build_sample_partial_offset(struct lp_build_context *bld,
721 unsigned block_length,
722 LLVMValueRef coord,
723 LLVMValueRef stride,
724 LLVMValueRef *out_offset,
725 LLVMValueRef *out_i);
726
727
728 void
729 lp_build_sample_offset(struct lp_build_context *bld,
730 const struct util_format_description *format_desc,
731 LLVMValueRef x,
732 LLVMValueRef y,
733 LLVMValueRef z,
734 LLVMValueRef y_stride,
735 LLVMValueRef z_stride,
736 LLVMValueRef *out_offset,
737 LLVMValueRef *out_i,
738 LLVMValueRef *out_j);
739
740
741 void
742 lp_build_sample_soa_code(struct gallivm_state *gallivm,
743 const struct lp_static_texture_state *static_texture_state,
744 const struct lp_static_sampler_state *static_sampler_state,
745 struct lp_sampler_dynamic_state *dynamic_state,
746 struct lp_type type,
747 unsigned sample_key,
748 unsigned texture_index,
749 unsigned sampler_index,
750 LLVMTypeRef resources_type,
751 LLVMValueRef resources_ptr,
752 LLVMTypeRef thread_data_type,
753 LLVMValueRef thread_data_ptr,
754 const LLVMValueRef *coords,
755 const LLVMValueRef *offsets,
756 const struct lp_derivatives *derivs, /* optional */
757 LLVMValueRef lod, /* optional */
758 LLVMValueRef ms_index, /* optional */
759 LLVMValueRef aniso_filter_table,
760 LLVMValueRef texel_out[4]);
761
762
763 void
764 lp_build_sample_soa(const struct lp_static_texture_state *static_texture_state,
765 const struct lp_static_sampler_state *static_sampler_state,
766 struct lp_sampler_dynamic_state *dynamic_texture_state,
767 struct gallivm_state *gallivm,
768 const struct lp_sampler_params *params);
769
770
771 void
772 lp_build_coord_repeat_npot_linear(struct lp_build_sample_context *bld,
773 LLVMValueRef coord_f,
774 LLVMValueRef length_i,
775 LLVMValueRef length_f,
776 LLVMValueRef *coord0_i,
777 LLVMValueRef *weight_f);
778
779
780 void
781 lp_build_size_query_soa(struct gallivm_state *gallivm,
782 const struct lp_static_texture_state *static_state,
783 struct lp_sampler_dynamic_state *dynamic_state,
784 const struct lp_sampler_size_query_params *params);
785
786 void
787 lp_build_sample_nop(struct gallivm_state *gallivm,
788 struct lp_type type,
789 const LLVMValueRef *coords,
790 LLVMValueRef texel_out[4]);
791
792
793 LLVMValueRef
794 lp_build_minify(struct lp_build_context *bld,
795 LLVMValueRef base_size,
796 LLVMValueRef level,
797 bool lod_scalar);
798
799 void
800 lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state,
801 struct lp_sampler_dynamic_state *dynamic_state,
802 struct gallivm_state *gallivm,
803 const struct lp_img_params *params,
804 LLVMValueRef outdata[4]);
805
806 void
807 lp_build_sample_array_init_soa(struct lp_build_sample_array_switch *switch_info,
808 struct gallivm_state *gallivm,
809 const struct lp_sampler_params *params,
810 LLVMValueRef idx,
811 unsigned base, unsigned range);
812
813 void
814 lp_build_sample_array_case_soa(struct lp_build_sample_array_switch *switch_info,
815 int idx,
816 const struct lp_static_texture_state *static_texture_state,
817 const struct lp_static_sampler_state *static_sampler_state,
818 struct lp_sampler_dynamic_state *dynamic_texture_state);
819
820 void
821 lp_build_sample_array_fini_soa(struct lp_build_sample_array_switch *switch_info);
822
823 void
824 lp_build_image_op_switch_soa(struct lp_build_img_op_array_switch *switch_info,
825 struct gallivm_state *gallivm,
826 const struct lp_img_params *params,
827 LLVMValueRef idx,
828 unsigned base, unsigned range);
829
830 void
831 lp_build_image_op_array_case(struct lp_build_img_op_array_switch *switch_info,
832 int idx,
833 const struct lp_static_texture_state *static_texture_state,
834 struct lp_sampler_dynamic_state *dynamic_state);
835
836 void
837 lp_build_image_op_array_fini_soa(struct lp_build_img_op_array_switch *switch_info);
838
839 void
840 lp_build_reduce_filter(struct lp_build_context *bld,
841 enum pipe_tex_reduction_mode mode,
842 unsigned flags,
843 unsigned num_chan,
844 LLVMValueRef x,
845 LLVMValueRef *v00,
846 LLVMValueRef *v01,
847 LLVMValueRef *out);
848 void
849 lp_build_reduce_filter_2d(struct lp_build_context *bld,
850 enum pipe_tex_reduction_mode mode,
851 unsigned flags,
852 unsigned num_chan,
853 LLVMValueRef x,
854 LLVMValueRef y,
855 LLVMValueRef *v00,
856 LLVMValueRef *v01,
857 LLVMValueRef *v10,
858 LLVMValueRef *v11,
859 LLVMValueRef *out);
860
861 void
862 lp_build_reduce_filter_3d(struct lp_build_context *bld,
863 enum pipe_tex_reduction_mode mode,
864 unsigned flags,
865 unsigned num_chan,
866 LLVMValueRef x,
867 LLVMValueRef y,
868 LLVMValueRef z,
869 LLVMValueRef *v000,
870 LLVMValueRef *v001,
871 LLVMValueRef *v010,
872 LLVMValueRef *v011,
873 LLVMValueRef *v100,
874 LLVMValueRef *v101,
875 LLVMValueRef *v110,
876 LLVMValueRef *v111,
877 LLVMValueRef *out);
878
879 struct lp_type
880 lp_build_texel_type(struct lp_type texel_type,
881 const struct util_format_description *format_desc);
882
883 LLVMValueRef lp_sample_load_mip_value(struct gallivm_state *gallivm,
884 LLVMTypeRef ptr_type,
885 LLVMValueRef offsets,
886 LLVMValueRef index1);
887
888 const float *lp_build_sample_aniso_filter_table(void);
889 #ifdef __cplusplus
890 }
891 #endif
892
893 #endif /* LP_BLD_SAMPLE_H */
894