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