softpipe: Silence uninitialized variable warnings.
[mesa.git] / src / gallium / drivers / softpipe / sp_tex_sample.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 * Copyright 2008-2010 VMware, Inc. All rights reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29 /**
30 * Texture sampling
31 *
32 * Authors:
33 * Brian Paul
34 * Keith Whitwell
35 */
36
37 #include "pipe/p_context.h"
38 #include "pipe/p_defines.h"
39 #include "pipe/p_shader_tokens.h"
40 #include "util/u_math.h"
41 #include "util/u_memory.h"
42 #include "sp_quad.h" /* only for #define QUAD_* tokens */
43 #include "sp_tex_sample.h"
44 #include "sp_tex_tile_cache.h"
45
46
47
48 /*
49 * Return fractional part of 'f'. Used for computing interpolation weights.
50 * Need to be careful with negative values.
51 * Note, if this function isn't perfect you'll sometimes see 1-pixel bands
52 * of improperly weighted linear-filtered textures.
53 * The tests/texwrap.c demo is a good test.
54 */
55 static INLINE float
56 frac(float f)
57 {
58 return f - util_ifloor(f);
59 }
60
61
62
63 /**
64 * Linear interpolation macro
65 */
66 static INLINE float
67 lerp(float a, float v0, float v1)
68 {
69 return v0 + a * (v1 - v0);
70 }
71
72
73 /**
74 * Do 2D/biliner interpolation of float values.
75 * v00, v10, v01 and v11 are typically four texture samples in a square/box.
76 * a and b are the horizontal and vertical interpolants.
77 * It's important that this function is inlined when compiled with
78 * optimization! If we find that's not true on some systems, convert
79 * to a macro.
80 */
81 static INLINE float
82 lerp_2d(float a, float b,
83 float v00, float v10, float v01, float v11)
84 {
85 const float temp0 = lerp(a, v00, v10);
86 const float temp1 = lerp(a, v01, v11);
87 return lerp(b, temp0, temp1);
88 }
89
90
91 /**
92 * As above, but 3D interpolation of 8 values.
93 */
94 static INLINE float
95 lerp_3d(float a, float b, float c,
96 float v000, float v100, float v010, float v110,
97 float v001, float v101, float v011, float v111)
98 {
99 const float temp0 = lerp_2d(a, b, v000, v100, v010, v110);
100 const float temp1 = lerp_2d(a, b, v001, v101, v011, v111);
101 return lerp(c, temp0, temp1);
102 }
103
104
105
106 /**
107 * Compute coord % size for repeat wrap modes.
108 * Note that if coord is a signed integer, coord % size doesn't give
109 * the right value for coord < 0 (in terms of texture repeat). Just
110 * casting to unsigned fixes that.
111 */
112 static INLINE int
113 repeat(int coord, unsigned size)
114 {
115 return (int) ((unsigned) coord % size);
116 }
117
118
119 /**
120 * Apply texture coord wrapping mode and return integer texture indexes
121 * for a vector of four texcoords (S or T or P).
122 * \param wrapMode PIPE_TEX_WRAP_x
123 * \param s the incoming texcoords
124 * \param size the texture image size
125 * \param icoord returns the integer texcoords
126 * \return integer texture index
127 */
128 static void
129 wrap_nearest_repeat(const float s[4], unsigned size, int icoord[4])
130 {
131 uint ch;
132 /* s limited to [0,1) */
133 /* i limited to [0,size-1] */
134 for (ch = 0; ch < 4; ch++) {
135 int i = util_ifloor(s[ch] * size);
136 icoord[ch] = repeat(i, size);
137 }
138 }
139
140
141 static void
142 wrap_nearest_clamp(const float s[4], unsigned size, int icoord[4])
143 {
144 uint ch;
145 /* s limited to [0,1] */
146 /* i limited to [0,size-1] */
147 for (ch = 0; ch < 4; ch++) {
148 if (s[ch] <= 0.0F)
149 icoord[ch] = 0;
150 else if (s[ch] >= 1.0F)
151 icoord[ch] = size - 1;
152 else
153 icoord[ch] = util_ifloor(s[ch] * size);
154 }
155 }
156
157
158 static void
159 wrap_nearest_clamp_to_edge(const float s[4], unsigned size, int icoord[4])
160 {
161 uint ch;
162 /* s limited to [min,max] */
163 /* i limited to [0, size-1] */
164 const float min = 1.0F / (2.0F * size);
165 const float max = 1.0F - min;
166 for (ch = 0; ch < 4; ch++) {
167 if (s[ch] < min)
168 icoord[ch] = 0;
169 else if (s[ch] > max)
170 icoord[ch] = size - 1;
171 else
172 icoord[ch] = util_ifloor(s[ch] * size);
173 }
174 }
175
176
177 static void
178 wrap_nearest_clamp_to_border(const float s[4], unsigned size, int icoord[4])
179 {
180 uint ch;
181 /* s limited to [min,max] */
182 /* i limited to [-1, size] */
183 const float min = -1.0F / (2.0F * size);
184 const float max = 1.0F - min;
185 for (ch = 0; ch < 4; ch++) {
186 if (s[ch] <= min)
187 icoord[ch] = -1;
188 else if (s[ch] >= max)
189 icoord[ch] = size;
190 else
191 icoord[ch] = util_ifloor(s[ch] * size);
192 }
193 }
194
195
196 static void
197 wrap_nearest_mirror_repeat(const float s[4], unsigned size, int icoord[4])
198 {
199 uint ch;
200 const float min = 1.0F / (2.0F * size);
201 const float max = 1.0F - min;
202 for (ch = 0; ch < 4; ch++) {
203 const int flr = util_ifloor(s[ch]);
204 float u;
205 if (flr & 1)
206 u = 1.0F - (s[ch] - (float) flr);
207 else
208 u = s[ch] - (float) flr;
209 if (u < min)
210 icoord[ch] = 0;
211 else if (u > max)
212 icoord[ch] = size - 1;
213 else
214 icoord[ch] = util_ifloor(u * size);
215 }
216 }
217
218
219 static void
220 wrap_nearest_mirror_clamp(const float s[4], unsigned size, int icoord[4])
221 {
222 uint ch;
223 for (ch = 0; ch < 4; ch++) {
224 /* s limited to [0,1] */
225 /* i limited to [0,size-1] */
226 const float u = fabsf(s[ch]);
227 if (u <= 0.0F)
228 icoord[ch] = 0;
229 else if (u >= 1.0F)
230 icoord[ch] = size - 1;
231 else
232 icoord[ch] = util_ifloor(u * size);
233 }
234 }
235
236
237 static void
238 wrap_nearest_mirror_clamp_to_edge(const float s[4], unsigned size,
239 int icoord[4])
240 {
241 uint ch;
242 /* s limited to [min,max] */
243 /* i limited to [0, size-1] */
244 const float min = 1.0F / (2.0F * size);
245 const float max = 1.0F - min;
246 for (ch = 0; ch < 4; ch++) {
247 const float u = fabsf(s[ch]);
248 if (u < min)
249 icoord[ch] = 0;
250 else if (u > max)
251 icoord[ch] = size - 1;
252 else
253 icoord[ch] = util_ifloor(u * size);
254 }
255 }
256
257
258 static void
259 wrap_nearest_mirror_clamp_to_border(const float s[4], unsigned size,
260 int icoord[4])
261 {
262 uint ch;
263 /* s limited to [min,max] */
264 /* i limited to [0, size-1] */
265 const float min = -1.0F / (2.0F * size);
266 const float max = 1.0F - min;
267 for (ch = 0; ch < 4; ch++) {
268 const float u = fabsf(s[ch]);
269 if (u < min)
270 icoord[ch] = -1;
271 else if (u > max)
272 icoord[ch] = size;
273 else
274 icoord[ch] = util_ifloor(u * size);
275 }
276 }
277
278
279 /**
280 * Used to compute texel locations for linear sampling for four texcoords.
281 * \param wrapMode PIPE_TEX_WRAP_x
282 * \param s the texcoords
283 * \param size the texture image size
284 * \param icoord0 returns first texture indexes
285 * \param icoord1 returns second texture indexes (usually icoord0 + 1)
286 * \param w returns blend factor/weight between texture indexes
287 * \param icoord returns the computed integer texture coords
288 */
289 static void
290 wrap_linear_repeat(const float s[4], unsigned size,
291 int icoord0[4], int icoord1[4], float w[4])
292 {
293 uint ch;
294 for (ch = 0; ch < 4; ch++) {
295 float u = s[ch] * size - 0.5F;
296 icoord0[ch] = repeat(util_ifloor(u), size);
297 icoord1[ch] = repeat(icoord0[ch] + 1, size);
298 w[ch] = frac(u);
299 }
300 }
301
302
303 static void
304 wrap_linear_clamp(const float s[4], unsigned size,
305 int icoord0[4], int icoord1[4], float w[4])
306 {
307 uint ch;
308 for (ch = 0; ch < 4; ch++) {
309 float u = CLAMP(s[ch], 0.0F, 1.0F);
310 u = u * size - 0.5f;
311 icoord0[ch] = util_ifloor(u);
312 icoord1[ch] = icoord0[ch] + 1;
313 w[ch] = frac(u);
314 }
315 }
316
317
318 static void
319 wrap_linear_clamp_to_edge(const float s[4], unsigned size,
320 int icoord0[4], int icoord1[4], float w[4])
321 {
322 uint ch;
323 for (ch = 0; ch < 4; ch++) {
324 float u = CLAMP(s[ch], 0.0F, 1.0F);
325 u = u * size - 0.5f;
326 icoord0[ch] = util_ifloor(u);
327 icoord1[ch] = icoord0[ch] + 1;
328 if (icoord0[ch] < 0)
329 icoord0[ch] = 0;
330 if (icoord1[ch] >= (int) size)
331 icoord1[ch] = size - 1;
332 w[ch] = frac(u);
333 }
334 }
335
336
337 static void
338 wrap_linear_clamp_to_border(const float s[4], unsigned size,
339 int icoord0[4], int icoord1[4], float w[4])
340 {
341 const float min = -1.0F / (2.0F * size);
342 const float max = 1.0F - min;
343 uint ch;
344 for (ch = 0; ch < 4; ch++) {
345 float u = CLAMP(s[ch], min, max);
346 u = u * size - 0.5f;
347 icoord0[ch] = util_ifloor(u);
348 icoord1[ch] = icoord0[ch] + 1;
349 w[ch] = frac(u);
350 }
351 }
352
353
354 static void
355 wrap_linear_mirror_repeat(const float s[4], unsigned size,
356 int icoord0[4], int icoord1[4], float w[4])
357 {
358 uint ch;
359 for (ch = 0; ch < 4; ch++) {
360 const int flr = util_ifloor(s[ch]);
361 float u;
362 if (flr & 1)
363 u = 1.0F - (s[ch] - (float) flr);
364 else
365 u = s[ch] - (float) flr;
366 u = u * size - 0.5F;
367 icoord0[ch] = util_ifloor(u);
368 icoord1[ch] = icoord0[ch] + 1;
369 if (icoord0[ch] < 0)
370 icoord0[ch] = 0;
371 if (icoord1[ch] >= (int) size)
372 icoord1[ch] = size - 1;
373 w[ch] = frac(u);
374 }
375 }
376
377
378 static void
379 wrap_linear_mirror_clamp(const float s[4], unsigned size,
380 int icoord0[4], int icoord1[4], float w[4])
381 {
382 uint ch;
383 for (ch = 0; ch < 4; ch++) {
384 float u = fabsf(s[ch]);
385 if (u >= 1.0F)
386 u = (float) size;
387 else
388 u *= size;
389 u -= 0.5F;
390 icoord0[ch] = util_ifloor(u);
391 icoord1[ch] = icoord0[ch] + 1;
392 w[ch] = frac(u);
393 }
394 }
395
396
397 static void
398 wrap_linear_mirror_clamp_to_edge(const float s[4], unsigned size,
399 int icoord0[4], int icoord1[4], float w[4])
400 {
401 uint ch;
402 for (ch = 0; ch < 4; ch++) {
403 float u = fabsf(s[ch]);
404 if (u >= 1.0F)
405 u = (float) size;
406 else
407 u *= size;
408 u -= 0.5F;
409 icoord0[ch] = util_ifloor(u);
410 icoord1[ch] = icoord0[ch] + 1;
411 if (icoord0[ch] < 0)
412 icoord0[ch] = 0;
413 if (icoord1[ch] >= (int) size)
414 icoord1[ch] = size - 1;
415 w[ch] = frac(u);
416 }
417 }
418
419
420 static void
421 wrap_linear_mirror_clamp_to_border(const float s[4], unsigned size,
422 int icoord0[4], int icoord1[4], float w[4])
423 {
424 const float min = -1.0F / (2.0F * size);
425 const float max = 1.0F - min;
426 uint ch;
427 for (ch = 0; ch < 4; ch++) {
428 float u = fabsf(s[ch]);
429 if (u <= min)
430 u = min * size;
431 else if (u >= max)
432 u = max * size;
433 else
434 u *= size;
435 u -= 0.5F;
436 icoord0[ch] = util_ifloor(u);
437 icoord1[ch] = icoord0[ch] + 1;
438 w[ch] = frac(u);
439 }
440 }
441
442
443 /**
444 * For RECT textures / unnormalized texcoords
445 * Only a subset of wrap modes supported.
446 */
447 static void
448 wrap_nearest_unorm_clamp(const float s[4], unsigned size, int icoord[4])
449 {
450 uint ch;
451 for (ch = 0; ch < 4; ch++) {
452 int i = util_ifloor(s[ch]);
453 icoord[ch]= CLAMP(i, 0, (int) size-1);
454 }
455 }
456
457
458 /**
459 * Handles clamp_to_edge and clamp_to_border:
460 */
461 static void
462 wrap_nearest_unorm_clamp_to_border(const float s[4], unsigned size,
463 int icoord[4])
464 {
465 uint ch;
466 for (ch = 0; ch < 4; ch++) {
467 icoord[ch]= util_ifloor( CLAMP(s[ch], 0.5F, (float) size - 0.5F) );
468 }
469 }
470
471
472 /**
473 * For RECT textures / unnormalized texcoords.
474 * Only a subset of wrap modes supported.
475 */
476 static void
477 wrap_linear_unorm_clamp(const float s[4], unsigned size,
478 int icoord0[4], int icoord1[4], float w[4])
479 {
480 uint ch;
481 for (ch = 0; ch < 4; ch++) {
482 /* Not exactly what the spec says, but it matches NVIDIA output */
483 float u = CLAMP(s[ch] - 0.5F, 0.0f, (float) size - 1.0f);
484 icoord0[ch] = util_ifloor(u);
485 icoord1[ch] = icoord0[ch] + 1;
486 w[ch] = frac(u);
487 }
488 }
489
490
491 static void
492 wrap_linear_unorm_clamp_to_border(const float s[4], unsigned size,
493 int icoord0[4], int icoord1[4], float w[4])
494 {
495 uint ch;
496 for (ch = 0; ch < 4; ch++) {
497 float u = CLAMP(s[ch], 0.5F, (float) size - 0.5F);
498 u -= 0.5F;
499 icoord0[ch] = util_ifloor(u);
500 icoord1[ch] = icoord0[ch] + 1;
501 if (icoord1[ch] > (int) size - 1)
502 icoord1[ch] = size - 1;
503 w[ch] = frac(u);
504 }
505 }
506
507
508
509 /**
510 * Examine the quad's texture coordinates to compute the partial
511 * derivatives w.r.t X and Y, then compute lambda (level of detail).
512 */
513 static float
514 compute_lambda_1d(const struct sp_sampler_varient *samp,
515 const float s[QUAD_SIZE],
516 const float t[QUAD_SIZE],
517 const float p[QUAD_SIZE])
518 {
519 const struct pipe_texture *texture = samp->texture;
520 float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]);
521 float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]);
522 float rho = MAX2(dsdx, dsdy) * texture->width0;
523
524 return util_fast_log2(rho);
525 }
526
527
528 static float
529 compute_lambda_2d(const struct sp_sampler_varient *samp,
530 const float s[QUAD_SIZE],
531 const float t[QUAD_SIZE],
532 const float p[QUAD_SIZE])
533 {
534 const struct pipe_texture *texture = samp->texture;
535 float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]);
536 float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]);
537 float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]);
538 float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]);
539 float maxx = MAX2(dsdx, dsdy) * texture->width0;
540 float maxy = MAX2(dtdx, dtdy) * texture->height0;
541 float rho = MAX2(maxx, maxy);
542
543 return util_fast_log2(rho);
544 }
545
546
547 static float
548 compute_lambda_3d(const struct sp_sampler_varient *samp,
549 const float s[QUAD_SIZE],
550 const float t[QUAD_SIZE],
551 const float p[QUAD_SIZE])
552 {
553 const struct pipe_texture *texture = samp->texture;
554 float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]);
555 float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]);
556 float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]);
557 float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]);
558 float dpdx = fabsf(p[QUAD_BOTTOM_RIGHT] - p[QUAD_BOTTOM_LEFT]);
559 float dpdy = fabsf(p[QUAD_TOP_LEFT] - p[QUAD_BOTTOM_LEFT]);
560 float maxx = MAX2(dsdx, dsdy) * texture->width0;
561 float maxy = MAX2(dtdx, dtdy) * texture->height0;
562 float maxz = MAX2(dpdx, dpdy) * texture->depth0;
563 float rho;
564
565 rho = MAX2(maxx, maxy);
566 rho = MAX2(rho, maxz);
567
568 return util_fast_log2(rho);
569 }
570
571
572 /**
573 * Compute lambda for a vertex texture sampler.
574 * Since there aren't derivatives to use, just return 0.
575 */
576 static float
577 compute_lambda_vert(const struct sp_sampler_varient *samp,
578 const float s[QUAD_SIZE],
579 const float t[QUAD_SIZE],
580 const float p[QUAD_SIZE])
581 {
582 return 0.0f;
583 }
584
585
586
587 /**
588 * Get a texel from a texture, using the texture tile cache.
589 *
590 * \param addr the template tex address containing cube, z, face info.
591 * \param x the x coord of texel within 2D image
592 * \param y the y coord of texel within 2D image
593 * \param rgba the quad to put the texel/color into
594 *
595 * XXX maybe move this into sp_tex_tile_cache.c and merge with the
596 * sp_get_cached_tile_tex() function. Also, get 4 texels instead of 1...
597 */
598
599
600
601
602 static INLINE const float *
603 get_texel_2d_no_border(const struct sp_sampler_varient *samp,
604 union tex_tile_address addr, int x, int y)
605 {
606 const struct softpipe_tex_cached_tile *tile;
607
608 addr.bits.x = x / TILE_SIZE;
609 addr.bits.y = y / TILE_SIZE;
610 y %= TILE_SIZE;
611 x %= TILE_SIZE;
612
613 tile = sp_get_cached_tile_tex(samp->cache, addr);
614
615 return &tile->data.color[y][x][0];
616 }
617
618
619 static INLINE const float *
620 get_texel_2d(const struct sp_sampler_varient *samp,
621 union tex_tile_address addr, int x, int y)
622 {
623 const struct pipe_texture *texture = samp->texture;
624 unsigned level = addr.bits.level;
625
626 if (x < 0 || x >= (int) u_minify(texture->width0, level) ||
627 y < 0 || y >= (int) u_minify(texture->height0, level)) {
628 return samp->sampler->border_color;
629 }
630 else {
631 return get_texel_2d_no_border( samp, addr, x, y );
632 }
633 }
634
635
636 /* Gather a quad of adjacent texels within a tile:
637 */
638 static INLINE void
639 get_texel_quad_2d_no_border_single_tile(const struct sp_sampler_varient *samp,
640 union tex_tile_address addr,
641 unsigned x, unsigned y,
642 const float *out[4])
643 {
644 const struct softpipe_tex_cached_tile *tile;
645
646 addr.bits.x = x / TILE_SIZE;
647 addr.bits.y = y / TILE_SIZE;
648 y %= TILE_SIZE;
649 x %= TILE_SIZE;
650
651 tile = sp_get_cached_tile_tex(samp->cache, addr);
652
653 out[0] = &tile->data.color[y ][x ][0];
654 out[1] = &tile->data.color[y ][x+1][0];
655 out[2] = &tile->data.color[y+1][x ][0];
656 out[3] = &tile->data.color[y+1][x+1][0];
657 }
658
659
660 /* Gather a quad of potentially non-adjacent texels:
661 */
662 static INLINE void
663 get_texel_quad_2d_no_border(const struct sp_sampler_varient *samp,
664 union tex_tile_address addr,
665 int x0, int y0,
666 int x1, int y1,
667 const float *out[4])
668 {
669 out[0] = get_texel_2d_no_border( samp, addr, x0, y0 );
670 out[1] = get_texel_2d_no_border( samp, addr, x1, y0 );
671 out[2] = get_texel_2d_no_border( samp, addr, x0, y1 );
672 out[3] = get_texel_2d_no_border( samp, addr, x1, y1 );
673 }
674
675 /* Can involve a lot of unnecessary checks for border color:
676 */
677 static INLINE void
678 get_texel_quad_2d(const struct sp_sampler_varient *samp,
679 union tex_tile_address addr,
680 int x0, int y0,
681 int x1, int y1,
682 const float *out[4])
683 {
684 out[0] = get_texel_2d( samp, addr, x0, y0 );
685 out[1] = get_texel_2d( samp, addr, x1, y0 );
686 out[3] = get_texel_2d( samp, addr, x1, y1 );
687 out[2] = get_texel_2d( samp, addr, x0, y1 );
688 }
689
690
691
692 /* 3d varients:
693 */
694 static INLINE const float *
695 get_texel_3d_no_border(const struct sp_sampler_varient *samp,
696 union tex_tile_address addr, int x, int y, int z)
697 {
698 const struct softpipe_tex_cached_tile *tile;
699
700 addr.bits.x = x / TILE_SIZE;
701 addr.bits.y = y / TILE_SIZE;
702 addr.bits.z = z;
703 y %= TILE_SIZE;
704 x %= TILE_SIZE;
705
706 tile = sp_get_cached_tile_tex(samp->cache, addr);
707
708 return &tile->data.color[y][x][0];
709 }
710
711
712 static INLINE const float *
713 get_texel_3d(const struct sp_sampler_varient *samp,
714 union tex_tile_address addr, int x, int y, int z)
715 {
716 const struct pipe_texture *texture = samp->texture;
717 unsigned level = addr.bits.level;
718
719 if (x < 0 || x >= (int) u_minify(texture->width0, level) ||
720 y < 0 || y >= (int) u_minify(texture->height0, level) ||
721 z < 0 || z >= (int) u_minify(texture->depth0, level)) {
722 return samp->sampler->border_color;
723 }
724 else {
725 return get_texel_3d_no_border( samp, addr, x, y, z );
726 }
727 }
728
729
730 /**
731 * Given the logbase2 of a mipmap's base level size and a mipmap level,
732 * return the size (in texels) of that mipmap level.
733 * For example, if level[0].width = 256 then base_pot will be 8.
734 * If level = 2, then we'll return 64 (the width at level=2).
735 * Return 1 if level > base_pot.
736 */
737 static INLINE unsigned
738 pot_level_size(unsigned base_pot, unsigned level)
739 {
740 return (base_pot >= level) ? (1 << (base_pot - level)) : 1;
741 }
742
743
744 /* Some image-filter fastpaths:
745 */
746 static INLINE void
747 img_filter_2d_linear_repeat_POT(struct tgsi_sampler *tgsi_sampler,
748 const float s[QUAD_SIZE],
749 const float t[QUAD_SIZE],
750 const float p[QUAD_SIZE],
751 const float c0[QUAD_SIZE],
752 enum tgsi_sampler_control control,
753 float rgba[NUM_CHANNELS][QUAD_SIZE])
754 {
755 const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
756 unsigned j;
757 unsigned level = samp->level;
758 unsigned xpot = pot_level_size(samp->xpot, level);
759 unsigned ypot = pot_level_size(samp->ypot, level);
760 unsigned xmax = (xpot - 1) & (TILE_SIZE - 1); /* MIN2(TILE_SIZE, xpot) - 1; */
761 unsigned ymax = (ypot - 1) & (TILE_SIZE - 1); /* MIN2(TILE_SIZE, ypot) - 1; */
762 union tex_tile_address addr;
763
764 addr.value = 0;
765 addr.bits.level = samp->level;
766
767 for (j = 0; j < QUAD_SIZE; j++) {
768 int c;
769
770 float u = s[j] * xpot - 0.5F;
771 float v = t[j] * ypot - 0.5F;
772
773 int uflr = util_ifloor(u);
774 int vflr = util_ifloor(v);
775
776 float xw = u - (float)uflr;
777 float yw = v - (float)vflr;
778
779 int x0 = uflr & (xpot - 1);
780 int y0 = vflr & (ypot - 1);
781
782 const float *tx[4];
783
784 /* Can we fetch all four at once:
785 */
786 if (x0 < xmax && y0 < ymax) {
787 get_texel_quad_2d_no_border_single_tile(samp, addr, x0, y0, tx);
788 }
789 else {
790 unsigned x1 = (x0 + 1) & (xpot - 1);
791 unsigned y1 = (y0 + 1) & (ypot - 1);
792 get_texel_quad_2d_no_border(samp, addr, x0, y0, x1, y1, tx);
793 }
794
795 /* interpolate R, G, B, A */
796 for (c = 0; c < 4; c++) {
797 rgba[c][j] = lerp_2d(xw, yw,
798 tx[0][c], tx[1][c],
799 tx[2][c], tx[3][c]);
800 }
801 }
802 }
803
804
805 static INLINE void
806 img_filter_2d_nearest_repeat_POT(struct tgsi_sampler *tgsi_sampler,
807 const float s[QUAD_SIZE],
808 const float t[QUAD_SIZE],
809 const float p[QUAD_SIZE],
810 const float c0[QUAD_SIZE],
811 enum tgsi_sampler_control control,
812 float rgba[NUM_CHANNELS][QUAD_SIZE])
813 {
814 const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
815 unsigned j;
816 unsigned level = samp->level;
817 unsigned xpot = pot_level_size(samp->xpot, level);
818 unsigned ypot = pot_level_size(samp->ypot, level);
819 union tex_tile_address addr;
820
821 addr.value = 0;
822 addr.bits.level = samp->level;
823
824 for (j = 0; j < QUAD_SIZE; j++) {
825 int c;
826
827 float u = s[j] * xpot;
828 float v = t[j] * ypot;
829
830 int uflr = util_ifloor(u);
831 int vflr = util_ifloor(v);
832
833 int x0 = uflr & (xpot - 1);
834 int y0 = vflr & (ypot - 1);
835
836 const float *out = get_texel_2d_no_border(samp, addr, x0, y0);
837
838 for (c = 0; c < 4; c++) {
839 rgba[c][j] = out[c];
840 }
841 }
842 }
843
844
845 static INLINE void
846 img_filter_2d_nearest_clamp_POT(struct tgsi_sampler *tgsi_sampler,
847 const float s[QUAD_SIZE],
848 const float t[QUAD_SIZE],
849 const float p[QUAD_SIZE],
850 const float c0[QUAD_SIZE],
851 enum tgsi_sampler_control control,
852 float rgba[NUM_CHANNELS][QUAD_SIZE])
853 {
854 const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
855 unsigned j;
856 unsigned level = samp->level;
857 unsigned xpot = pot_level_size(samp->xpot, level);
858 unsigned ypot = pot_level_size(samp->ypot, level);
859 union tex_tile_address addr;
860
861 addr.value = 0;
862 addr.bits.level = samp->level;
863
864 for (j = 0; j < QUAD_SIZE; j++) {
865 int c;
866
867 float u = s[j] * xpot;
868 float v = t[j] * ypot;
869
870 int x0, y0;
871 const float *out;
872
873 x0 = util_ifloor(u);
874 if (x0 < 0)
875 x0 = 0;
876 else if (x0 > xpot - 1)
877 x0 = xpot - 1;
878
879 y0 = util_ifloor(v);
880 if (y0 < 0)
881 y0 = 0;
882 else if (y0 > ypot - 1)
883 y0 = ypot - 1;
884
885 out = get_texel_2d_no_border(samp, addr, x0, y0);
886
887 for (c = 0; c < 4; c++) {
888 rgba[c][j] = out[c];
889 }
890 }
891 }
892
893
894 static void
895 img_filter_1d_nearest(struct tgsi_sampler *tgsi_sampler,
896 const float s[QUAD_SIZE],
897 const float t[QUAD_SIZE],
898 const float p[QUAD_SIZE],
899 const float c0[QUAD_SIZE],
900 enum tgsi_sampler_control control,
901 float rgba[NUM_CHANNELS][QUAD_SIZE])
902 {
903 const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
904 const struct pipe_texture *texture = samp->texture;
905 unsigned level0, j;
906 int width;
907 int x[4];
908 union tex_tile_address addr;
909
910 level0 = samp->level;
911 width = u_minify(texture->width0, level0);
912
913 assert(width > 0);
914
915 addr.value = 0;
916 addr.bits.level = samp->level;
917
918 samp->nearest_texcoord_s(s, width, x);
919
920 for (j = 0; j < QUAD_SIZE; j++) {
921 const float *out = get_texel_2d(samp, addr, x[j], 0);
922 int c;
923 for (c = 0; c < 4; c++) {
924 rgba[c][j] = out[c];
925 }
926 }
927 }
928
929
930 static void
931 img_filter_2d_nearest(struct tgsi_sampler *tgsi_sampler,
932 const float s[QUAD_SIZE],
933 const float t[QUAD_SIZE],
934 const float p[QUAD_SIZE],
935 const float c0[QUAD_SIZE],
936 enum tgsi_sampler_control control,
937 float rgba[NUM_CHANNELS][QUAD_SIZE])
938 {
939 const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
940 const struct pipe_texture *texture = samp->texture;
941 unsigned level0, j;
942 int width, height;
943 int x[4], y[4];
944 union tex_tile_address addr;
945
946
947 level0 = samp->level;
948 width = u_minify(texture->width0, level0);
949 height = u_minify(texture->height0, level0);
950
951 assert(width > 0);
952 assert(height > 0);
953
954 addr.value = 0;
955 addr.bits.level = samp->level;
956
957 samp->nearest_texcoord_s(s, width, x);
958 samp->nearest_texcoord_t(t, height, y);
959
960 for (j = 0; j < QUAD_SIZE; j++) {
961 const float *out = get_texel_2d(samp, addr, x[j], y[j]);
962 int c;
963 for (c = 0; c < 4; c++) {
964 rgba[c][j] = out[c];
965 }
966 }
967 }
968
969
970 static INLINE union tex_tile_address
971 face(union tex_tile_address addr, unsigned face )
972 {
973 addr.bits.face = face;
974 return addr;
975 }
976
977
978 static void
979 img_filter_cube_nearest(struct tgsi_sampler *tgsi_sampler,
980 const float s[QUAD_SIZE],
981 const float t[QUAD_SIZE],
982 const float p[QUAD_SIZE],
983 const float c0[QUAD_SIZE],
984 enum tgsi_sampler_control control,
985 float rgba[NUM_CHANNELS][QUAD_SIZE])
986 {
987 const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
988 const struct pipe_texture *texture = samp->texture;
989 const unsigned *faces = samp->faces; /* zero when not cube-mapping */
990 unsigned level0, j;
991 int width, height;
992 int x[4], y[4];
993 union tex_tile_address addr;
994
995 level0 = samp->level;
996 width = u_minify(texture->width0, level0);
997 height = u_minify(texture->height0, level0);
998
999 assert(width > 0);
1000 assert(height > 0);
1001
1002 addr.value = 0;
1003 addr.bits.level = samp->level;
1004
1005 samp->nearest_texcoord_s(s, width, x);
1006 samp->nearest_texcoord_t(t, height, y);
1007
1008 for (j = 0; j < QUAD_SIZE; j++) {
1009 const float *out = get_texel_2d(samp, face(addr, faces[j]), x[j], y[j]);
1010 int c;
1011 for (c = 0; c < 4; c++) {
1012 rgba[c][j] = out[c];
1013 }
1014 }
1015 }
1016
1017
1018 static void
1019 img_filter_3d_nearest(struct tgsi_sampler *tgsi_sampler,
1020 const float s[QUAD_SIZE],
1021 const float t[QUAD_SIZE],
1022 const float p[QUAD_SIZE],
1023 const float c0[QUAD_SIZE],
1024 enum tgsi_sampler_control control,
1025 float rgba[NUM_CHANNELS][QUAD_SIZE])
1026 {
1027 const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
1028 const struct pipe_texture *texture = samp->texture;
1029 unsigned level0, j;
1030 int width, height, depth;
1031 int x[4], y[4], z[4];
1032 union tex_tile_address addr;
1033
1034 level0 = samp->level;
1035 width = u_minify(texture->width0, level0);
1036 height = u_minify(texture->height0, level0);
1037 depth = u_minify(texture->depth0, level0);
1038
1039 assert(width > 0);
1040 assert(height > 0);
1041 assert(depth > 0);
1042
1043 samp->nearest_texcoord_s(s, width, x);
1044 samp->nearest_texcoord_t(t, height, y);
1045 samp->nearest_texcoord_p(p, depth, z);
1046
1047 addr.value = 0;
1048 addr.bits.level = samp->level;
1049
1050 for (j = 0; j < QUAD_SIZE; j++) {
1051 const float *out = get_texel_3d(samp, addr, x[j], y[j], z[j]);
1052 int c;
1053 for (c = 0; c < 4; c++) {
1054 rgba[c][j] = out[c];
1055 }
1056 }
1057 }
1058
1059
1060 static void
1061 img_filter_1d_linear(struct tgsi_sampler *tgsi_sampler,
1062 const float s[QUAD_SIZE],
1063 const float t[QUAD_SIZE],
1064 const float p[QUAD_SIZE],
1065 const float c0[QUAD_SIZE],
1066 enum tgsi_sampler_control control,
1067 float rgba[NUM_CHANNELS][QUAD_SIZE])
1068 {
1069 const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
1070 const struct pipe_texture *texture = samp->texture;
1071 unsigned level0, j;
1072 int width;
1073 int x0[4], x1[4];
1074 float xw[4]; /* weights */
1075 union tex_tile_address addr;
1076
1077 level0 = samp->level;
1078 width = u_minify(texture->width0, level0);
1079
1080 assert(width > 0);
1081
1082 addr.value = 0;
1083 addr.bits.level = samp->level;
1084
1085 samp->linear_texcoord_s(s, width, x0, x1, xw);
1086
1087 for (j = 0; j < QUAD_SIZE; j++) {
1088 const float *tx0 = get_texel_2d(samp, addr, x0[j], 0);
1089 const float *tx1 = get_texel_2d(samp, addr, x1[j], 0);
1090 int c;
1091
1092 /* interpolate R, G, B, A */
1093 for (c = 0; c < 4; c++) {
1094 rgba[c][j] = lerp(xw[j], tx0[c], tx1[c]);
1095 }
1096 }
1097 }
1098
1099
1100 static void
1101 img_filter_2d_linear(struct tgsi_sampler *tgsi_sampler,
1102 const float s[QUAD_SIZE],
1103 const float t[QUAD_SIZE],
1104 const float p[QUAD_SIZE],
1105 const float c0[QUAD_SIZE],
1106 enum tgsi_sampler_control control,
1107 float rgba[NUM_CHANNELS][QUAD_SIZE])
1108 {
1109 const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
1110 const struct pipe_texture *texture = samp->texture;
1111 unsigned level0, j;
1112 int width, height;
1113 int x0[4], y0[4], x1[4], y1[4];
1114 float xw[4], yw[4]; /* weights */
1115 union tex_tile_address addr;
1116
1117 level0 = samp->level;
1118 width = u_minify(texture->width0, level0);
1119 height = u_minify(texture->height0, level0);
1120
1121 assert(width > 0);
1122 assert(height > 0);
1123
1124 addr.value = 0;
1125 addr.bits.level = samp->level;
1126
1127 samp->linear_texcoord_s(s, width, x0, x1, xw);
1128 samp->linear_texcoord_t(t, height, y0, y1, yw);
1129
1130 for (j = 0; j < QUAD_SIZE; j++) {
1131 const float *tx0 = get_texel_2d(samp, addr, x0[j], y0[j]);
1132 const float *tx1 = get_texel_2d(samp, addr, x1[j], y0[j]);
1133 const float *tx2 = get_texel_2d(samp, addr, x0[j], y1[j]);
1134 const float *tx3 = get_texel_2d(samp, addr, x1[j], y1[j]);
1135 int c;
1136
1137 /* interpolate R, G, B, A */
1138 for (c = 0; c < 4; c++) {
1139 rgba[c][j] = lerp_2d(xw[j], yw[j],
1140 tx0[c], tx1[c],
1141 tx2[c], tx3[c]);
1142 }
1143 }
1144 }
1145
1146
1147 static void
1148 img_filter_cube_linear(struct tgsi_sampler *tgsi_sampler,
1149 const float s[QUAD_SIZE],
1150 const float t[QUAD_SIZE],
1151 const float p[QUAD_SIZE],
1152 const float c0[QUAD_SIZE],
1153 enum tgsi_sampler_control control,
1154 float rgba[NUM_CHANNELS][QUAD_SIZE])
1155 {
1156 const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
1157 const struct pipe_texture *texture = samp->texture;
1158 const unsigned *faces = samp->faces; /* zero when not cube-mapping */
1159 unsigned level0, j;
1160 int width, height;
1161 int x0[4], y0[4], x1[4], y1[4];
1162 float xw[4], yw[4]; /* weights */
1163 union tex_tile_address addr;
1164
1165 level0 = samp->level;
1166 width = u_minify(texture->width0, level0);
1167 height = u_minify(texture->height0, level0);
1168
1169 assert(width > 0);
1170 assert(height > 0);
1171
1172 addr.value = 0;
1173 addr.bits.level = samp->level;
1174
1175 samp->linear_texcoord_s(s, width, x0, x1, xw);
1176 samp->linear_texcoord_t(t, height, y0, y1, yw);
1177
1178 for (j = 0; j < QUAD_SIZE; j++) {
1179 union tex_tile_address addrj = face(addr, faces[j]);
1180 const float *tx0 = get_texel_2d(samp, addrj, x0[j], y0[j]);
1181 const float *tx1 = get_texel_2d(samp, addrj, x1[j], y0[j]);
1182 const float *tx2 = get_texel_2d(samp, addrj, x0[j], y1[j]);
1183 const float *tx3 = get_texel_2d(samp, addrj, x1[j], y1[j]);
1184 int c;
1185
1186 /* interpolate R, G, B, A */
1187 for (c = 0; c < 4; c++) {
1188 rgba[c][j] = lerp_2d(xw[j], yw[j],
1189 tx0[c], tx1[c],
1190 tx2[c], tx3[c]);
1191 }
1192 }
1193 }
1194
1195
1196 static void
1197 img_filter_3d_linear(struct tgsi_sampler *tgsi_sampler,
1198 const float s[QUAD_SIZE],
1199 const float t[QUAD_SIZE],
1200 const float p[QUAD_SIZE],
1201 const float c0[QUAD_SIZE],
1202 enum tgsi_sampler_control control,
1203 float rgba[NUM_CHANNELS][QUAD_SIZE])
1204 {
1205 const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
1206 const struct pipe_texture *texture = samp->texture;
1207 unsigned level0, j;
1208 int width, height, depth;
1209 int x0[4], x1[4], y0[4], y1[4], z0[4], z1[4];
1210 float xw[4], yw[4], zw[4]; /* interpolation weights */
1211 union tex_tile_address addr;
1212
1213 level0 = samp->level;
1214 width = u_minify(texture->width0, level0);
1215 height = u_minify(texture->height0, level0);
1216 depth = u_minify(texture->depth0, level0);
1217
1218 addr.value = 0;
1219 addr.bits.level = level0;
1220
1221 assert(width > 0);
1222 assert(height > 0);
1223 assert(depth > 0);
1224
1225 samp->linear_texcoord_s(s, width, x0, x1, xw);
1226 samp->linear_texcoord_t(t, height, y0, y1, yw);
1227 samp->linear_texcoord_p(p, depth, z0, z1, zw);
1228
1229 for (j = 0; j < QUAD_SIZE; j++) {
1230 int c;
1231
1232 const float *tx00 = get_texel_3d(samp, addr, x0[j], y0[j], z0[j]);
1233 const float *tx01 = get_texel_3d(samp, addr, x1[j], y0[j], z0[j]);
1234 const float *tx02 = get_texel_3d(samp, addr, x0[j], y1[j], z0[j]);
1235 const float *tx03 = get_texel_3d(samp, addr, x1[j], y1[j], z0[j]);
1236
1237 const float *tx10 = get_texel_3d(samp, addr, x0[j], y0[j], z1[j]);
1238 const float *tx11 = get_texel_3d(samp, addr, x1[j], y0[j], z1[j]);
1239 const float *tx12 = get_texel_3d(samp, addr, x0[j], y1[j], z1[j]);
1240 const float *tx13 = get_texel_3d(samp, addr, x1[j], y1[j], z1[j]);
1241
1242 /* interpolate R, G, B, A */
1243 for (c = 0; c < 4; c++) {
1244 rgba[c][j] = lerp_3d(xw[j], yw[j], zw[j],
1245 tx00[c], tx01[c],
1246 tx02[c], tx03[c],
1247 tx10[c], tx11[c],
1248 tx12[c], tx13[c]);
1249 }
1250 }
1251 }
1252
1253
1254 /* Calculate level of detail for every fragment.
1255 * Note that lambda has already been biased by global LOD bias.
1256 */
1257 static INLINE void
1258 compute_lod(const struct pipe_sampler_state *sampler,
1259 const float biased_lambda,
1260 const float lodbias[QUAD_SIZE],
1261 float lod[QUAD_SIZE])
1262 {
1263 uint i;
1264
1265 for (i = 0; i < QUAD_SIZE; i++) {
1266 lod[i] = biased_lambda + lodbias[i];
1267 lod[i] = CLAMP(lod[i], sampler->min_lod, sampler->max_lod);
1268 }
1269 }
1270
1271
1272 static void
1273 mip_filter_linear(struct tgsi_sampler *tgsi_sampler,
1274 const float s[QUAD_SIZE],
1275 const float t[QUAD_SIZE],
1276 const float p[QUAD_SIZE],
1277 const float c0[QUAD_SIZE],
1278 enum tgsi_sampler_control control,
1279 float rgba[NUM_CHANNELS][QUAD_SIZE])
1280 {
1281 struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
1282 const struct pipe_texture *texture = samp->texture;
1283 int level0;
1284 float lambda;
1285 float lod[QUAD_SIZE];
1286
1287 if (control == tgsi_sampler_lod_bias) {
1288 lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias;
1289 compute_lod(samp->sampler, lambda, c0, lod);
1290 } else {
1291 assert(control == tgsi_sampler_lod_explicit);
1292
1293 memcpy(lod, c0, sizeof(lod));
1294 }
1295
1296 /* XXX: Take into account all lod values.
1297 */
1298 lambda = lod[0];
1299 level0 = (int)lambda;
1300
1301 if (lambda < 0.0) {
1302 samp->level = 0;
1303 samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba);
1304 }
1305 else if (level0 >= texture->last_level) {
1306 samp->level = texture->last_level;
1307 samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba);
1308 }
1309 else {
1310 float levelBlend = lambda - level0;
1311 float rgba0[4][4];
1312 float rgba1[4][4];
1313 int c,j;
1314
1315 samp->level = level0;
1316 samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba0);
1317
1318 samp->level = level0+1;
1319 samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba1);
1320
1321 for (j = 0; j < QUAD_SIZE; j++) {
1322 for (c = 0; c < 4; c++) {
1323 rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]);
1324 }
1325 }
1326 }
1327 }
1328
1329
1330 /**
1331 * Compute nearest mipmap level from texcoords.
1332 * Then sample the texture level for four elements of a quad.
1333 * \param c0 the LOD bias factors, or absolute LODs (depending on control)
1334 */
1335 static void
1336 mip_filter_nearest(struct tgsi_sampler *tgsi_sampler,
1337 const float s[QUAD_SIZE],
1338 const float t[QUAD_SIZE],
1339 const float p[QUAD_SIZE],
1340 const float c0[QUAD_SIZE],
1341 enum tgsi_sampler_control control,
1342 float rgba[NUM_CHANNELS][QUAD_SIZE])
1343 {
1344 struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
1345 const struct pipe_texture *texture = samp->texture;
1346 float lambda;
1347 float lod[QUAD_SIZE];
1348
1349 if (control == tgsi_sampler_lod_bias) {
1350 lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias;
1351 compute_lod(samp->sampler, lambda, c0, lod);
1352 } else {
1353 assert(control == tgsi_sampler_lod_explicit);
1354
1355 memcpy(lod, c0, sizeof(lod));
1356 }
1357
1358 /* XXX: Take into account all lod values.
1359 */
1360 lambda = lod[0];
1361
1362 if (lambda < 0.0) {
1363 samp->level = 0;
1364 samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba);
1365 }
1366 else {
1367 samp->level = (int)(lambda + 0.5) ;
1368 samp->level = MIN2(samp->level, (int)texture->last_level);
1369 samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba);
1370 }
1371
1372 #if 0
1373 printf("RGBA %g %g %g %g, %g %g %g %g, %g %g %g %g, %g %g %g %g\n",
1374 rgba[0][0], rgba[1][0], rgba[2][0], rgba[3][0],
1375 rgba[0][1], rgba[1][1], rgba[2][1], rgba[3][1],
1376 rgba[0][2], rgba[1][2], rgba[2][2], rgba[3][2],
1377 rgba[0][3], rgba[1][3], rgba[2][3], rgba[3][3]);
1378 #endif
1379 }
1380
1381
1382 static void
1383 mip_filter_none(struct tgsi_sampler *tgsi_sampler,
1384 const float s[QUAD_SIZE],
1385 const float t[QUAD_SIZE],
1386 const float p[QUAD_SIZE],
1387 const float c0[QUAD_SIZE],
1388 enum tgsi_sampler_control control,
1389 float rgba[NUM_CHANNELS][QUAD_SIZE])
1390 {
1391 struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
1392 float lambda;
1393 float lod[QUAD_SIZE];
1394
1395 if (control == tgsi_sampler_lod_bias) {
1396 lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias;
1397 compute_lod(samp->sampler, lambda, c0, lod);
1398 } else {
1399 assert(control == tgsi_sampler_lod_explicit);
1400
1401 memcpy(lod, c0, sizeof(lod));
1402 }
1403
1404 /* XXX: Take into account all lod values.
1405 */
1406 lambda = lod[0];
1407
1408 if (lambda < 0.0) {
1409 samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba);
1410 }
1411 else {
1412 samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba);
1413 }
1414 }
1415
1416
1417
1418 /**
1419 * Specialized version of mip_filter_linear with hard-wired calls to
1420 * 2d lambda calculation and 2d_linear_repeat_POT img filters.
1421 */
1422 static void
1423 mip_filter_linear_2d_linear_repeat_POT(
1424 struct tgsi_sampler *tgsi_sampler,
1425 const float s[QUAD_SIZE],
1426 const float t[QUAD_SIZE],
1427 const float p[QUAD_SIZE],
1428 const float c0[QUAD_SIZE],
1429 enum tgsi_sampler_control control,
1430 float rgba[NUM_CHANNELS][QUAD_SIZE])
1431 {
1432 struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
1433 const struct pipe_texture *texture = samp->texture;
1434 int level0;
1435 float lambda;
1436 float lod[QUAD_SIZE];
1437
1438 if (control == tgsi_sampler_lod_bias) {
1439 lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias;
1440 compute_lod(samp->sampler, lambda, c0, lod);
1441 } else {
1442 assert(control == tgsi_sampler_lod_explicit);
1443
1444 memcpy(lod, c0, sizeof(lod));
1445 }
1446
1447 /* XXX: Take into account all lod values.
1448 */
1449 lambda = lod[0];
1450 level0 = (int)lambda;
1451
1452 /* Catches both negative and large values of level0:
1453 */
1454 if ((unsigned)level0 >= texture->last_level) {
1455 if (level0 < 0)
1456 samp->level = 0;
1457 else
1458 samp->level = texture->last_level;
1459
1460 img_filter_2d_linear_repeat_POT(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba);
1461 }
1462 else {
1463 float levelBlend = lambda - level0;
1464 float rgba0[4][4];
1465 float rgba1[4][4];
1466 int c,j;
1467
1468 samp->level = level0;
1469 img_filter_2d_linear_repeat_POT(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba0);
1470
1471 samp->level = level0+1;
1472 img_filter_2d_linear_repeat_POT(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba1);
1473
1474 for (j = 0; j < QUAD_SIZE; j++) {
1475 for (c = 0; c < 4; c++) {
1476 rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]);
1477 }
1478 }
1479 }
1480 }
1481
1482
1483
1484 /**
1485 * Do shadow/depth comparisons.
1486 */
1487 static void
1488 sample_compare(struct tgsi_sampler *tgsi_sampler,
1489 const float s[QUAD_SIZE],
1490 const float t[QUAD_SIZE],
1491 const float p[QUAD_SIZE],
1492 const float c0[QUAD_SIZE],
1493 enum tgsi_sampler_control control,
1494 float rgba[NUM_CHANNELS][QUAD_SIZE])
1495 {
1496 struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
1497 const struct pipe_sampler_state *sampler = samp->sampler;
1498 int j, k0, k1, k2, k3;
1499 float val;
1500
1501 samp->mip_filter(tgsi_sampler, s, t, p, c0, control, rgba);
1502
1503 /**
1504 * Compare texcoord 'p' (aka R) against texture value 'rgba[0]'
1505 * When we sampled the depth texture, the depth value was put into all
1506 * RGBA channels. We look at the red channel here.
1507 */
1508
1509 /* compare four texcoords vs. four texture samples */
1510 switch (sampler->compare_func) {
1511 case PIPE_FUNC_LESS:
1512 k0 = p[0] < rgba[0][0];
1513 k1 = p[1] < rgba[0][1];
1514 k2 = p[2] < rgba[0][2];
1515 k3 = p[3] < rgba[0][3];
1516 break;
1517 case PIPE_FUNC_LEQUAL:
1518 k0 = p[0] <= rgba[0][0];
1519 k1 = p[1] <= rgba[0][1];
1520 k2 = p[2] <= rgba[0][2];
1521 k3 = p[3] <= rgba[0][3];
1522 break;
1523 case PIPE_FUNC_GREATER:
1524 k0 = p[0] > rgba[0][0];
1525 k1 = p[1] > rgba[0][1];
1526 k2 = p[2] > rgba[0][2];
1527 k3 = p[3] > rgba[0][3];
1528 break;
1529 case PIPE_FUNC_GEQUAL:
1530 k0 = p[0] >= rgba[0][0];
1531 k1 = p[1] >= rgba[0][1];
1532 k2 = p[2] >= rgba[0][2];
1533 k3 = p[3] >= rgba[0][3];
1534 break;
1535 case PIPE_FUNC_EQUAL:
1536 k0 = p[0] == rgba[0][0];
1537 k1 = p[1] == rgba[0][1];
1538 k2 = p[2] == rgba[0][2];
1539 k3 = p[3] == rgba[0][3];
1540 break;
1541 case PIPE_FUNC_NOTEQUAL:
1542 k0 = p[0] != rgba[0][0];
1543 k1 = p[1] != rgba[0][1];
1544 k2 = p[2] != rgba[0][2];
1545 k3 = p[3] != rgba[0][3];
1546 break;
1547 case PIPE_FUNC_ALWAYS:
1548 k0 = k1 = k2 = k3 = 1;
1549 break;
1550 case PIPE_FUNC_NEVER:
1551 k0 = k1 = k2 = k3 = 0;
1552 break;
1553 default:
1554 k0 = k1 = k2 = k3 = 0;
1555 assert(0);
1556 break;
1557 }
1558
1559 /* convert four pass/fail values to an intensity in [0,1] */
1560 val = 0.25F * (k0 + k1 + k2 + k3);
1561
1562 /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */
1563 for (j = 0; j < 4; j++) {
1564 rgba[0][j] = rgba[1][j] = rgba[2][j] = val;
1565 rgba[3][j] = 1.0F;
1566 }
1567 }
1568
1569
1570 /**
1571 * Use 3D texcoords to choose a cube face, then sample the 2D cube faces.
1572 * Put face info into the sampler faces[] array.
1573 */
1574 static void
1575 sample_cube(struct tgsi_sampler *tgsi_sampler,
1576 const float s[QUAD_SIZE],
1577 const float t[QUAD_SIZE],
1578 const float p[QUAD_SIZE],
1579 const float c0[QUAD_SIZE],
1580 enum tgsi_sampler_control control,
1581 float rgba[NUM_CHANNELS][QUAD_SIZE])
1582 {
1583 struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
1584 unsigned j;
1585 float ssss[4], tttt[4];
1586 unsigned face;
1587
1588 /*
1589 major axis
1590 direction target sc tc ma
1591 ---------- ------------------------------- --- --- ---
1592 +rx TEXTURE_CUBE_MAP_POSITIVE_X_EXT -rz -ry rx
1593 -rx TEXTURE_CUBE_MAP_NEGATIVE_X_EXT +rz -ry rx
1594 +ry TEXTURE_CUBE_MAP_POSITIVE_Y_EXT +rx +rz ry
1595 -ry TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT +rx -rz ry
1596 +rz TEXTURE_CUBE_MAP_POSITIVE_Z_EXT +rx -ry rz
1597 -rz TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT -rx -ry rz
1598 */
1599
1600 /* First choose the cube face.
1601 * Use the same cube face for all four pixels in the quad.
1602 *
1603 * This isn't ideal, but if we want to use a different cube face
1604 * per pixel in the quad, we'd have to also compute the per-face
1605 * LOD here too. That's because the four post-face-selection
1606 * texcoords are no longer related to each other (they're
1607 * per-face!) so we can't use subtraction to compute the partial
1608 * deriviates to compute the LOD. Doing so (near cube edges
1609 * anyway) gives us pretty much random values.
1610 */
1611 {
1612 /* use the average of the four pixel's texcoords to choose the face */
1613 const float rx = 0.25 * (s[0] + s[1] + s[2] + s[3]);
1614 const float ry = 0.25 * (t[0] + t[1] + t[2] + t[3]);
1615 const float rz = 0.25 * (p[0] + p[1] + p[2] + p[3]);
1616 const float arx = fabsf(rx), ary = fabsf(ry), arz = fabsf(rz);
1617
1618 if (arx >= ary && arx >= arz) {
1619 if (rx >= 0.0F) {
1620 face = PIPE_TEX_FACE_POS_X;
1621 }
1622 else {
1623 face = PIPE_TEX_FACE_NEG_X;
1624 }
1625 }
1626 else if (ary >= arx && ary >= arz) {
1627 if (ry >= 0.0F) {
1628 face = PIPE_TEX_FACE_POS_Y;
1629 }
1630 else {
1631 face = PIPE_TEX_FACE_NEG_Y;
1632 }
1633 }
1634 else {
1635 if (rz > 0.0F) {
1636 face = PIPE_TEX_FACE_POS_Z;
1637 }
1638 else {
1639 face = PIPE_TEX_FACE_NEG_Z;
1640 }
1641 }
1642 }
1643
1644 /* Now compute the 2D _face_ texture coords from the
1645 * 3D _cube_ texture coords.
1646 */
1647 for (j = 0; j < QUAD_SIZE; j++) {
1648 const float rx = s[j], ry = t[j], rz = p[j];
1649 const float arx = fabsf(rx), ary = fabsf(ry), arz = fabsf(rz);
1650 float sc, tc, ma;
1651
1652 switch (face) {
1653 case PIPE_TEX_FACE_POS_X:
1654 sc = -rz;
1655 tc = -ry;
1656 ma = arx;
1657 break;
1658 case PIPE_TEX_FACE_NEG_X:
1659 sc = rz;
1660 tc = -ry;
1661 ma = arx;
1662 break;
1663 case PIPE_TEX_FACE_POS_Y:
1664 sc = rx;
1665 tc = rz;
1666 ma = ary;
1667 break;
1668 case PIPE_TEX_FACE_NEG_Y:
1669 sc = rx;
1670 tc = -rz;
1671 ma = ary;
1672 break;
1673 case PIPE_TEX_FACE_POS_Z:
1674 sc = rx;
1675 tc = -ry;
1676 ma = arz;
1677 break;
1678 case PIPE_TEX_FACE_NEG_Z:
1679 sc = -rx;
1680 tc = -ry;
1681 ma = arz;
1682 break;
1683 default:
1684 assert(0 && "bad cube face");
1685 sc = 0.0F;
1686 tc = 0.0F;
1687 ma = 0.0F;
1688 }
1689
1690 {
1691 const float ima = 1.0 / ma;
1692 ssss[j] = ( sc * ima + 1.0F ) * 0.5F;
1693 tttt[j] = ( tc * ima + 1.0F ) * 0.5F;
1694 samp->faces[j] = face;
1695 }
1696 }
1697
1698 /* In our little pipeline, the compare stage is next. If compare
1699 * is not active, this will point somewhere deeper into the
1700 * pipeline, eg. to mip_filter or even img_filter.
1701 */
1702 samp->compare(tgsi_sampler, ssss, tttt, NULL, c0, control, rgba);
1703 }
1704
1705
1706
1707 static wrap_nearest_func
1708 get_nearest_unorm_wrap(unsigned mode)
1709 {
1710 switch (mode) {
1711 case PIPE_TEX_WRAP_CLAMP:
1712 return wrap_nearest_unorm_clamp;
1713 case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
1714 case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
1715 return wrap_nearest_unorm_clamp_to_border;
1716 default:
1717 assert(0);
1718 return wrap_nearest_unorm_clamp;
1719 }
1720 }
1721
1722
1723 static wrap_nearest_func
1724 get_nearest_wrap(unsigned mode)
1725 {
1726 switch (mode) {
1727 case PIPE_TEX_WRAP_REPEAT:
1728 return wrap_nearest_repeat;
1729 case PIPE_TEX_WRAP_CLAMP:
1730 return wrap_nearest_clamp;
1731 case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
1732 return wrap_nearest_clamp_to_edge;
1733 case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
1734 return wrap_nearest_clamp_to_border;
1735 case PIPE_TEX_WRAP_MIRROR_REPEAT:
1736 return wrap_nearest_mirror_repeat;
1737 case PIPE_TEX_WRAP_MIRROR_CLAMP:
1738 return wrap_nearest_mirror_clamp;
1739 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
1740 return wrap_nearest_mirror_clamp_to_edge;
1741 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
1742 return wrap_nearest_mirror_clamp_to_border;
1743 default:
1744 assert(0);
1745 return wrap_nearest_repeat;
1746 }
1747 }
1748
1749
1750 static wrap_linear_func
1751 get_linear_unorm_wrap(unsigned mode)
1752 {
1753 switch (mode) {
1754 case PIPE_TEX_WRAP_CLAMP:
1755 return wrap_linear_unorm_clamp;
1756 case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
1757 case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
1758 return wrap_linear_unorm_clamp_to_border;
1759 default:
1760 assert(0);
1761 return wrap_linear_unorm_clamp;
1762 }
1763 }
1764
1765
1766 static wrap_linear_func
1767 get_linear_wrap(unsigned mode)
1768 {
1769 switch (mode) {
1770 case PIPE_TEX_WRAP_REPEAT:
1771 return wrap_linear_repeat;
1772 case PIPE_TEX_WRAP_CLAMP:
1773 return wrap_linear_clamp;
1774 case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
1775 return wrap_linear_clamp_to_edge;
1776 case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
1777 return wrap_linear_clamp_to_border;
1778 case PIPE_TEX_WRAP_MIRROR_REPEAT:
1779 return wrap_linear_mirror_repeat;
1780 case PIPE_TEX_WRAP_MIRROR_CLAMP:
1781 return wrap_linear_mirror_clamp;
1782 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
1783 return wrap_linear_mirror_clamp_to_edge;
1784 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
1785 return wrap_linear_mirror_clamp_to_border;
1786 default:
1787 assert(0);
1788 return wrap_linear_repeat;
1789 }
1790 }
1791
1792
1793 static compute_lambda_func
1794 get_lambda_func(const union sp_sampler_key key)
1795 {
1796 if (key.bits.processor == TGSI_PROCESSOR_VERTEX)
1797 return compute_lambda_vert;
1798
1799 switch (key.bits.target) {
1800 case PIPE_TEXTURE_1D:
1801 return compute_lambda_1d;
1802 case PIPE_TEXTURE_2D:
1803 case PIPE_TEXTURE_CUBE:
1804 return compute_lambda_2d;
1805 case PIPE_TEXTURE_3D:
1806 return compute_lambda_3d;
1807 default:
1808 assert(0);
1809 return compute_lambda_1d;
1810 }
1811 }
1812
1813
1814 static filter_func
1815 get_img_filter(const union sp_sampler_key key,
1816 unsigned filter,
1817 const struct pipe_sampler_state *sampler)
1818 {
1819 switch (key.bits.target) {
1820 case PIPE_TEXTURE_1D:
1821 if (filter == PIPE_TEX_FILTER_NEAREST)
1822 return img_filter_1d_nearest;
1823 else
1824 return img_filter_1d_linear;
1825 break;
1826 case PIPE_TEXTURE_2D:
1827 /* Try for fast path:
1828 */
1829 if (key.bits.is_pot &&
1830 sampler->wrap_s == sampler->wrap_t &&
1831 sampler->normalized_coords)
1832 {
1833 switch (sampler->wrap_s) {
1834 case PIPE_TEX_WRAP_REPEAT:
1835 switch (filter) {
1836 case PIPE_TEX_FILTER_NEAREST:
1837 return img_filter_2d_nearest_repeat_POT;
1838 case PIPE_TEX_FILTER_LINEAR:
1839 return img_filter_2d_linear_repeat_POT;
1840 default:
1841 break;
1842 }
1843 break;
1844 case PIPE_TEX_WRAP_CLAMP:
1845 switch (filter) {
1846 case PIPE_TEX_FILTER_NEAREST:
1847 return img_filter_2d_nearest_clamp_POT;
1848 default:
1849 break;
1850 }
1851 }
1852 }
1853 /* Otherwise use default versions:
1854 */
1855 if (filter == PIPE_TEX_FILTER_NEAREST)
1856 return img_filter_2d_nearest;
1857 else
1858 return img_filter_2d_linear;
1859 break;
1860 case PIPE_TEXTURE_CUBE:
1861 if (filter == PIPE_TEX_FILTER_NEAREST)
1862 return img_filter_cube_nearest;
1863 else
1864 return img_filter_cube_linear;
1865 break;
1866 case PIPE_TEXTURE_3D:
1867 if (filter == PIPE_TEX_FILTER_NEAREST)
1868 return img_filter_3d_nearest;
1869 else
1870 return img_filter_3d_linear;
1871 break;
1872 default:
1873 assert(0);
1874 return img_filter_1d_nearest;
1875 }
1876 }
1877
1878
1879 /**
1880 * Bind the given texture object and texture cache to the sampler varient.
1881 */
1882 void
1883 sp_sampler_varient_bind_texture( struct sp_sampler_varient *samp,
1884 struct softpipe_tex_tile_cache *tex_cache,
1885 const struct pipe_texture *texture )
1886 {
1887 const struct pipe_sampler_state *sampler = samp->sampler;
1888
1889 samp->texture = texture;
1890 samp->cache = tex_cache;
1891 samp->xpot = util_unsigned_logbase2( texture->width0 );
1892 samp->ypot = util_unsigned_logbase2( texture->height0 );
1893 samp->level = CLAMP((int) sampler->min_lod, 0, (int) texture->last_level);
1894 }
1895
1896
1897 void
1898 sp_sampler_varient_destroy( struct sp_sampler_varient *samp )
1899 {
1900 FREE(samp);
1901 }
1902
1903
1904 /**
1905 * Create a sampler varient for a given set of non-orthogonal state.
1906 */
1907 struct sp_sampler_varient *
1908 sp_create_sampler_varient( const struct pipe_sampler_state *sampler,
1909 const union sp_sampler_key key )
1910 {
1911 struct sp_sampler_varient *samp = CALLOC_STRUCT(sp_sampler_varient);
1912 if (!samp)
1913 return NULL;
1914
1915 samp->sampler = sampler;
1916 samp->key = key;
1917
1918 /* Note that (for instance) linear_texcoord_s and
1919 * nearest_texcoord_s may be active at the same time, if the
1920 * sampler min_img_filter differs from its mag_img_filter.
1921 */
1922 if (sampler->normalized_coords) {
1923 samp->linear_texcoord_s = get_linear_wrap( sampler->wrap_s );
1924 samp->linear_texcoord_t = get_linear_wrap( sampler->wrap_t );
1925 samp->linear_texcoord_p = get_linear_wrap( sampler->wrap_r );
1926
1927 samp->nearest_texcoord_s = get_nearest_wrap( sampler->wrap_s );
1928 samp->nearest_texcoord_t = get_nearest_wrap( sampler->wrap_t );
1929 samp->nearest_texcoord_p = get_nearest_wrap( sampler->wrap_r );
1930 }
1931 else {
1932 samp->linear_texcoord_s = get_linear_unorm_wrap( sampler->wrap_s );
1933 samp->linear_texcoord_t = get_linear_unorm_wrap( sampler->wrap_t );
1934 samp->linear_texcoord_p = get_linear_unorm_wrap( sampler->wrap_r );
1935
1936 samp->nearest_texcoord_s = get_nearest_unorm_wrap( sampler->wrap_s );
1937 samp->nearest_texcoord_t = get_nearest_unorm_wrap( sampler->wrap_t );
1938 samp->nearest_texcoord_p = get_nearest_unorm_wrap( sampler->wrap_r );
1939 }
1940
1941 samp->compute_lambda = get_lambda_func( key );
1942
1943 samp->min_img_filter = get_img_filter(key, sampler->min_img_filter, sampler);
1944 samp->mag_img_filter = get_img_filter(key, sampler->mag_img_filter, sampler);
1945
1946 switch (sampler->min_mip_filter) {
1947 case PIPE_TEX_MIPFILTER_NONE:
1948 if (sampler->min_img_filter == sampler->mag_img_filter)
1949 samp->mip_filter = samp->min_img_filter;
1950 else
1951 samp->mip_filter = mip_filter_none;
1952 break;
1953
1954 case PIPE_TEX_MIPFILTER_NEAREST:
1955 samp->mip_filter = mip_filter_nearest;
1956 break;
1957
1958 case PIPE_TEX_MIPFILTER_LINEAR:
1959 if (key.bits.is_pot &&
1960 sampler->min_img_filter == sampler->mag_img_filter &&
1961 sampler->normalized_coords &&
1962 sampler->wrap_s == PIPE_TEX_WRAP_REPEAT &&
1963 sampler->wrap_t == PIPE_TEX_WRAP_REPEAT &&
1964 sampler->min_img_filter == PIPE_TEX_FILTER_LINEAR)
1965 {
1966 samp->mip_filter = mip_filter_linear_2d_linear_repeat_POT;
1967 }
1968 else
1969 {
1970 samp->mip_filter = mip_filter_linear;
1971 }
1972 break;
1973 }
1974
1975 if (sampler->compare_mode != PIPE_TEX_COMPARE_NONE) {
1976 samp->compare = sample_compare;
1977 }
1978 else {
1979 /* Skip compare operation by promoting the mip_filter function
1980 * pointer:
1981 */
1982 samp->compare = samp->mip_filter;
1983 }
1984
1985 if (key.bits.target == PIPE_TEXTURE_CUBE) {
1986 samp->base.get_samples = sample_cube;
1987 }
1988 else {
1989 samp->faces[0] = 0;
1990 samp->faces[1] = 0;
1991 samp->faces[2] = 0;
1992 samp->faces[3] = 0;
1993
1994 /* Skip cube face determination by promoting the compare
1995 * function pointer:
1996 */
1997 samp->base.get_samples = samp->compare;
1998 }
1999
2000 return samp;
2001 }