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