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