1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * Copyright 2008-2010 VMware, Inc. All rights reserved.
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:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
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.
27 **************************************************************************/
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"
47 /** Set to one to help debug texture sampling */
52 * Return fractional part of 'f'. Used for computing interpolation weights.
53 * Need to be careful with negative values.
54 * Note, if this function isn't perfect you'll sometimes see 1-pixel bands
55 * of improperly weighted linear-filtered textures.
56 * The tests/texwrap.c demo is a good test.
67 * Linear interpolation macro
70 lerp(float a
, float v0
, float v1
)
72 return v0
+ a
* (v1
- v0
);
77 * Do 2D/bilinear interpolation of float values.
78 * v00, v10, v01 and v11 are typically four texture samples in a square/box.
79 * a and b are the horizontal and vertical interpolants.
80 * It's important that this function is inlined when compiled with
81 * optimization! If we find that's not true on some systems, convert
85 lerp_2d(float a
, float b
,
86 float v00
, float v10
, float v01
, float v11
)
88 const float temp0
= lerp(a
, v00
, v10
);
89 const float temp1
= lerp(a
, v01
, v11
);
90 return lerp(b
, temp0
, temp1
);
95 * As above, but 3D interpolation of 8 values.
98 lerp_3d(float a
, float b
, float c
,
99 float v000
, float v100
, float v010
, float v110
,
100 float v001
, float v101
, float v011
, float v111
)
102 const float temp0
= lerp_2d(a
, b
, v000
, v100
, v010
, v110
);
103 const float temp1
= lerp_2d(a
, b
, v001
, v101
, v011
, v111
);
104 return lerp(c
, temp0
, temp1
);
110 * Compute coord % size for repeat wrap modes.
111 * Note that if coord is negative, coord % size doesn't give the right
112 * value. To avoid that problem we add a large multiple of the size
113 * (rather than using a conditional).
116 repeat(int coord
, unsigned size
)
118 return (coord
+ size
* 1024) % size
;
123 * Apply texture coord wrapping mode and return integer texture indexes
124 * for a vector of four texcoords (S or T or P).
125 * \param wrapMode PIPE_TEX_WRAP_x
126 * \param s the incoming texcoords
127 * \param size the texture image size
128 * \param icoord returns the integer texcoords
129 * \return integer texture index
132 wrap_nearest_repeat(float s
, unsigned size
, int *icoord
)
134 /* s limited to [0,1) */
135 /* i limited to [0,size-1] */
136 int i
= util_ifloor(s
* size
);
137 *icoord
= repeat(i
, size
);
142 wrap_nearest_clamp(float s
, unsigned size
, int *icoord
)
144 /* s limited to [0,1] */
145 /* i limited to [0,size-1] */
151 *icoord
= util_ifloor(s
* size
);
156 wrap_nearest_clamp_to_edge(float s
, unsigned size
, int *icoord
)
158 /* s limited to [min,max] */
159 /* i limited to [0, size-1] */
160 const float min
= 1.0F
/ (2.0F
* size
);
161 const float max
= 1.0F
- min
;
167 *icoord
= util_ifloor(s
* size
);
172 wrap_nearest_clamp_to_border(float s
, unsigned size
, int *icoord
)
174 /* s limited to [min,max] */
175 /* i limited to [-1, size] */
176 const float min
= -1.0F
/ (2.0F
* size
);
177 const float max
= 1.0F
- min
;
183 *icoord
= util_ifloor(s
* size
);
188 wrap_nearest_mirror_repeat(float s
, unsigned size
, int *icoord
)
190 const float min
= 1.0F
/ (2.0F
* size
);
191 const float max
= 1.0F
- min
;
192 const int flr
= util_ifloor(s
);
201 *icoord
= util_ifloor(u
* size
);
206 wrap_nearest_mirror_clamp(float s
, unsigned size
, int *icoord
)
208 /* s limited to [0,1] */
209 /* i limited to [0,size-1] */
210 const float u
= fabsf(s
);
216 *icoord
= util_ifloor(u
* size
);
221 wrap_nearest_mirror_clamp_to_edge(float s
, unsigned size
, int *icoord
)
223 /* s limited to [min,max] */
224 /* i limited to [0, size-1] */
225 const float min
= 1.0F
/ (2.0F
* size
);
226 const float max
= 1.0F
- min
;
227 const float u
= fabsf(s
);
233 *icoord
= util_ifloor(u
* size
);
238 wrap_nearest_mirror_clamp_to_border(float s
, unsigned size
, int *icoord
)
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 const float u
= fabsf(s
);
250 *icoord
= util_ifloor(u
* size
);
255 * Used to compute texel locations for linear sampling
256 * \param wrapMode PIPE_TEX_WRAP_x
257 * \param s the texcoord
258 * \param size the texture image size
259 * \param icoord0 returns first texture index
260 * \param icoord1 returns second texture index (usually icoord0 + 1)
261 * \param w returns blend factor/weight between texture indices
262 * \param icoord returns the computed integer texture coord
265 wrap_linear_repeat(float s
, unsigned size
,
266 int *icoord0
, int *icoord1
, float *w
)
268 float u
= s
* size
- 0.5F
;
269 *icoord0
= repeat(util_ifloor(u
), size
);
270 *icoord1
= repeat(*icoord0
+ 1, size
);
276 wrap_linear_clamp(float s
, unsigned size
,
277 int *icoord0
, int *icoord1
, float *w
)
279 float u
= CLAMP(s
, 0.0F
, 1.0F
);
281 *icoord0
= util_ifloor(u
);
282 *icoord1
= *icoord0
+ 1;
288 wrap_linear_clamp_to_edge(float s
, unsigned size
,
289 int *icoord0
, int *icoord1
, float *w
)
291 float u
= CLAMP(s
, 0.0F
, 1.0F
);
293 *icoord0
= util_ifloor(u
);
294 *icoord1
= *icoord0
+ 1;
297 if (*icoord1
>= (int) size
)
304 wrap_linear_clamp_to_border(float s
, unsigned size
,
305 int *icoord0
, int *icoord1
, float *w
)
307 const float min
= -1.0F
/ (2.0F
* size
);
308 const float max
= 1.0F
- min
;
309 float u
= CLAMP(s
, min
, max
);
311 *icoord0
= util_ifloor(u
);
312 *icoord1
= *icoord0
+ 1;
318 wrap_linear_mirror_repeat(float s
, unsigned size
,
319 int *icoord0
, int *icoord1
, float *w
)
321 const int flr
= util_ifloor(s
);
326 *icoord0
= util_ifloor(u
);
327 *icoord1
= *icoord0
+ 1;
330 if (*icoord1
>= (int) size
)
337 wrap_linear_mirror_clamp(float s
, unsigned size
,
338 int *icoord0
, int *icoord1
, float *w
)
346 *icoord0
= util_ifloor(u
);
347 *icoord1
= *icoord0
+ 1;
353 wrap_linear_mirror_clamp_to_edge(float s
, unsigned size
,
354 int *icoord0
, int *icoord1
, float *w
)
362 *icoord0
= util_ifloor(u
);
363 *icoord1
= *icoord0
+ 1;
366 if (*icoord1
>= (int) size
)
373 wrap_linear_mirror_clamp_to_border(float s
, unsigned size
,
374 int *icoord0
, int *icoord1
, float *w
)
376 const float min
= -1.0F
/ (2.0F
* size
);
377 const float max
= 1.0F
- min
;
386 *icoord0
= util_ifloor(u
);
387 *icoord1
= *icoord0
+ 1;
393 * PIPE_TEX_WRAP_CLAMP for nearest sampling, unnormalized coords.
396 wrap_nearest_unorm_clamp(float s
, unsigned size
, int *icoord
)
398 int i
= util_ifloor(s
);
399 *icoord
= CLAMP(i
, 0, (int) size
-1);
404 * PIPE_TEX_WRAP_CLAMP_TO_BORDER for nearest sampling, unnormalized coords.
407 wrap_nearest_unorm_clamp_to_border(float s
, unsigned size
, int *icoord
)
409 *icoord
= util_ifloor( CLAMP(s
, -0.5F
, (float) size
+ 0.5F
) );
414 * PIPE_TEX_WRAP_CLAMP_TO_EDGE for nearest sampling, unnormalized coords.
417 wrap_nearest_unorm_clamp_to_edge(float s
, unsigned size
, int *icoord
)
419 *icoord
= util_ifloor( CLAMP(s
, 0.5F
, (float) size
- 0.5F
) );
424 * PIPE_TEX_WRAP_CLAMP for linear sampling, unnormalized coords.
427 wrap_linear_unorm_clamp(float s
, unsigned size
,
428 int *icoord0
, int *icoord1
, float *w
)
430 /* Not exactly what the spec says, but it matches NVIDIA output */
431 float u
= CLAMP(s
- 0.5F
, 0.0f
, (float) size
- 1.0f
);
432 *icoord0
= util_ifloor(u
);
433 *icoord1
= *icoord0
+ 1;
439 * PIPE_TEX_WRAP_CLAMP_TO_BORDER for linear sampling, unnormalized coords.
442 wrap_linear_unorm_clamp_to_border(float s
, unsigned size
,
443 int *icoord0
, int *icoord1
, float *w
)
445 float u
= CLAMP(s
, -0.5F
, (float) size
+ 0.5F
);
447 *icoord0
= util_ifloor(u
);
448 *icoord1
= *icoord0
+ 1;
449 if (*icoord1
> (int) size
- 1)
456 * PIPE_TEX_WRAP_CLAMP_TO_EDGE for linear sampling, unnormalized coords.
459 wrap_linear_unorm_clamp_to_edge(float s
, unsigned size
,
460 int *icoord0
, int *icoord1
, float *w
)
462 float u
= CLAMP(s
, +0.5F
, (float) size
- 0.5F
);
464 *icoord0
= util_ifloor(u
);
465 *icoord1
= *icoord0
+ 1;
466 if (*icoord1
> (int) size
- 1)
473 * Do coordinate to array index conversion. For array textures.
476 wrap_array_layer(float coord
, unsigned size
, int *layer
)
478 int c
= util_ifloor(coord
+ 0.5F
);
479 *layer
= CLAMP(c
, 0, size
- 1);
484 * Examine the quad's texture coordinates to compute the partial
485 * derivatives w.r.t X and Y, then compute lambda (level of detail).
488 compute_lambda_1d(const struct sp_sampler_variant
*samp
,
489 const float s
[TGSI_QUAD_SIZE
],
490 const float t
[TGSI_QUAD_SIZE
],
491 const float p
[TGSI_QUAD_SIZE
])
493 const struct pipe_resource
*texture
= samp
->view
->texture
;
494 float dsdx
= fabsf(s
[QUAD_BOTTOM_RIGHT
] - s
[QUAD_BOTTOM_LEFT
]);
495 float dsdy
= fabsf(s
[QUAD_TOP_LEFT
] - s
[QUAD_BOTTOM_LEFT
]);
496 float rho
= MAX2(dsdx
, dsdy
) * u_minify(texture
->width0
, samp
->view
->u
.tex
.first_level
);
498 return util_fast_log2(rho
);
503 compute_lambda_2d(const struct sp_sampler_variant
*samp
,
504 const float s
[TGSI_QUAD_SIZE
],
505 const float t
[TGSI_QUAD_SIZE
],
506 const float p
[TGSI_QUAD_SIZE
])
508 const struct pipe_resource
*texture
= samp
->view
->texture
;
509 float dsdx
= fabsf(s
[QUAD_BOTTOM_RIGHT
] - s
[QUAD_BOTTOM_LEFT
]);
510 float dsdy
= fabsf(s
[QUAD_TOP_LEFT
] - s
[QUAD_BOTTOM_LEFT
]);
511 float dtdx
= fabsf(t
[QUAD_BOTTOM_RIGHT
] - t
[QUAD_BOTTOM_LEFT
]);
512 float dtdy
= fabsf(t
[QUAD_TOP_LEFT
] - t
[QUAD_BOTTOM_LEFT
]);
513 float maxx
= MAX2(dsdx
, dsdy
) * u_minify(texture
->width0
, samp
->view
->u
.tex
.first_level
);
514 float maxy
= MAX2(dtdx
, dtdy
) * u_minify(texture
->height0
, samp
->view
->u
.tex
.first_level
);
515 float rho
= MAX2(maxx
, maxy
);
517 return util_fast_log2(rho
);
522 compute_lambda_3d(const struct sp_sampler_variant
*samp
,
523 const float s
[TGSI_QUAD_SIZE
],
524 const float t
[TGSI_QUAD_SIZE
],
525 const float p
[TGSI_QUAD_SIZE
])
527 const struct pipe_resource
*texture
= samp
->view
->texture
;
528 float dsdx
= fabsf(s
[QUAD_BOTTOM_RIGHT
] - s
[QUAD_BOTTOM_LEFT
]);
529 float dsdy
= fabsf(s
[QUAD_TOP_LEFT
] - s
[QUAD_BOTTOM_LEFT
]);
530 float dtdx
= fabsf(t
[QUAD_BOTTOM_RIGHT
] - t
[QUAD_BOTTOM_LEFT
]);
531 float dtdy
= fabsf(t
[QUAD_TOP_LEFT
] - t
[QUAD_BOTTOM_LEFT
]);
532 float dpdx
= fabsf(p
[QUAD_BOTTOM_RIGHT
] - p
[QUAD_BOTTOM_LEFT
]);
533 float dpdy
= fabsf(p
[QUAD_TOP_LEFT
] - p
[QUAD_BOTTOM_LEFT
]);
534 float maxx
= MAX2(dsdx
, dsdy
) * u_minify(texture
->width0
, samp
->view
->u
.tex
.first_level
);
535 float maxy
= MAX2(dtdx
, dtdy
) * u_minify(texture
->height0
, samp
->view
->u
.tex
.first_level
);
536 float maxz
= MAX2(dpdx
, dpdy
) * u_minify(texture
->depth0
, samp
->view
->u
.tex
.first_level
);
539 rho
= MAX2(maxx
, maxy
);
540 rho
= MAX2(rho
, maxz
);
542 return util_fast_log2(rho
);
547 * Compute lambda for a vertex texture sampler.
548 * Since there aren't derivatives to use, just return 0.
551 compute_lambda_vert(const struct sp_sampler_variant
*samp
,
552 const float s
[TGSI_QUAD_SIZE
],
553 const float t
[TGSI_QUAD_SIZE
],
554 const float p
[TGSI_QUAD_SIZE
])
562 * Get a texel from a texture, using the texture tile cache.
564 * \param addr the template tex address containing cube, z, face info.
565 * \param x the x coord of texel within 2D image
566 * \param y the y coord of texel within 2D image
567 * \param rgba the quad to put the texel/color into
569 * XXX maybe move this into sp_tex_tile_cache.c and merge with the
570 * sp_get_cached_tile_tex() function.
576 static INLINE
const float *
577 get_texel_2d_no_border(const struct sp_sampler_variant
*samp
,
578 union tex_tile_address addr
, int x
, int y
)
580 const struct softpipe_tex_cached_tile
*tile
;
582 addr
.bits
.x
= x
/ TILE_SIZE
;
583 addr
.bits
.y
= y
/ TILE_SIZE
;
587 tile
= sp_get_cached_tile_tex(samp
->cache
, addr
);
589 return &tile
->data
.color
[y
][x
][0];
593 static INLINE
const float *
594 get_texel_2d(const struct sp_sampler_variant
*samp
,
595 union tex_tile_address addr
, int x
, int y
)
597 const struct pipe_resource
*texture
= samp
->view
->texture
;
598 unsigned level
= addr
.bits
.level
;
600 if (x
< 0 || x
>= (int) u_minify(texture
->width0
, level
) ||
601 y
< 0 || y
>= (int) u_minify(texture
->height0
, level
)) {
602 return samp
->sampler
->border_color
.f
;
605 return get_texel_2d_no_border( samp
, addr
, x
, y
);
610 /* Gather a quad of adjacent texels within a tile:
613 get_texel_quad_2d_no_border_single_tile(const struct sp_sampler_variant
*samp
,
614 union tex_tile_address addr
,
615 unsigned x
, unsigned y
,
618 const struct softpipe_tex_cached_tile
*tile
;
620 addr
.bits
.x
= x
/ TILE_SIZE
;
621 addr
.bits
.y
= y
/ TILE_SIZE
;
625 tile
= sp_get_cached_tile_tex(samp
->cache
, addr
);
627 out
[0] = &tile
->data
.color
[y
][x
][0];
628 out
[1] = &tile
->data
.color
[y
][x
+1][0];
629 out
[2] = &tile
->data
.color
[y
+1][x
][0];
630 out
[3] = &tile
->data
.color
[y
+1][x
+1][0];
634 /* Gather a quad of potentially non-adjacent texels:
637 get_texel_quad_2d_no_border(const struct sp_sampler_variant
*samp
,
638 union tex_tile_address addr
,
643 out
[0] = get_texel_2d_no_border( samp
, addr
, x0
, y0
);
644 out
[1] = get_texel_2d_no_border( samp
, addr
, x1
, y0
);
645 out
[2] = get_texel_2d_no_border( samp
, addr
, x0
, y1
);
646 out
[3] = get_texel_2d_no_border( samp
, addr
, x1
, y1
);
649 /* Can involve a lot of unnecessary checks for border color:
652 get_texel_quad_2d(const struct sp_sampler_variant
*samp
,
653 union tex_tile_address addr
,
658 out
[0] = get_texel_2d( samp
, addr
, x0
, y0
);
659 out
[1] = get_texel_2d( samp
, addr
, x1
, y0
);
660 out
[3] = get_texel_2d( samp
, addr
, x1
, y1
);
661 out
[2] = get_texel_2d( samp
, addr
, x0
, y1
);
668 static INLINE
const float *
669 get_texel_3d_no_border(const struct sp_sampler_variant
*samp
,
670 union tex_tile_address addr
, int x
, int y
, int z
)
672 const struct softpipe_tex_cached_tile
*tile
;
674 addr
.bits
.x
= x
/ TILE_SIZE
;
675 addr
.bits
.y
= y
/ TILE_SIZE
;
680 tile
= sp_get_cached_tile_tex(samp
->cache
, addr
);
682 return &tile
->data
.color
[y
][x
][0];
686 static INLINE
const float *
687 get_texel_3d(const struct sp_sampler_variant
*samp
,
688 union tex_tile_address addr
, int x
, int y
, int z
)
690 const struct pipe_resource
*texture
= samp
->view
->texture
;
691 unsigned level
= addr
.bits
.level
;
693 if (x
< 0 || x
>= (int) u_minify(texture
->width0
, level
) ||
694 y
< 0 || y
>= (int) u_minify(texture
->height0
, level
) ||
695 z
< 0 || z
>= (int) u_minify(texture
->depth0
, level
)) {
696 return samp
->sampler
->border_color
.f
;
699 return get_texel_3d_no_border( samp
, addr
, x
, y
, z
);
704 /* Get texel pointer for 1D array texture */
705 static INLINE
const float *
706 get_texel_1d_array(const struct sp_sampler_variant
*samp
,
707 union tex_tile_address addr
, int x
, int y
)
709 const struct pipe_resource
*texture
= samp
->view
->texture
;
710 unsigned level
= addr
.bits
.level
;
712 if (x
< 0 || x
>= (int) u_minify(texture
->width0
, level
)) {
713 return samp
->sampler
->border_color
.f
;
716 return get_texel_2d_no_border(samp
, addr
, x
, y
);
721 /* Get texel pointer for 2D array texture */
722 static INLINE
const float *
723 get_texel_2d_array(const struct sp_sampler_variant
*samp
,
724 union tex_tile_address addr
, int x
, int y
, int layer
)
726 const struct pipe_resource
*texture
= samp
->view
->texture
;
727 unsigned level
= addr
.bits
.level
;
729 assert(layer
< (int) texture
->array_size
);
732 if (x
< 0 || x
>= (int) u_minify(texture
->width0
, level
) ||
733 y
< 0 || y
>= (int) u_minify(texture
->height0
, level
)) {
734 return samp
->sampler
->border_color
.f
;
737 return get_texel_3d_no_border(samp
, addr
, x
, y
, layer
);
742 /* Get texel pointer for cube array texture */
743 static INLINE
const float *
744 get_texel_cube_array(const struct sp_sampler_variant
*samp
,
745 union tex_tile_address addr
, int x
, int y
, int layer
)
747 const struct pipe_resource
*texture
= samp
->view
->texture
;
748 unsigned level
= addr
.bits
.level
;
750 assert(layer
< (int) texture
->array_size
);
753 if (x
< 0 || x
>= (int) u_minify(texture
->width0
, level
) ||
754 y
< 0 || y
>= (int) u_minify(texture
->height0
, level
)) {
755 return samp
->sampler
->border_color
.f
;
758 return get_texel_3d_no_border(samp
, addr
, x
, y
, layer
);
762 * Given the logbase2 of a mipmap's base level size and a mipmap level,
763 * return the size (in texels) of that mipmap level.
764 * For example, if level[0].width = 256 then base_pot will be 8.
765 * If level = 2, then we'll return 64 (the width at level=2).
766 * Return 1 if level > base_pot.
768 static INLINE
unsigned
769 pot_level_size(unsigned base_pot
, unsigned level
)
771 return (base_pot
>= level
) ? (1 << (base_pot
- level
)) : 1;
776 print_sample(const char *function
, const float *rgba
)
778 debug_printf("%s %g %g %g %g\n",
780 rgba
[0], rgba
[TGSI_NUM_CHANNELS
], rgba
[2*TGSI_NUM_CHANNELS
], rgba
[3*TGSI_NUM_CHANNELS
]);
785 print_sample_4(const char *function
, float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
787 debug_printf("%s %g %g %g %g, %g %g %g %g, %g %g %g %g, %g %g %g %g\n",
789 rgba
[0][0], rgba
[1][0], rgba
[2][0], rgba
[3][0],
790 rgba
[0][1], rgba
[1][1], rgba
[2][1], rgba
[3][1],
791 rgba
[0][2], rgba
[1][2], rgba
[2][2], rgba
[3][2],
792 rgba
[0][3], rgba
[1][3], rgba
[2][3], rgba
[3][3]);
795 /* Some image-filter fastpaths:
798 img_filter_2d_linear_repeat_POT(struct tgsi_sampler
*tgsi_sampler
,
804 enum tgsi_sampler_control control
,
807 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
808 unsigned xpot
= pot_level_size(samp
->xpot
, level
);
809 unsigned ypot
= pot_level_size(samp
->ypot
, level
);
810 unsigned xmax
= (xpot
- 1) & (TILE_SIZE
- 1); /* MIN2(TILE_SIZE, xpot) - 1; */
811 unsigned ymax
= (ypot
- 1) & (TILE_SIZE
- 1); /* MIN2(TILE_SIZE, ypot) - 1; */
812 union tex_tile_address addr
;
815 float u
= s
* xpot
- 0.5F
;
816 float v
= t
* ypot
- 0.5F
;
818 int uflr
= util_ifloor(u
);
819 int vflr
= util_ifloor(v
);
821 float xw
= u
- (float)uflr
;
822 float yw
= v
- (float)vflr
;
824 int x0
= uflr
& (xpot
- 1);
825 int y0
= vflr
& (ypot
- 1);
830 addr
.bits
.level
= level
;
832 /* Can we fetch all four at once:
834 if (x0
< xmax
&& y0
< ymax
) {
835 get_texel_quad_2d_no_border_single_tile(samp
, addr
, x0
, y0
, tx
);
838 unsigned x1
= (x0
+ 1) & (xpot
- 1);
839 unsigned y1
= (y0
+ 1) & (ypot
- 1);
840 get_texel_quad_2d_no_border(samp
, addr
, x0
, y0
, x1
, y1
, tx
);
843 /* interpolate R, G, B, A */
844 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++) {
845 rgba
[TGSI_NUM_CHANNELS
*c
] = lerp_2d(xw
, yw
,
851 print_sample(__FUNCTION__
, rgba
);
857 img_filter_2d_nearest_repeat_POT(struct tgsi_sampler
*tgsi_sampler
,
863 enum tgsi_sampler_control control
,
864 float rgba
[TGSI_QUAD_SIZE
])
866 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
867 unsigned xpot
= pot_level_size(samp
->xpot
, level
);
868 unsigned ypot
= pot_level_size(samp
->ypot
, level
);
870 union tex_tile_address addr
;
876 int uflr
= util_ifloor(u
);
877 int vflr
= util_ifloor(v
);
879 int x0
= uflr
& (xpot
- 1);
880 int y0
= vflr
& (ypot
- 1);
883 addr
.bits
.level
= level
;
885 out
= get_texel_2d_no_border(samp
, addr
, x0
, y0
);
886 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
887 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
890 print_sample(__FUNCTION__
, rgba
);
896 img_filter_2d_nearest_clamp_POT(struct tgsi_sampler
*tgsi_sampler
,
902 enum tgsi_sampler_control control
,
903 float rgba
[TGSI_QUAD_SIZE
])
905 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
906 unsigned xpot
= pot_level_size(samp
->xpot
, level
);
907 unsigned ypot
= pot_level_size(samp
->ypot
, level
);
908 union tex_tile_address addr
;
918 addr
.bits
.level
= level
;
923 else if (x0
> xpot
- 1)
929 else if (y0
> ypot
- 1)
932 out
= get_texel_2d_no_border(samp
, addr
, x0
, y0
);
933 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
934 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
937 print_sample(__FUNCTION__
, rgba
);
943 img_filter_1d_nearest(struct tgsi_sampler
*tgsi_sampler
,
949 enum tgsi_sampler_control control
,
950 float rgba
[TGSI_QUAD_SIZE
])
952 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
953 const struct pipe_resource
*texture
= samp
->view
->texture
;
956 union tex_tile_address addr
;
960 width
= u_minify(texture
->width0
, level
);
965 addr
.bits
.level
= level
;
967 samp
->nearest_texcoord_s(s
, width
, &x
);
969 out
= get_texel_2d(samp
, addr
, x
, 0);
970 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
971 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
974 print_sample(__FUNCTION__
, rgba
);
980 img_filter_1d_array_nearest(struct tgsi_sampler
*tgsi_sampler
,
986 enum tgsi_sampler_control control
,
989 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
990 const struct pipe_resource
*texture
= samp
->view
->texture
;
993 union tex_tile_address addr
;
997 width
= u_minify(texture
->width0
, level
);
1002 addr
.bits
.level
= level
;
1004 samp
->nearest_texcoord_s(s
, width
, &x
);
1005 wrap_array_layer(t
, texture
->array_size
, &layer
);
1007 out
= get_texel_1d_array(samp
, addr
, x
, layer
);
1008 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1009 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
1012 print_sample(__FUNCTION__
, rgba
);
1018 img_filter_2d_nearest(struct tgsi_sampler
*tgsi_sampler
,
1024 enum tgsi_sampler_control control
,
1027 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1028 const struct pipe_resource
*texture
= samp
->view
->texture
;
1031 union tex_tile_address addr
;
1035 width
= u_minify(texture
->width0
, level
);
1036 height
= u_minify(texture
->height0
, level
);
1042 addr
.bits
.level
= level
;
1044 samp
->nearest_texcoord_s(s
, width
, &x
);
1045 samp
->nearest_texcoord_t(t
, height
, &y
);
1047 out
= get_texel_2d(samp
, addr
, x
, y
);
1048 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1049 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
1052 print_sample(__FUNCTION__
, rgba
);
1058 img_filter_2d_array_nearest(struct tgsi_sampler
*tgsi_sampler
,
1064 enum tgsi_sampler_control control
,
1067 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1068 const struct pipe_resource
*texture
= samp
->view
->texture
;
1071 union tex_tile_address addr
;
1075 width
= u_minify(texture
->width0
, level
);
1076 height
= u_minify(texture
->height0
, level
);
1082 addr
.bits
.level
= level
;
1084 samp
->nearest_texcoord_s(s
, width
, &x
);
1085 samp
->nearest_texcoord_t(t
, height
, &y
);
1086 wrap_array_layer(p
, texture
->array_size
, &layer
);
1088 out
= get_texel_2d_array(samp
, addr
, x
, y
, layer
);
1089 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1090 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
1093 print_sample(__FUNCTION__
, rgba
);
1098 static INLINE
union tex_tile_address
1099 face(union tex_tile_address addr
, unsigned face
)
1101 addr
.bits
.face
= face
;
1107 img_filter_cube_nearest(struct tgsi_sampler
*tgsi_sampler
,
1113 enum tgsi_sampler_control control
,
1116 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1117 const struct pipe_resource
*texture
= samp
->view
->texture
;
1120 union tex_tile_address addr
;
1124 width
= u_minify(texture
->width0
, level
);
1125 height
= u_minify(texture
->height0
, level
);
1131 addr
.bits
.level
= level
;
1133 samp
->nearest_texcoord_s(s
, width
, &x
);
1134 samp
->nearest_texcoord_t(t
, height
, &y
);
1136 out
= get_texel_2d(samp
, face(addr
, face_id
), x
, y
);
1137 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1138 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
1141 print_sample(__FUNCTION__
, rgba
);
1146 img_filter_cube_array_nearest(struct tgsi_sampler
*tgsi_sampler
,
1152 enum tgsi_sampler_control control
,
1155 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1156 const struct pipe_resource
*texture
= samp
->view
->texture
;
1159 union tex_tile_address addr
;
1163 width
= u_minify(texture
->width0
, level
);
1164 height
= u_minify(texture
->height0
, level
);
1170 addr
.bits
.level
= level
;
1172 samp
->nearest_texcoord_s(s
, width
, &x
);
1173 samp
->nearest_texcoord_t(t
, height
, &y
);
1174 wrap_array_layer(p
, texture
->array_size
, &layer
);
1176 out
= get_texel_cube_array(samp
, addr
, x
, y
, layer
* 6 + face_id
);
1177 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1178 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
1181 print_sample(__FUNCTION__
, rgba
);
1186 img_filter_3d_nearest(struct tgsi_sampler
*tgsi_sampler
,
1192 enum tgsi_sampler_control control
,
1195 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1196 const struct pipe_resource
*texture
= samp
->view
->texture
;
1197 int width
, height
, depth
;
1199 union tex_tile_address addr
;
1203 width
= u_minify(texture
->width0
, level
);
1204 height
= u_minify(texture
->height0
, level
);
1205 depth
= u_minify(texture
->depth0
, level
);
1211 samp
->nearest_texcoord_s(s
, width
, &x
);
1212 samp
->nearest_texcoord_t(t
, height
, &y
);
1213 samp
->nearest_texcoord_p(p
, depth
, &z
);
1216 addr
.bits
.level
= level
;
1218 out
= get_texel_3d(samp
, addr
, x
, y
, z
);
1219 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1220 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
1225 img_filter_1d_linear(struct tgsi_sampler
*tgsi_sampler
,
1231 enum tgsi_sampler_control control
,
1234 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1235 const struct pipe_resource
*texture
= samp
->view
->texture
;
1238 float xw
; /* weights */
1239 union tex_tile_address addr
;
1240 const float *tx0
, *tx1
;
1243 width
= u_minify(texture
->width0
, level
);
1248 addr
.bits
.level
= level
;
1250 samp
->linear_texcoord_s(s
, width
, &x0
, &x1
, &xw
);
1252 tx0
= get_texel_2d(samp
, addr
, x0
, 0);
1253 tx1
= get_texel_2d(samp
, addr
, x1
, 0);
1255 /* interpolate R, G, B, A */
1256 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1257 rgba
[TGSI_NUM_CHANNELS
*c
] = lerp(xw
, tx0
[c
], tx1
[c
]);
1262 img_filter_1d_array_linear(struct tgsi_sampler
*tgsi_sampler
,
1268 enum tgsi_sampler_control control
,
1271 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1272 const struct pipe_resource
*texture
= samp
->view
->texture
;
1275 float xw
; /* weights */
1276 union tex_tile_address addr
;
1277 const float *tx0
, *tx1
;
1280 width
= u_minify(texture
->width0
, level
);
1285 addr
.bits
.level
= level
;
1287 samp
->linear_texcoord_s(s
, width
, &x0
, &x1
, &xw
);
1288 wrap_array_layer(t
, texture
->array_size
, &layer
);
1290 tx0
= get_texel_1d_array(samp
, addr
, x0
, layer
);
1291 tx1
= get_texel_1d_array(samp
, addr
, x1
, layer
);
1293 /* interpolate R, G, B, A */
1294 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1295 rgba
[TGSI_NUM_CHANNELS
*c
] = lerp(xw
, tx0
[c
], tx1
[c
]);
1300 img_filter_2d_linear(struct tgsi_sampler
*tgsi_sampler
,
1306 enum tgsi_sampler_control control
,
1309 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1310 const struct pipe_resource
*texture
= samp
->view
->texture
;
1313 float xw
, yw
; /* weights */
1314 union tex_tile_address addr
;
1315 const float *tx0
, *tx1
, *tx2
, *tx3
;
1318 width
= u_minify(texture
->width0
, level
);
1319 height
= u_minify(texture
->height0
, level
);
1325 addr
.bits
.level
= level
;
1327 samp
->linear_texcoord_s(s
, width
, &x0
, &x1
, &xw
);
1328 samp
->linear_texcoord_t(t
, height
, &y0
, &y1
, &yw
);
1330 tx0
= get_texel_2d(samp
, addr
, x0
, y0
);
1331 tx1
= get_texel_2d(samp
, addr
, x1
, y0
);
1332 tx2
= get_texel_2d(samp
, addr
, x0
, y1
);
1333 tx3
= get_texel_2d(samp
, addr
, x1
, y1
);
1335 /* interpolate R, G, B, A */
1336 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1337 rgba
[TGSI_NUM_CHANNELS
*c
] = lerp_2d(xw
, yw
,
1344 img_filter_2d_array_linear(struct tgsi_sampler
*tgsi_sampler
,
1350 enum tgsi_sampler_control control
,
1353 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1354 const struct pipe_resource
*texture
= samp
->view
->texture
;
1356 int x0
, y0
, x1
, y1
, layer
;
1357 float xw
, yw
; /* weights */
1358 union tex_tile_address addr
;
1359 const float *tx0
, *tx1
, *tx2
, *tx3
;
1362 width
= u_minify(texture
->width0
, level
);
1363 height
= u_minify(texture
->height0
, level
);
1369 addr
.bits
.level
= level
;
1371 samp
->linear_texcoord_s(s
, width
, &x0
, &x1
, &xw
);
1372 samp
->linear_texcoord_t(t
, height
, &y0
, &y1
, &yw
);
1373 wrap_array_layer(p
, texture
->array_size
, &layer
);
1375 tx0
= get_texel_2d_array(samp
, addr
, x0
, y0
, layer
);
1376 tx1
= get_texel_2d_array(samp
, addr
, x1
, y0
, layer
);
1377 tx2
= get_texel_2d_array(samp
, addr
, x0
, y1
, layer
);
1378 tx3
= get_texel_2d_array(samp
, addr
, x1
, y1
, layer
);
1380 /* interpolate R, G, B, A */
1381 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1382 rgba
[TGSI_NUM_CHANNELS
*c
] = lerp_2d(xw
, yw
,
1389 img_filter_cube_linear(struct tgsi_sampler
*tgsi_sampler
,
1395 enum tgsi_sampler_control control
,
1398 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1399 const struct pipe_resource
*texture
= samp
->view
->texture
;
1402 float xw
, yw
; /* weights */
1403 union tex_tile_address addr
, addrj
;
1404 const float *tx0
, *tx1
, *tx2
, *tx3
;
1407 width
= u_minify(texture
->width0
, level
);
1408 height
= u_minify(texture
->height0
, level
);
1414 addr
.bits
.level
= level
;
1416 samp
->linear_texcoord_s(s
, width
, &x0
, &x1
, &xw
);
1417 samp
->linear_texcoord_t(t
, height
, &y0
, &y1
, &yw
);
1419 addrj
= face(addr
, face_id
);
1420 tx0
= get_texel_2d(samp
, addrj
, x0
, y0
);
1421 tx1
= get_texel_2d(samp
, addrj
, x1
, y0
);
1422 tx2
= get_texel_2d(samp
, addrj
, x0
, y1
);
1423 tx3
= get_texel_2d(samp
, addrj
, x1
, y1
);
1425 /* interpolate R, G, B, A */
1426 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1427 rgba
[TGSI_NUM_CHANNELS
*c
] = lerp_2d(xw
, yw
,
1434 img_filter_cube_array_linear(struct tgsi_sampler
*tgsi_sampler
,
1440 enum tgsi_sampler_control control
,
1443 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1444 const struct pipe_resource
*texture
= samp
->view
->texture
;
1446 int x0
, y0
, x1
, y1
, layer
;
1447 float xw
, yw
; /* weights */
1448 union tex_tile_address addr
, addrj
;
1449 const float *tx0
, *tx1
, *tx2
, *tx3
;
1452 width
= u_minify(texture
->width0
, level
);
1453 height
= u_minify(texture
->height0
, level
);
1459 addr
.bits
.level
= level
;
1461 samp
->linear_texcoord_s(s
, width
, &x0
, &x1
, &xw
);
1462 samp
->linear_texcoord_t(t
, height
, &y0
, &y1
, &yw
);
1463 wrap_array_layer(p
, texture
->array_size
, &layer
);
1465 tx0
= get_texel_cube_array(samp
, addr
, x0
, y0
, layer
* 6 + face_id
);
1466 tx1
= get_texel_cube_array(samp
, addr
, x1
, y0
, layer
* 6 + face_id
);
1467 tx2
= get_texel_cube_array(samp
, addr
, x0
, y1
, layer
* 6 + face_id
);
1468 tx3
= get_texel_cube_array(samp
, addr
, x1
, y1
, layer
* 6 + face_id
);
1470 /* interpolate R, G, B, A */
1471 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1472 rgba
[TGSI_NUM_CHANNELS
*c
] = lerp_2d(xw
, yw
,
1478 img_filter_3d_linear(struct tgsi_sampler
*tgsi_sampler
,
1484 enum tgsi_sampler_control control
,
1487 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1488 const struct pipe_resource
*texture
= samp
->view
->texture
;
1489 int width
, height
, depth
;
1490 int x0
, x1
, y0
, y1
, z0
, z1
;
1491 float xw
, yw
, zw
; /* interpolation weights */
1492 union tex_tile_address addr
;
1493 const float *tx00
, *tx01
, *tx02
, *tx03
, *tx10
, *tx11
, *tx12
, *tx13
;
1496 width
= u_minify(texture
->width0
, level
);
1497 height
= u_minify(texture
->height0
, level
);
1498 depth
= u_minify(texture
->depth0
, level
);
1501 addr
.bits
.level
= level
;
1507 samp
->linear_texcoord_s(s
, width
, &x0
, &x1
, &xw
);
1508 samp
->linear_texcoord_t(t
, height
, &y0
, &y1
, &yw
);
1509 samp
->linear_texcoord_p(p
, depth
, &z0
, &z1
, &zw
);
1512 tx00
= get_texel_3d(samp
, addr
, x0
, y0
, z0
);
1513 tx01
= get_texel_3d(samp
, addr
, x1
, y0
, z0
);
1514 tx02
= get_texel_3d(samp
, addr
, x0
, y1
, z0
);
1515 tx03
= get_texel_3d(samp
, addr
, x1
, y1
, z0
);
1517 tx10
= get_texel_3d(samp
, addr
, x0
, y0
, z1
);
1518 tx11
= get_texel_3d(samp
, addr
, x1
, y0
, z1
);
1519 tx12
= get_texel_3d(samp
, addr
, x0
, y1
, z1
);
1520 tx13
= get_texel_3d(samp
, addr
, x1
, y1
, z1
);
1522 /* interpolate R, G, B, A */
1523 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1524 rgba
[TGSI_NUM_CHANNELS
*c
] = lerp_3d(xw
, yw
, zw
,
1532 /* Calculate level of detail for every fragment.
1533 * Note that lambda has already been biased by global LOD bias.
1536 compute_lod(const struct pipe_sampler_state
*sampler
,
1537 const float biased_lambda
,
1538 const float lodbias
[TGSI_QUAD_SIZE
],
1539 float lod
[TGSI_QUAD_SIZE
])
1543 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1544 lod
[i
] = biased_lambda
+ lodbias
[i
];
1545 lod
[i
] = CLAMP(lod
[i
], sampler
->min_lod
, sampler
->max_lod
);
1551 mip_filter_linear(struct tgsi_sampler
*tgsi_sampler
,
1552 const float s
[TGSI_QUAD_SIZE
],
1553 const float t
[TGSI_QUAD_SIZE
],
1554 const float p
[TGSI_QUAD_SIZE
],
1555 const float c0
[TGSI_QUAD_SIZE
],
1556 const float c1
[TGSI_QUAD_SIZE
],
1557 enum tgsi_sampler_control control
,
1558 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
1560 struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1561 const struct pipe_resource
*texture
= samp
->view
->texture
;
1563 float lod
[TGSI_QUAD_SIZE
];
1565 if (control
== tgsi_sampler_lod_bias
) {
1566 float lambda
= samp
->compute_lambda(samp
, s
, t
, p
) + samp
->sampler
->lod_bias
;
1567 if (samp
->key
.bits
.target
== PIPE_TEXTURE_CUBE_ARRAY
)
1568 compute_lod(samp
->sampler
, lambda
, c1
, lod
);
1570 compute_lod(samp
->sampler
, lambda
, c0
, lod
);
1572 assert(control
== tgsi_sampler_lod_explicit
);
1574 if (samp
->key
.bits
.target
== PIPE_TEXTURE_CUBE_ARRAY
)
1575 memcpy(lod
, c1
, sizeof(lod
));
1577 memcpy(lod
, c0
, sizeof(lod
));
1581 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
1582 int level0
= samp
->view
->u
.tex
.first_level
+ (int)lod
[j
];
1585 samp
->mag_img_filter(tgsi_sampler
, s
[j
], t
[j
], p
[j
], samp
->view
->u
.tex
.first_level
, samp
->faces
[j
], tgsi_sampler_lod_bias
, &rgba
[0][j
]);
1587 else if (level0
>= texture
->last_level
)
1588 samp
->min_img_filter(tgsi_sampler
, s
[j
], t
[j
], p
[j
], texture
->last_level
, samp
->faces
[j
], tgsi_sampler_lod_bias
, &rgba
[0][j
]);
1591 float levelBlend
= frac(lod
[j
]);
1592 float rgbax
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
1595 samp
->min_img_filter(tgsi_sampler
, s
[j
], t
[j
], p
[j
], level0
, samp
->faces
[j
], tgsi_sampler_lod_bias
, &rgbax
[0][0]);
1596 samp
->min_img_filter(tgsi_sampler
, s
[j
], t
[j
], p
[j
], level0
+1, samp
->faces
[j
], tgsi_sampler_lod_bias
, &rgbax
[0][1]);
1598 for (c
= 0; c
< 4; c
++) {
1599 rgba
[c
][j
] = lerp(levelBlend
, rgbax
[c
][0], rgbax
[c
][1]);
1605 print_sample_4(__FUNCTION__
, rgba
);
1611 * Compute nearest mipmap level from texcoords.
1612 * Then sample the texture level for four elements of a quad.
1613 * \param c0 the LOD bias factors, or absolute LODs (depending on control)
1616 mip_filter_nearest(struct tgsi_sampler
*tgsi_sampler
,
1617 const float s
[TGSI_QUAD_SIZE
],
1618 const float t
[TGSI_QUAD_SIZE
],
1619 const float p
[TGSI_QUAD_SIZE
],
1620 const float c0
[TGSI_QUAD_SIZE
],
1621 const float c1
[TGSI_QUAD_SIZE
],
1622 enum tgsi_sampler_control control
,
1623 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
1625 struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1626 const struct pipe_resource
*texture
= samp
->view
->texture
;
1627 float lod
[TGSI_QUAD_SIZE
];
1630 if (control
== tgsi_sampler_lod_bias
) {
1631 float lambda
= samp
->compute_lambda(samp
, s
, t
, p
) + samp
->sampler
->lod_bias
;
1632 if (samp
->key
.bits
.target
== PIPE_TEXTURE_CUBE_ARRAY
)
1633 compute_lod(samp
->sampler
, lambda
, c1
, lod
);
1635 compute_lod(samp
->sampler
, lambda
, c0
, lod
);
1637 assert(control
== tgsi_sampler_lod_explicit
);
1639 if (samp
->key
.bits
.target
== PIPE_TEXTURE_CUBE_ARRAY
)
1640 memcpy(lod
, c1
, sizeof(lod
));
1642 memcpy(lod
, c0
, sizeof(lod
));
1645 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
1647 samp
->mag_img_filter(tgsi_sampler
, s
[j
], t
[j
], p
[j
], samp
->view
->u
.tex
.first_level
, samp
->faces
[j
], tgsi_sampler_lod_bias
, &rgba
[0][j
]);
1649 float level
= samp
->view
->u
.tex
.first_level
+ (int)(lod
[j
] + 0.5F
) ;
1650 level
= MIN2(level
, (int)texture
->last_level
);
1651 samp
->min_img_filter(tgsi_sampler
, s
[j
], t
[j
], p
[j
], level
, samp
->faces
[j
], tgsi_sampler_lod_bias
, &rgba
[0][j
]);
1656 print_sample_4(__FUNCTION__
, rgba
);
1662 mip_filter_none(struct tgsi_sampler
*tgsi_sampler
,
1663 const float s
[TGSI_QUAD_SIZE
],
1664 const float t
[TGSI_QUAD_SIZE
],
1665 const float p
[TGSI_QUAD_SIZE
],
1666 const float c0
[TGSI_QUAD_SIZE
],
1667 const float c1
[TGSI_QUAD_SIZE
],
1668 enum tgsi_sampler_control control
,
1669 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
1671 struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1672 float lod
[TGSI_QUAD_SIZE
];
1675 if (control
== tgsi_sampler_lod_bias
) {
1676 float lambda
= samp
->compute_lambda(samp
, s
, t
, p
) + samp
->sampler
->lod_bias
;
1677 if (samp
->key
.bits
.target
== PIPE_TEXTURE_CUBE_ARRAY
)
1678 compute_lod(samp
->sampler
, lambda
, c1
, lod
);
1680 compute_lod(samp
->sampler
, lambda
, c0
, lod
);
1682 assert(control
== tgsi_sampler_lod_explicit
);
1684 if (samp
->key
.bits
.target
== PIPE_TEXTURE_CUBE_ARRAY
)
1685 memcpy(lod
, c1
, sizeof(lod
));
1687 memcpy(lod
, c0
, sizeof(lod
));
1690 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
1692 samp
->mag_img_filter(tgsi_sampler
, s
[j
], t
[j
], p
[j
], samp
->view
->u
.tex
.first_level
, samp
->faces
[j
], tgsi_sampler_lod_bias
, &rgba
[0][j
]);
1695 samp
->min_img_filter(tgsi_sampler
, s
[j
], t
[j
], p
[j
], samp
->view
->u
.tex
.first_level
, samp
->faces
[j
], tgsi_sampler_lod_bias
, &rgba
[0][j
]);
1702 mip_filter_none_no_filter_select(struct tgsi_sampler
*tgsi_sampler
,
1703 const float s
[TGSI_QUAD_SIZE
],
1704 const float t
[TGSI_QUAD_SIZE
],
1705 const float p
[TGSI_QUAD_SIZE
],
1706 const float c0
[TGSI_QUAD_SIZE
],
1707 const float c1
[TGSI_QUAD_SIZE
],
1708 enum tgsi_sampler_control control
,
1709 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
1711 struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1714 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++)
1715 samp
->mag_img_filter(tgsi_sampler
, s
[j
], t
[j
], p
[j
], samp
->view
->u
.tex
.first_level
, samp
->faces
[j
], tgsi_sampler_lod_bias
, &rgba
[0][j
]);
1719 /* For anisotropic filtering */
1720 #define WEIGHT_LUT_SIZE 1024
1722 static float *weightLut
= NULL
;
1725 * Creates the look-up table used to speed-up EWA sampling
1728 create_filter_table(void)
1732 weightLut
= (float *) MALLOC(WEIGHT_LUT_SIZE
* sizeof(float));
1734 for (i
= 0; i
< WEIGHT_LUT_SIZE
; ++i
) {
1736 float r2
= (float) i
/ (float) (WEIGHT_LUT_SIZE
- 1);
1737 float weight
= (float) exp(-alpha
* r2
);
1738 weightLut
[i
] = weight
;
1745 * Elliptical weighted average (EWA) filter for producing high quality
1746 * anisotropic filtered results.
1747 * Based on the Higher Quality Elliptical Weighted Average Filter
1748 * published by Paul S. Heckbert in his Master's Thesis
1749 * "Fundamentals of Texture Mapping and Image Warping" (1989)
1752 img_filter_2d_ewa(struct tgsi_sampler
*tgsi_sampler
,
1753 const float s
[TGSI_QUAD_SIZE
],
1754 const float t
[TGSI_QUAD_SIZE
],
1755 const float p
[TGSI_QUAD_SIZE
],
1757 enum tgsi_sampler_control control
,
1758 const float dudx
, const float dvdx
,
1759 const float dudy
, const float dvdy
,
1760 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
1762 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1763 const struct pipe_resource
*texture
= samp
->view
->texture
;
1765 // ??? Won't the image filters blow up if level is negative?
1766 unsigned level0
= level
> 0 ? level
: 0;
1767 float scaling
= 1.0 / (1 << level0
);
1768 int width
= u_minify(texture
->width0
, level0
);
1769 int height
= u_minify(texture
->height0
, level0
);
1771 float ux
= dudx
* scaling
;
1772 float vx
= dvdx
* scaling
;
1773 float uy
= dudy
* scaling
;
1774 float vy
= dvdy
* scaling
;
1776 /* compute ellipse coefficients to bound the region:
1777 * A*x*x + B*x*y + C*y*y = F.
1779 float A
= vx
*vx
+vy
*vy
+1;
1780 float B
= -2*(ux
*vx
+uy
*vy
);
1781 float C
= ux
*ux
+uy
*uy
+1;
1782 float F
= A
*C
-B
*B
/4.0;
1784 /* check if it is an ellipse */
1785 /* ASSERT(F > 0.0); */
1787 /* Compute the ellipse's (u,v) bounding box in texture space */
1788 float d
= -B
*B
+4.0*C
*A
;
1789 float box_u
= 2.0 / d
* sqrt(d
*C
*F
); /* box_u -> half of bbox with */
1790 float box_v
= 2.0 / d
* sqrt(A
*d
*F
); /* box_v -> half of bbox height */
1792 float rgba_temp
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
1793 float s_buffer
[TGSI_QUAD_SIZE
];
1794 float t_buffer
[TGSI_QUAD_SIZE
];
1795 float weight_buffer
[TGSI_QUAD_SIZE
];
1796 unsigned buffer_next
;
1798 float den
; /* = 0.0F; */
1800 float U
; /* = u0 - tex_u; */
1803 /* Scale ellipse formula to directly index the Filter Lookup Table.
1804 * i.e. scale so that F = WEIGHT_LUT_SIZE-1
1806 double formScale
= (double) (WEIGHT_LUT_SIZE
- 1) / F
;
1810 /* F *= formScale; */ /* no need to scale F as we don't use it below here */
1812 /* For each quad, the du and dx values are the same and so the ellipse is
1813 * also the same. Note that texel/image access can only be performed using
1814 * a quad, i.e. it is not possible to get the pixel value for a single
1815 * tex coord. In order to have a better performance, the access is buffered
1816 * using the s_buffer/t_buffer and weight_buffer. Only when the buffer is
1817 * full, then the pixel values are read from the image.
1821 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
1822 /* Heckbert MS thesis, p. 59; scan over the bounding box of the ellipse
1823 * and incrementally update the value of Ax^2+Bxy*Cy^2; when this
1824 * value, q, is less than F, we're inside the ellipse
1826 float tex_u
= -0.5F
+ s
[j
] * texture
->width0
* scaling
;
1827 float tex_v
= -0.5F
+ t
[j
] * texture
->height0
* scaling
;
1829 int u0
= (int) floorf(tex_u
- box_u
);
1830 int u1
= (int) ceilf(tex_u
+ box_u
);
1831 int v0
= (int) floorf(tex_v
- box_v
);
1832 int v1
= (int) ceilf(tex_v
+ box_v
);
1834 float num
[4] = {0.0F
, 0.0F
, 0.0F
, 0.0F
};
1838 for (v
= v0
; v
<= v1
; ++v
) {
1839 float V
= v
- tex_v
;
1840 float dq
= A
* (2 * U
+ 1) + B
* V
;
1841 float q
= (C
* V
+ B
* U
) * V
+ A
* U
* U
;
1844 for (u
= u0
; u
<= u1
; ++u
) {
1845 /* Note that the ellipse has been pre-scaled so F =
1846 * WEIGHT_LUT_SIZE - 1
1848 if (q
< WEIGHT_LUT_SIZE
) {
1849 /* as a LUT is used, q must never be negative;
1850 * should not happen, though
1852 const int qClamped
= q
>= 0.0F
? q
: 0;
1853 float weight
= weightLut
[qClamped
];
1855 weight_buffer
[buffer_next
] = weight
;
1856 s_buffer
[buffer_next
] = u
/ ((float) width
);
1857 t_buffer
[buffer_next
] = v
/ ((float) height
);
1860 if (buffer_next
== TGSI_QUAD_SIZE
) {
1861 /* 4 texel coords are in the buffer -> read it now */
1863 /* it is assumed that samp->min_img_filter is set to
1864 * img_filter_2d_nearest or one of the
1865 * accelerated img_filter_2d_nearest_XXX functions.
1867 for (jj
= 0; jj
< buffer_next
; jj
++) {
1868 samp
->min_img_filter(tgsi_sampler
, s_buffer
[jj
], t_buffer
[jj
], p
[jj
], level
, samp
->faces
[j
],
1869 tgsi_sampler_lod_bias
, &rgba_temp
[0][jj
]);
1870 num
[0] += weight_buffer
[jj
] * rgba_temp
[0][jj
];
1871 num
[1] += weight_buffer
[jj
] * rgba_temp
[1][jj
];
1872 num
[2] += weight_buffer
[jj
] * rgba_temp
[2][jj
];
1873 num
[3] += weight_buffer
[jj
] * rgba_temp
[3][jj
];
1886 /* if the tex coord buffer contains unread values, we will read
1889 if (buffer_next
> 0) {
1891 /* it is assumed that samp->min_img_filter is set to
1892 * img_filter_2d_nearest or one of the
1893 * accelerated img_filter_2d_nearest_XXX functions.
1895 for (jj
= 0; jj
< buffer_next
; jj
++) {
1896 samp
->min_img_filter(tgsi_sampler
, s_buffer
[jj
], t_buffer
[jj
], p
[jj
], level
, samp
->faces
[j
],
1897 tgsi_sampler_lod_bias
, &rgba_temp
[0][jj
]);
1898 num
[0] += weight_buffer
[jj
] * rgba_temp
[0][jj
];
1899 num
[1] += weight_buffer
[jj
] * rgba_temp
[1][jj
];
1900 num
[2] += weight_buffer
[jj
] * rgba_temp
[2][jj
];
1901 num
[3] += weight_buffer
[jj
] * rgba_temp
[3][jj
];
1906 /* Reaching this place would mean that no pixels intersected
1907 * the ellipse. This should never happen because the filter
1908 * we use always intersects at least one pixel.
1915 /* not enough pixels in resampling, resort to direct interpolation */
1916 samp
->min_img_filter(tgsi_sampler
, s
[j
], t
[j
], p
[j
], level
, samp
->faces
[j
],
1917 tgsi_sampler_lod_bias
, &rgba_temp
[0][j
]);
1919 num
[0] = rgba_temp
[0][j
];
1920 num
[1] = rgba_temp
[1][j
];
1921 num
[2] = rgba_temp
[2][j
];
1922 num
[3] = rgba_temp
[3][j
];
1925 rgba
[0][j
] = num
[0] / den
;
1926 rgba
[1][j
] = num
[1] / den
;
1927 rgba
[2][j
] = num
[2] / den
;
1928 rgba
[3][j
] = num
[3] / den
;
1934 * Sample 2D texture using an anisotropic filter.
1937 mip_filter_linear_aniso(struct tgsi_sampler
*tgsi_sampler
,
1938 const float s
[TGSI_QUAD_SIZE
],
1939 const float t
[TGSI_QUAD_SIZE
],
1940 const float p
[TGSI_QUAD_SIZE
],
1941 const float c0
[TGSI_QUAD_SIZE
],
1942 const float c1
[TGSI_QUAD_SIZE
],
1943 enum tgsi_sampler_control control
,
1944 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
1946 struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
1947 const struct pipe_resource
*texture
= samp
->view
->texture
;
1950 float lod
[TGSI_QUAD_SIZE
];
1952 float s_to_u
= u_minify(texture
->width0
, samp
->view
->u
.tex
.first_level
);
1953 float t_to_v
= u_minify(texture
->height0
, samp
->view
->u
.tex
.first_level
);
1954 float dudx
= (s
[QUAD_BOTTOM_RIGHT
] - s
[QUAD_BOTTOM_LEFT
]) * s_to_u
;
1955 float dudy
= (s
[QUAD_TOP_LEFT
] - s
[QUAD_BOTTOM_LEFT
]) * s_to_u
;
1956 float dvdx
= (t
[QUAD_BOTTOM_RIGHT
] - t
[QUAD_BOTTOM_LEFT
]) * t_to_v
;
1957 float dvdy
= (t
[QUAD_TOP_LEFT
] - t
[QUAD_BOTTOM_LEFT
]) * t_to_v
;
1959 if (control
== tgsi_sampler_lod_bias
) {
1960 /* note: instead of working with Px and Py, we will use the
1961 * squared length instead, to avoid sqrt.
1963 float Px2
= dudx
* dudx
+ dvdx
* dvdx
;
1964 float Py2
= dudy
* dudy
+ dvdy
* dvdy
;
1969 const float maxEccentricity
= samp
->sampler
->max_anisotropy
* samp
->sampler
->max_anisotropy
;
1980 /* if the eccentricity of the ellipse is too big, scale up the shorter
1981 * of the two vectors to limit the maximum amount of work per pixel
1984 if (e
> maxEccentricity
) {
1985 /* float s=e / maxEccentricity;
1989 Pmin2
= Pmax2
/ maxEccentricity
;
1992 /* note: we need to have Pmin=sqrt(Pmin2) here, but we can avoid
1993 * this since 0.5*log(x) = log(sqrt(x))
1995 lambda
= 0.5F
* util_fast_log2(Pmin2
) + samp
->sampler
->lod_bias
;
1996 compute_lod(samp
->sampler
, lambda
, c0
, lod
);
1999 assert(control
== tgsi_sampler_lod_explicit
);
2001 memcpy(lod
, c0
, sizeof(lod
));
2004 /* XXX: Take into account all lod values.
2007 level0
= samp
->view
->u
.tex
.first_level
+ (int)lambda
;
2009 /* If the ellipse covers the whole image, we can
2010 * simply return the average of the whole image.
2012 if (level0
>= (int) texture
->last_level
) {
2014 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++)
2015 samp
->min_img_filter(tgsi_sampler
, s
[j
], t
[j
], p
[j
], texture
->last_level
, samp
->faces
[j
], tgsi_sampler_lod_bias
, &rgba
[0][j
]);
2018 /* don't bother interpolating between multiple LODs; it doesn't
2019 * seem to be worth the extra running time.
2021 img_filter_2d_ewa(tgsi_sampler
, s
, t
, p
, level0
, tgsi_sampler_lod_bias
,
2022 dudx
, dvdx
, dudy
, dvdy
, rgba
);
2026 print_sample_4(__FUNCTION__
, rgba
);
2032 * Specialized version of mip_filter_linear with hard-wired calls to
2033 * 2d lambda calculation and 2d_linear_repeat_POT img filters.
2036 mip_filter_linear_2d_linear_repeat_POT(
2037 struct tgsi_sampler
*tgsi_sampler
,
2038 const float s
[TGSI_QUAD_SIZE
],
2039 const float t
[TGSI_QUAD_SIZE
],
2040 const float p
[TGSI_QUAD_SIZE
],
2041 const float c0
[TGSI_QUAD_SIZE
],
2042 const float c1
[TGSI_QUAD_SIZE
],
2043 enum tgsi_sampler_control control
,
2044 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
2046 struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
2047 const struct pipe_resource
*texture
= samp
->view
->texture
;
2050 float lod
[TGSI_QUAD_SIZE
];
2052 if (control
== tgsi_sampler_lod_bias
) {
2053 lambda
= samp
->compute_lambda(samp
, s
, t
, p
) + samp
->sampler
->lod_bias
;
2054 compute_lod(samp
->sampler
, lambda
, c0
, lod
);
2056 assert(control
== tgsi_sampler_lod_explicit
);
2058 memcpy(lod
, c0
, sizeof(lod
));
2061 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2062 int level0
= samp
->view
->u
.tex
.first_level
+ (int)lod
[j
];
2064 /* Catches both negative and large values of level0:
2066 if ((unsigned)level0
>= texture
->last_level
) {
2068 img_filter_2d_linear_repeat_POT(tgsi_sampler
, s
[j
], t
[j
], p
[j
], samp
->view
->u
.tex
.first_level
, samp
->faces
[j
], tgsi_sampler_lod_bias
, &rgba
[0][j
]);
2070 img_filter_2d_linear_repeat_POT(tgsi_sampler
, s
[j
], t
[j
], p
[j
], samp
->view
->texture
->last_level
, samp
->faces
[j
], tgsi_sampler_lod_bias
, &rgba
[0][j
]);
2074 float levelBlend
= frac(lod
[j
]);
2075 float rgbax
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
2078 img_filter_2d_linear_repeat_POT(tgsi_sampler
, s
[j
], t
[j
], p
[j
], level0
, samp
->faces
[j
], tgsi_sampler_lod_bias
, &rgbax
[0][0]);
2079 img_filter_2d_linear_repeat_POT(tgsi_sampler
, s
[j
], t
[j
], p
[j
], level0
+1, samp
->faces
[j
], tgsi_sampler_lod_bias
, &rgbax
[0][1]);
2081 for (c
= 0; c
< TGSI_NUM_CHANNELS
; c
++)
2082 rgba
[c
][j
] = lerp(levelBlend
, rgbax
[c
][0], rgbax
[c
][1]);
2087 print_sample_4(__FUNCTION__
, rgba
);
2093 * Do shadow/depth comparisons.
2096 sample_compare(struct tgsi_sampler
*tgsi_sampler
,
2097 const float s
[TGSI_QUAD_SIZE
],
2098 const float t
[TGSI_QUAD_SIZE
],
2099 const float p
[TGSI_QUAD_SIZE
],
2100 const float c0
[TGSI_QUAD_SIZE
],
2101 const float c1
[TGSI_QUAD_SIZE
],
2102 enum tgsi_sampler_control control
,
2103 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
2105 struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
2106 const struct pipe_sampler_state
*sampler
= samp
->sampler
;
2107 int j
, k0
, k1
, k2
, k3
;
2109 float pc0
, pc1
, pc2
, pc3
;
2111 samp
->mip_filter(tgsi_sampler
, s
, t
, p
, c0
, c1
, control
, rgba
);
2114 * Compare texcoord 'p' (aka R) against texture value 'rgba[0]'
2115 * for 2D Array texture we need to use the 'c0' (aka Q).
2116 * When we sampled the depth texture, the depth value was put into all
2117 * RGBA channels. We look at the red channel here.
2120 if (samp
->view
->texture
->target
== PIPE_TEXTURE_2D_ARRAY
||
2121 samp
->view
->texture
->target
== PIPE_TEXTURE_CUBE
) {
2122 pc0
= CLAMP(c0
[0], 0.0F
, 1.0F
);
2123 pc1
= CLAMP(c0
[1], 0.0F
, 1.0F
);
2124 pc2
= CLAMP(c0
[2], 0.0F
, 1.0F
);
2125 pc3
= CLAMP(c0
[3], 0.0F
, 1.0F
);
2126 } else if (samp
->view
->texture
->target
== PIPE_TEXTURE_CUBE_ARRAY
) {
2127 pc0
= CLAMP(c1
[0], 0.0F
, 1.0F
);
2128 pc1
= CLAMP(c1
[1], 0.0F
, 1.0F
);
2129 pc2
= CLAMP(c1
[2], 0.0F
, 1.0F
);
2130 pc3
= CLAMP(c1
[3], 0.0F
, 1.0F
);
2132 pc0
= CLAMP(p
[0], 0.0F
, 1.0F
);
2133 pc1
= CLAMP(p
[1], 0.0F
, 1.0F
);
2134 pc2
= CLAMP(p
[2], 0.0F
, 1.0F
);
2135 pc3
= CLAMP(p
[3], 0.0F
, 1.0F
);
2137 /* compare four texcoords vs. four texture samples */
2138 switch (sampler
->compare_func
) {
2139 case PIPE_FUNC_LESS
:
2140 k0
= pc0
< rgba
[0][0];
2141 k1
= pc1
< rgba
[0][1];
2142 k2
= pc2
< rgba
[0][2];
2143 k3
= pc3
< rgba
[0][3];
2145 case PIPE_FUNC_LEQUAL
:
2146 k0
= pc0
<= rgba
[0][0];
2147 k1
= pc1
<= rgba
[0][1];
2148 k2
= pc2
<= rgba
[0][2];
2149 k3
= pc3
<= rgba
[0][3];
2151 case PIPE_FUNC_GREATER
:
2152 k0
= pc0
> rgba
[0][0];
2153 k1
= pc1
> rgba
[0][1];
2154 k2
= pc2
> rgba
[0][2];
2155 k3
= pc3
> rgba
[0][3];
2157 case PIPE_FUNC_GEQUAL
:
2158 k0
= pc0
>= rgba
[0][0];
2159 k1
= pc1
>= rgba
[0][1];
2160 k2
= pc2
>= rgba
[0][2];
2161 k3
= pc3
>= rgba
[0][3];
2163 case PIPE_FUNC_EQUAL
:
2164 k0
= pc0
== rgba
[0][0];
2165 k1
= pc1
== rgba
[0][1];
2166 k2
= pc2
== rgba
[0][2];
2167 k3
= pc3
== rgba
[0][3];
2169 case PIPE_FUNC_NOTEQUAL
:
2170 k0
= pc0
!= rgba
[0][0];
2171 k1
= pc1
!= rgba
[0][1];
2172 k2
= pc2
!= rgba
[0][2];
2173 k3
= pc3
!= rgba
[0][3];
2175 case PIPE_FUNC_ALWAYS
:
2176 k0
= k1
= k2
= k3
= 1;
2178 case PIPE_FUNC_NEVER
:
2179 k0
= k1
= k2
= k3
= 0;
2182 k0
= k1
= k2
= k3
= 0;
2187 if (sampler
->mag_img_filter
== PIPE_TEX_FILTER_LINEAR
) {
2188 /* convert four pass/fail values to an intensity in [0,1] */
2189 val
= 0.25F
* (k0
+ k1
+ k2
+ k3
);
2191 /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */
2192 for (j
= 0; j
< 4; j
++) {
2193 rgba
[0][j
] = rgba
[1][j
] = rgba
[2][j
] = val
;
2197 for (j
= 0; j
< 4; j
++) {
2208 * Use 3D texcoords to choose a cube face, then sample the 2D cube faces.
2209 * Put face info into the sampler faces[] array.
2212 sample_cube(struct tgsi_sampler
*tgsi_sampler
,
2213 const float s
[TGSI_QUAD_SIZE
],
2214 const float t
[TGSI_QUAD_SIZE
],
2215 const float p
[TGSI_QUAD_SIZE
],
2216 const float c0
[TGSI_QUAD_SIZE
],
2217 const float c1
[TGSI_QUAD_SIZE
],
2218 enum tgsi_sampler_control control
,
2219 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
2221 struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
2223 float ssss
[4], tttt
[4];
2225 /* Not actually used, but the intermediate steps that do the
2226 * dereferencing don't know it.
2228 static float pppp
[4] = { 0, 0, 0, 0 };
2236 direction target sc tc ma
2237 ---------- ------------------------------- --- --- ---
2238 +rx TEXTURE_CUBE_MAP_POSITIVE_X_EXT -rz -ry rx
2239 -rx TEXTURE_CUBE_MAP_NEGATIVE_X_EXT +rz -ry rx
2240 +ry TEXTURE_CUBE_MAP_POSITIVE_Y_EXT +rx +rz ry
2241 -ry TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT +rx -rz ry
2242 +rz TEXTURE_CUBE_MAP_POSITIVE_Z_EXT +rx -ry rz
2243 -rz TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT -rx -ry rz
2246 /* Choose the cube face and compute new s/t coords for the 2D face.
2248 * Use the same cube face for all four pixels in the quad.
2250 * This isn't ideal, but if we want to use a different cube face
2251 * per pixel in the quad, we'd have to also compute the per-face
2252 * LOD here too. That's because the four post-face-selection
2253 * texcoords are no longer related to each other (they're
2254 * per-face!) so we can't use subtraction to compute the partial
2255 * deriviates to compute the LOD. Doing so (near cube edges
2256 * anyway) gives us pretty much random values.
2259 /* use the average of the four pixel's texcoords to choose the face */
2260 const float rx
= 0.25F
* (s
[0] + s
[1] + s
[2] + s
[3]);
2261 const float ry
= 0.25F
* (t
[0] + t
[1] + t
[2] + t
[3]);
2262 const float rz
= 0.25F
* (p
[0] + p
[1] + p
[2] + p
[3]);
2263 const float arx
= fabsf(rx
), ary
= fabsf(ry
), arz
= fabsf(rz
);
2265 if (arx
>= ary
&& arx
>= arz
) {
2266 float sign
= (rx
>= 0.0F
) ? 1.0F
: -1.0F
;
2267 uint face
= (rx
>= 0.0F
) ? PIPE_TEX_FACE_POS_X
: PIPE_TEX_FACE_NEG_X
;
2268 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2269 const float ima
= -0.5F
/ fabsf(s
[j
]);
2270 ssss
[j
] = sign
* p
[j
] * ima
+ 0.5F
;
2271 tttt
[j
] = t
[j
] * ima
+ 0.5F
;
2272 samp
->faces
[j
] = face
;
2275 else if (ary
>= arx
&& ary
>= arz
) {
2276 float sign
= (ry
>= 0.0F
) ? 1.0F
: -1.0F
;
2277 uint face
= (ry
>= 0.0F
) ? PIPE_TEX_FACE_POS_Y
: PIPE_TEX_FACE_NEG_Y
;
2278 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2279 const float ima
= -0.5F
/ fabsf(t
[j
]);
2280 ssss
[j
] = -s
[j
] * ima
+ 0.5F
;
2281 tttt
[j
] = sign
* -p
[j
] * ima
+ 0.5F
;
2282 samp
->faces
[j
] = face
;
2286 float sign
= (rz
>= 0.0F
) ? 1.0F
: -1.0F
;
2287 uint face
= (rz
>= 0.0F
) ? PIPE_TEX_FACE_POS_Z
: PIPE_TEX_FACE_NEG_Z
;
2288 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2289 const float ima
= -0.5F
/ fabsf(p
[j
]);
2290 ssss
[j
] = sign
* -s
[j
] * ima
+ 0.5F
;
2291 tttt
[j
] = t
[j
] * ima
+ 0.5F
;
2292 samp
->faces
[j
] = face
;
2297 /* In our little pipeline, the compare stage is next. If compare
2298 * is not active, this will point somewhere deeper into the
2299 * pipeline, eg. to mip_filter or even img_filter.
2301 samp
->compare(tgsi_sampler
, ssss
, tttt
, pppp
, c0
, c1
, control
, rgba
);
2306 do_swizzling(const struct sp_sampler_variant
*samp
,
2307 float in
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
],
2308 float out
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
2311 const unsigned swizzle_r
= samp
->key
.bits
.swizzle_r
;
2312 const unsigned swizzle_g
= samp
->key
.bits
.swizzle_g
;
2313 const unsigned swizzle_b
= samp
->key
.bits
.swizzle_b
;
2314 const unsigned swizzle_a
= samp
->key
.bits
.swizzle_a
;
2316 switch (swizzle_r
) {
2317 case PIPE_SWIZZLE_ZERO
:
2318 for (j
= 0; j
< 4; j
++)
2321 case PIPE_SWIZZLE_ONE
:
2322 for (j
= 0; j
< 4; j
++)
2326 assert(swizzle_r
< 4);
2327 for (j
= 0; j
< 4; j
++)
2328 out
[0][j
] = in
[swizzle_r
][j
];
2331 switch (swizzle_g
) {
2332 case PIPE_SWIZZLE_ZERO
:
2333 for (j
= 0; j
< 4; j
++)
2336 case PIPE_SWIZZLE_ONE
:
2337 for (j
= 0; j
< 4; j
++)
2341 assert(swizzle_g
< 4);
2342 for (j
= 0; j
< 4; j
++)
2343 out
[1][j
] = in
[swizzle_g
][j
];
2346 switch (swizzle_b
) {
2347 case PIPE_SWIZZLE_ZERO
:
2348 for (j
= 0; j
< 4; j
++)
2351 case PIPE_SWIZZLE_ONE
:
2352 for (j
= 0; j
< 4; j
++)
2356 assert(swizzle_b
< 4);
2357 for (j
= 0; j
< 4; j
++)
2358 out
[2][j
] = in
[swizzle_b
][j
];
2361 switch (swizzle_a
) {
2362 case PIPE_SWIZZLE_ZERO
:
2363 for (j
= 0; j
< 4; j
++)
2366 case PIPE_SWIZZLE_ONE
:
2367 for (j
= 0; j
< 4; j
++)
2371 assert(swizzle_a
< 4);
2372 for (j
= 0; j
< 4; j
++)
2373 out
[3][j
] = in
[swizzle_a
][j
];
2379 sample_swizzle(struct tgsi_sampler
*tgsi_sampler
,
2380 const float s
[TGSI_QUAD_SIZE
],
2381 const float t
[TGSI_QUAD_SIZE
],
2382 const float p
[TGSI_QUAD_SIZE
],
2383 const float c0
[TGSI_QUAD_SIZE
],
2384 const float c1
[TGSI_QUAD_SIZE
],
2385 enum tgsi_sampler_control control
,
2386 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
2388 struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
2389 float rgba_temp
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
2391 samp
->sample_target(tgsi_sampler
, s
, t
, p
, c0
, c1
, control
, rgba_temp
);
2393 do_swizzling(samp
, rgba_temp
, rgba
);
2397 static wrap_nearest_func
2398 get_nearest_unorm_wrap(unsigned mode
)
2401 case PIPE_TEX_WRAP_CLAMP
:
2402 return wrap_nearest_unorm_clamp
;
2403 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
2404 return wrap_nearest_unorm_clamp_to_edge
;
2405 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
2406 return wrap_nearest_unorm_clamp_to_border
;
2409 return wrap_nearest_unorm_clamp
;
2414 static wrap_nearest_func
2415 get_nearest_wrap(unsigned mode
)
2418 case PIPE_TEX_WRAP_REPEAT
:
2419 return wrap_nearest_repeat
;
2420 case PIPE_TEX_WRAP_CLAMP
:
2421 return wrap_nearest_clamp
;
2422 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
2423 return wrap_nearest_clamp_to_edge
;
2424 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
2425 return wrap_nearest_clamp_to_border
;
2426 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
2427 return wrap_nearest_mirror_repeat
;
2428 case PIPE_TEX_WRAP_MIRROR_CLAMP
:
2429 return wrap_nearest_mirror_clamp
;
2430 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
:
2431 return wrap_nearest_mirror_clamp_to_edge
;
2432 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
:
2433 return wrap_nearest_mirror_clamp_to_border
;
2436 return wrap_nearest_repeat
;
2441 static wrap_linear_func
2442 get_linear_unorm_wrap(unsigned mode
)
2445 case PIPE_TEX_WRAP_CLAMP
:
2446 return wrap_linear_unorm_clamp
;
2447 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
2448 return wrap_linear_unorm_clamp_to_edge
;
2449 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
2450 return wrap_linear_unorm_clamp_to_border
;
2453 return wrap_linear_unorm_clamp
;
2458 static wrap_linear_func
2459 get_linear_wrap(unsigned mode
)
2462 case PIPE_TEX_WRAP_REPEAT
:
2463 return wrap_linear_repeat
;
2464 case PIPE_TEX_WRAP_CLAMP
:
2465 return wrap_linear_clamp
;
2466 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
2467 return wrap_linear_clamp_to_edge
;
2468 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
2469 return wrap_linear_clamp_to_border
;
2470 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
2471 return wrap_linear_mirror_repeat
;
2472 case PIPE_TEX_WRAP_MIRROR_CLAMP
:
2473 return wrap_linear_mirror_clamp
;
2474 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
:
2475 return wrap_linear_mirror_clamp_to_edge
;
2476 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
:
2477 return wrap_linear_mirror_clamp_to_border
;
2480 return wrap_linear_repeat
;
2486 * Is swizzling needed for the given state key?
2489 any_swizzle(union sp_sampler_key key
)
2491 return (key
.bits
.swizzle_r
!= PIPE_SWIZZLE_RED
||
2492 key
.bits
.swizzle_g
!= PIPE_SWIZZLE_GREEN
||
2493 key
.bits
.swizzle_b
!= PIPE_SWIZZLE_BLUE
||
2494 key
.bits
.swizzle_a
!= PIPE_SWIZZLE_ALPHA
);
2498 static compute_lambda_func
2499 get_lambda_func(const union sp_sampler_key key
)
2501 if (key
.bits
.processor
== TGSI_PROCESSOR_VERTEX
)
2502 return compute_lambda_vert
;
2504 switch (key
.bits
.target
) {
2505 case PIPE_TEXTURE_1D
:
2506 case PIPE_TEXTURE_1D_ARRAY
:
2507 return compute_lambda_1d
;
2508 case PIPE_TEXTURE_2D
:
2509 case PIPE_TEXTURE_2D_ARRAY
:
2510 case PIPE_TEXTURE_RECT
:
2511 case PIPE_TEXTURE_CUBE
:
2512 case PIPE_TEXTURE_CUBE_ARRAY
:
2513 return compute_lambda_2d
;
2514 case PIPE_TEXTURE_3D
:
2515 return compute_lambda_3d
;
2518 return compute_lambda_1d
;
2523 static img_filter_func
2524 get_img_filter(const union sp_sampler_key key
,
2526 const struct pipe_sampler_state
*sampler
)
2528 switch (key
.bits
.target
) {
2529 case PIPE_TEXTURE_1D
:
2530 if (filter
== PIPE_TEX_FILTER_NEAREST
)
2531 return img_filter_1d_nearest
;
2533 return img_filter_1d_linear
;
2535 case PIPE_TEXTURE_1D_ARRAY
:
2536 if (filter
== PIPE_TEX_FILTER_NEAREST
)
2537 return img_filter_1d_array_nearest
;
2539 return img_filter_1d_array_linear
;
2541 case PIPE_TEXTURE_2D
:
2542 case PIPE_TEXTURE_RECT
:
2543 /* Try for fast path:
2545 if (key
.bits
.is_pot
&&
2546 sampler
->wrap_s
== sampler
->wrap_t
&&
2547 sampler
->normalized_coords
)
2549 switch (sampler
->wrap_s
) {
2550 case PIPE_TEX_WRAP_REPEAT
:
2552 case PIPE_TEX_FILTER_NEAREST
:
2553 return img_filter_2d_nearest_repeat_POT
;
2554 case PIPE_TEX_FILTER_LINEAR
:
2555 return img_filter_2d_linear_repeat_POT
;
2560 case PIPE_TEX_WRAP_CLAMP
:
2562 case PIPE_TEX_FILTER_NEAREST
:
2563 return img_filter_2d_nearest_clamp_POT
;
2569 /* Otherwise use default versions:
2571 if (filter
== PIPE_TEX_FILTER_NEAREST
)
2572 return img_filter_2d_nearest
;
2574 return img_filter_2d_linear
;
2576 case PIPE_TEXTURE_2D_ARRAY
:
2577 if (filter
== PIPE_TEX_FILTER_NEAREST
)
2578 return img_filter_2d_array_nearest
;
2580 return img_filter_2d_array_linear
;
2582 case PIPE_TEXTURE_CUBE
:
2583 if (filter
== PIPE_TEX_FILTER_NEAREST
)
2584 return img_filter_cube_nearest
;
2586 return img_filter_cube_linear
;
2588 case PIPE_TEXTURE_CUBE_ARRAY
:
2589 if (filter
== PIPE_TEX_FILTER_NEAREST
)
2590 return img_filter_cube_array_nearest
;
2592 return img_filter_cube_array_linear
;
2594 case PIPE_TEXTURE_3D
:
2595 if (filter
== PIPE_TEX_FILTER_NEAREST
)
2596 return img_filter_3d_nearest
;
2598 return img_filter_3d_linear
;
2602 return img_filter_1d_nearest
;
2608 * Bind the given texture object and texture cache to the sampler variant.
2611 sp_sampler_variant_bind_view( struct sp_sampler_variant
*samp
,
2612 struct softpipe_tex_tile_cache
*tex_cache
,
2613 const struct pipe_sampler_view
*view
)
2615 const struct pipe_resource
*texture
= view
->texture
;
2618 samp
->cache
= tex_cache
;
2619 samp
->xpot
= util_logbase2( texture
->width0
);
2620 samp
->ypot
= util_logbase2( texture
->height0
);
2625 sp_sampler_variant_destroy( struct sp_sampler_variant
*samp
)
2632 sample_get_dims(struct tgsi_sampler
*tgsi_sampler
, int level
,
2635 struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
2636 const struct pipe_sampler_view
*view
= samp
->view
;
2637 const struct pipe_resource
*texture
= view
->texture
;
2639 /* undefined according to EXT_gpu_program */
2640 level
+= view
->u
.tex
.first_level
;
2641 if (level
> view
->u
.tex
.last_level
)
2644 dims
[0] = u_minify(texture
->width0
, level
);
2646 switch(texture
->target
) {
2647 case PIPE_TEXTURE_1D_ARRAY
:
2648 dims
[1] = texture
->array_size
;
2650 case PIPE_TEXTURE_1D
:
2653 case PIPE_TEXTURE_2D_ARRAY
:
2654 dims
[2] = texture
->array_size
;
2656 case PIPE_TEXTURE_2D
:
2657 case PIPE_TEXTURE_CUBE
:
2658 case PIPE_TEXTURE_RECT
:
2659 dims
[1] = u_minify(texture
->height0
, level
);
2661 case PIPE_TEXTURE_3D
:
2662 dims
[1] = u_minify(texture
->height0
, level
);
2663 dims
[2] = u_minify(texture
->depth0
, level
);
2665 case PIPE_TEXTURE_CUBE_ARRAY
:
2666 dims
[1] = u_minify(texture
->height0
, level
);
2667 dims
[2] = texture
->array_size
/ 6;
2670 assert(!"unexpected texture target in sample_get_dims()");
2676 * This function is only used for getting unfiltered texels via the
2677 * TXF opcode. The GL spec says that out-of-bounds texel fetches
2678 * produce undefined results. Instead of crashing, lets just clamp
2679 * coords to the texture image size.
2682 sample_get_texels(struct tgsi_sampler
*tgsi_sampler
,
2683 const int v_i
[TGSI_QUAD_SIZE
],
2684 const int v_j
[TGSI_QUAD_SIZE
],
2685 const int v_k
[TGSI_QUAD_SIZE
],
2686 const int lod
[TGSI_QUAD_SIZE
],
2687 const int8_t offset
[3],
2688 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
2690 const struct sp_sampler_variant
*samp
= sp_sampler_variant(tgsi_sampler
);
2691 union tex_tile_address addr
;
2692 const struct pipe_resource
*texture
= samp
->view
->texture
;
2695 const bool need_swizzle
= any_swizzle(samp
->key
);
2696 int width
, height
, depth
, layers
;
2699 /* TODO write a better test for LOD */
2700 addr
.bits
.level
= lod
[0];
2702 width
= u_minify(texture
->width0
, addr
.bits
.level
);
2703 height
= u_minify(texture
->height0
, addr
.bits
.level
);
2704 depth
= u_minify(texture
->depth0
, addr
.bits
.level
);
2705 layers
= texture
->array_size
;
2707 switch(texture
->target
) {
2708 case PIPE_TEXTURE_1D
:
2709 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2710 int x
= CLAMP(v_i
[j
] + offset
[0], 0, width
- 1);
2711 tx
= get_texel_2d(samp
, addr
, x
, 0);
2712 for (c
= 0; c
< 4; c
++) {
2717 case PIPE_TEXTURE_1D_ARRAY
:
2718 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2719 int x
= CLAMP(v_i
[j
] + offset
[0], 0, width
- 1);
2720 int y
= CLAMP(v_j
[j
], 0, layers
- 1);
2721 tx
= get_texel_1d_array(samp
, addr
, x
, y
);
2722 for (c
= 0; c
< 4; c
++) {
2727 case PIPE_TEXTURE_2D
:
2728 case PIPE_TEXTURE_RECT
:
2729 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2730 int x
= CLAMP(v_i
[j
] + offset
[0], 0, width
- 1);
2731 int y
= CLAMP(v_j
[j
] + offset
[1], 0, height
- 1);
2732 tx
= get_texel_2d(samp
, addr
, x
, y
);
2733 for (c
= 0; c
< 4; c
++) {
2738 case PIPE_TEXTURE_2D_ARRAY
:
2739 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2740 int x
= CLAMP(v_i
[j
] + offset
[0], 0, width
- 1);
2741 int y
= CLAMP(v_j
[j
] + offset
[1], 0, height
- 1);
2742 int layer
= CLAMP(v_k
[j
], 0, layers
- 1);
2743 tx
= get_texel_2d_array(samp
, addr
, x
, y
, layer
);
2744 for (c
= 0; c
< 4; c
++) {
2749 case PIPE_TEXTURE_3D
:
2750 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2751 int x
= CLAMP(v_i
[j
] + offset
[0], 0, width
- 1);
2752 int y
= CLAMP(v_j
[j
] + offset
[1], 0, height
- 1);
2753 int z
= CLAMP(v_k
[j
] + offset
[2], 0, depth
- 1);
2755 tx
= get_texel_3d(samp
, addr
, x
, y
, z
);
2756 for (c
= 0; c
< 4; c
++) {
2761 case PIPE_TEXTURE_CUBE
: /* TXF can't work on CUBE according to spec */
2763 assert(!"Unknown or CUBE texture type in TXF processing\n");
2768 float rgba_temp
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
2769 memcpy(rgba_temp
, rgba
, sizeof(rgba_temp
));
2770 do_swizzling(samp
, rgba_temp
, rgba
);
2776 * Create a sampler variant for a given set of non-orthogonal state.
2778 struct sp_sampler_variant
*
2779 sp_create_sampler_variant( const struct pipe_sampler_state
*sampler
,
2780 const union sp_sampler_key key
)
2782 struct sp_sampler_variant
*samp
= CALLOC_STRUCT(sp_sampler_variant
);
2786 samp
->sampler
= sampler
;
2789 /* Note that (for instance) linear_texcoord_s and
2790 * nearest_texcoord_s may be active at the same time, if the
2791 * sampler min_img_filter differs from its mag_img_filter.
2793 if (sampler
->normalized_coords
) {
2794 samp
->linear_texcoord_s
= get_linear_wrap( sampler
->wrap_s
);
2795 samp
->linear_texcoord_t
= get_linear_wrap( sampler
->wrap_t
);
2796 samp
->linear_texcoord_p
= get_linear_wrap( sampler
->wrap_r
);
2798 samp
->nearest_texcoord_s
= get_nearest_wrap( sampler
->wrap_s
);
2799 samp
->nearest_texcoord_t
= get_nearest_wrap( sampler
->wrap_t
);
2800 samp
->nearest_texcoord_p
= get_nearest_wrap( sampler
->wrap_r
);
2803 samp
->linear_texcoord_s
= get_linear_unorm_wrap( sampler
->wrap_s
);
2804 samp
->linear_texcoord_t
= get_linear_unorm_wrap( sampler
->wrap_t
);
2805 samp
->linear_texcoord_p
= get_linear_unorm_wrap( sampler
->wrap_r
);
2807 samp
->nearest_texcoord_s
= get_nearest_unorm_wrap( sampler
->wrap_s
);
2808 samp
->nearest_texcoord_t
= get_nearest_unorm_wrap( sampler
->wrap_t
);
2809 samp
->nearest_texcoord_p
= get_nearest_unorm_wrap( sampler
->wrap_r
);
2812 samp
->compute_lambda
= get_lambda_func( key
);
2814 samp
->min_img_filter
= get_img_filter(key
, sampler
->min_img_filter
, sampler
);
2815 samp
->mag_img_filter
= get_img_filter(key
, sampler
->mag_img_filter
, sampler
);
2817 switch (sampler
->min_mip_filter
) {
2818 case PIPE_TEX_MIPFILTER_NONE
:
2819 if (sampler
->min_img_filter
== sampler
->mag_img_filter
)
2820 samp
->mip_filter
= mip_filter_none_no_filter_select
;
2822 samp
->mip_filter
= mip_filter_none
;
2825 case PIPE_TEX_MIPFILTER_NEAREST
:
2826 samp
->mip_filter
= mip_filter_nearest
;
2829 case PIPE_TEX_MIPFILTER_LINEAR
:
2830 if (key
.bits
.is_pot
&&
2831 sampler
->min_img_filter
== sampler
->mag_img_filter
&&
2832 sampler
->normalized_coords
&&
2833 sampler
->wrap_s
== PIPE_TEX_WRAP_REPEAT
&&
2834 sampler
->wrap_t
== PIPE_TEX_WRAP_REPEAT
&&
2835 sampler
->min_img_filter
== PIPE_TEX_FILTER_LINEAR
) {
2836 samp
->mip_filter
= mip_filter_linear_2d_linear_repeat_POT
;
2839 samp
->mip_filter
= mip_filter_linear
;
2842 /* Anisotropic filtering extension. */
2843 if (sampler
->max_anisotropy
> 1) {
2844 samp
->mip_filter
= mip_filter_linear_aniso
;
2846 /* Override min_img_filter:
2847 * min_img_filter needs to be set to NEAREST since we need to access
2848 * each texture pixel as it is and weight it later; using linear
2849 * filters will have incorrect results.
2850 * By setting the filter to NEAREST here, we can avoid calling the
2851 * generic img_filter_2d_nearest in the anisotropic filter function,
2852 * making it possible to use one of the accelerated implementations
2854 samp
->min_img_filter
= get_img_filter(key
, PIPE_TEX_FILTER_NEAREST
, sampler
);
2856 /* on first access create the lookup table containing the filter weights. */
2858 create_filter_table();
2865 if (sampler
->compare_mode
!= PIPE_TEX_COMPARE_NONE
) {
2866 samp
->compare
= sample_compare
;
2869 /* Skip compare operation by promoting the mip_filter function
2872 samp
->compare
= samp
->mip_filter
;
2875 if (key
.bits
.target
== PIPE_TEXTURE_CUBE
|| key
.bits
.target
== PIPE_TEXTURE_CUBE_ARRAY
) {
2876 samp
->sample_target
= sample_cube
;
2884 /* Skip cube face determination by promoting the compare
2887 samp
->sample_target
= samp
->compare
;
2890 if (any_swizzle(key
)) {
2891 samp
->base
.get_samples
= sample_swizzle
;
2894 samp
->base
.get_samples
= samp
->sample_target
;
2897 samp
->base
.get_dims
= sample_get_dims
;
2898 samp
->base
.get_texel
= sample_get_texels
;