1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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 VMWARE 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_format.h"
42 #include "util/u_memory.h"
43 #include "util/u_inlines.h"
44 #include "sp_quad.h" /* only for #define QUAD_* tokens */
45 #include "sp_tex_sample.h"
46 #include "sp_texture.h"
47 #include "sp_tex_tile_cache.h"
50 /** Set to one to help debug texture sampling */
55 * Return fractional part of 'f'. Used for computing interpolation weights.
56 * Need to be careful with negative values.
57 * Note, if this function isn't perfect you'll sometimes see 1-pixel bands
58 * of improperly weighted linear-filtered textures.
59 * The tests/texwrap.c demo is a good test.
70 * Linear interpolation macro
73 lerp(float a
, float v0
, float v1
)
75 return v0
+ a
* (v1
- v0
);
80 * Do 2D/bilinear interpolation of float values.
81 * v00, v10, v01 and v11 are typically four texture samples in a square/box.
82 * a and b are the horizontal and vertical interpolants.
83 * It's important that this function is inlined when compiled with
84 * optimization! If we find that's not true on some systems, convert
88 lerp_2d(float a
, float b
,
89 float v00
, float v10
, float v01
, float v11
)
91 const float temp0
= lerp(a
, v00
, v10
);
92 const float temp1
= lerp(a
, v01
, v11
);
93 return lerp(b
, temp0
, temp1
);
98 * As above, but 3D interpolation of 8 values.
101 lerp_3d(float a
, float b
, float c
,
102 float v000
, float v100
, float v010
, float v110
,
103 float v001
, float v101
, float v011
, float v111
)
105 const float temp0
= lerp_2d(a
, b
, v000
, v100
, v010
, v110
);
106 const float temp1
= lerp_2d(a
, b
, v001
, v101
, v011
, v111
);
107 return lerp(c
, temp0
, temp1
);
113 * Compute coord % size for repeat wrap modes.
114 * Note that if coord is negative, coord % size doesn't give the right
115 * value. To avoid that problem we add a large multiple of the size
116 * (rather than using a conditional).
119 repeat(int coord
, unsigned size
)
121 return (coord
+ size
* 1024) % size
;
126 * Apply texture coord wrapping mode and return integer texture indexes
127 * for a vector of four texcoords (S or T or P).
128 * \param wrapMode PIPE_TEX_WRAP_x
129 * \param s the incoming texcoords
130 * \param size the texture image size
131 * \param icoord returns the integer texcoords
134 wrap_nearest_repeat(float s
, unsigned size
, int *icoord
)
136 /* s limited to [0,1) */
137 /* i limited to [0,size-1] */
138 int i
= util_ifloor(s
* size
);
139 *icoord
= repeat(i
, size
);
144 wrap_nearest_clamp(float s
, unsigned size
, int *icoord
)
146 /* s limited to [0,1] */
147 /* i limited to [0,size-1] */
153 *icoord
= util_ifloor(s
* size
);
158 wrap_nearest_clamp_to_edge(float s
, unsigned size
, int *icoord
)
160 /* s limited to [min,max] */
161 /* i limited to [0, size-1] */
162 const float min
= 1.0F
/ (2.0F
* size
);
163 const float max
= 1.0F
- min
;
169 *icoord
= util_ifloor(s
* size
);
174 wrap_nearest_clamp_to_border(float s
, unsigned size
, int *icoord
)
176 /* s limited to [min,max] */
177 /* i limited to [-1, size] */
178 const float min
= -1.0F
/ (2.0F
* size
);
179 const float max
= 1.0F
- min
;
185 *icoord
= util_ifloor(s
* size
);
190 wrap_nearest_mirror_repeat(float s
, unsigned size
, int *icoord
)
192 const float min
= 1.0F
/ (2.0F
* size
);
193 const float max
= 1.0F
- min
;
194 const int flr
= util_ifloor(s
);
203 *icoord
= util_ifloor(u
* size
);
208 wrap_nearest_mirror_clamp(float s
, unsigned size
, int *icoord
)
210 /* s limited to [0,1] */
211 /* i limited to [0,size-1] */
212 const float u
= fabsf(s
);
218 *icoord
= util_ifloor(u
* size
);
223 wrap_nearest_mirror_clamp_to_edge(float s
, unsigned size
, int *icoord
)
225 /* s limited to [min,max] */
226 /* i limited to [0, size-1] */
227 const float min
= 1.0F
/ (2.0F
* size
);
228 const float max
= 1.0F
- min
;
229 const float u
= fabsf(s
);
235 *icoord
= util_ifloor(u
* size
);
240 wrap_nearest_mirror_clamp_to_border(float s
, unsigned size
, int *icoord
)
242 /* s limited to [min,max] */
243 /* i limited to [0, size-1] */
244 const float min
= -1.0F
/ (2.0F
* size
);
245 const float max
= 1.0F
- min
;
246 const float u
= fabsf(s
);
252 *icoord
= util_ifloor(u
* size
);
257 * Used to compute texel locations for linear sampling
258 * \param wrapMode PIPE_TEX_WRAP_x
259 * \param s the texcoord
260 * \param size the texture image size
261 * \param icoord0 returns first texture index
262 * \param icoord1 returns second texture index (usually icoord0 + 1)
263 * \param w returns blend factor/weight between texture indices
264 * \param icoord returns the computed integer texture coord
267 wrap_linear_repeat(float s
, unsigned size
,
268 int *icoord0
, int *icoord1
, float *w
)
270 float u
= s
* size
- 0.5F
;
271 *icoord0
= repeat(util_ifloor(u
), size
);
272 *icoord1
= repeat(*icoord0
+ 1, size
);
278 wrap_linear_clamp(float s
, unsigned size
,
279 int *icoord0
, int *icoord1
, float *w
)
281 float u
= CLAMP(s
, 0.0F
, 1.0F
);
283 *icoord0
= util_ifloor(u
);
284 *icoord1
= *icoord0
+ 1;
290 wrap_linear_clamp_to_edge(float s
, unsigned size
,
291 int *icoord0
, int *icoord1
, float *w
)
293 float u
= CLAMP(s
, 0.0F
, 1.0F
);
295 *icoord0
= util_ifloor(u
);
296 *icoord1
= *icoord0
+ 1;
299 if (*icoord1
>= (int) size
)
306 wrap_linear_clamp_to_border(float s
, unsigned size
,
307 int *icoord0
, int *icoord1
, float *w
)
309 const float min
= -1.0F
/ (2.0F
* size
);
310 const float max
= 1.0F
- min
;
311 float u
= CLAMP(s
, min
, max
);
313 *icoord0
= util_ifloor(u
);
314 *icoord1
= *icoord0
+ 1;
320 wrap_linear_mirror_repeat(float s
, unsigned size
,
321 int *icoord0
, int *icoord1
, float *w
)
323 const int flr
= util_ifloor(s
);
328 *icoord0
= util_ifloor(u
);
329 *icoord1
= *icoord0
+ 1;
332 if (*icoord1
>= (int) size
)
339 wrap_linear_mirror_clamp(float s
, unsigned size
,
340 int *icoord0
, int *icoord1
, float *w
)
348 *icoord0
= util_ifloor(u
);
349 *icoord1
= *icoord0
+ 1;
355 wrap_linear_mirror_clamp_to_edge(float s
, unsigned size
,
356 int *icoord0
, int *icoord1
, float *w
)
364 *icoord0
= util_ifloor(u
);
365 *icoord1
= *icoord0
+ 1;
368 if (*icoord1
>= (int) size
)
375 wrap_linear_mirror_clamp_to_border(float s
, unsigned size
,
376 int *icoord0
, int *icoord1
, float *w
)
378 const float min
= -1.0F
/ (2.0F
* size
);
379 const float max
= 1.0F
- min
;
388 *icoord0
= util_ifloor(u
);
389 *icoord1
= *icoord0
+ 1;
395 * PIPE_TEX_WRAP_CLAMP for nearest sampling, unnormalized coords.
398 wrap_nearest_unorm_clamp(float s
, unsigned size
, int *icoord
)
400 int i
= util_ifloor(s
);
401 *icoord
= CLAMP(i
, 0, (int) size
-1);
406 * PIPE_TEX_WRAP_CLAMP_TO_BORDER for nearest sampling, unnormalized coords.
409 wrap_nearest_unorm_clamp_to_border(float s
, unsigned size
, int *icoord
)
411 *icoord
= util_ifloor( CLAMP(s
, -0.5F
, (float) size
+ 0.5F
) );
416 * PIPE_TEX_WRAP_CLAMP_TO_EDGE for nearest sampling, unnormalized coords.
419 wrap_nearest_unorm_clamp_to_edge(float s
, unsigned size
, int *icoord
)
421 *icoord
= util_ifloor( CLAMP(s
, 0.5F
, (float) size
- 0.5F
) );
426 * PIPE_TEX_WRAP_CLAMP for linear sampling, unnormalized coords.
429 wrap_linear_unorm_clamp(float s
, unsigned size
,
430 int *icoord0
, int *icoord1
, float *w
)
432 /* Not exactly what the spec says, but it matches NVIDIA output */
433 float u
= CLAMP(s
- 0.5F
, 0.0f
, (float) size
- 1.0f
);
434 *icoord0
= util_ifloor(u
);
435 *icoord1
= *icoord0
+ 1;
441 * PIPE_TEX_WRAP_CLAMP_TO_BORDER for linear sampling, unnormalized coords.
444 wrap_linear_unorm_clamp_to_border(float s
, unsigned size
,
445 int *icoord0
, int *icoord1
, float *w
)
447 float u
= CLAMP(s
, -0.5F
, (float) size
+ 0.5F
);
449 *icoord0
= util_ifloor(u
);
450 *icoord1
= *icoord0
+ 1;
451 if (*icoord1
> (int) size
- 1)
458 * PIPE_TEX_WRAP_CLAMP_TO_EDGE for linear sampling, unnormalized coords.
461 wrap_linear_unorm_clamp_to_edge(float s
, unsigned size
,
462 int *icoord0
, int *icoord1
, float *w
)
464 float u
= CLAMP(s
, +0.5F
, (float) size
- 0.5F
);
466 *icoord0
= util_ifloor(u
);
467 *icoord1
= *icoord0
+ 1;
468 if (*icoord1
> (int) size
- 1)
475 * Do coordinate to array index conversion. For array textures.
478 coord_to_layer(float coord
, unsigned first_layer
, unsigned last_layer
)
480 int c
= util_ifloor(coord
+ 0.5F
);
481 return CLAMP(c
, (int)first_layer
, (int)last_layer
);
486 * Examine the quad's texture coordinates to compute the partial
487 * derivatives w.r.t X and Y, then compute lambda (level of detail).
490 compute_lambda_1d(const struct sp_sampler_view
*sview
,
491 const float s
[TGSI_QUAD_SIZE
],
492 const float t
[TGSI_QUAD_SIZE
],
493 const float p
[TGSI_QUAD_SIZE
])
495 const struct pipe_resource
*texture
= sview
->base
.texture
;
496 float dsdx
= fabsf(s
[QUAD_BOTTOM_RIGHT
] - s
[QUAD_BOTTOM_LEFT
]);
497 float dsdy
= fabsf(s
[QUAD_TOP_LEFT
] - s
[QUAD_BOTTOM_LEFT
]);
498 float rho
= MAX2(dsdx
, dsdy
) * u_minify(texture
->width0
, sview
->base
.u
.tex
.first_level
);
500 return util_fast_log2(rho
);
505 compute_lambda_2d(const struct sp_sampler_view
*sview
,
506 const float s
[TGSI_QUAD_SIZE
],
507 const float t
[TGSI_QUAD_SIZE
],
508 const float p
[TGSI_QUAD_SIZE
])
510 const struct pipe_resource
*texture
= sview
->base
.texture
;
511 float dsdx
= fabsf(s
[QUAD_BOTTOM_RIGHT
] - s
[QUAD_BOTTOM_LEFT
]);
512 float dsdy
= fabsf(s
[QUAD_TOP_LEFT
] - s
[QUAD_BOTTOM_LEFT
]);
513 float dtdx
= fabsf(t
[QUAD_BOTTOM_RIGHT
] - t
[QUAD_BOTTOM_LEFT
]);
514 float dtdy
= fabsf(t
[QUAD_TOP_LEFT
] - t
[QUAD_BOTTOM_LEFT
]);
515 float maxx
= MAX2(dsdx
, dsdy
) * u_minify(texture
->width0
, sview
->base
.u
.tex
.first_level
);
516 float maxy
= MAX2(dtdx
, dtdy
) * u_minify(texture
->height0
, sview
->base
.u
.tex
.first_level
);
517 float rho
= MAX2(maxx
, maxy
);
519 return util_fast_log2(rho
);
524 compute_lambda_3d(const struct sp_sampler_view
*sview
,
525 const float s
[TGSI_QUAD_SIZE
],
526 const float t
[TGSI_QUAD_SIZE
],
527 const float p
[TGSI_QUAD_SIZE
])
529 const struct pipe_resource
*texture
= sview
->base
.texture
;
530 float dsdx
= fabsf(s
[QUAD_BOTTOM_RIGHT
] - s
[QUAD_BOTTOM_LEFT
]);
531 float dsdy
= fabsf(s
[QUAD_TOP_LEFT
] - s
[QUAD_BOTTOM_LEFT
]);
532 float dtdx
= fabsf(t
[QUAD_BOTTOM_RIGHT
] - t
[QUAD_BOTTOM_LEFT
]);
533 float dtdy
= fabsf(t
[QUAD_TOP_LEFT
] - t
[QUAD_BOTTOM_LEFT
]);
534 float dpdx
= fabsf(p
[QUAD_BOTTOM_RIGHT
] - p
[QUAD_BOTTOM_LEFT
]);
535 float dpdy
= fabsf(p
[QUAD_TOP_LEFT
] - p
[QUAD_BOTTOM_LEFT
]);
536 float maxx
= MAX2(dsdx
, dsdy
) * u_minify(texture
->width0
, sview
->base
.u
.tex
.first_level
);
537 float maxy
= MAX2(dtdx
, dtdy
) * u_minify(texture
->height0
, sview
->base
.u
.tex
.first_level
);
538 float maxz
= MAX2(dpdx
, dpdy
) * u_minify(texture
->depth0
, sview
->base
.u
.tex
.first_level
);
541 rho
= MAX2(maxx
, maxy
);
542 rho
= MAX2(rho
, maxz
);
544 return util_fast_log2(rho
);
549 * Compute lambda for a vertex texture sampler.
550 * Since there aren't derivatives to use, just return 0.
553 compute_lambda_vert(const struct sp_sampler_view
*sview
,
554 const float s
[TGSI_QUAD_SIZE
],
555 const float t
[TGSI_QUAD_SIZE
],
556 const float p
[TGSI_QUAD_SIZE
])
564 * Get a texel from a texture, using the texture tile cache.
566 * \param addr the template tex address containing cube, z, face info.
567 * \param x the x coord of texel within 2D image
568 * \param y the y coord of texel within 2D image
569 * \param rgba the quad to put the texel/color into
571 * XXX maybe move this into sp_tex_tile_cache.c and merge with the
572 * sp_get_cached_tile_tex() function.
578 static INLINE
const float *
579 get_texel_2d_no_border(const struct sp_sampler_view
*sp_sview
,
580 union tex_tile_address addr
, int x
, int y
)
582 const struct softpipe_tex_cached_tile
*tile
;
583 addr
.bits
.x
= x
/ TEX_TILE_SIZE
;
584 addr
.bits
.y
= y
/ TEX_TILE_SIZE
;
588 tile
= sp_get_cached_tile_tex(sp_sview
->cache
, addr
);
590 return &tile
->data
.color
[y
][x
][0];
594 static INLINE
const float *
595 get_texel_2d(const struct sp_sampler_view
*sp_sview
,
596 const struct sp_sampler
*sp_samp
,
597 union tex_tile_address addr
, int x
, int y
)
599 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
600 unsigned level
= addr
.bits
.level
;
602 if (x
< 0 || x
>= (int) u_minify(texture
->width0
, level
) ||
603 y
< 0 || y
>= (int) u_minify(texture
->height0
, level
)) {
604 return sp_samp
->base
.border_color
.f
;
607 return get_texel_2d_no_border( sp_sview
, addr
, x
, y
);
613 * Here's the complete logic (HOLY CRAP) for finding next face and doing the
614 * corresponding coord wrapping, implemented by get_next_face,
615 * get_next_xcoord, get_next_ycoord.
616 * Read like that (first line):
617 * If face is +x and s coord is below zero, then
618 * new face is +z, new s is max , new t is old t
619 * (max is always cube size - 1).
621 * +x s- -> +z: s = max, t = t
622 * +x s+ -> -z: s = 0, t = t
623 * +x t- -> +y: s = max, t = max-s
624 * +x t+ -> -y: s = max, t = s
626 * -x s- -> -z: s = max, t = t
627 * -x s+ -> +z: s = 0, t = t
628 * -x t- -> +y: s = 0, t = s
629 * -x t+ -> -y: s = 0, t = max-s
631 * +y s- -> -x: s = t, t = 0
632 * +y s+ -> +x: s = max-t, t = 0
633 * +y t- -> -z: s = max-s, t = 0
634 * +y t+ -> +z: s = s, t = 0
636 * -y s- -> -x: s = max-t, t = max
637 * -y s+ -> +x: s = t, t = max
638 * -y t- -> +z: s = s, t = max
639 * -y t+ -> -z: s = max-s, t = max
641 * +z s- -> -x: s = max, t = t
642 * +z s+ -> +x: s = 0, t = t
643 * +z t- -> +y: s = s, t = max
644 * +z t+ -> -y: s = s, t = 0
646 * -z s- -> +x: s = max, t = t
647 * -z s+ -> -x: s = 0, t = t
648 * -z t- -> +y: s = max-s, t = 0
649 * -z t+ -> -y: s = max-s, t = max
654 * seamless cubemap neighbour array.
655 * this array is used to find the adjacent face in each of 4 directions,
656 * left, right, up, down. (or -x, +x, -y, +y).
658 static const unsigned face_array
[PIPE_TEX_FACE_MAX
][4] = {
659 /* pos X first then neg X is Z different, Y the same */
660 /* PIPE_TEX_FACE_POS_X,*/
661 { PIPE_TEX_FACE_POS_Z
, PIPE_TEX_FACE_NEG_Z
,
662 PIPE_TEX_FACE_POS_Y
, PIPE_TEX_FACE_NEG_Y
},
663 /* PIPE_TEX_FACE_NEG_X */
664 { PIPE_TEX_FACE_NEG_Z
, PIPE_TEX_FACE_POS_Z
,
665 PIPE_TEX_FACE_POS_Y
, PIPE_TEX_FACE_NEG_Y
},
667 /* pos Y first then neg Y is X different, X the same */
668 /* PIPE_TEX_FACE_POS_Y */
669 { PIPE_TEX_FACE_NEG_X
, PIPE_TEX_FACE_POS_X
,
670 PIPE_TEX_FACE_NEG_Z
, PIPE_TEX_FACE_POS_Z
},
672 /* PIPE_TEX_FACE_NEG_Y */
673 { PIPE_TEX_FACE_NEG_X
, PIPE_TEX_FACE_POS_X
,
674 PIPE_TEX_FACE_POS_Z
, PIPE_TEX_FACE_NEG_Z
},
676 /* pos Z first then neg Y is X different, X the same */
677 /* PIPE_TEX_FACE_POS_Z */
678 { PIPE_TEX_FACE_NEG_X
, PIPE_TEX_FACE_POS_X
,
679 PIPE_TEX_FACE_POS_Y
, PIPE_TEX_FACE_NEG_Y
},
681 /* PIPE_TEX_FACE_NEG_Z */
682 { PIPE_TEX_FACE_POS_X
, PIPE_TEX_FACE_NEG_X
,
683 PIPE_TEX_FACE_POS_Y
, PIPE_TEX_FACE_NEG_Y
}
686 static INLINE
unsigned
687 get_next_face(unsigned face
, int idx
)
689 return face_array
[face
][idx
];
693 * return a new xcoord based on old face, old coords, cube size
694 * and fall_off_index (0 for x-, 1 for x+, 2 for y-, 3 for y+)
697 get_next_xcoord(unsigned face
, unsigned fall_off_index
, int max
, int xc
, int yc
)
699 if ((face
== 0 && fall_off_index
!= 1) ||
700 (face
== 1 && fall_off_index
== 0) ||
701 (face
== 4 && fall_off_index
== 0) ||
702 (face
== 5 && fall_off_index
== 0)) {
705 if ((face
== 1 && fall_off_index
!= 0) ||
706 (face
== 0 && fall_off_index
== 1) ||
707 (face
== 4 && fall_off_index
== 1) ||
708 (face
== 5 && fall_off_index
== 1)) {
711 if ((face
== 4 && fall_off_index
>= 2) ||
712 (face
== 2 && fall_off_index
== 3) ||
713 (face
== 3 && fall_off_index
== 2)) {
716 if ((face
== 5 && fall_off_index
>= 2) ||
717 (face
== 2 && fall_off_index
== 2) ||
718 (face
== 3 && fall_off_index
== 3)) {
721 if ((face
== 2 && fall_off_index
== 0) ||
722 (face
== 3 && fall_off_index
== 1)) {
725 /* (face == 2 && fall_off_index == 1) ||
726 (face == 3 && fall_off_index == 0)) */
731 * return a new ycoord based on old face, old coords, cube size
732 * and fall_off_index (0 for x-, 1 for x+, 2 for y-, 3 for y+)
735 get_next_ycoord(unsigned face
, unsigned fall_off_index
, int max
, int xc
, int yc
)
737 if ((fall_off_index
<= 1) && (face
<= 1 || face
>= 4)) {
741 (face
== 4 && fall_off_index
== 3) ||
742 (face
== 5 && fall_off_index
== 2)) {
746 (face
== 4 && fall_off_index
== 2) ||
747 (face
== 5 && fall_off_index
== 3)) {
750 if ((face
== 0 && fall_off_index
== 3) ||
751 (face
== 1 && fall_off_index
== 2)) {
754 /* (face == 0 && fall_off_index == 2) ||
755 (face == 1 && fall_off_index == 3) */
760 /* Gather a quad of adjacent texels within a tile:
763 get_texel_quad_2d_no_border_single_tile(const struct sp_sampler_view
*sp_sview
,
764 union tex_tile_address addr
,
765 unsigned x
, unsigned y
,
768 const struct softpipe_tex_cached_tile
*tile
;
770 addr
.bits
.x
= x
/ TEX_TILE_SIZE
;
771 addr
.bits
.y
= y
/ TEX_TILE_SIZE
;
775 tile
= sp_get_cached_tile_tex(sp_sview
->cache
, addr
);
777 out
[0] = &tile
->data
.color
[y
][x
][0];
778 out
[1] = &tile
->data
.color
[y
][x
+1][0];
779 out
[2] = &tile
->data
.color
[y
+1][x
][0];
780 out
[3] = &tile
->data
.color
[y
+1][x
+1][0];
784 /* Gather a quad of potentially non-adjacent texels:
787 get_texel_quad_2d_no_border(const struct sp_sampler_view
*sp_sview
,
788 union tex_tile_address addr
,
793 out
[0] = get_texel_2d_no_border( sp_sview
, addr
, x0
, y0
);
794 out
[1] = get_texel_2d_no_border( sp_sview
, addr
, x1
, y0
);
795 out
[2] = get_texel_2d_no_border( sp_sview
, addr
, x0
, y1
);
796 out
[3] = get_texel_2d_no_border( sp_sview
, addr
, x1
, y1
);
799 /* Can involve a lot of unnecessary checks for border color:
802 get_texel_quad_2d(const struct sp_sampler_view
*sp_sview
,
803 const struct sp_sampler
*sp_samp
,
804 union tex_tile_address addr
,
809 out
[0] = get_texel_2d( sp_sview
, sp_samp
, addr
, x0
, y0
);
810 out
[1] = get_texel_2d( sp_sview
, sp_samp
, addr
, x1
, y0
);
811 out
[3] = get_texel_2d( sp_sview
, sp_samp
, addr
, x1
, y1
);
812 out
[2] = get_texel_2d( sp_sview
, sp_samp
, addr
, x0
, y1
);
819 static INLINE
const float *
820 get_texel_3d_no_border(const struct sp_sampler_view
*sp_sview
,
821 union tex_tile_address addr
, int x
, int y
, int z
)
823 const struct softpipe_tex_cached_tile
*tile
;
825 addr
.bits
.x
= x
/ TEX_TILE_SIZE
;
826 addr
.bits
.y
= y
/ TEX_TILE_SIZE
;
831 tile
= sp_get_cached_tile_tex(sp_sview
->cache
, addr
);
833 return &tile
->data
.color
[y
][x
][0];
837 static INLINE
const float *
838 get_texel_3d(const struct sp_sampler_view
*sp_sview
,
839 const struct sp_sampler
*sp_samp
,
840 union tex_tile_address addr
, int x
, int y
, int z
)
842 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
843 unsigned level
= addr
.bits
.level
;
845 if (x
< 0 || x
>= (int) u_minify(texture
->width0
, level
) ||
846 y
< 0 || y
>= (int) u_minify(texture
->height0
, level
) ||
847 z
< 0 || z
>= (int) u_minify(texture
->depth0
, level
)) {
848 return sp_samp
->base
.border_color
.f
;
851 return get_texel_3d_no_border( sp_sview
, addr
, x
, y
, z
);
856 /* Get texel pointer for 1D array texture */
857 static INLINE
const float *
858 get_texel_1d_array(const struct sp_sampler_view
*sp_sview
,
859 const struct sp_sampler
*sp_samp
,
860 union tex_tile_address addr
, int x
, int y
)
862 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
863 unsigned level
= addr
.bits
.level
;
865 if (x
< 0 || x
>= (int) u_minify(texture
->width0
, level
)) {
866 return sp_samp
->base
.border_color
.f
;
869 return get_texel_2d_no_border(sp_sview
, addr
, x
, y
);
874 /* Get texel pointer for 2D array texture */
875 static INLINE
const float *
876 get_texel_2d_array(const struct sp_sampler_view
*sp_sview
,
877 const struct sp_sampler
*sp_samp
,
878 union tex_tile_address addr
, int x
, int y
, int layer
)
880 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
881 unsigned level
= addr
.bits
.level
;
883 assert(layer
< (int) texture
->array_size
);
886 if (x
< 0 || x
>= (int) u_minify(texture
->width0
, level
) ||
887 y
< 0 || y
>= (int) u_minify(texture
->height0
, level
)) {
888 return sp_samp
->base
.border_color
.f
;
891 return get_texel_3d_no_border(sp_sview
, addr
, x
, y
, layer
);
896 static INLINE
const float *
897 get_texel_cube_seamless(const struct sp_sampler_view
*sp_sview
,
898 union tex_tile_address addr
, int x
, int y
,
899 float *corner
, int layer
, unsigned face
)
901 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
902 unsigned level
= addr
.bits
.level
;
903 int new_x
, new_y
, max_x
;
905 max_x
= (int) u_minify(texture
->width0
, level
);
907 assert(texture
->width0
== texture
->height0
);
911 /* change the face */
914 * Cheat with corners. They are difficult and I believe because we don't get
915 * per-pixel faces we can actually have multiple corner texels per pixel,
916 * which screws things up majorly in any case (as the per spec behavior is
917 * to average the 3 remaining texels, which we might not have).
918 * Hence just make sure that the 2nd coord is clamped, will simply pick the
919 * sample which would have fallen off the x coord, but not y coord.
920 * So the filter weight of the samples will be wrong, but at least this
921 * ensures that only valid texels near the corner are used.
923 if (y
< 0 || y
>= max_x
) {
924 y
= CLAMP(y
, 0, max_x
- 1);
926 new_x
= get_next_xcoord(face
, 0, max_x
-1, x
, y
);
927 new_y
= get_next_ycoord(face
, 0, max_x
-1, x
, y
);
928 face
= get_next_face(face
, 0);
929 } else if (x
>= max_x
) {
930 if (y
< 0 || y
>= max_x
) {
931 y
= CLAMP(y
, 0, max_x
- 1);
933 new_x
= get_next_xcoord(face
, 1, max_x
-1, x
, y
);
934 new_y
= get_next_ycoord(face
, 1, max_x
-1, x
, y
);
935 face
= get_next_face(face
, 1);
937 new_x
= get_next_xcoord(face
, 2, max_x
-1, x
, y
);
938 new_y
= get_next_ycoord(face
, 2, max_x
-1, x
, y
);
939 face
= get_next_face(face
, 2);
940 } else if (y
>= max_x
) {
941 new_x
= get_next_xcoord(face
, 3, max_x
-1, x
, y
);
942 new_y
= get_next_ycoord(face
, 3, max_x
-1, x
, y
);
943 face
= get_next_face(face
, 3);
946 return get_texel_3d_no_border(sp_sview
, addr
, new_x
, new_y
, layer
+ face
);
950 /* Get texel pointer for cube array texture */
951 static INLINE
const float *
952 get_texel_cube_array(const struct sp_sampler_view
*sp_sview
,
953 const struct sp_sampler
*sp_samp
,
954 union tex_tile_address addr
, int x
, int y
, int layer
)
956 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
957 unsigned level
= addr
.bits
.level
;
959 assert(layer
< (int) texture
->array_size
);
962 if (x
< 0 || x
>= (int) u_minify(texture
->width0
, level
) ||
963 y
< 0 || y
>= (int) u_minify(texture
->height0
, level
)) {
964 return sp_samp
->base
.border_color
.f
;
967 return get_texel_3d_no_border(sp_sview
, addr
, x
, y
, layer
);
971 * Given the logbase2 of a mipmap's base level size and a mipmap level,
972 * return the size (in texels) of that mipmap level.
973 * For example, if level[0].width = 256 then base_pot will be 8.
974 * If level = 2, then we'll return 64 (the width at level=2).
975 * Return 1 if level > base_pot.
977 static INLINE
unsigned
978 pot_level_size(unsigned base_pot
, unsigned level
)
980 return (base_pot
>= level
) ? (1 << (base_pot
- level
)) : 1;
985 print_sample(const char *function
, const float *rgba
)
987 debug_printf("%s %g %g %g %g\n",
989 rgba
[0], rgba
[TGSI_NUM_CHANNELS
], rgba
[2*TGSI_NUM_CHANNELS
], rgba
[3*TGSI_NUM_CHANNELS
]);
994 print_sample_4(const char *function
, float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
996 debug_printf("%s %g %g %g %g, %g %g %g %g, %g %g %g %g, %g %g %g %g\n",
998 rgba
[0][0], rgba
[1][0], rgba
[2][0], rgba
[3][0],
999 rgba
[0][1], rgba
[1][1], rgba
[2][1], rgba
[3][1],
1000 rgba
[0][2], rgba
[1][2], rgba
[2][2], rgba
[3][2],
1001 rgba
[0][3], rgba
[1][3], rgba
[2][3], rgba
[3][3]);
1005 /* Some image-filter fastpaths:
1008 img_filter_2d_linear_repeat_POT(struct sp_sampler_view
*sp_sview
,
1009 struct sp_sampler
*sp_samp
,
1010 const struct img_filter_args
*args
,
1013 unsigned xpot
= pot_level_size(sp_sview
->xpot
, args
->level
);
1014 unsigned ypot
= pot_level_size(sp_sview
->ypot
, args
->level
);
1015 int xmax
= (xpot
- 1) & (TEX_TILE_SIZE
- 1); /* MIN2(TEX_TILE_SIZE, xpot) - 1; */
1016 int ymax
= (ypot
- 1) & (TEX_TILE_SIZE
- 1); /* MIN2(TEX_TILE_SIZE, ypot) - 1; */
1017 union tex_tile_address addr
;
1020 float u
= args
->s
* xpot
- 0.5F
;
1021 float v
= args
->t
* ypot
- 0.5F
;
1023 int uflr
= util_ifloor(u
);
1024 int vflr
= util_ifloor(v
);
1026 float xw
= u
- (float)uflr
;
1027 float yw
= v
- (float)vflr
;
1029 int x0
= uflr
& (xpot
- 1);
1030 int y0
= vflr
& (ypot
- 1);
1035 addr
.bits
.level
= args
->level
;
1037 /* Can we fetch all four at once:
1039 if (x0
< xmax
&& y0
< ymax
) {
1040 get_texel_quad_2d_no_border_single_tile(sp_sview
, addr
, x0
, y0
, tx
);
1043 unsigned x1
= (x0
+ 1) & (xpot
- 1);
1044 unsigned y1
= (y0
+ 1) & (ypot
- 1);
1045 get_texel_quad_2d_no_border(sp_sview
, addr
, x0
, y0
, x1
, y1
, tx
);
1048 /* interpolate R, G, B, A */
1049 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++) {
1050 rgba
[TGSI_NUM_CHANNELS
*c
] = lerp_2d(xw
, yw
,
1052 tx
[2][c
], tx
[3][c
]);
1056 print_sample(__FUNCTION__
, rgba
);
1062 img_filter_2d_nearest_repeat_POT(struct sp_sampler_view
*sp_sview
,
1063 struct sp_sampler
*sp_samp
,
1064 const struct img_filter_args
*args
,
1065 float rgba
[TGSI_QUAD_SIZE
])
1067 unsigned xpot
= pot_level_size(sp_sview
->xpot
, args
->level
);
1068 unsigned ypot
= pot_level_size(sp_sview
->ypot
, args
->level
);
1070 union tex_tile_address addr
;
1073 float u
= args
->s
* xpot
;
1074 float v
= args
->t
* ypot
;
1076 int uflr
= util_ifloor(u
);
1077 int vflr
= util_ifloor(v
);
1079 int x0
= uflr
& (xpot
- 1);
1080 int y0
= vflr
& (ypot
- 1);
1083 addr
.bits
.level
= args
->level
;
1085 out
= get_texel_2d_no_border(sp_sview
, addr
, x0
, y0
);
1086 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1087 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
1090 print_sample(__FUNCTION__
, rgba
);
1096 img_filter_2d_nearest_clamp_POT(struct sp_sampler_view
*sp_sview
,
1097 struct sp_sampler
*sp_samp
,
1098 const struct img_filter_args
*args
,
1099 float rgba
[TGSI_QUAD_SIZE
])
1101 unsigned xpot
= pot_level_size(sp_sview
->xpot
, args
->level
);
1102 unsigned ypot
= pot_level_size(sp_sview
->ypot
, args
->level
);
1103 union tex_tile_address addr
;
1106 float u
= args
->s
* xpot
;
1107 float v
= args
->t
* ypot
;
1113 addr
.bits
.level
= args
->level
;
1115 x0
= util_ifloor(u
);
1118 else if (x0
> (int) xpot
- 1)
1121 y0
= util_ifloor(v
);
1124 else if (y0
> (int) ypot
- 1)
1127 out
= get_texel_2d_no_border(sp_sview
, addr
, x0
, y0
);
1128 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1129 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
1132 print_sample(__FUNCTION__
, rgba
);
1138 img_filter_1d_nearest(struct sp_sampler_view
*sp_sview
,
1139 struct sp_sampler
*sp_samp
,
1140 const struct img_filter_args
*args
,
1141 float rgba
[TGSI_QUAD_SIZE
])
1143 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
1146 union tex_tile_address addr
;
1150 width
= u_minify(texture
->width0
, args
->level
);
1155 addr
.bits
.level
= args
->level
;
1157 sp_samp
->nearest_texcoord_s(args
->s
, width
, &x
);
1159 out
= get_texel_2d(sp_sview
, sp_samp
, addr
, x
, 0);
1160 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1161 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
1164 print_sample(__FUNCTION__
, rgba
);
1170 img_filter_1d_array_nearest(struct sp_sampler_view
*sp_sview
,
1171 struct sp_sampler
*sp_samp
,
1172 const struct img_filter_args
*args
,
1175 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
1178 union tex_tile_address addr
;
1182 width
= u_minify(texture
->width0
, args
->level
);
1187 addr
.bits
.level
= args
->level
;
1189 sp_samp
->nearest_texcoord_s(args
->s
, width
, &x
);
1190 layer
= coord_to_layer(args
->t
, sp_sview
->base
.u
.tex
.first_layer
,
1191 sp_sview
->base
.u
.tex
.last_layer
);
1193 out
= get_texel_1d_array(sp_sview
, sp_samp
, addr
, x
, layer
);
1194 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1195 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
1198 print_sample(__FUNCTION__
, rgba
);
1204 img_filter_2d_nearest(struct sp_sampler_view
*sp_sview
,
1205 struct sp_sampler
*sp_samp
,
1206 const struct img_filter_args
*args
,
1209 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
1212 union tex_tile_address addr
;
1216 width
= u_minify(texture
->width0
, args
->level
);
1217 height
= u_minify(texture
->height0
, args
->level
);
1223 addr
.bits
.level
= args
->level
;
1225 sp_samp
->nearest_texcoord_s(args
->s
, width
, &x
);
1226 sp_samp
->nearest_texcoord_t(args
->t
, height
, &y
);
1228 out
= get_texel_2d(sp_sview
, sp_samp
, addr
, x
, y
);
1229 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1230 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
1233 print_sample(__FUNCTION__
, rgba
);
1239 img_filter_2d_array_nearest(struct sp_sampler_view
*sp_sview
,
1240 struct sp_sampler
*sp_samp
,
1241 const struct img_filter_args
*args
,
1244 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
1247 union tex_tile_address addr
;
1251 width
= u_minify(texture
->width0
, args
->level
);
1252 height
= u_minify(texture
->height0
, args
->level
);
1258 addr
.bits
.level
= args
->level
;
1260 sp_samp
->nearest_texcoord_s(args
->s
, width
, &x
);
1261 sp_samp
->nearest_texcoord_t(args
->t
, height
, &y
);
1262 layer
= coord_to_layer(args
->p
, sp_sview
->base
.u
.tex
.first_layer
,
1263 sp_sview
->base
.u
.tex
.last_layer
);
1265 out
= get_texel_2d_array(sp_sview
, sp_samp
, addr
, x
, y
, layer
);
1266 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1267 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
1270 print_sample(__FUNCTION__
, rgba
);
1276 img_filter_cube_nearest(struct sp_sampler_view
*sp_sview
,
1277 struct sp_sampler
*sp_samp
,
1278 const struct img_filter_args
*args
,
1281 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
1283 int x
, y
, layerface
;
1284 union tex_tile_address addr
;
1288 width
= u_minify(texture
->width0
, args
->level
);
1289 height
= u_minify(texture
->height0
, args
->level
);
1295 addr
.bits
.level
= args
->level
;
1298 * If NEAREST filtering is done within a miplevel, always apply wrap
1299 * mode CLAMP_TO_EDGE.
1301 if (sp_samp
->base
.seamless_cube_map
) {
1302 wrap_nearest_clamp_to_edge(args
->s
, width
, &x
);
1303 wrap_nearest_clamp_to_edge(args
->t
, height
, &y
);
1305 /* Would probably make sense to ignore mode and just do edge clamp */
1306 sp_samp
->nearest_texcoord_s(args
->s
, width
, &x
);
1307 sp_samp
->nearest_texcoord_t(args
->t
, height
, &y
);
1310 layerface
= args
->face_id
+ sp_sview
->base
.u
.tex
.first_layer
;
1311 out
= get_texel_cube_array(sp_sview
, sp_samp
, addr
, x
, y
, layerface
);
1312 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1313 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
1316 print_sample(__FUNCTION__
, rgba
);
1321 img_filter_cube_array_nearest(struct sp_sampler_view
*sp_sview
,
1322 struct sp_sampler
*sp_samp
,
1323 const struct img_filter_args
*args
,
1326 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
1328 int x
, y
, layerface
;
1329 union tex_tile_address addr
;
1333 width
= u_minify(texture
->width0
, args
->level
);
1334 height
= u_minify(texture
->height0
, args
->level
);
1340 addr
.bits
.level
= args
->level
;
1342 sp_samp
->nearest_texcoord_s(args
->s
, width
, &x
);
1343 sp_samp
->nearest_texcoord_t(args
->t
, height
, &y
);
1344 layerface
= coord_to_layer(6 * args
->p
+ sp_sview
->base
.u
.tex
.first_layer
,
1345 sp_sview
->base
.u
.tex
.first_layer
,
1346 sp_sview
->base
.u
.tex
.last_layer
- 5) + args
->face_id
;
1348 out
= get_texel_cube_array(sp_sview
, sp_samp
, addr
, x
, y
, layerface
);
1349 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1350 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
1353 print_sample(__FUNCTION__
, rgba
);
1358 img_filter_3d_nearest(struct sp_sampler_view
*sp_sview
,
1359 struct sp_sampler
*sp_samp
,
1360 const struct img_filter_args
*args
,
1363 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
1364 int width
, height
, depth
;
1366 union tex_tile_address addr
;
1370 width
= u_minify(texture
->width0
, args
->level
);
1371 height
= u_minify(texture
->height0
, args
->level
);
1372 depth
= u_minify(texture
->depth0
, args
->level
);
1378 sp_samp
->nearest_texcoord_s(args
->s
, width
, &x
);
1379 sp_samp
->nearest_texcoord_t(args
->t
, height
, &y
);
1380 sp_samp
->nearest_texcoord_p(args
->p
, depth
, &z
);
1383 addr
.bits
.level
= args
->level
;
1385 out
= get_texel_3d(sp_sview
, sp_samp
, addr
, x
, y
, z
);
1386 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1387 rgba
[TGSI_NUM_CHANNELS
*c
] = out
[c
];
1392 img_filter_1d_linear(struct sp_sampler_view
*sp_sview
,
1393 struct sp_sampler
*sp_samp
,
1394 const struct img_filter_args
*args
,
1397 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
1400 float xw
; /* weights */
1401 union tex_tile_address addr
;
1402 const float *tx0
, *tx1
;
1405 width
= u_minify(texture
->width0
, args
->level
);
1410 addr
.bits
.level
= args
->level
;
1412 sp_samp
->linear_texcoord_s(args
->s
, width
, &x0
, &x1
, &xw
);
1414 tx0
= get_texel_2d(sp_sview
, sp_samp
, addr
, x0
, 0);
1415 tx1
= get_texel_2d(sp_sview
, sp_samp
, addr
, x1
, 0);
1417 /* interpolate R, G, B, A */
1418 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1419 rgba
[TGSI_NUM_CHANNELS
*c
] = lerp(xw
, tx0
[c
], tx1
[c
]);
1424 img_filter_1d_array_linear(struct sp_sampler_view
*sp_sview
,
1425 struct sp_sampler
*sp_samp
,
1426 const struct img_filter_args
*args
,
1429 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
1432 float xw
; /* weights */
1433 union tex_tile_address addr
;
1434 const float *tx0
, *tx1
;
1437 width
= u_minify(texture
->width0
, args
->level
);
1442 addr
.bits
.level
= args
->level
;
1444 sp_samp
->linear_texcoord_s(args
->s
, width
, &x0
, &x1
, &xw
);
1445 layer
= coord_to_layer(args
->t
, sp_sview
->base
.u
.tex
.first_layer
,
1446 sp_sview
->base
.u
.tex
.last_layer
);
1448 tx0
= get_texel_1d_array(sp_sview
, sp_samp
, addr
, x0
, layer
);
1449 tx1
= get_texel_1d_array(sp_sview
, sp_samp
, addr
, x1
, layer
);
1451 /* interpolate R, G, B, A */
1452 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1453 rgba
[TGSI_NUM_CHANNELS
*c
] = lerp(xw
, tx0
[c
], tx1
[c
]);
1458 img_filter_2d_linear(struct sp_sampler_view
*sp_sview
,
1459 struct sp_sampler
*sp_samp
,
1460 const struct img_filter_args
*args
,
1463 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
1466 float xw
, yw
; /* weights */
1467 union tex_tile_address addr
;
1468 const float *tx0
, *tx1
, *tx2
, *tx3
;
1471 width
= u_minify(texture
->width0
, args
->level
);
1472 height
= u_minify(texture
->height0
, args
->level
);
1478 addr
.bits
.level
= args
->level
;
1480 sp_samp
->linear_texcoord_s(args
->s
, width
, &x0
, &x1
, &xw
);
1481 sp_samp
->linear_texcoord_t(args
->t
, height
, &y0
, &y1
, &yw
);
1483 tx0
= get_texel_2d(sp_sview
, sp_samp
, addr
, x0
, y0
);
1484 tx1
= get_texel_2d(sp_sview
, sp_samp
, addr
, x1
, y0
);
1485 tx2
= get_texel_2d(sp_sview
, sp_samp
, addr
, x0
, y1
);
1486 tx3
= get_texel_2d(sp_sview
, sp_samp
, addr
, x1
, y1
);
1488 /* interpolate R, G, B, A */
1489 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1490 rgba
[TGSI_NUM_CHANNELS
*c
] = lerp_2d(xw
, yw
,
1497 img_filter_2d_array_linear(struct sp_sampler_view
*sp_sview
,
1498 struct sp_sampler
*sp_samp
,
1499 const struct img_filter_args
*args
,
1502 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
1504 int x0
, y0
, x1
, y1
, layer
;
1505 float xw
, yw
; /* weights */
1506 union tex_tile_address addr
;
1507 const float *tx0
, *tx1
, *tx2
, *tx3
;
1510 width
= u_minify(texture
->width0
, args
->level
);
1511 height
= u_minify(texture
->height0
, args
->level
);
1517 addr
.bits
.level
= args
->level
;
1519 sp_samp
->linear_texcoord_s(args
->s
, width
, &x0
, &x1
, &xw
);
1520 sp_samp
->linear_texcoord_t(args
->t
, height
, &y0
, &y1
, &yw
);
1521 layer
= coord_to_layer(args
->p
, sp_sview
->base
.u
.tex
.first_layer
,
1522 sp_sview
->base
.u
.tex
.last_layer
);
1524 tx0
= get_texel_2d_array(sp_sview
, sp_samp
, addr
, x0
, y0
, layer
);
1525 tx1
= get_texel_2d_array(sp_sview
, sp_samp
, addr
, x1
, y0
, layer
);
1526 tx2
= get_texel_2d_array(sp_sview
, sp_samp
, addr
, x0
, y1
, layer
);
1527 tx3
= get_texel_2d_array(sp_sview
, sp_samp
, addr
, x1
, y1
, layer
);
1529 /* interpolate R, G, B, A */
1530 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1531 rgba
[TGSI_NUM_CHANNELS
*c
] = lerp_2d(xw
, yw
,
1538 img_filter_cube_linear(struct sp_sampler_view
*sp_sview
,
1539 struct sp_sampler
*sp_samp
,
1540 const struct img_filter_args
*args
,
1543 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
1545 int x0
, y0
, x1
, y1
, layer
;
1546 float xw
, yw
; /* weights */
1547 union tex_tile_address addr
;
1548 const float *tx0
, *tx1
, *tx2
, *tx3
;
1549 float corner0
[TGSI_QUAD_SIZE
], corner1
[TGSI_QUAD_SIZE
],
1550 corner2
[TGSI_QUAD_SIZE
], corner3
[TGSI_QUAD_SIZE
];
1553 width
= u_minify(texture
->width0
, args
->level
);
1554 height
= u_minify(texture
->height0
, args
->level
);
1560 addr
.bits
.level
= args
->level
;
1563 * For seamless if LINEAR filtering is done within a miplevel,
1564 * always apply wrap mode CLAMP_TO_BORDER.
1566 if (sp_samp
->base
.seamless_cube_map
) {
1567 /* Note this is a bit overkill, actual clamping is not required */
1568 wrap_linear_clamp_to_border(args
->s
, width
, &x0
, &x1
, &xw
);
1569 wrap_linear_clamp_to_border(args
->t
, height
, &y0
, &y1
, &yw
);
1571 /* Would probably make sense to ignore mode and just do edge clamp */
1572 sp_samp
->linear_texcoord_s(args
->s
, width
, &x0
, &x1
, &xw
);
1573 sp_samp
->linear_texcoord_t(args
->t
, height
, &y0
, &y1
, &yw
);
1576 layer
= sp_sview
->base
.u
.tex
.first_layer
;
1578 if (sp_samp
->base
.seamless_cube_map
) {
1579 tx0
= get_texel_cube_seamless(sp_sview
, addr
, x0
, y0
, corner0
, layer
, args
->face_id
);
1580 tx1
= get_texel_cube_seamless(sp_sview
, addr
, x1
, y0
, corner1
, layer
, args
->face_id
);
1581 tx2
= get_texel_cube_seamless(sp_sview
, addr
, x0
, y1
, corner2
, layer
, args
->face_id
);
1582 tx3
= get_texel_cube_seamless(sp_sview
, addr
, x1
, y1
, corner3
, layer
, args
->face_id
);
1584 tx0
= get_texel_cube_array(sp_sview
, sp_samp
, addr
, x0
, y0
, layer
+ args
->face_id
);
1585 tx1
= get_texel_cube_array(sp_sview
, sp_samp
, addr
, x1
, y0
, layer
+ args
->face_id
);
1586 tx2
= get_texel_cube_array(sp_sview
, sp_samp
, addr
, x0
, y1
, layer
+ args
->face_id
);
1587 tx3
= get_texel_cube_array(sp_sview
, sp_samp
, addr
, x1
, y1
, layer
+ args
->face_id
);
1590 /* interpolate R, G, B, A */
1591 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1592 rgba
[TGSI_NUM_CHANNELS
*c
] = lerp_2d(xw
, yw
,
1599 img_filter_cube_array_linear(struct sp_sampler_view
*sp_sview
,
1600 struct sp_sampler
*sp_samp
,
1601 const struct img_filter_args
*args
,
1604 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
1606 int x0
, y0
, x1
, y1
, layer
;
1607 float xw
, yw
; /* weights */
1608 union tex_tile_address addr
;
1609 const float *tx0
, *tx1
, *tx2
, *tx3
;
1610 float corner0
[TGSI_QUAD_SIZE
], corner1
[TGSI_QUAD_SIZE
],
1611 corner2
[TGSI_QUAD_SIZE
], corner3
[TGSI_QUAD_SIZE
];
1614 width
= u_minify(texture
->width0
, args
->level
);
1615 height
= u_minify(texture
->height0
, args
->level
);
1621 addr
.bits
.level
= args
->level
;
1624 * For seamless if LINEAR filtering is done within a miplevel,
1625 * always apply wrap mode CLAMP_TO_BORDER.
1627 if (sp_samp
->base
.seamless_cube_map
) {
1628 /* Note this is a bit overkill, actual clamping is not required */
1629 wrap_linear_clamp_to_border(args
->s
, width
, &x0
, &x1
, &xw
);
1630 wrap_linear_clamp_to_border(args
->t
, height
, &y0
, &y1
, &yw
);
1632 /* Would probably make sense to ignore mode and just do edge clamp */
1633 sp_samp
->linear_texcoord_s(args
->s
, width
, &x0
, &x1
, &xw
);
1634 sp_samp
->linear_texcoord_t(args
->t
, height
, &y0
, &y1
, &yw
);
1637 layer
= coord_to_layer(6 * args
->p
+ sp_sview
->base
.u
.tex
.first_layer
,
1638 sp_sview
->base
.u
.tex
.first_layer
,
1639 sp_sview
->base
.u
.tex
.last_layer
- 5);
1641 if (sp_samp
->base
.seamless_cube_map
) {
1642 tx0
= get_texel_cube_seamless(sp_sview
, addr
, x0
, y0
, corner0
, layer
, args
->face_id
);
1643 tx1
= get_texel_cube_seamless(sp_sview
, addr
, x1
, y0
, corner1
, layer
, args
->face_id
);
1644 tx2
= get_texel_cube_seamless(sp_sview
, addr
, x0
, y1
, corner2
, layer
, args
->face_id
);
1645 tx3
= get_texel_cube_seamless(sp_sview
, addr
, x1
, y1
, corner3
, layer
, args
->face_id
);
1647 tx0
= get_texel_cube_array(sp_sview
, sp_samp
, addr
, x0
, y0
, layer
+ args
->face_id
);
1648 tx1
= get_texel_cube_array(sp_sview
, sp_samp
, addr
, x1
, y0
, layer
+ args
->face_id
);
1649 tx2
= get_texel_cube_array(sp_sview
, sp_samp
, addr
, x0
, y1
, layer
+ args
->face_id
);
1650 tx3
= get_texel_cube_array(sp_sview
, sp_samp
, addr
, x1
, y1
, layer
+ args
->face_id
);
1653 /* interpolate R, G, B, A */
1654 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1655 rgba
[TGSI_NUM_CHANNELS
*c
] = lerp_2d(xw
, yw
,
1661 img_filter_3d_linear(struct sp_sampler_view
*sp_sview
,
1662 struct sp_sampler
*sp_samp
,
1663 const struct img_filter_args
*args
,
1666 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
1667 int width
, height
, depth
;
1668 int x0
, x1
, y0
, y1
, z0
, z1
;
1669 float xw
, yw
, zw
; /* interpolation weights */
1670 union tex_tile_address addr
;
1671 const float *tx00
, *tx01
, *tx02
, *tx03
, *tx10
, *tx11
, *tx12
, *tx13
;
1674 width
= u_minify(texture
->width0
, args
->level
);
1675 height
= u_minify(texture
->height0
, args
->level
);
1676 depth
= u_minify(texture
->depth0
, args
->level
);
1679 addr
.bits
.level
= args
->level
;
1685 sp_samp
->linear_texcoord_s(args
->s
, width
, &x0
, &x1
, &xw
);
1686 sp_samp
->linear_texcoord_t(args
->t
, height
, &y0
, &y1
, &yw
);
1687 sp_samp
->linear_texcoord_p(args
->p
, depth
, &z0
, &z1
, &zw
);
1689 tx00
= get_texel_3d(sp_sview
, sp_samp
, addr
, x0
, y0
, z0
);
1690 tx01
= get_texel_3d(sp_sview
, sp_samp
, addr
, x1
, y0
, z0
);
1691 tx02
= get_texel_3d(sp_sview
, sp_samp
, addr
, x0
, y1
, z0
);
1692 tx03
= get_texel_3d(sp_sview
, sp_samp
, addr
, x1
, y1
, z0
);
1694 tx10
= get_texel_3d(sp_sview
, sp_samp
, addr
, x0
, y0
, z1
);
1695 tx11
= get_texel_3d(sp_sview
, sp_samp
, addr
, x1
, y0
, z1
);
1696 tx12
= get_texel_3d(sp_sview
, sp_samp
, addr
, x0
, y1
, z1
);
1697 tx13
= get_texel_3d(sp_sview
, sp_samp
, addr
, x1
, y1
, z1
);
1699 /* interpolate R, G, B, A */
1700 for (c
= 0; c
< TGSI_QUAD_SIZE
; c
++)
1701 rgba
[TGSI_NUM_CHANNELS
*c
] = lerp_3d(xw
, yw
, zw
,
1709 /* Calculate level of detail for every fragment,
1710 * with lambda already computed.
1711 * Note that lambda has already been biased by global LOD bias.
1712 * \param biased_lambda per-quad lambda.
1713 * \param lod_in per-fragment lod_bias or explicit_lod.
1714 * \param lod returns the per-fragment lod.
1717 compute_lod(const struct pipe_sampler_state
*sampler
,
1718 enum tgsi_sampler_control control
,
1719 const float biased_lambda
,
1720 const float lod_in
[TGSI_QUAD_SIZE
],
1721 float lod
[TGSI_QUAD_SIZE
])
1723 float min_lod
= sampler
->min_lod
;
1724 float max_lod
= sampler
->max_lod
;
1728 case tgsi_sampler_lod_none
:
1729 case tgsi_sampler_lod_zero
:
1731 case tgsi_sampler_derivs_explicit
:
1732 lod
[0] = lod
[1] = lod
[2] = lod
[3] = CLAMP(biased_lambda
, min_lod
, max_lod
);
1734 case tgsi_sampler_lod_bias
:
1735 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1736 lod
[i
] = biased_lambda
+ lod_in
[i
];
1737 lod
[i
] = CLAMP(lod
[i
], min_lod
, max_lod
);
1740 case tgsi_sampler_lod_explicit
:
1741 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1742 lod
[i
] = CLAMP(lod_in
[i
], min_lod
, max_lod
);
1747 lod
[0] = lod
[1] = lod
[2] = lod
[3] = 0.0f
;
1752 /* Calculate level of detail for every fragment.
1753 * \param lod_in per-fragment lod_bias or explicit_lod.
1754 * \param lod results per-fragment lod.
1757 compute_lambda_lod(struct sp_sampler_view
*sp_sview
,
1758 struct sp_sampler
*sp_samp
,
1759 const float s
[TGSI_QUAD_SIZE
],
1760 const float t
[TGSI_QUAD_SIZE
],
1761 const float p
[TGSI_QUAD_SIZE
],
1762 const float lod_in
[TGSI_QUAD_SIZE
],
1763 enum tgsi_sampler_control control
,
1764 float lod
[TGSI_QUAD_SIZE
])
1766 const struct pipe_sampler_state
*sampler
= &sp_samp
->base
;
1767 float lod_bias
= sampler
->lod_bias
;
1768 float min_lod
= sampler
->min_lod
;
1769 float max_lod
= sampler
->max_lod
;
1774 case tgsi_sampler_lod_none
:
1776 case tgsi_sampler_derivs_explicit
:
1777 lambda
= sp_sview
->compute_lambda(sp_sview
, s
, t
, p
) + lod_bias
;
1778 lod
[0] = lod
[1] = lod
[2] = lod
[3] = CLAMP(lambda
, min_lod
, max_lod
);
1780 case tgsi_sampler_lod_bias
:
1781 lambda
= sp_sview
->compute_lambda(sp_sview
, s
, t
, p
) + lod_bias
;
1782 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1783 lod
[i
] = lambda
+ lod_in
[i
];
1784 lod
[i
] = CLAMP(lod
[i
], min_lod
, max_lod
);
1787 case tgsi_sampler_lod_explicit
:
1788 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1789 lod
[i
] = CLAMP(lod_in
[i
], min_lod
, max_lod
);
1792 case tgsi_sampler_lod_zero
:
1793 /* this is all static state in the sampler really need clamp here? */
1794 lod
[0] = lod
[1] = lod
[2] = lod
[3] = CLAMP(lod_bias
, min_lod
, max_lod
);
1798 lod
[0] = lod
[1] = lod
[2] = lod
[3] = 0.0f
;
1804 mip_filter_linear(struct sp_sampler_view
*sp_sview
,
1805 struct sp_sampler
*sp_samp
,
1806 img_filter_func min_filter
,
1807 img_filter_func mag_filter
,
1808 const float s
[TGSI_QUAD_SIZE
],
1809 const float t
[TGSI_QUAD_SIZE
],
1810 const float p
[TGSI_QUAD_SIZE
],
1811 const float c0
[TGSI_QUAD_SIZE
],
1812 const float lod_in
[TGSI_QUAD_SIZE
],
1813 enum tgsi_sampler_control control
,
1814 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
1816 const struct pipe_sampler_view
*psview
= &sp_sview
->base
;
1818 float lod
[TGSI_QUAD_SIZE
];
1819 struct img_filter_args args
;
1821 compute_lambda_lod(sp_sview
, sp_samp
, s
, t
, p
, lod_in
, control
, lod
);
1823 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
1824 int level0
= psview
->u
.tex
.first_level
+ (int)lod
[j
];
1829 args
.face_id
= sp_sview
->faces
[j
];
1832 args
.level
= psview
->u
.tex
.first_level
;
1833 mag_filter(sp_sview
, sp_samp
, &args
, &rgba
[0][j
]);
1835 else if (level0
>= (int) psview
->u
.tex
.last_level
) {
1836 args
.level
= psview
->u
.tex
.last_level
;
1837 min_filter(sp_sview
, sp_samp
, &args
, &rgba
[0][j
]);
1840 float levelBlend
= frac(lod
[j
]);
1841 float rgbax
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
1844 args
.level
= level0
;
1845 min_filter(sp_sview
, sp_samp
, &args
, &rgbax
[0][0]);
1846 args
.level
= level0
+1;
1847 min_filter(sp_sview
, sp_samp
, &args
, &rgbax
[0][1]);
1849 for (c
= 0; c
< 4; c
++) {
1850 rgba
[c
][j
] = lerp(levelBlend
, rgbax
[c
][0], rgbax
[c
][1]);
1856 print_sample_4(__FUNCTION__
, rgba
);
1862 * Compute nearest mipmap level from texcoords.
1863 * Then sample the texture level for four elements of a quad.
1864 * \param c0 the LOD bias factors, or absolute LODs (depending on control)
1867 mip_filter_nearest(struct sp_sampler_view
*sp_sview
,
1868 struct sp_sampler
*sp_samp
,
1869 img_filter_func min_filter
,
1870 img_filter_func mag_filter
,
1871 const float s
[TGSI_QUAD_SIZE
],
1872 const float t
[TGSI_QUAD_SIZE
],
1873 const float p
[TGSI_QUAD_SIZE
],
1874 const float c0
[TGSI_QUAD_SIZE
],
1875 const float lod_in
[TGSI_QUAD_SIZE
],
1876 enum tgsi_sampler_control control
,
1877 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
1879 const struct pipe_sampler_view
*psview
= &sp_sview
->base
;
1880 float lod
[TGSI_QUAD_SIZE
];
1882 struct img_filter_args args
;
1883 compute_lambda_lod(sp_sview
, sp_samp
, s
, t
, p
, lod_in
, control
, lod
);
1885 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
1889 args
.face_id
= sp_sview
->faces
[j
];
1892 args
.level
= psview
->u
.tex
.first_level
;
1893 mag_filter(sp_sview
, sp_samp
, &args
, &rgba
[0][j
]);
1895 int level
= psview
->u
.tex
.first_level
+ (int)(lod
[j
] + 0.5F
);
1896 args
.level
= MIN2(level
, (int)psview
->u
.tex
.last_level
);
1897 min_filter(sp_sview
, sp_samp
, &args
, &rgba
[0][j
]);
1902 print_sample_4(__FUNCTION__
, rgba
);
1908 mip_filter_none(struct sp_sampler_view
*sp_sview
,
1909 struct sp_sampler
*sp_samp
,
1910 img_filter_func min_filter
,
1911 img_filter_func mag_filter
,
1912 const float s
[TGSI_QUAD_SIZE
],
1913 const float t
[TGSI_QUAD_SIZE
],
1914 const float p
[TGSI_QUAD_SIZE
],
1915 const float c0
[TGSI_QUAD_SIZE
],
1916 const float lod_in
[TGSI_QUAD_SIZE
],
1917 enum tgsi_sampler_control control
,
1918 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
1920 float lod
[TGSI_QUAD_SIZE
];
1922 struct img_filter_args args
;
1924 args
.level
= sp_sview
->base
.u
.tex
.first_level
;
1925 compute_lambda_lod(sp_sview
, sp_samp
, s
, t
, p
, lod_in
, control
, lod
);
1927 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
1931 args
.face_id
= sp_sview
->faces
[j
];
1933 mag_filter(sp_sview
, sp_samp
, &args
, &rgba
[0][j
]);
1936 min_filter(sp_sview
, sp_samp
, &args
, &rgba
[0][j
]);
1943 mip_filter_none_no_filter_select(struct sp_sampler_view
*sp_sview
,
1944 struct sp_sampler
*sp_samp
,
1945 img_filter_func min_filter
,
1946 img_filter_func mag_filter
,
1947 const float s
[TGSI_QUAD_SIZE
],
1948 const float t
[TGSI_QUAD_SIZE
],
1949 const float p
[TGSI_QUAD_SIZE
],
1950 const float c0
[TGSI_QUAD_SIZE
],
1951 const float lod_in
[TGSI_QUAD_SIZE
],
1952 enum tgsi_sampler_control control
,
1953 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
1956 struct img_filter_args args
;
1957 args
.level
= sp_sview
->base
.u
.tex
.first_level
;
1958 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
1962 args
.face_id
= sp_sview
->faces
[j
];
1963 mag_filter(sp_sview
, sp_samp
, &args
, &rgba
[0][j
]);
1968 /* For anisotropic filtering */
1969 #define WEIGHT_LUT_SIZE 1024
1971 static float *weightLut
= NULL
;
1974 * Creates the look-up table used to speed-up EWA sampling
1977 create_filter_table(void)
1981 weightLut
= (float *) MALLOC(WEIGHT_LUT_SIZE
* sizeof(float));
1983 for (i
= 0; i
< WEIGHT_LUT_SIZE
; ++i
) {
1985 float r2
= (float) i
/ (float) (WEIGHT_LUT_SIZE
- 1);
1986 float weight
= (float) exp(-alpha
* r2
);
1987 weightLut
[i
] = weight
;
1994 * Elliptical weighted average (EWA) filter for producing high quality
1995 * anisotropic filtered results.
1996 * Based on the Higher Quality Elliptical Weighted Average Filter
1997 * published by Paul S. Heckbert in his Master's Thesis
1998 * "Fundamentals of Texture Mapping and Image Warping" (1989)
2001 img_filter_2d_ewa(struct sp_sampler_view
*sp_sview
,
2002 struct sp_sampler
*sp_samp
,
2003 img_filter_func min_filter
,
2004 img_filter_func mag_filter
,
2005 const float s
[TGSI_QUAD_SIZE
],
2006 const float t
[TGSI_QUAD_SIZE
],
2007 const float p
[TGSI_QUAD_SIZE
],
2009 const float dudx
, const float dvdx
,
2010 const float dudy
, const float dvdy
,
2011 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
2013 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
2015 // ??? Won't the image filters blow up if level is negative?
2016 unsigned level0
= level
> 0 ? level
: 0;
2017 float scaling
= 1.0f
/ (1 << level0
);
2018 int width
= u_minify(texture
->width0
, level0
);
2019 int height
= u_minify(texture
->height0
, level0
);
2020 struct img_filter_args args
;
2021 float ux
= dudx
* scaling
;
2022 float vx
= dvdx
* scaling
;
2023 float uy
= dudy
* scaling
;
2024 float vy
= dvdy
* scaling
;
2026 /* compute ellipse coefficients to bound the region:
2027 * A*x*x + B*x*y + C*y*y = F.
2029 float A
= vx
*vx
+vy
*vy
+1;
2030 float B
= -2*(ux
*vx
+uy
*vy
);
2031 float C
= ux
*ux
+uy
*uy
+1;
2032 float F
= A
*C
-B
*B
/4.0f
;
2034 /* check if it is an ellipse */
2035 /* assert(F > 0.0); */
2037 /* Compute the ellipse's (u,v) bounding box in texture space */
2038 float d
= -B
*B
+4.0f
*C
*A
;
2039 float box_u
= 2.0f
/ d
* sqrtf(d
*C
*F
); /* box_u -> half of bbox with */
2040 float box_v
= 2.0f
/ d
* sqrtf(A
*d
*F
); /* box_v -> half of bbox height */
2042 float rgba_temp
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
2043 float s_buffer
[TGSI_QUAD_SIZE
];
2044 float t_buffer
[TGSI_QUAD_SIZE
];
2045 float weight_buffer
[TGSI_QUAD_SIZE
];
2046 unsigned buffer_next
;
2048 float den
; /* = 0.0F; */
2050 float U
; /* = u0 - tex_u; */
2053 /* Scale ellipse formula to directly index the Filter Lookup Table.
2054 * i.e. scale so that F = WEIGHT_LUT_SIZE-1
2056 double formScale
= (double) (WEIGHT_LUT_SIZE
- 1) / F
;
2060 /* F *= formScale; */ /* no need to scale F as we don't use it below here */
2062 /* For each quad, the du and dx values are the same and so the ellipse is
2063 * also the same. Note that texel/image access can only be performed using
2064 * a quad, i.e. it is not possible to get the pixel value for a single
2065 * tex coord. In order to have a better performance, the access is buffered
2066 * using the s_buffer/t_buffer and weight_buffer. Only when the buffer is
2067 * full, then the pixel values are read from the image.
2072 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2073 /* Heckbert MS thesis, p. 59; scan over the bounding box of the ellipse
2074 * and incrementally update the value of Ax^2+Bxy*Cy^2; when this
2075 * value, q, is less than F, we're inside the ellipse
2077 float tex_u
= -0.5F
+ s
[j
] * texture
->width0
* scaling
;
2078 float tex_v
= -0.5F
+ t
[j
] * texture
->height0
* scaling
;
2080 int u0
= (int) floorf(tex_u
- box_u
);
2081 int u1
= (int) ceilf(tex_u
+ box_u
);
2082 int v0
= (int) floorf(tex_v
- box_v
);
2083 int v1
= (int) ceilf(tex_v
+ box_v
);
2085 float num
[4] = {0.0F
, 0.0F
, 0.0F
, 0.0F
};
2088 args
.face_id
= sp_sview
->faces
[j
];
2091 for (v
= v0
; v
<= v1
; ++v
) {
2092 float V
= v
- tex_v
;
2093 float dq
= A
* (2 * U
+ 1) + B
* V
;
2094 float q
= (C
* V
+ B
* U
) * V
+ A
* U
* U
;
2097 for (u
= u0
; u
<= u1
; ++u
) {
2098 /* Note that the ellipse has been pre-scaled so F =
2099 * WEIGHT_LUT_SIZE - 1
2101 if (q
< WEIGHT_LUT_SIZE
) {
2102 /* as a LUT is used, q must never be negative;
2103 * should not happen, though
2105 const int qClamped
= q
>= 0.0F
? q
: 0;
2106 float weight
= weightLut
[qClamped
];
2108 weight_buffer
[buffer_next
] = weight
;
2109 s_buffer
[buffer_next
] = u
/ ((float) width
);
2110 t_buffer
[buffer_next
] = v
/ ((float) height
);
2113 if (buffer_next
== TGSI_QUAD_SIZE
) {
2114 /* 4 texel coords are in the buffer -> read it now */
2116 /* it is assumed that samp->min_img_filter is set to
2117 * img_filter_2d_nearest or one of the
2118 * accelerated img_filter_2d_nearest_XXX functions.
2120 for (jj
= 0; jj
< buffer_next
; jj
++) {
2121 args
.s
= s_buffer
[jj
];
2122 args
.t
= t_buffer
[jj
];
2124 min_filter(sp_sview
, sp_samp
, &args
, &rgba_temp
[0][jj
]);
2125 num
[0] += weight_buffer
[jj
] * rgba_temp
[0][jj
];
2126 num
[1] += weight_buffer
[jj
] * rgba_temp
[1][jj
];
2127 num
[2] += weight_buffer
[jj
] * rgba_temp
[2][jj
];
2128 num
[3] += weight_buffer
[jj
] * rgba_temp
[3][jj
];
2141 /* if the tex coord buffer contains unread values, we will read
2144 if (buffer_next
> 0) {
2146 /* it is assumed that samp->min_img_filter is set to
2147 * img_filter_2d_nearest or one of the
2148 * accelerated img_filter_2d_nearest_XXX functions.
2150 for (jj
= 0; jj
< buffer_next
; jj
++) {
2151 args
.s
= s_buffer
[jj
];
2152 args
.t
= t_buffer
[jj
];
2154 min_filter(sp_sview
, sp_samp
, &args
, &rgba_temp
[0][jj
]);
2155 num
[0] += weight_buffer
[jj
] * rgba_temp
[0][jj
];
2156 num
[1] += weight_buffer
[jj
] * rgba_temp
[1][jj
];
2157 num
[2] += weight_buffer
[jj
] * rgba_temp
[2][jj
];
2158 num
[3] += weight_buffer
[jj
] * rgba_temp
[3][jj
];
2163 /* Reaching this place would mean that no pixels intersected
2164 * the ellipse. This should never happen because the filter
2165 * we use always intersects at least one pixel.
2172 /* not enough pixels in resampling, resort to direct interpolation */
2176 min_filter(sp_sview
, sp_samp
, &args
, &rgba_temp
[0][j
]);
2178 num
[0] = rgba_temp
[0][j
];
2179 num
[1] = rgba_temp
[1][j
];
2180 num
[2] = rgba_temp
[2][j
];
2181 num
[3] = rgba_temp
[3][j
];
2184 rgba
[0][j
] = num
[0] / den
;
2185 rgba
[1][j
] = num
[1] / den
;
2186 rgba
[2][j
] = num
[2] / den
;
2187 rgba
[3][j
] = num
[3] / den
;
2193 * Sample 2D texture using an anisotropic filter.
2196 mip_filter_linear_aniso(struct sp_sampler_view
*sp_sview
,
2197 struct sp_sampler
*sp_samp
,
2198 img_filter_func min_filter
,
2199 img_filter_func mag_filter
,
2200 const float s
[TGSI_QUAD_SIZE
],
2201 const float t
[TGSI_QUAD_SIZE
],
2202 const float p
[TGSI_QUAD_SIZE
],
2203 const float c0
[TGSI_QUAD_SIZE
],
2204 const float lod_in
[TGSI_QUAD_SIZE
],
2205 enum tgsi_sampler_control control
,
2206 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
2208 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
2209 const struct pipe_sampler_view
*psview
= &sp_sview
->base
;
2212 float lod
[TGSI_QUAD_SIZE
];
2214 float s_to_u
= u_minify(texture
->width0
, psview
->u
.tex
.first_level
);
2215 float t_to_v
= u_minify(texture
->height0
, psview
->u
.tex
.first_level
);
2216 float dudx
= (s
[QUAD_BOTTOM_RIGHT
] - s
[QUAD_BOTTOM_LEFT
]) * s_to_u
;
2217 float dudy
= (s
[QUAD_TOP_LEFT
] - s
[QUAD_BOTTOM_LEFT
]) * s_to_u
;
2218 float dvdx
= (t
[QUAD_BOTTOM_RIGHT
] - t
[QUAD_BOTTOM_LEFT
]) * t_to_v
;
2219 float dvdy
= (t
[QUAD_TOP_LEFT
] - t
[QUAD_BOTTOM_LEFT
]) * t_to_v
;
2220 struct img_filter_args args
;
2222 if (control
== tgsi_sampler_lod_bias
||
2223 control
== tgsi_sampler_lod_none
||
2225 control
== tgsi_sampler_derivs_explicit
) {
2226 /* note: instead of working with Px and Py, we will use the
2227 * squared length instead, to avoid sqrt.
2229 float Px2
= dudx
* dudx
+ dvdx
* dvdx
;
2230 float Py2
= dudy
* dudy
+ dvdy
* dvdy
;
2235 const float maxEccentricity
= sp_samp
->base
.max_anisotropy
* sp_samp
->base
.max_anisotropy
;
2246 /* if the eccentricity of the ellipse is too big, scale up the shorter
2247 * of the two vectors to limit the maximum amount of work per pixel
2250 if (e
> maxEccentricity
) {
2251 /* float s=e / maxEccentricity;
2255 Pmin2
= Pmax2
/ maxEccentricity
;
2258 /* note: we need to have Pmin=sqrt(Pmin2) here, but we can avoid
2259 * this since 0.5*log(x) = log(sqrt(x))
2261 lambda
= 0.5F
* util_fast_log2(Pmin2
) + sp_samp
->base
.lod_bias
;
2262 compute_lod(&sp_samp
->base
, control
, lambda
, lod_in
, lod
);
2265 assert(control
== tgsi_sampler_lod_explicit
||
2266 control
== tgsi_sampler_lod_zero
);
2267 compute_lod(&sp_samp
->base
, control
, sp_samp
->base
.lod_bias
, lod_in
, lod
);
2270 /* XXX: Take into account all lod values.
2273 level0
= psview
->u
.tex
.first_level
+ (int)lambda
;
2275 /* If the ellipse covers the whole image, we can
2276 * simply return the average of the whole image.
2278 if (level0
>= (int) psview
->u
.tex
.last_level
) {
2280 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2284 args
.level
= psview
->u
.tex
.last_level
;
2285 args
.face_id
= sp_sview
->faces
[j
];
2286 min_filter(sp_sview
, sp_samp
, &args
, &rgba
[0][j
]);
2290 /* don't bother interpolating between multiple LODs; it doesn't
2291 * seem to be worth the extra running time.
2293 img_filter_2d_ewa(sp_sview
, sp_samp
, min_filter
, mag_filter
,
2295 dudx
, dvdx
, dudy
, dvdy
, rgba
);
2299 print_sample_4(__FUNCTION__
, rgba
);
2305 * Specialized version of mip_filter_linear with hard-wired calls to
2306 * 2d lambda calculation and 2d_linear_repeat_POT img filters.
2309 mip_filter_linear_2d_linear_repeat_POT(
2310 struct sp_sampler_view
*sp_sview
,
2311 struct sp_sampler
*sp_samp
,
2312 img_filter_func min_filter
,
2313 img_filter_func mag_filter
,
2314 const float s
[TGSI_QUAD_SIZE
],
2315 const float t
[TGSI_QUAD_SIZE
],
2316 const float p
[TGSI_QUAD_SIZE
],
2317 const float c0
[TGSI_QUAD_SIZE
],
2318 const float lod_in
[TGSI_QUAD_SIZE
],
2319 enum tgsi_sampler_control control
,
2320 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
2322 const struct pipe_sampler_view
*psview
= &sp_sview
->base
;
2324 float lod
[TGSI_QUAD_SIZE
];
2326 compute_lambda_lod(sp_sview
, sp_samp
, s
, t
, p
, lod_in
, control
, lod
);
2328 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2329 int level0
= psview
->u
.tex
.first_level
+ (int)lod
[j
];
2330 struct img_filter_args args
;
2331 /* Catches both negative and large values of level0:
2336 args
.face_id
= sp_sview
->faces
[j
];
2337 if ((unsigned)level0
>= psview
->u
.tex
.last_level
) {
2339 args
.level
= psview
->u
.tex
.first_level
;
2341 args
.level
= psview
->u
.tex
.last_level
;
2342 img_filter_2d_linear_repeat_POT(sp_sview
, sp_samp
, &args
,
2347 float levelBlend
= frac(lod
[j
]);
2348 float rgbax
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
2351 args
.level
= level0
;
2352 img_filter_2d_linear_repeat_POT(sp_sview
, sp_samp
, &args
, &rgbax
[0][0]);
2353 args
.level
= level0
+1;
2354 img_filter_2d_linear_repeat_POT(sp_sview
, sp_samp
, &args
, &rgbax
[0][1]);
2356 for (c
= 0; c
< TGSI_NUM_CHANNELS
; c
++)
2357 rgba
[c
][j
] = lerp(levelBlend
, rgbax
[c
][0], rgbax
[c
][1]);
2362 print_sample_4(__FUNCTION__
, rgba
);
2368 * Do shadow/depth comparisons.
2371 sample_compare(struct sp_sampler_view
*sp_sview
,
2372 struct sp_sampler
*sp_samp
,
2373 const float s
[TGSI_QUAD_SIZE
],
2374 const float t
[TGSI_QUAD_SIZE
],
2375 const float p
[TGSI_QUAD_SIZE
],
2376 const float c0
[TGSI_QUAD_SIZE
],
2377 const float c1
[TGSI_QUAD_SIZE
],
2378 enum tgsi_sampler_control control
,
2379 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
2381 const struct pipe_sampler_state
*sampler
= &sp_samp
->base
;
2385 const struct util_format_description
*format_desc
;
2389 * Compare texcoord 'p' (aka R) against texture value 'rgba[0]'
2390 * for 2D Array texture we need to use the 'c0' (aka Q).
2391 * When we sampled the depth texture, the depth value was put into all
2392 * RGBA channels. We look at the red channel here.
2395 if (sp_sview
->base
.target
== PIPE_TEXTURE_2D_ARRAY
||
2396 sp_sview
->base
.target
== PIPE_TEXTURE_CUBE
) {
2401 } else if (sp_sview
->base
.target
== PIPE_TEXTURE_CUBE_ARRAY
) {
2413 format_desc
= util_format_description(sp_sview
->base
.format
);
2414 /* not entirely sure we couldn't end up with non-valid swizzle here */
2415 chan_type
= format_desc
->swizzle
[0] <= UTIL_FORMAT_SWIZZLE_W
?
2416 format_desc
->channel
[format_desc
->swizzle
[0]].type
:
2417 UTIL_FORMAT_TYPE_FLOAT
;
2418 if (chan_type
!= UTIL_FORMAT_TYPE_FLOAT
) {
2420 * clamping is a result of conversion to texture format, hence
2421 * doesn't happen with floats. Technically also should do comparison
2422 * in texture format (quantization!).
2424 pc
[0] = CLAMP(pc
[0], 0.0F
, 1.0F
);
2425 pc
[1] = CLAMP(pc
[1], 0.0F
, 1.0F
);
2426 pc
[2] = CLAMP(pc
[2], 0.0F
, 1.0F
);
2427 pc
[3] = CLAMP(pc
[3], 0.0F
, 1.0F
);
2430 /* compare four texcoords vs. four texture samples */
2431 switch (sampler
->compare_func
) {
2432 case PIPE_FUNC_LESS
:
2433 k
[0] = pc
[0] < rgba
[0][0];
2434 k
[1] = pc
[1] < rgba
[0][1];
2435 k
[2] = pc
[2] < rgba
[0][2];
2436 k
[3] = pc
[3] < rgba
[0][3];
2438 case PIPE_FUNC_LEQUAL
:
2439 k
[0] = pc
[0] <= rgba
[0][0];
2440 k
[1] = pc
[1] <= rgba
[0][1];
2441 k
[2] = pc
[2] <= rgba
[0][2];
2442 k
[3] = pc
[3] <= rgba
[0][3];
2444 case PIPE_FUNC_GREATER
:
2445 k
[0] = pc
[0] > rgba
[0][0];
2446 k
[1] = pc
[1] > rgba
[0][1];
2447 k
[2] = pc
[2] > rgba
[0][2];
2448 k
[3] = pc
[3] > rgba
[0][3];
2450 case PIPE_FUNC_GEQUAL
:
2451 k
[0] = pc
[0] >= rgba
[0][0];
2452 k
[1] = pc
[1] >= rgba
[0][1];
2453 k
[2] = pc
[2] >= rgba
[0][2];
2454 k
[3] = pc
[3] >= rgba
[0][3];
2456 case PIPE_FUNC_EQUAL
:
2457 k
[0] = pc
[0] == rgba
[0][0];
2458 k
[1] = pc
[1] == rgba
[0][1];
2459 k
[2] = pc
[2] == rgba
[0][2];
2460 k
[3] = pc
[3] == rgba
[0][3];
2462 case PIPE_FUNC_NOTEQUAL
:
2463 k
[0] = pc
[0] != rgba
[0][0];
2464 k
[1] = pc
[1] != rgba
[0][1];
2465 k
[2] = pc
[2] != rgba
[0][2];
2466 k
[3] = pc
[3] != rgba
[0][3];
2468 case PIPE_FUNC_ALWAYS
:
2469 k
[0] = k
[1] = k
[2] = k
[3] = 1;
2471 case PIPE_FUNC_NEVER
:
2472 k
[0] = k
[1] = k
[2] = k
[3] = 0;
2475 k
[0] = k
[1] = k
[2] = k
[3] = 0;
2480 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2490 do_swizzling(const struct pipe_sampler_view
*sview
,
2491 float in
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
],
2492 float out
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
2495 const unsigned swizzle_r
= sview
->swizzle_r
;
2496 const unsigned swizzle_g
= sview
->swizzle_g
;
2497 const unsigned swizzle_b
= sview
->swizzle_b
;
2498 const unsigned swizzle_a
= sview
->swizzle_a
;
2500 switch (swizzle_r
) {
2501 case PIPE_SWIZZLE_ZERO
:
2502 for (j
= 0; j
< 4; j
++)
2505 case PIPE_SWIZZLE_ONE
:
2506 for (j
= 0; j
< 4; j
++)
2510 assert(swizzle_r
< 4);
2511 for (j
= 0; j
< 4; j
++)
2512 out
[0][j
] = in
[swizzle_r
][j
];
2515 switch (swizzle_g
) {
2516 case PIPE_SWIZZLE_ZERO
:
2517 for (j
= 0; j
< 4; j
++)
2520 case PIPE_SWIZZLE_ONE
:
2521 for (j
= 0; j
< 4; j
++)
2525 assert(swizzle_g
< 4);
2526 for (j
= 0; j
< 4; j
++)
2527 out
[1][j
] = in
[swizzle_g
][j
];
2530 switch (swizzle_b
) {
2531 case PIPE_SWIZZLE_ZERO
:
2532 for (j
= 0; j
< 4; j
++)
2535 case PIPE_SWIZZLE_ONE
:
2536 for (j
= 0; j
< 4; j
++)
2540 assert(swizzle_b
< 4);
2541 for (j
= 0; j
< 4; j
++)
2542 out
[2][j
] = in
[swizzle_b
][j
];
2545 switch (swizzle_a
) {
2546 case PIPE_SWIZZLE_ZERO
:
2547 for (j
= 0; j
< 4; j
++)
2550 case PIPE_SWIZZLE_ONE
:
2551 for (j
= 0; j
< 4; j
++)
2555 assert(swizzle_a
< 4);
2556 for (j
= 0; j
< 4; j
++)
2557 out
[3][j
] = in
[swizzle_a
][j
];
2562 static wrap_nearest_func
2563 get_nearest_unorm_wrap(unsigned mode
)
2566 case PIPE_TEX_WRAP_CLAMP
:
2567 return wrap_nearest_unorm_clamp
;
2568 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
2569 return wrap_nearest_unorm_clamp_to_edge
;
2570 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
2571 return wrap_nearest_unorm_clamp_to_border
;
2573 debug_printf("illegal wrap mode %d with non-normalized coords\n", mode
);
2574 return wrap_nearest_unorm_clamp
;
2579 static wrap_nearest_func
2580 get_nearest_wrap(unsigned mode
)
2583 case PIPE_TEX_WRAP_REPEAT
:
2584 return wrap_nearest_repeat
;
2585 case PIPE_TEX_WRAP_CLAMP
:
2586 return wrap_nearest_clamp
;
2587 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
2588 return wrap_nearest_clamp_to_edge
;
2589 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
2590 return wrap_nearest_clamp_to_border
;
2591 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
2592 return wrap_nearest_mirror_repeat
;
2593 case PIPE_TEX_WRAP_MIRROR_CLAMP
:
2594 return wrap_nearest_mirror_clamp
;
2595 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
:
2596 return wrap_nearest_mirror_clamp_to_edge
;
2597 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
:
2598 return wrap_nearest_mirror_clamp_to_border
;
2601 return wrap_nearest_repeat
;
2606 static wrap_linear_func
2607 get_linear_unorm_wrap(unsigned mode
)
2610 case PIPE_TEX_WRAP_CLAMP
:
2611 return wrap_linear_unorm_clamp
;
2612 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
2613 return wrap_linear_unorm_clamp_to_edge
;
2614 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
2615 return wrap_linear_unorm_clamp_to_border
;
2617 debug_printf("illegal wrap mode %d with non-normalized coords\n", mode
);
2618 return wrap_linear_unorm_clamp
;
2623 static wrap_linear_func
2624 get_linear_wrap(unsigned mode
)
2627 case PIPE_TEX_WRAP_REPEAT
:
2628 return wrap_linear_repeat
;
2629 case PIPE_TEX_WRAP_CLAMP
:
2630 return wrap_linear_clamp
;
2631 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
2632 return wrap_linear_clamp_to_edge
;
2633 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
2634 return wrap_linear_clamp_to_border
;
2635 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
2636 return wrap_linear_mirror_repeat
;
2637 case PIPE_TEX_WRAP_MIRROR_CLAMP
:
2638 return wrap_linear_mirror_clamp
;
2639 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
:
2640 return wrap_linear_mirror_clamp_to_edge
;
2641 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
:
2642 return wrap_linear_mirror_clamp_to_border
;
2645 return wrap_linear_repeat
;
2651 * Is swizzling needed for the given state key?
2654 any_swizzle(const struct pipe_sampler_view
*view
)
2656 return (view
->swizzle_r
!= PIPE_SWIZZLE_RED
||
2657 view
->swizzle_g
!= PIPE_SWIZZLE_GREEN
||
2658 view
->swizzle_b
!= PIPE_SWIZZLE_BLUE
||
2659 view
->swizzle_a
!= PIPE_SWIZZLE_ALPHA
);
2663 static img_filter_func
2664 get_img_filter(const struct sp_sampler_view
*sp_sview
,
2665 const struct pipe_sampler_state
*sampler
,
2668 switch (sp_sview
->base
.target
) {
2670 case PIPE_TEXTURE_1D
:
2671 if (filter
== PIPE_TEX_FILTER_NEAREST
)
2672 return img_filter_1d_nearest
;
2674 return img_filter_1d_linear
;
2676 case PIPE_TEXTURE_1D_ARRAY
:
2677 if (filter
== PIPE_TEX_FILTER_NEAREST
)
2678 return img_filter_1d_array_nearest
;
2680 return img_filter_1d_array_linear
;
2682 case PIPE_TEXTURE_2D
:
2683 case PIPE_TEXTURE_RECT
:
2684 /* Try for fast path:
2686 if (sp_sview
->pot2d
&&
2687 sampler
->wrap_s
== sampler
->wrap_t
&&
2688 sampler
->normalized_coords
)
2690 switch (sampler
->wrap_s
) {
2691 case PIPE_TEX_WRAP_REPEAT
:
2693 case PIPE_TEX_FILTER_NEAREST
:
2694 return img_filter_2d_nearest_repeat_POT
;
2695 case PIPE_TEX_FILTER_LINEAR
:
2696 return img_filter_2d_linear_repeat_POT
;
2701 case PIPE_TEX_WRAP_CLAMP
:
2703 case PIPE_TEX_FILTER_NEAREST
:
2704 return img_filter_2d_nearest_clamp_POT
;
2710 /* Otherwise use default versions:
2712 if (filter
== PIPE_TEX_FILTER_NEAREST
)
2713 return img_filter_2d_nearest
;
2715 return img_filter_2d_linear
;
2717 case PIPE_TEXTURE_2D_ARRAY
:
2718 if (filter
== PIPE_TEX_FILTER_NEAREST
)
2719 return img_filter_2d_array_nearest
;
2721 return img_filter_2d_array_linear
;
2723 case PIPE_TEXTURE_CUBE
:
2724 if (filter
== PIPE_TEX_FILTER_NEAREST
)
2725 return img_filter_cube_nearest
;
2727 return img_filter_cube_linear
;
2729 case PIPE_TEXTURE_CUBE_ARRAY
:
2730 if (filter
== PIPE_TEX_FILTER_NEAREST
)
2731 return img_filter_cube_array_nearest
;
2733 return img_filter_cube_array_linear
;
2735 case PIPE_TEXTURE_3D
:
2736 if (filter
== PIPE_TEX_FILTER_NEAREST
)
2737 return img_filter_3d_nearest
;
2739 return img_filter_3d_linear
;
2743 return img_filter_1d_nearest
;
2749 sample_mip(struct sp_sampler_view
*sp_sview
,
2750 struct sp_sampler
*sp_samp
,
2751 const float s
[TGSI_QUAD_SIZE
],
2752 const float t
[TGSI_QUAD_SIZE
],
2753 const float p
[TGSI_QUAD_SIZE
],
2754 const float c0
[TGSI_QUAD_SIZE
],
2755 const float lod
[TGSI_QUAD_SIZE
],
2756 enum tgsi_sampler_control control
,
2757 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
2759 mip_filter_func mip_filter
;
2760 img_filter_func min_img_filter
= NULL
;
2761 img_filter_func mag_img_filter
= NULL
;
2763 if (sp_sview
->pot2d
& sp_samp
->min_mag_equal_repeat_linear
) {
2764 mip_filter
= mip_filter_linear_2d_linear_repeat_POT
;
2767 mip_filter
= sp_samp
->mip_filter
;
2768 min_img_filter
= get_img_filter(sp_sview
, &sp_samp
->base
, sp_samp
->min_img_filter
);
2769 if (sp_samp
->min_mag_equal
) {
2770 mag_img_filter
= min_img_filter
;
2773 mag_img_filter
= get_img_filter(sp_sview
, &sp_samp
->base
, sp_samp
->base
.mag_img_filter
);
2777 mip_filter(sp_sview
, sp_samp
, min_img_filter
, mag_img_filter
,
2778 s
, t
, p
, c0
, lod
, control
, rgba
);
2780 if (sp_samp
->base
.compare_mode
!= PIPE_TEX_COMPARE_NONE
) {
2781 sample_compare(sp_sview
, sp_samp
, s
, t
, p
, c0
, lod
, control
, rgba
);
2784 if (sp_sview
->need_swizzle
) {
2785 float rgba_temp
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
2786 memcpy(rgba_temp
, rgba
, sizeof(rgba_temp
));
2787 do_swizzling(&sp_sview
->base
, rgba_temp
, rgba
);
2794 * Use 3D texcoords to choose a cube face, then sample the 2D cube faces.
2795 * Put face info into the sampler faces[] array.
2798 sample_cube(struct sp_sampler_view
*sp_sview
,
2799 struct sp_sampler
*sp_samp
,
2800 const float s
[TGSI_QUAD_SIZE
],
2801 const float t
[TGSI_QUAD_SIZE
],
2802 const float p
[TGSI_QUAD_SIZE
],
2803 const float c0
[TGSI_QUAD_SIZE
],
2804 const float c1
[TGSI_QUAD_SIZE
],
2805 enum tgsi_sampler_control control
,
2806 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
2809 float ssss
[4], tttt
[4];
2811 /* Not actually used, but the intermediate steps that do the
2812 * dereferencing don't know it.
2814 static float pppp
[4] = { 0, 0, 0, 0 };
2822 direction target sc tc ma
2823 ---------- ------------------------------- --- --- ---
2824 +rx TEXTURE_CUBE_MAP_POSITIVE_X_EXT -rz -ry rx
2825 -rx TEXTURE_CUBE_MAP_NEGATIVE_X_EXT +rz -ry rx
2826 +ry TEXTURE_CUBE_MAP_POSITIVE_Y_EXT +rx +rz ry
2827 -ry TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT +rx -rz ry
2828 +rz TEXTURE_CUBE_MAP_POSITIVE_Z_EXT +rx -ry rz
2829 -rz TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT -rx -ry rz
2832 /* Choose the cube face and compute new s/t coords for the 2D face.
2834 * Use the same cube face for all four pixels in the quad.
2836 * This isn't ideal, but if we want to use a different cube face
2837 * per pixel in the quad, we'd have to also compute the per-face
2838 * LOD here too. That's because the four post-face-selection
2839 * texcoords are no longer related to each other (they're
2840 * per-face!) so we can't use subtraction to compute the partial
2841 * deriviates to compute the LOD. Doing so (near cube edges
2842 * anyway) gives us pretty much random values.
2845 /* use the average of the four pixel's texcoords to choose the face */
2846 const float rx
= 0.25F
* (s
[0] + s
[1] + s
[2] + s
[3]);
2847 const float ry
= 0.25F
* (t
[0] + t
[1] + t
[2] + t
[3]);
2848 const float rz
= 0.25F
* (p
[0] + p
[1] + p
[2] + p
[3]);
2849 const float arx
= fabsf(rx
), ary
= fabsf(ry
), arz
= fabsf(rz
);
2851 if (arx
>= ary
&& arx
>= arz
) {
2852 float sign
= (rx
>= 0.0F
) ? 1.0F
: -1.0F
;
2853 uint face
= (rx
>= 0.0F
) ? PIPE_TEX_FACE_POS_X
: PIPE_TEX_FACE_NEG_X
;
2854 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2855 const float ima
= -0.5F
/ fabsf(s
[j
]);
2856 ssss
[j
] = sign
* p
[j
] * ima
+ 0.5F
;
2857 tttt
[j
] = t
[j
] * ima
+ 0.5F
;
2858 sp_sview
->faces
[j
] = face
;
2861 else if (ary
>= arx
&& ary
>= arz
) {
2862 float sign
= (ry
>= 0.0F
) ? 1.0F
: -1.0F
;
2863 uint face
= (ry
>= 0.0F
) ? PIPE_TEX_FACE_POS_Y
: PIPE_TEX_FACE_NEG_Y
;
2864 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2865 const float ima
= -0.5F
/ fabsf(t
[j
]);
2866 ssss
[j
] = -s
[j
] * ima
+ 0.5F
;
2867 tttt
[j
] = sign
* -p
[j
] * ima
+ 0.5F
;
2868 sp_sview
->faces
[j
] = face
;
2872 float sign
= (rz
>= 0.0F
) ? 1.0F
: -1.0F
;
2873 uint face
= (rz
>= 0.0F
) ? PIPE_TEX_FACE_POS_Z
: PIPE_TEX_FACE_NEG_Z
;
2874 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2875 const float ima
= -0.5F
/ fabsf(p
[j
]);
2876 ssss
[j
] = sign
* -s
[j
] * ima
+ 0.5F
;
2877 tttt
[j
] = t
[j
] * ima
+ 0.5F
;
2878 sp_sview
->faces
[j
] = face
;
2883 sample_mip(sp_sview
, sp_samp
, ssss
, tttt
, pppp
, c0
, c1
, control
, rgba
);
2888 sp_get_dims(struct sp_sampler_view
*sp_sview
, int level
,
2891 const struct pipe_sampler_view
*view
= &sp_sview
->base
;
2892 const struct pipe_resource
*texture
= view
->texture
;
2894 if (view
->target
== PIPE_BUFFER
) {
2895 dims
[0] = (view
->u
.buf
.last_element
- view
->u
.buf
.first_element
) + 1;
2896 /* the other values are undefined, but let's avoid potential valgrind
2899 dims
[1] = dims
[2] = dims
[3] = 0;
2903 /* undefined according to EXT_gpu_program */
2904 level
+= view
->u
.tex
.first_level
;
2905 if (level
> view
->u
.tex
.last_level
)
2908 dims
[3] = view
->u
.tex
.last_level
- view
->u
.tex
.first_level
+ 1;
2909 dims
[0] = u_minify(texture
->width0
, level
);
2911 switch (view
->target
) {
2912 case PIPE_TEXTURE_1D_ARRAY
:
2913 dims
[1] = view
->u
.tex
.last_layer
- view
->u
.tex
.first_layer
+ 1;
2915 case PIPE_TEXTURE_1D
:
2917 case PIPE_TEXTURE_2D_ARRAY
:
2918 dims
[2] = view
->u
.tex
.last_layer
- view
->u
.tex
.first_layer
+ 1;
2920 case PIPE_TEXTURE_2D
:
2921 case PIPE_TEXTURE_CUBE
:
2922 case PIPE_TEXTURE_RECT
:
2923 dims
[1] = u_minify(texture
->height0
, level
);
2925 case PIPE_TEXTURE_3D
:
2926 dims
[1] = u_minify(texture
->height0
, level
);
2927 dims
[2] = u_minify(texture
->depth0
, level
);
2929 case PIPE_TEXTURE_CUBE_ARRAY
:
2930 dims
[1] = u_minify(texture
->height0
, level
);
2931 dims
[2] = (view
->u
.tex
.last_layer
- view
->u
.tex
.first_layer
+ 1) / 6;
2934 assert(!"unexpected texture target in sp_get_dims()");
2940 * This function is only used for getting unfiltered texels via the
2941 * TXF opcode. The GL spec says that out-of-bounds texel fetches
2942 * produce undefined results. Instead of crashing, lets just clamp
2943 * coords to the texture image size.
2946 sp_get_texels(struct sp_sampler_view
*sp_sview
,
2947 const int v_i
[TGSI_QUAD_SIZE
],
2948 const int v_j
[TGSI_QUAD_SIZE
],
2949 const int v_k
[TGSI_QUAD_SIZE
],
2950 const int lod
[TGSI_QUAD_SIZE
],
2951 const int8_t offset
[3],
2952 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
2954 union tex_tile_address addr
;
2955 const struct pipe_resource
*texture
= sp_sview
->base
.texture
;
2958 int width
, height
, depth
;
2961 /* TODO write a better test for LOD */
2962 addr
.bits
.level
= sp_sview
->base
.target
== PIPE_BUFFER
? 0 :
2963 CLAMP(lod
[0] + sp_sview
->base
.u
.tex
.first_level
,
2964 sp_sview
->base
.u
.tex
.first_level
,
2965 sp_sview
->base
.u
.tex
.last_level
);
2967 width
= u_minify(texture
->width0
, addr
.bits
.level
);
2968 height
= u_minify(texture
->height0
, addr
.bits
.level
);
2969 depth
= u_minify(texture
->depth0
, addr
.bits
.level
);
2971 switch (sp_sview
->base
.target
) {
2973 case PIPE_TEXTURE_1D
:
2974 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2975 int x
= CLAMP(v_i
[j
] + offset
[0], 0, width
- 1);
2976 tx
= get_texel_2d_no_border(sp_sview
, addr
, x
, 0);
2977 for (c
= 0; c
< 4; c
++) {
2982 case PIPE_TEXTURE_1D_ARRAY
:
2983 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2984 int x
= CLAMP(v_i
[j
] + offset
[0], 0, width
- 1);
2985 int y
= CLAMP(v_j
[j
], sp_sview
->base
.u
.tex
.first_layer
,
2986 sp_sview
->base
.u
.tex
.last_layer
);
2987 tx
= get_texel_2d_no_border(sp_sview
, addr
, x
, y
);
2988 for (c
= 0; c
< 4; c
++) {
2993 case PIPE_TEXTURE_2D
:
2994 case PIPE_TEXTURE_RECT
:
2995 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2996 int x
= CLAMP(v_i
[j
] + offset
[0], 0, width
- 1);
2997 int y
= CLAMP(v_j
[j
] + offset
[1], 0, height
- 1);
2998 tx
= get_texel_2d_no_border(sp_sview
, addr
, x
, y
);
2999 for (c
= 0; c
< 4; c
++) {
3004 case PIPE_TEXTURE_2D_ARRAY
:
3005 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
3006 int x
= CLAMP(v_i
[j
] + offset
[0], 0, width
- 1);
3007 int y
= CLAMP(v_j
[j
] + offset
[1], 0, height
- 1);
3008 int layer
= CLAMP(v_k
[j
], sp_sview
->base
.u
.tex
.first_layer
,
3009 sp_sview
->base
.u
.tex
.last_layer
);
3010 tx
= get_texel_3d_no_border(sp_sview
, addr
, x
, y
, layer
);
3011 for (c
= 0; c
< 4; c
++) {
3016 case PIPE_TEXTURE_3D
:
3017 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
3018 int x
= CLAMP(v_i
[j
] + offset
[0], 0, width
- 1);
3019 int y
= CLAMP(v_j
[j
] + offset
[1], 0, height
- 1);
3020 int z
= CLAMP(v_k
[j
] + offset
[2], 0, depth
- 1);
3021 tx
= get_texel_3d_no_border(sp_sview
, addr
, x
, y
, z
);
3022 for (c
= 0; c
< 4; c
++) {
3027 case PIPE_TEXTURE_CUBE
: /* TXF can't work on CUBE according to spec */
3029 assert(!"Unknown or CUBE texture type in TXF processing\n");
3033 if (sp_sview
->need_swizzle
) {
3034 float rgba_temp
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
3035 memcpy(rgba_temp
, rgba
, sizeof(rgba_temp
));
3036 do_swizzling(&sp_sview
->base
, rgba_temp
, rgba
);
3042 softpipe_create_sampler_state(struct pipe_context
*pipe
,
3043 const struct pipe_sampler_state
*sampler
)
3045 struct sp_sampler
*samp
= CALLOC_STRUCT(sp_sampler
);
3047 samp
->base
= *sampler
;
3049 /* Note that (for instance) linear_texcoord_s and
3050 * nearest_texcoord_s may be active at the same time, if the
3051 * sampler min_img_filter differs from its mag_img_filter.
3053 if (sampler
->normalized_coords
) {
3054 samp
->linear_texcoord_s
= get_linear_wrap( sampler
->wrap_s
);
3055 samp
->linear_texcoord_t
= get_linear_wrap( sampler
->wrap_t
);
3056 samp
->linear_texcoord_p
= get_linear_wrap( sampler
->wrap_r
);
3058 samp
->nearest_texcoord_s
= get_nearest_wrap( sampler
->wrap_s
);
3059 samp
->nearest_texcoord_t
= get_nearest_wrap( sampler
->wrap_t
);
3060 samp
->nearest_texcoord_p
= get_nearest_wrap( sampler
->wrap_r
);
3063 samp
->linear_texcoord_s
= get_linear_unorm_wrap( sampler
->wrap_s
);
3064 samp
->linear_texcoord_t
= get_linear_unorm_wrap( sampler
->wrap_t
);
3065 samp
->linear_texcoord_p
= get_linear_unorm_wrap( sampler
->wrap_r
);
3067 samp
->nearest_texcoord_s
= get_nearest_unorm_wrap( sampler
->wrap_s
);
3068 samp
->nearest_texcoord_t
= get_nearest_unorm_wrap( sampler
->wrap_t
);
3069 samp
->nearest_texcoord_p
= get_nearest_unorm_wrap( sampler
->wrap_r
);
3072 samp
->min_img_filter
= sampler
->min_img_filter
;
3074 switch (sampler
->min_mip_filter
) {
3075 case PIPE_TEX_MIPFILTER_NONE
:
3076 if (sampler
->min_img_filter
== sampler
->mag_img_filter
)
3077 samp
->mip_filter
= mip_filter_none_no_filter_select
;
3079 samp
->mip_filter
= mip_filter_none
;
3082 case PIPE_TEX_MIPFILTER_NEAREST
:
3083 samp
->mip_filter
= mip_filter_nearest
;
3086 case PIPE_TEX_MIPFILTER_LINEAR
:
3087 if (sampler
->min_img_filter
== sampler
->mag_img_filter
&&
3088 sampler
->normalized_coords
&&
3089 sampler
->wrap_s
== PIPE_TEX_WRAP_REPEAT
&&
3090 sampler
->wrap_t
== PIPE_TEX_WRAP_REPEAT
&&
3091 sampler
->min_img_filter
== PIPE_TEX_FILTER_LINEAR
&&
3092 sampler
->max_anisotropy
<= 1) {
3093 samp
->min_mag_equal_repeat_linear
= TRUE
;
3095 samp
->mip_filter
= mip_filter_linear
;
3097 /* Anisotropic filtering extension. */
3098 if (sampler
->max_anisotropy
> 1) {
3099 samp
->mip_filter
= mip_filter_linear_aniso
;
3101 /* Override min_img_filter:
3102 * min_img_filter needs to be set to NEAREST since we need to access
3103 * each texture pixel as it is and weight it later; using linear
3104 * filters will have incorrect results.
3105 * By setting the filter to NEAREST here, we can avoid calling the
3106 * generic img_filter_2d_nearest in the anisotropic filter function,
3107 * making it possible to use one of the accelerated implementations
3109 samp
->min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
3111 /* on first access create the lookup table containing the filter weights. */
3113 create_filter_table();
3118 if (samp
->min_img_filter
== sampler
->mag_img_filter
) {
3119 samp
->min_mag_equal
= TRUE
;
3122 return (void *)samp
;
3127 softpipe_get_lambda_func(const struct pipe_sampler_view
*view
, unsigned shader
)
3129 if (shader
!= PIPE_SHADER_FRAGMENT
)
3130 return compute_lambda_vert
;
3132 switch (view
->target
) {
3134 case PIPE_TEXTURE_1D
:
3135 case PIPE_TEXTURE_1D_ARRAY
:
3136 return compute_lambda_1d
;
3137 case PIPE_TEXTURE_2D
:
3138 case PIPE_TEXTURE_2D_ARRAY
:
3139 case PIPE_TEXTURE_RECT
:
3140 case PIPE_TEXTURE_CUBE
:
3141 case PIPE_TEXTURE_CUBE_ARRAY
:
3142 return compute_lambda_2d
;
3143 case PIPE_TEXTURE_3D
:
3144 return compute_lambda_3d
;
3147 return compute_lambda_1d
;
3152 struct pipe_sampler_view
*
3153 softpipe_create_sampler_view(struct pipe_context
*pipe
,
3154 struct pipe_resource
*resource
,
3155 const struct pipe_sampler_view
*templ
)
3157 struct sp_sampler_view
*sview
= CALLOC_STRUCT(sp_sampler_view
);
3158 struct softpipe_resource
*spr
= (struct softpipe_resource
*)resource
;
3161 struct pipe_sampler_view
*view
= &sview
->base
;
3163 view
->reference
.count
= 1;
3164 view
->texture
= NULL
;
3165 pipe_resource_reference(&view
->texture
, resource
);
3166 view
->context
= pipe
;
3170 * This is possibly too lenient, but the primary reason is just
3171 * to catch state trackers which forget to initialize this, so
3172 * it only catches clearly impossible view targets.
3174 if (view
->target
!= resource
->target
) {
3175 if (view
->target
== PIPE_TEXTURE_1D
)
3176 assert(resource
->target
== PIPE_TEXTURE_1D_ARRAY
);
3177 else if (view
->target
== PIPE_TEXTURE_1D_ARRAY
)
3178 assert(resource
->target
== PIPE_TEXTURE_1D
);
3179 else if (view
->target
== PIPE_TEXTURE_2D
)
3180 assert(resource
->target
== PIPE_TEXTURE_2D_ARRAY
||
3181 resource
->target
== PIPE_TEXTURE_CUBE
||
3182 resource
->target
== PIPE_TEXTURE_CUBE_ARRAY
);
3183 else if (view
->target
== PIPE_TEXTURE_2D_ARRAY
)
3184 assert(resource
->target
== PIPE_TEXTURE_2D
||
3185 resource
->target
== PIPE_TEXTURE_CUBE
||
3186 resource
->target
== PIPE_TEXTURE_CUBE_ARRAY
);
3187 else if (view
->target
== PIPE_TEXTURE_CUBE
)
3188 assert(resource
->target
== PIPE_TEXTURE_CUBE_ARRAY
||
3189 resource
->target
== PIPE_TEXTURE_2D_ARRAY
);
3190 else if (view
->target
== PIPE_TEXTURE_CUBE_ARRAY
)
3191 assert(resource
->target
== PIPE_TEXTURE_CUBE
||
3192 resource
->target
== PIPE_TEXTURE_2D_ARRAY
);
3198 if (any_swizzle(view
)) {
3199 sview
->need_swizzle
= TRUE
;
3202 if (view
->target
== PIPE_TEXTURE_CUBE
||
3203 view
->target
== PIPE_TEXTURE_CUBE_ARRAY
)
3204 sview
->get_samples
= sample_cube
;
3206 sview
->get_samples
= sample_mip
;
3208 sview
->pot2d
= spr
->pot
&&
3209 (view
->target
== PIPE_TEXTURE_2D
||
3210 view
->target
== PIPE_TEXTURE_RECT
);
3212 sview
->xpot
= util_logbase2( resource
->width0
);
3213 sview
->ypot
= util_logbase2( resource
->height0
);
3216 return (struct pipe_sampler_view
*) sview
;
3221 sp_tgsi_get_dims(struct tgsi_sampler
*tgsi_sampler
,
3222 const unsigned sview_index
,
3223 int level
, int dims
[4])
3225 struct sp_tgsi_sampler
*sp_samp
= (struct sp_tgsi_sampler
*)tgsi_sampler
;
3227 assert(sview_index
< PIPE_MAX_SHADER_SAMPLER_VIEWS
);
3228 /* always have a view here but texture is NULL if no sampler view was set. */
3229 if (!sp_samp
->sp_sview
[sview_index
].base
.texture
) {
3230 dims
[0] = dims
[1] = dims
[2] = dims
[3] = 0;
3233 sp_get_dims(&sp_samp
->sp_sview
[sview_index
], level
, dims
);
3238 sp_tgsi_get_samples(struct tgsi_sampler
*tgsi_sampler
,
3239 const unsigned sview_index
,
3240 const unsigned sampler_index
,
3241 const float s
[TGSI_QUAD_SIZE
],
3242 const float t
[TGSI_QUAD_SIZE
],
3243 const float p
[TGSI_QUAD_SIZE
],
3244 const float c0
[TGSI_QUAD_SIZE
],
3245 const float lod
[TGSI_QUAD_SIZE
],
3246 float derivs
[3][2][TGSI_QUAD_SIZE
],
3247 const int8_t offset
[3],
3248 enum tgsi_sampler_control control
,
3249 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
3251 struct sp_tgsi_sampler
*sp_samp
= (struct sp_tgsi_sampler
*)tgsi_sampler
;
3253 assert(sview_index
< PIPE_MAX_SHADER_SAMPLER_VIEWS
);
3254 assert(sampler_index
< PIPE_MAX_SAMPLERS
);
3255 assert(sp_samp
->sp_sampler
[sampler_index
]);
3256 /* always have a view here but texture is NULL if no sampler view was set. */
3257 if (!sp_samp
->sp_sview
[sview_index
].base
.texture
) {
3259 for (j
= 0; j
< TGSI_NUM_CHANNELS
; j
++) {
3260 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
3266 sp_samp
->sp_sview
[sview_index
].get_samples(&sp_samp
->sp_sview
[sview_index
],
3267 sp_samp
->sp_sampler
[sampler_index
],
3268 s
, t
, p
, c0
, lod
, control
, rgba
);
3273 sp_tgsi_get_texel(struct tgsi_sampler
*tgsi_sampler
,
3274 const unsigned sview_index
,
3275 const int i
[TGSI_QUAD_SIZE
],
3276 const int j
[TGSI_QUAD_SIZE
], const int k
[TGSI_QUAD_SIZE
],
3277 const int lod
[TGSI_QUAD_SIZE
], const int8_t offset
[3],
3278 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
])
3280 struct sp_tgsi_sampler
*sp_samp
= (struct sp_tgsi_sampler
*)tgsi_sampler
;
3282 assert(sview_index
< PIPE_MAX_SHADER_SAMPLER_VIEWS
);
3283 /* always have a view here but texture is NULL if no sampler view was set. */
3284 if (!sp_samp
->sp_sview
[sview_index
].base
.texture
) {
3286 for (j
= 0; j
< TGSI_NUM_CHANNELS
; j
++) {
3287 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
3293 sp_get_texels(&sp_samp
->sp_sview
[sview_index
], i
, j
, k
, lod
, offset
, rgba
);
3297 struct sp_tgsi_sampler
*
3298 sp_create_tgsi_sampler(void)
3300 struct sp_tgsi_sampler
*samp
= CALLOC_STRUCT(sp_tgsi_sampler
);
3304 samp
->base
.get_dims
= sp_tgsi_get_dims
;
3305 samp
->base
.get_samples
= sp_tgsi_get_samples
;
3306 samp
->base
.get_texel
= sp_tgsi_get_texel
;