gallivm: fix copy&paste bug
[mesa.git] / src / gallium / auxiliary / gallivm / lp_bld_sample_soa.c
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 -- SoA.
31 *
32 * @author Jose Fonseca <jfonseca@vmware.com>
33 * @author Brian Paul <brianp@vmware.com>
34 */
35
36 #include "pipe/p_defines.h"
37 #include "pipe/p_state.h"
38 #include "util/u_debug.h"
39 #include "util/u_dump.h"
40 #include "util/u_memory.h"
41 #include "util/u_math.h"
42 #include "util/u_format.h"
43 #include "lp_bld_debug.h"
44 #include "lp_bld_type.h"
45 #include "lp_bld_const.h"
46 #include "lp_bld_conv.h"
47 #include "lp_bld_arit.h"
48 #include "lp_bld_bitarit.h"
49 #include "lp_bld_logic.h"
50 #include "lp_bld_printf.h"
51 #include "lp_bld_swizzle.h"
52 #include "lp_bld_flow.h"
53 #include "lp_bld_gather.h"
54 #include "lp_bld_format.h"
55 #include "lp_bld_sample.h"
56 #include "lp_bld_sample_aos.h"
57 #include "lp_bld_struct.h"
58 #include "lp_bld_quad.h"
59
60
61 /**
62 * Does the given texture wrap mode allow sampling the texture border color?
63 * XXX maybe move this into gallium util code.
64 */
65 static boolean
66 wrap_mode_uses_border_color(unsigned mode)
67 {
68 switch (mode) {
69 case PIPE_TEX_WRAP_REPEAT:
70 case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
71 case PIPE_TEX_WRAP_MIRROR_REPEAT:
72 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
73 return FALSE;
74 case PIPE_TEX_WRAP_CLAMP:
75 case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
76 case PIPE_TEX_WRAP_MIRROR_CLAMP:
77 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
78 return TRUE;
79 default:
80 assert(0 && "unexpected wrap mode");
81 return FALSE;
82 }
83 }
84
85
86 /**
87 * Generate code to fetch a texel from a texture at int coords (x, y, z).
88 * The computation depends on whether the texture is 1D, 2D or 3D.
89 * The result, texel, will be float vectors:
90 * texel[0] = red values
91 * texel[1] = green values
92 * texel[2] = blue values
93 * texel[3] = alpha values
94 */
95 static void
96 lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
97 unsigned unit,
98 LLVMValueRef width,
99 LLVMValueRef height,
100 LLVMValueRef depth,
101 LLVMValueRef x,
102 LLVMValueRef y,
103 LLVMValueRef z,
104 LLVMValueRef y_stride,
105 LLVMValueRef z_stride,
106 LLVMValueRef data_ptr,
107 LLVMValueRef texel_out[4])
108 {
109 const int dims = texture_dims(bld->static_state->target);
110 struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
111 LLVMValueRef offset;
112 LLVMValueRef i, j;
113 LLVMValueRef use_border = NULL;
114
115 /* use_border = x < 0 || x >= width || y < 0 || y >= height */
116 if (wrap_mode_uses_border_color(bld->static_state->wrap_s)) {
117 LLVMValueRef b1, b2;
118 b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, x, int_coord_bld->zero);
119 b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, x, width);
120 use_border = LLVMBuildOr(bld->builder, b1, b2, "b1_or_b2");
121 }
122
123 if (dims >= 2 && wrap_mode_uses_border_color(bld->static_state->wrap_t)) {
124 LLVMValueRef b1, b2;
125 b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, y, int_coord_bld->zero);
126 b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, y, height);
127 if (use_border) {
128 use_border = LLVMBuildOr(bld->builder, use_border, b1, "ub_or_b1");
129 use_border = LLVMBuildOr(bld->builder, use_border, b2, "ub_or_b2");
130 }
131 else {
132 use_border = LLVMBuildOr(bld->builder, b1, b2, "b1_or_b2");
133 }
134 }
135
136 if (dims == 3 && wrap_mode_uses_border_color(bld->static_state->wrap_r)) {
137 LLVMValueRef b1, b2;
138 b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, z, int_coord_bld->zero);
139 b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, z, depth);
140 if (use_border) {
141 use_border = LLVMBuildOr(bld->builder, use_border, b1, "ub_or_b1");
142 use_border = LLVMBuildOr(bld->builder, use_border, b2, "ub_or_b2");
143 }
144 else {
145 use_border = LLVMBuildOr(bld->builder, b1, b2, "b1_or_b2");
146 }
147 }
148
149 /* convert x,y,z coords to linear offset from start of texture, in bytes */
150 lp_build_sample_offset(&bld->uint_coord_bld,
151 bld->format_desc,
152 x, y, z, y_stride, z_stride,
153 &offset, &i, &j);
154
155 if (use_border) {
156 /* If we can sample the border color, it means that texcoords may
157 * lie outside the bounds of the texture image. We need to do
158 * something to prevent reading out of bounds and causing a segfault.
159 *
160 * Simply AND the texture coords with !use_border. This will cause
161 * coords which are out of bounds to become zero. Zero's guaranteed
162 * to be inside the texture image.
163 */
164 offset = lp_build_andnot(&bld->uint_coord_bld, offset, use_border);
165 }
166
167 lp_build_fetch_rgba_soa(bld->builder,
168 bld->format_desc,
169 bld->texel_type,
170 data_ptr, offset,
171 i, j,
172 texel_out);
173
174 apply_sampler_swizzle(bld, texel_out);
175
176 /*
177 * Note: if we find an app which frequently samples the texture border
178 * we might want to implement a true conditional here to avoid sampling
179 * the texture whenever possible (since that's quite a bit of code).
180 * Ex:
181 * if (use_border) {
182 * texel = border_color;
183 * }
184 * else {
185 * texel = sample_texture(coord);
186 * }
187 * As it is now, we always sample the texture, then selectively replace
188 * the texel color results with the border color.
189 */
190
191 if (use_border) {
192 /* select texel color or border color depending on use_border */
193 LLVMValueRef border_color_ptr =
194 bld->dynamic_state->border_color(bld->dynamic_state,
195 bld->builder, unit);
196 int chan;
197 for (chan = 0; chan < 4; chan++) {
198 LLVMValueRef border_chan =
199 lp_build_array_get(bld->builder, border_color_ptr,
200 lp_build_const_int32(chan));
201 LLVMValueRef border_chan_vec =
202 lp_build_broadcast_scalar(&bld->float_vec_bld, border_chan);
203 texel_out[chan] = lp_build_select(&bld->texel_bld, use_border,
204 border_chan_vec, texel_out[chan]);
205 }
206 }
207 }
208
209
210 /**
211 * Helper to compute the mirror function for the PIPE_WRAP_MIRROR modes.
212 */
213 static LLVMValueRef
214 lp_build_coord_mirror(struct lp_build_sample_context *bld,
215 LLVMValueRef coord)
216 {
217 struct lp_build_context *coord_bld = &bld->coord_bld;
218 struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
219 LLVMValueRef fract, flr, isOdd;
220
221 /* fract = coord - floor(coord) */
222 fract = lp_build_sub(coord_bld, coord, lp_build_floor(coord_bld, coord));
223
224 /* flr = ifloor(coord); */
225 flr = lp_build_ifloor(coord_bld, coord);
226
227 /* isOdd = flr & 1 */
228 isOdd = LLVMBuildAnd(bld->builder, flr, int_coord_bld->one, "");
229
230 /* make coord positive or negative depending on isOdd */
231 coord = lp_build_set_sign(coord_bld, fract, isOdd);
232
233 /* convert isOdd to float */
234 isOdd = lp_build_int_to_float(coord_bld, isOdd);
235
236 /* add isOdd to coord */
237 coord = lp_build_add(coord_bld, coord, isOdd);
238
239 return coord;
240 }
241
242
243 /**
244 * Build LLVM code for texture wrap mode for linear filtering.
245 * \param x0_out returns first integer texcoord
246 * \param x1_out returns second integer texcoord
247 * \param weight_out returns linear interpolation weight
248 */
249 static void
250 lp_build_sample_wrap_linear(struct lp_build_sample_context *bld,
251 LLVMValueRef coord,
252 LLVMValueRef length,
253 boolean is_pot,
254 unsigned wrap_mode,
255 LLVMValueRef *x0_out,
256 LLVMValueRef *x1_out,
257 LLVMValueRef *weight_out)
258 {
259 struct lp_build_context *coord_bld = &bld->coord_bld;
260 struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
261 struct lp_build_context *uint_coord_bld = &bld->uint_coord_bld;
262 LLVMValueRef half = lp_build_const_vec(coord_bld->type, 0.5);
263 LLVMValueRef length_f = lp_build_int_to_float(coord_bld, length);
264 LLVMValueRef length_minus_one = lp_build_sub(uint_coord_bld, length, uint_coord_bld->one);
265 LLVMValueRef coord0, coord1, weight;
266
267 switch(wrap_mode) {
268 case PIPE_TEX_WRAP_REPEAT:
269 /* mul by size and subtract 0.5 */
270 coord = lp_build_mul(coord_bld, coord, length_f);
271 coord = lp_build_sub(coord_bld, coord, half);
272 /* convert to int */
273 coord0 = lp_build_ifloor(coord_bld, coord);
274 coord1 = lp_build_add(uint_coord_bld, coord0, uint_coord_bld->one);
275 /* compute lerp weight */
276 weight = lp_build_fract(coord_bld, coord);
277 /* repeat wrap */
278 if (is_pot) {
279 coord0 = LLVMBuildAnd(bld->builder, coord0, length_minus_one, "");
280 coord1 = LLVMBuildAnd(bld->builder, coord1, length_minus_one, "");
281 }
282 else {
283 /* Signed remainder won't give the right results for negative
284 * dividends but unsigned remainder does.*/
285 coord0 = LLVMBuildURem(bld->builder, coord0, length, "");
286 coord1 = LLVMBuildURem(bld->builder, coord1, length, "");
287 }
288 break;
289
290 case PIPE_TEX_WRAP_CLAMP:
291 if (bld->static_state->normalized_coords) {
292 /* scale coord to length */
293 coord = lp_build_mul(coord_bld, coord, length_f);
294 }
295
296 /* clamp to [0, length] */
297 coord = lp_build_clamp(coord_bld, coord, coord_bld->zero, length_f);
298
299 coord = lp_build_sub(coord_bld, coord, half);
300
301 weight = lp_build_fract(coord_bld, coord);
302 coord0 = lp_build_ifloor(coord_bld, coord);
303 coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one);
304 break;
305
306 case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
307 if (bld->static_state->normalized_coords) {
308 /* clamp to [0,1] */
309 coord = lp_build_clamp(coord_bld, coord, coord_bld->zero, coord_bld->one);
310 /* mul by tex size and subtract 0.5 */
311 coord = lp_build_mul(coord_bld, coord, length_f);
312 coord = lp_build_sub(coord_bld, coord, half);
313 }
314 else {
315 LLVMValueRef min, max;
316 /* clamp to [0.5, length - 0.5] */
317 min = half;
318 max = lp_build_sub(coord_bld, length_f, min);
319 coord = lp_build_clamp(coord_bld, coord, min, max);
320 }
321 /* compute lerp weight */
322 weight = lp_build_fract(coord_bld, coord);
323 /* coord0 = floor(coord); */
324 coord0 = lp_build_ifloor(coord_bld, coord);
325 coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one);
326 /* coord0 = max(coord0, 0) */
327 coord0 = lp_build_max(int_coord_bld, coord0, int_coord_bld->zero);
328 /* coord1 = min(coord1, length-1) */
329 coord1 = lp_build_min(int_coord_bld, coord1, length_minus_one);
330 break;
331
332 case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
333 {
334 LLVMValueRef min, max;
335 if (bld->static_state->normalized_coords) {
336 /* scale coord to length */
337 coord = lp_build_mul(coord_bld, coord, length_f);
338 }
339 /* clamp to [-0.5, length + 0.5] */
340 min = lp_build_const_vec(coord_bld->type, -0.5F);
341 max = lp_build_sub(coord_bld, length_f, min);
342 coord = lp_build_clamp(coord_bld, coord, min, max);
343 coord = lp_build_sub(coord_bld, coord, half);
344 /* compute lerp weight */
345 weight = lp_build_fract(coord_bld, coord);
346 /* convert to int */
347 coord0 = lp_build_ifloor(coord_bld, coord);
348 coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one);
349 }
350 break;
351
352 case PIPE_TEX_WRAP_MIRROR_REPEAT:
353 /* compute mirror function */
354 coord = lp_build_coord_mirror(bld, coord);
355
356 /* scale coord to length */
357 coord = lp_build_mul(coord_bld, coord, length_f);
358 coord = lp_build_sub(coord_bld, coord, half);
359
360 /* compute lerp weight */
361 weight = lp_build_fract(coord_bld, coord);
362
363 /* convert to int coords */
364 coord0 = lp_build_ifloor(coord_bld, coord);
365 coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one);
366
367 /* coord0 = max(coord0, 0) */
368 coord0 = lp_build_max(int_coord_bld, coord0, int_coord_bld->zero);
369 /* coord1 = min(coord1, length-1) */
370 coord1 = lp_build_min(int_coord_bld, coord1, length_minus_one);
371 break;
372
373 case PIPE_TEX_WRAP_MIRROR_CLAMP:
374 coord = lp_build_abs(coord_bld, coord);
375
376 if (bld->static_state->normalized_coords) {
377 /* scale coord to length */
378 coord = lp_build_mul(coord_bld, coord, length_f);
379 }
380
381 /* clamp to [0, length] */
382 coord = lp_build_min(coord_bld, coord, length_f);
383
384 coord = lp_build_sub(coord_bld, coord, half);
385
386 weight = lp_build_fract(coord_bld, coord);
387 coord0 = lp_build_ifloor(coord_bld, coord);
388 coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one);
389 break;
390
391 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
392 {
393 LLVMValueRef min, max;
394
395 coord = lp_build_abs(coord_bld, coord);
396
397 if (bld->static_state->normalized_coords) {
398 /* scale coord to length */
399 coord = lp_build_mul(coord_bld, coord, length_f);
400 }
401
402 /* clamp to [0.5, length - 0.5] */
403 min = half;
404 max = lp_build_sub(coord_bld, length_f, min);
405 coord = lp_build_clamp(coord_bld, coord, min, max);
406
407 coord = lp_build_sub(coord_bld, coord, half);
408
409 weight = lp_build_fract(coord_bld, coord);
410 coord0 = lp_build_ifloor(coord_bld, coord);
411 coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one);
412 }
413 break;
414
415 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
416 {
417 LLVMValueRef min, max;
418
419 coord = lp_build_abs(coord_bld, coord);
420
421 if (bld->static_state->normalized_coords) {
422 /* scale coord to length */
423 coord = lp_build_mul(coord_bld, coord, length_f);
424 }
425
426 /* clamp to [-0.5, length + 0.5] */
427 min = lp_build_negate(coord_bld, half);
428 max = lp_build_sub(coord_bld, length_f, min);
429 coord = lp_build_clamp(coord_bld, coord, min, max);
430
431 coord = lp_build_sub(coord_bld, coord, half);
432
433 weight = lp_build_fract(coord_bld, coord);
434 coord0 = lp_build_ifloor(coord_bld, coord);
435 coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one);
436 }
437 break;
438
439 default:
440 assert(0);
441 coord0 = NULL;
442 coord1 = NULL;
443 weight = NULL;
444 }
445
446 *x0_out = coord0;
447 *x1_out = coord1;
448 *weight_out = weight;
449 }
450
451
452 /**
453 * Build LLVM code for texture wrap mode for nearest filtering.
454 * \param coord the incoming texcoord (nominally in [0,1])
455 * \param length the texture size along one dimension, as int vector
456 * \param is_pot if TRUE, length is a power of two
457 * \param wrap_mode one of PIPE_TEX_WRAP_x
458 */
459 static LLVMValueRef
460 lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld,
461 LLVMValueRef coord,
462 LLVMValueRef length,
463 boolean is_pot,
464 unsigned wrap_mode)
465 {
466 struct lp_build_context *coord_bld = &bld->coord_bld;
467 struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
468 struct lp_build_context *uint_coord_bld = &bld->uint_coord_bld;
469 LLVMValueRef length_f = lp_build_int_to_float(coord_bld, length);
470 LLVMValueRef length_minus_one = lp_build_sub(uint_coord_bld, length, uint_coord_bld->one);
471 LLVMValueRef icoord;
472
473 switch(wrap_mode) {
474 case PIPE_TEX_WRAP_REPEAT:
475 coord = lp_build_mul(coord_bld, coord, length_f);
476 icoord = lp_build_ifloor(coord_bld, coord);
477 if (is_pot)
478 icoord = LLVMBuildAnd(bld->builder, icoord, length_minus_one, "");
479 else
480 /* Signed remainder won't give the right results for negative
481 * dividends but unsigned remainder does.*/
482 icoord = LLVMBuildURem(bld->builder, icoord, length, "");
483 break;
484
485 case PIPE_TEX_WRAP_CLAMP:
486 case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
487 if (bld->static_state->normalized_coords) {
488 /* scale coord to length */
489 coord = lp_build_mul(coord_bld, coord, length_f);
490 }
491
492 /* floor */
493 icoord = lp_build_ifloor(coord_bld, coord);
494
495 /* clamp to [0, length - 1]. */
496 icoord = lp_build_clamp(int_coord_bld, icoord, int_coord_bld->zero,
497 length_minus_one);
498 break;
499
500 case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
501 /* Note: this is the same as CLAMP_TO_EDGE, except min = -min */
502 {
503 LLVMValueRef min, max;
504
505 if (bld->static_state->normalized_coords) {
506 /* scale coord to length */
507 coord = lp_build_mul(coord_bld, coord, length_f);
508 }
509
510 icoord = lp_build_ifloor(coord_bld, coord);
511
512 /* clamp to [-1, length] */
513 min = lp_build_negate(int_coord_bld, int_coord_bld->one);
514 max = length;
515 icoord = lp_build_clamp(int_coord_bld, icoord, min, max);
516 }
517 break;
518
519 case PIPE_TEX_WRAP_MIRROR_REPEAT:
520 /* compute mirror function */
521 coord = lp_build_coord_mirror(bld, coord);
522
523 /* scale coord to length */
524 assert(bld->static_state->normalized_coords);
525 coord = lp_build_mul(coord_bld, coord, length_f);
526
527 icoord = lp_build_ifloor(coord_bld, coord);
528
529 /* clamp to [0, length - 1] */
530 icoord = lp_build_min(int_coord_bld, icoord, length_minus_one);
531 break;
532
533 case PIPE_TEX_WRAP_MIRROR_CLAMP:
534 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
535 coord = lp_build_abs(coord_bld, coord);
536
537 if (bld->static_state->normalized_coords) {
538 /* scale coord to length */
539 coord = lp_build_mul(coord_bld, coord, length_f);
540 }
541
542 icoord = lp_build_ifloor(coord_bld, coord);
543
544 /* clamp to [0, length - 1] */
545 icoord = lp_build_min(int_coord_bld, icoord, length_minus_one);
546 break;
547
548 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
549 coord = lp_build_abs(coord_bld, coord);
550
551 if (bld->static_state->normalized_coords) {
552 /* scale coord to length */
553 coord = lp_build_mul(coord_bld, coord, length_f);
554 }
555
556 icoord = lp_build_ifloor(coord_bld, coord);
557
558 /* clamp to [0, length] */
559 icoord = lp_build_min(int_coord_bld, icoord, length);
560 break;
561
562 default:
563 assert(0);
564 icoord = NULL;
565 }
566
567 return icoord;
568 }
569
570
571 /**
572 * Generate code to sample a mipmap level with nearest filtering.
573 * If sampling a cube texture, r = cube face in [0,5].
574 */
575 static void
576 lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
577 unsigned unit,
578 LLVMValueRef width_vec,
579 LLVMValueRef height_vec,
580 LLVMValueRef depth_vec,
581 LLVMValueRef row_stride_vec,
582 LLVMValueRef img_stride_vec,
583 LLVMValueRef data_ptr,
584 LLVMValueRef s,
585 LLVMValueRef t,
586 LLVMValueRef r,
587 LLVMValueRef colors_out[4])
588 {
589 const int dims = texture_dims(bld->static_state->target);
590 LLVMValueRef x, y, z;
591
592 /*
593 * Compute integer texcoords.
594 */
595 x = lp_build_sample_wrap_nearest(bld, s, width_vec,
596 bld->static_state->pot_width,
597 bld->static_state->wrap_s);
598 lp_build_name(x, "tex.x.wrapped");
599
600 if (dims >= 2) {
601 y = lp_build_sample_wrap_nearest(bld, t, height_vec,
602 bld->static_state->pot_height,
603 bld->static_state->wrap_t);
604 lp_build_name(y, "tex.y.wrapped");
605
606 if (dims == 3) {
607 z = lp_build_sample_wrap_nearest(bld, r, depth_vec,
608 bld->static_state->pot_depth,
609 bld->static_state->wrap_r);
610 lp_build_name(z, "tex.z.wrapped");
611 }
612 else if (bld->static_state->target == PIPE_TEXTURE_CUBE) {
613 z = r;
614 }
615 else {
616 z = NULL;
617 }
618 }
619 else {
620 y = z = NULL;
621 }
622
623 /*
624 * Get texture colors.
625 */
626 lp_build_sample_texel_soa(bld, unit,
627 width_vec, height_vec, depth_vec,
628 x, y, z,
629 row_stride_vec, img_stride_vec,
630 data_ptr, colors_out);
631 }
632
633
634 /**
635 * Generate code to sample a mipmap level with linear filtering.
636 * If sampling a cube texture, r = cube face in [0,5].
637 */
638 static void
639 lp_build_sample_image_linear(struct lp_build_sample_context *bld,
640 unsigned unit,
641 LLVMValueRef width_vec,
642 LLVMValueRef height_vec,
643 LLVMValueRef depth_vec,
644 LLVMValueRef row_stride_vec,
645 LLVMValueRef img_stride_vec,
646 LLVMValueRef data_ptr,
647 LLVMValueRef s,
648 LLVMValueRef t,
649 LLVMValueRef r,
650 LLVMValueRef colors_out[4])
651 {
652 const int dims = texture_dims(bld->static_state->target);
653 LLVMValueRef x0, y0, z0, x1, y1, z1;
654 LLVMValueRef s_fpart, t_fpart, r_fpart;
655 LLVMValueRef neighbors[2][2][4];
656 int chan;
657
658 /*
659 * Compute integer texcoords.
660 */
661 lp_build_sample_wrap_linear(bld, s, width_vec,
662 bld->static_state->pot_width,
663 bld->static_state->wrap_s,
664 &x0, &x1, &s_fpart);
665 lp_build_name(x0, "tex.x0.wrapped");
666 lp_build_name(x1, "tex.x1.wrapped");
667
668 if (dims >= 2) {
669 lp_build_sample_wrap_linear(bld, t, height_vec,
670 bld->static_state->pot_height,
671 bld->static_state->wrap_t,
672 &y0, &y1, &t_fpart);
673 lp_build_name(y0, "tex.y0.wrapped");
674 lp_build_name(y1, "tex.y1.wrapped");
675
676 if (dims == 3) {
677 lp_build_sample_wrap_linear(bld, r, depth_vec,
678 bld->static_state->pot_depth,
679 bld->static_state->wrap_r,
680 &z0, &z1, &r_fpart);
681 lp_build_name(z0, "tex.z0.wrapped");
682 lp_build_name(z1, "tex.z1.wrapped");
683 }
684 else if (bld->static_state->target == PIPE_TEXTURE_CUBE) {
685 z0 = z1 = r; /* cube face */
686 r_fpart = NULL;
687 }
688 else {
689 z0 = z1 = NULL;
690 r_fpart = NULL;
691 }
692 }
693 else {
694 y0 = y1 = t_fpart = NULL;
695 z0 = z1 = r_fpart = NULL;
696 }
697
698 /*
699 * Get texture colors.
700 */
701 /* get x0/x1 texels */
702 lp_build_sample_texel_soa(bld, unit,
703 width_vec, height_vec, depth_vec,
704 x0, y0, z0,
705 row_stride_vec, img_stride_vec,
706 data_ptr, neighbors[0][0]);
707 lp_build_sample_texel_soa(bld, unit,
708 width_vec, height_vec, depth_vec,
709 x1, y0, z0,
710 row_stride_vec, img_stride_vec,
711 data_ptr, neighbors[0][1]);
712
713 if (dims == 1) {
714 /* Interpolate two samples from 1D image to produce one color */
715 for (chan = 0; chan < 4; chan++) {
716 colors_out[chan] = lp_build_lerp(&bld->texel_bld, s_fpart,
717 neighbors[0][0][chan],
718 neighbors[0][1][chan]);
719 }
720 }
721 else {
722 /* 2D/3D texture */
723 LLVMValueRef colors0[4];
724
725 /* get x0/x1 texels at y1 */
726 lp_build_sample_texel_soa(bld, unit,
727 width_vec, height_vec, depth_vec,
728 x0, y1, z0,
729 row_stride_vec, img_stride_vec,
730 data_ptr, neighbors[1][0]);
731 lp_build_sample_texel_soa(bld, unit,
732 width_vec, height_vec, depth_vec,
733 x1, y1, z0,
734 row_stride_vec, img_stride_vec,
735 data_ptr, neighbors[1][1]);
736
737 /* Bilinear interpolate the four samples from the 2D image / 3D slice */
738 for (chan = 0; chan < 4; chan++) {
739 colors0[chan] = lp_build_lerp_2d(&bld->texel_bld,
740 s_fpart, t_fpart,
741 neighbors[0][0][chan],
742 neighbors[0][1][chan],
743 neighbors[1][0][chan],
744 neighbors[1][1][chan]);
745 }
746
747 if (dims == 3) {
748 LLVMValueRef neighbors1[2][2][4];
749 LLVMValueRef colors1[4];
750
751 /* get x0/x1/y0/y1 texels at z1 */
752 lp_build_sample_texel_soa(bld, unit,
753 width_vec, height_vec, depth_vec,
754 x0, y0, z1,
755 row_stride_vec, img_stride_vec,
756 data_ptr, neighbors1[0][0]);
757 lp_build_sample_texel_soa(bld, unit,
758 width_vec, height_vec, depth_vec,
759 x1, y0, z1,
760 row_stride_vec, img_stride_vec,
761 data_ptr, neighbors1[0][1]);
762 lp_build_sample_texel_soa(bld, unit,
763 width_vec, height_vec, depth_vec,
764 x0, y1, z1,
765 row_stride_vec, img_stride_vec,
766 data_ptr, neighbors1[1][0]);
767 lp_build_sample_texel_soa(bld, unit,
768 width_vec, height_vec, depth_vec,
769 x1, y1, z1,
770 row_stride_vec, img_stride_vec,
771 data_ptr, neighbors1[1][1]);
772
773 /* Bilinear interpolate the four samples from the second Z slice */
774 for (chan = 0; chan < 4; chan++) {
775 colors1[chan] = lp_build_lerp_2d(&bld->texel_bld,
776 s_fpart, t_fpart,
777 neighbors1[0][0][chan],
778 neighbors1[0][1][chan],
779 neighbors1[1][0][chan],
780 neighbors1[1][1][chan]);
781 }
782
783 /* Linearly interpolate the two samples from the two 3D slices */
784 for (chan = 0; chan < 4; chan++) {
785 colors_out[chan] = lp_build_lerp(&bld->texel_bld,
786 r_fpart,
787 colors0[chan], colors1[chan]);
788 }
789 }
790 else {
791 /* 2D tex */
792 for (chan = 0; chan < 4; chan++) {
793 colors_out[chan] = colors0[chan];
794 }
795 }
796 }
797 }
798
799
800 /**
801 * Sample the texture/mipmap using given image filter and mip filter.
802 * data0_ptr and data1_ptr point to the two mipmap levels to sample
803 * from. width0/1_vec, height0/1_vec, depth0/1_vec indicate their sizes.
804 * If we're using nearest miplevel sampling the '1' values will be null/unused.
805 */
806 static void
807 lp_build_sample_mipmap(struct lp_build_sample_context *bld,
808 unsigned unit,
809 unsigned img_filter,
810 unsigned mip_filter,
811 LLVMValueRef s,
812 LLVMValueRef t,
813 LLVMValueRef r,
814 LLVMValueRef lod_fpart,
815 LLVMValueRef width0_vec,
816 LLVMValueRef width1_vec,
817 LLVMValueRef height0_vec,
818 LLVMValueRef height1_vec,
819 LLVMValueRef depth0_vec,
820 LLVMValueRef depth1_vec,
821 LLVMValueRef row_stride0_vec,
822 LLVMValueRef row_stride1_vec,
823 LLVMValueRef img_stride0_vec,
824 LLVMValueRef img_stride1_vec,
825 LLVMValueRef data_ptr0,
826 LLVMValueRef data_ptr1,
827 LLVMValueRef *colors_out)
828 {
829 LLVMValueRef colors0[4], colors1[4];
830 int chan;
831
832 if (img_filter == PIPE_TEX_FILTER_NEAREST) {
833 /* sample the first mipmap level */
834 lp_build_sample_image_nearest(bld, unit,
835 width0_vec, height0_vec, depth0_vec,
836 row_stride0_vec, img_stride0_vec,
837 data_ptr0, s, t, r, colors0);
838
839 if (mip_filter == PIPE_TEX_MIPFILTER_LINEAR) {
840 /* sample the second mipmap level */
841 lp_build_sample_image_nearest(bld, unit,
842 width1_vec, height1_vec, depth1_vec,
843 row_stride1_vec, img_stride1_vec,
844 data_ptr1, s, t, r, colors1);
845 }
846 }
847 else {
848 assert(img_filter == PIPE_TEX_FILTER_LINEAR);
849
850 /* sample the first mipmap level */
851 lp_build_sample_image_linear(bld, unit,
852 width0_vec, height0_vec, depth0_vec,
853 row_stride0_vec, img_stride0_vec,
854 data_ptr0, s, t, r, colors0);
855
856 if (mip_filter == PIPE_TEX_MIPFILTER_LINEAR) {
857 /* sample the second mipmap level */
858 lp_build_sample_image_linear(bld, unit,
859 width1_vec, height1_vec, depth1_vec,
860 row_stride1_vec, img_stride1_vec,
861 data_ptr1, s, t, r, colors1);
862 }
863 }
864
865 if (mip_filter == PIPE_TEX_MIPFILTER_LINEAR) {
866 /* interpolate samples from the two mipmap levels */
867 for (chan = 0; chan < 4; chan++) {
868 colors_out[chan] = lp_build_lerp(&bld->texel_bld, lod_fpart,
869 colors0[chan], colors1[chan]);
870 }
871 }
872 else {
873 /* use first/only level's colors */
874 for (chan = 0; chan < 4; chan++) {
875 colors_out[chan] = colors0[chan];
876 }
877 }
878 }
879
880
881
882 /**
883 * General texture sampling codegen.
884 * This function handles texture sampling for all texture targets (1D,
885 * 2D, 3D, cube) and all filtering modes.
886 */
887 static void
888 lp_build_sample_general(struct lp_build_sample_context *bld,
889 unsigned unit,
890 LLVMValueRef s,
891 LLVMValueRef t,
892 LLVMValueRef r,
893 const LLVMValueRef *ddx,
894 const LLVMValueRef *ddy,
895 LLVMValueRef lod_bias, /* optional */
896 LLVMValueRef explicit_lod, /* optional */
897 LLVMValueRef width,
898 LLVMValueRef height,
899 LLVMValueRef depth,
900 LLVMValueRef width_vec,
901 LLVMValueRef height_vec,
902 LLVMValueRef depth_vec,
903 LLVMValueRef row_stride_array,
904 LLVMValueRef img_stride_array,
905 LLVMValueRef data_array,
906 LLVMValueRef *colors_out)
907 {
908 struct lp_build_context *float_bld = &bld->float_bld;
909 const unsigned mip_filter = bld->static_state->min_mip_filter;
910 const unsigned min_filter = bld->static_state->min_img_filter;
911 const unsigned mag_filter = bld->static_state->mag_img_filter;
912 const int dims = texture_dims(bld->static_state->target);
913 LLVMValueRef lod = NULL, lod_fpart = NULL;
914 LLVMValueRef ilevel0, ilevel1 = NULL;
915 LLVMValueRef width0_vec = NULL, height0_vec = NULL, depth0_vec = NULL;
916 LLVMValueRef width1_vec = NULL, height1_vec = NULL, depth1_vec = NULL;
917 LLVMValueRef row_stride0_vec = NULL, row_stride1_vec = NULL;
918 LLVMValueRef img_stride0_vec = NULL, img_stride1_vec = NULL;
919 LLVMValueRef data_ptr0, data_ptr1 = NULL;
920 LLVMValueRef face_ddx[4], face_ddy[4];
921
922 /*
923 printf("%s mip %d min %d mag %d\n", __FUNCTION__,
924 mip_filter, min_filter, mag_filter);
925 */
926
927 /*
928 * Choose cube face, recompute texcoords and derivatives for the chosen face.
929 */
930 if (bld->static_state->target == PIPE_TEXTURE_CUBE) {
931 LLVMValueRef face, face_s, face_t;
932 lp_build_cube_lookup(bld, s, t, r, &face, &face_s, &face_t);
933 s = face_s; /* vec */
934 t = face_t; /* vec */
935 /* use 'r' to indicate cube face */
936 r = lp_build_broadcast_scalar(&bld->int_coord_bld, face); /* vec */
937
938 /* recompute ddx, ddy using the new (s,t) face texcoords */
939 face_ddx[0] = lp_build_ddx(&bld->coord_bld, s);
940 face_ddx[1] = lp_build_ddx(&bld->coord_bld, t);
941 face_ddx[2] = NULL;
942 face_ddx[3] = NULL;
943 face_ddy[0] = lp_build_ddy(&bld->coord_bld, s);
944 face_ddy[1] = lp_build_ddy(&bld->coord_bld, t);
945 face_ddy[2] = NULL;
946 face_ddy[3] = NULL;
947 ddx = face_ddx;
948 ddy = face_ddy;
949 }
950
951 /*
952 * Compute the level of detail (float).
953 */
954 if (min_filter != mag_filter ||
955 mip_filter != PIPE_TEX_MIPFILTER_NONE) {
956 /* Need to compute lod either to choose mipmap levels or to
957 * distinguish between minification/magnification with one mipmap level.
958 */
959 lod = lp_build_lod_selector(bld, unit, ddx, ddy,
960 lod_bias, explicit_lod,
961 width, height, depth);
962 }
963
964 /*
965 * Compute integer mipmap level(s) to fetch texels from.
966 */
967 if (mip_filter == PIPE_TEX_MIPFILTER_NONE) {
968 /* always use mip level 0 */
969 if (bld->static_state->target == PIPE_TEXTURE_CUBE) {
970 /* XXX this is a work-around for an apparent bug in LLVM 2.7.
971 * We should be able to set ilevel0 = const(0) but that causes
972 * bad x86 code to be emitted.
973 */
974 lod = lp_build_const_elem(bld->coord_bld.type, 0.0);
975 lp_build_nearest_mip_level(bld, unit, lod, &ilevel0);
976 }
977 else {
978 ilevel0 = LLVMConstInt(LLVMInt32Type(), 0, 0);
979 }
980 }
981 else {
982 assert(lod);
983 if (mip_filter == PIPE_TEX_MIPFILTER_NEAREST) {
984 lp_build_nearest_mip_level(bld, unit, lod, &ilevel0);
985 }
986 else {
987 assert(mip_filter == PIPE_TEX_MIPFILTER_LINEAR);
988 lp_build_linear_mip_levels(bld, unit, lod, &ilevel0, &ilevel1,
989 &lod_fpart);
990 lod_fpart = lp_build_broadcast_scalar(&bld->coord_bld, lod_fpart);
991 }
992 }
993
994 /* compute image size(s) of source mipmap level(s) */
995 lp_build_mipmap_level_sizes(bld, dims, width_vec, height_vec, depth_vec,
996 ilevel0, ilevel1,
997 row_stride_array, img_stride_array,
998 &width0_vec, &width1_vec,
999 &height0_vec, &height1_vec,
1000 &depth0_vec, &depth1_vec,
1001 &row_stride0_vec, &row_stride1_vec,
1002 &img_stride0_vec, &img_stride1_vec);
1003
1004 /*
1005 * Get pointer(s) to image data for mipmap level(s).
1006 */
1007 data_ptr0 = lp_build_get_mipmap_level(bld, data_array, ilevel0);
1008 if (mip_filter == PIPE_TEX_MIPFILTER_LINEAR) {
1009 data_ptr1 = lp_build_get_mipmap_level(bld, data_array, ilevel1);
1010 }
1011
1012 /*
1013 * Get/interpolate texture colors.
1014 */
1015 if (min_filter == mag_filter) {
1016 /* no need to distinquish between minification and magnification */
1017 lp_build_sample_mipmap(bld, unit,
1018 min_filter, mip_filter, s, t, r, lod_fpart,
1019 width0_vec, width1_vec,
1020 height0_vec, height1_vec,
1021 depth0_vec, depth1_vec,
1022 row_stride0_vec, row_stride1_vec,
1023 img_stride0_vec, img_stride1_vec,
1024 data_ptr0, data_ptr1,
1025 colors_out);
1026 }
1027 else {
1028 /* Emit conditional to choose min image filter or mag image filter
1029 * depending on the lod being >0 or <= 0, respectively.
1030 */
1031 struct lp_build_flow_context *flow_ctx;
1032 struct lp_build_if_state if_ctx;
1033 LLVMValueRef minify;
1034
1035 flow_ctx = lp_build_flow_create(bld->builder);
1036 lp_build_flow_scope_begin(flow_ctx);
1037
1038 lp_build_flow_scope_declare(flow_ctx, &colors_out[0]);
1039 lp_build_flow_scope_declare(flow_ctx, &colors_out[1]);
1040 lp_build_flow_scope_declare(flow_ctx, &colors_out[2]);
1041 lp_build_flow_scope_declare(flow_ctx, &colors_out[3]);
1042
1043 /* minify = lod > 0.0 */
1044 minify = LLVMBuildFCmp(bld->builder, LLVMRealUGE,
1045 lod, float_bld->zero, "");
1046
1047 lp_build_if(&if_ctx, flow_ctx, bld->builder, minify);
1048 {
1049 /* Use the minification filter */
1050 lp_build_sample_mipmap(bld, unit,
1051 min_filter, mip_filter,
1052 s, t, r, lod_fpart,
1053 width0_vec, width1_vec,
1054 height0_vec, height1_vec,
1055 depth0_vec, depth1_vec,
1056 row_stride0_vec, row_stride1_vec,
1057 img_stride0_vec, img_stride1_vec,
1058 data_ptr0, data_ptr1,
1059 colors_out);
1060 }
1061 lp_build_else(&if_ctx);
1062 {
1063 /* Use the magnification filter */
1064 lp_build_sample_mipmap(bld, unit,
1065 mag_filter, mip_filter,
1066 s, t, r, lod_fpart,
1067 width0_vec, width1_vec,
1068 height0_vec, height1_vec,
1069 depth0_vec, depth1_vec,
1070 row_stride0_vec, row_stride1_vec,
1071 img_stride0_vec, img_stride1_vec,
1072 data_ptr0, data_ptr1,
1073 colors_out);
1074 }
1075 lp_build_endif(&if_ctx);
1076
1077 lp_build_flow_scope_end(flow_ctx);
1078 lp_build_flow_destroy(flow_ctx);
1079 }
1080 }
1081
1082
1083 /**
1084 * Do shadow test/comparison.
1085 * \param p the texcoord Z (aka R, aka P) component
1086 * \param texel the texel to compare against (use the X channel)
1087 */
1088 static void
1089 lp_build_sample_compare(struct lp_build_sample_context *bld,
1090 LLVMValueRef p,
1091 LLVMValueRef texel[4])
1092 {
1093 struct lp_build_context *texel_bld = &bld->texel_bld;
1094 LLVMValueRef res;
1095 const unsigned chan = 0;
1096
1097 if (bld->static_state->compare_mode == PIPE_TEX_COMPARE_NONE)
1098 return;
1099
1100 /* debug code */
1101 if (0) {
1102 LLVMValueRef indx = lp_build_const_int32(0);
1103 LLVMValueRef coord = LLVMBuildExtractElement(bld->builder, p, indx, "");
1104 LLVMValueRef tex = LLVMBuildExtractElement(bld->builder,
1105 texel[chan], indx, "");
1106 lp_build_printf(bld->builder, "shadow compare coord %f to texture %f\n",
1107 coord, tex);
1108 }
1109
1110 /* result = (p FUNC texel) ? 1 : 0 */
1111 res = lp_build_cmp(texel_bld, bld->static_state->compare_func,
1112 p, texel[chan]);
1113 res = lp_build_select(texel_bld, res, texel_bld->one, texel_bld->zero);
1114
1115 /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */
1116 texel[0] =
1117 texel[1] =
1118 texel[2] = res;
1119 texel[3] = texel_bld->one;
1120 }
1121
1122
1123 /**
1124 * Just set texels to white instead of actually sampling the texture.
1125 * For debugging.
1126 */
1127 void
1128 lp_build_sample_nop(struct lp_type type,
1129 LLVMValueRef texel_out[4])
1130 {
1131 LLVMValueRef one = lp_build_one(type);
1132 unsigned chan;
1133
1134 for (chan = 0; chan < 4; chan++) {
1135 texel_out[chan] = one;
1136 }
1137 }
1138
1139
1140 /**
1141 * Build texture sampling code.
1142 * 'texel' will return a vector of four LLVMValueRefs corresponding to
1143 * R, G, B, A.
1144 * \param type vector float type to use for coords, etc.
1145 * \param ddx partial derivatives of (s,t,r,q) with respect to x
1146 * \param ddy partial derivatives of (s,t,r,q) with respect to y
1147 */
1148 void
1149 lp_build_sample_soa(LLVMBuilderRef builder,
1150 const struct lp_sampler_static_state *static_state,
1151 struct lp_sampler_dynamic_state *dynamic_state,
1152 struct lp_type type,
1153 unsigned unit,
1154 unsigned num_coords,
1155 const LLVMValueRef *coords,
1156 const LLVMValueRef ddx[4],
1157 const LLVMValueRef ddy[4],
1158 LLVMValueRef lod_bias, /* optional */
1159 LLVMValueRef explicit_lod, /* optional */
1160 LLVMValueRef texel_out[4])
1161 {
1162 struct lp_build_sample_context bld;
1163 LLVMValueRef width, width_vec;
1164 LLVMValueRef height, height_vec;
1165 LLVMValueRef depth, depth_vec;
1166 LLVMValueRef row_stride_array, img_stride_array;
1167 LLVMValueRef data_array;
1168 LLVMValueRef s;
1169 LLVMValueRef t;
1170 LLVMValueRef r;
1171 struct lp_type float_vec_type;
1172
1173 if (0) {
1174 enum pipe_format fmt = static_state->format;
1175 debug_printf("Sample from %s\n", util_format_name(fmt));
1176 }
1177
1178 assert(type.floating);
1179
1180 /* Setup our build context */
1181 memset(&bld, 0, sizeof bld);
1182 bld.builder = builder;
1183 bld.static_state = static_state;
1184 bld.dynamic_state = dynamic_state;
1185 bld.format_desc = util_format_description(static_state->format);
1186
1187 bld.float_type = lp_type_float(32);
1188 bld.int_type = lp_type_int(32);
1189 bld.coord_type = type;
1190 bld.uint_coord_type = lp_uint_type(type);
1191 bld.int_coord_type = lp_int_type(type);
1192 bld.texel_type = type;
1193
1194 float_vec_type = lp_type_float_vec(32);
1195
1196 lp_build_context_init(&bld.float_bld, builder, bld.float_type);
1197 lp_build_context_init(&bld.float_vec_bld, builder, float_vec_type);
1198 lp_build_context_init(&bld.int_bld, builder, bld.int_type);
1199 lp_build_context_init(&bld.coord_bld, builder, bld.coord_type);
1200 lp_build_context_init(&bld.uint_coord_bld, builder, bld.uint_coord_type);
1201 lp_build_context_init(&bld.int_coord_bld, builder, bld.int_coord_type);
1202 lp_build_context_init(&bld.texel_bld, builder, bld.texel_type);
1203
1204 /* Get the dynamic state */
1205 width = dynamic_state->width(dynamic_state, builder, unit);
1206 height = dynamic_state->height(dynamic_state, builder, unit);
1207 depth = dynamic_state->depth(dynamic_state, builder, unit);
1208 row_stride_array = dynamic_state->row_stride(dynamic_state, builder, unit);
1209 img_stride_array = dynamic_state->img_stride(dynamic_state, builder, unit);
1210 data_array = dynamic_state->data_ptr(dynamic_state, builder, unit);
1211 /* Note that data_array is an array[level] of pointers to texture images */
1212
1213 s = coords[0];
1214 t = coords[1];
1215 r = coords[2];
1216
1217 /* width, height, depth as uint vectors */
1218 width_vec = lp_build_broadcast_scalar(&bld.uint_coord_bld, width);
1219 height_vec = lp_build_broadcast_scalar(&bld.uint_coord_bld, height);
1220 depth_vec = lp_build_broadcast_scalar(&bld.uint_coord_bld, depth);
1221
1222 if (0) {
1223 /* For debug: no-op texture sampling */
1224 lp_build_sample_nop(bld.texel_type, texel_out);
1225 }
1226 else if (util_format_fits_8unorm(bld.format_desc) &&
1227 lp_is_simple_wrap_mode(static_state->wrap_s) &&
1228 lp_is_simple_wrap_mode(static_state->wrap_t)) {
1229 /* do sampling/filtering with fixed pt arithmetic */
1230 lp_build_sample_aos(&bld, unit, s, t, r, ddx, ddy,
1231 lod_bias, explicit_lod,
1232 width, height, depth,
1233 width_vec, height_vec, depth_vec,
1234 row_stride_array, img_stride_array,
1235 data_array, texel_out);
1236 }
1237
1238 else {
1239 if ((gallivm_debug & GALLIVM_DEBUG_PERF) &&
1240 util_format_fits_8unorm(bld.format_desc)) {
1241 debug_printf("%s: using floating point linear filtering for %s\n",
1242 __FUNCTION__, bld.format_desc->short_name);
1243 debug_printf(" min_img %d mag_img %d mip %d wraps %d wrapt %d\n",
1244 static_state->min_img_filter,
1245 static_state->mag_img_filter,
1246 static_state->min_mip_filter,
1247 static_state->wrap_s,
1248 static_state->wrap_t);
1249 }
1250
1251 lp_build_sample_general(&bld, unit, s, t, r, ddx, ddy,
1252 lod_bias, explicit_lod,
1253 width, height, depth,
1254 width_vec, height_vec, depth_vec,
1255 row_stride_array, img_stride_array,
1256 data_array,
1257 texel_out);
1258 }
1259
1260 lp_build_sample_compare(&bld, r, texel_out);
1261 }