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