1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * Copyright 2008 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 "sp_context.h"
39 #include "sp_surface.h"
40 #include "sp_texture.h"
41 #include "sp_tex_sample.h"
42 #include "sp_tile_cache.h"
43 #include "pipe/p_context.h"
44 #include "pipe/p_defines.h"
45 #include "pipe/p_shader_tokens.h"
46 #include "util/u_math.h"
47 #include "util/u_memory.h"
52 * Note, the FRAC macro has to work perfectly. Otherwise you'll sometimes
53 * see 1-pixel bands of improperly weighted linear-filtered textures.
54 * The tests/texwrap.c demo is a good test.
55 * Also note, FRAC(x) doesn't truly return the fractional part of x for x < 0.
56 * Instead, if x < 0 then FRAC(x) = 1 - true_frac(x).
58 #define FRAC(f) ((f) - util_ifloor(f))
62 * Linear interpolation macro
65 lerp(float a
, float v0
, float v1
)
67 return v0
+ a
* (v1
- v0
);
72 * Do 2D/biliner interpolation of float values.
73 * v00, v10, v01 and v11 are typically four texture samples in a square/box.
74 * a and b are the horizontal and vertical interpolants.
75 * It's important that this function is inlined when compiled with
76 * optimization! If we find that's not true on some systems, convert
80 lerp_2d(float a
, float b
,
81 float v00
, float v10
, float v01
, float v11
)
83 const float temp0
= lerp(a
, v00
, v10
);
84 const float temp1
= lerp(a
, v01
, v11
);
85 return lerp(b
, temp0
, temp1
);
90 * As above, but 3D interpolation of 8 values.
93 lerp_3d(float a
, float b
, float c
,
94 float v000
, float v100
, float v010
, float v110
,
95 float v001
, float v101
, float v011
, float v111
)
97 const float temp0
= lerp_2d(a
, b
, v000
, v100
, v010
, v110
);
98 const float temp1
= lerp_2d(a
, b
, v001
, v101
, v011
, v111
);
99 return lerp(c
, temp0
, temp1
);
105 * If A is a signed integer, A % B doesn't give the right value for A < 0
106 * (in terms of texture repeat). Just casting to unsigned fixes that.
108 #define REMAINDER(A, B) ((unsigned) (A) % (unsigned) (B))
112 * Apply texture coord wrapping mode and return integer texture indexes
113 * for a vector of four texcoords (S or T or P).
114 * \param wrapMode PIPE_TEX_WRAP_x
115 * \param s the incoming texcoords
116 * \param size the texture image size
117 * \param icoord returns the integer texcoords
118 * \return integer texture index
121 wrap_nearest_repeat(const float s
[4], unsigned size
,
126 /* s limited to [0,1) */
127 /* i limited to [0,size-1] */
128 for (ch
= 0; ch
< 4; ch
++) {
129 int i
= util_ifloor(s
[ch
] * size
);
130 icoord
[ch
] = REMAINDER(i
, size
);
136 wrap_nearest_clamp(const float s
[4], unsigned size
,
140 /* s limited to [0,1] */
141 /* i limited to [0,size-1] */
142 for (ch
= 0; ch
< 4; ch
++) {
145 else if (s
[ch
] >= 1.0F
)
146 icoord
[ch
] = size
- 1;
148 icoord
[ch
] = util_ifloor(s
[ch
] * size
);
154 wrap_nearest_clamp_to_edge(const float s
[4], unsigned size
,
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
;
162 for (ch
= 0; ch
< 4; ch
++) {
165 else if (s
[ch
] > max
)
166 icoord
[ch
] = size
- 1;
168 icoord
[ch
] = util_ifloor(s
[ch
] * size
);
174 wrap_nearest_clamp_to_border(const float s
[4], unsigned size
,
178 /* s limited to [min,max] */
179 /* i limited to [-1, size] */
180 const float min
= -1.0F
/ (2.0F
* size
);
181 const float max
= 1.0F
- min
;
182 for (ch
= 0; ch
< 4; ch
++) {
185 else if (s
[ch
] >= max
)
188 icoord
[ch
] = util_ifloor(s
[ch
] * size
);
193 wrap_nearest_mirror_repeat(const float s
[4], unsigned size
,
197 const float min
= 1.0F
/ (2.0F
* size
);
198 const float max
= 1.0F
- min
;
199 for (ch
= 0; ch
< 4; ch
++) {
200 const int flr
= util_ifloor(s
[ch
]);
203 u
= 1.0F
- (s
[ch
] - (float) flr
);
205 u
= s
[ch
] - (float) flr
;
209 icoord
[ch
] = size
- 1;
211 icoord
[ch
] = util_ifloor(u
* size
);
216 wrap_nearest_mirror_clamp(const float s
[4], unsigned size
,
220 for (ch
= 0; ch
< 4; ch
++) {
221 /* s limited to [0,1] */
222 /* i limited to [0,size-1] */
223 const float u
= fabsf(s
[ch
]);
227 icoord
[ch
] = size
- 1;
229 icoord
[ch
] = util_ifloor(u
* size
);
234 wrap_nearest_mirror_clamp_to_edge(const float s
[4], unsigned size
,
238 /* s limited to [min,max] */
239 /* i limited to [0, size-1] */
240 const float min
= 1.0F
/ (2.0F
* size
);
241 const float max
= 1.0F
- min
;
242 for (ch
= 0; ch
< 4; ch
++) {
243 const float u
= fabsf(s
[ch
]);
247 icoord
[ch
] = size
- 1;
249 icoord
[ch
] = util_ifloor(u
* size
);
255 wrap_nearest_mirror_clamp_to_border(const float s
[4], unsigned size
,
259 /* s limited to [min,max] */
260 /* i limited to [0, size-1] */
261 const float min
= -1.0F
/ (2.0F
* size
);
262 const float max
= 1.0F
- min
;
263 for (ch
= 0; ch
< 4; ch
++) {
264 const float u
= fabsf(s
[ch
]);
270 icoord
[ch
] = util_ifloor(u
* size
);
276 * Used to compute texel locations for linear sampling for four texcoords.
277 * \param wrapMode PIPE_TEX_WRAP_x
278 * \param s the texcoords
279 * \param size the texture image size
280 * \param icoord0 returns first texture indexes
281 * \param icoord1 returns second texture indexes (usually icoord0 + 1)
282 * \param w returns blend factor/weight between texture indexes
283 * \param icoord returns the computed integer texture coords
286 wrap_linear_repeat(const float s
[4], unsigned size
,
287 int icoord0
[4], int icoord1
[4], float w
[4])
291 for (ch
= 0; ch
< 4; ch
++) {
292 float u
= s
[ch
] * size
- 0.5F
;
293 icoord0
[ch
] = REMAINDER(util_ifloor(u
), size
);
294 icoord1
[ch
] = REMAINDER(icoord0
[ch
] + 1, size
);
300 wrap_linear_clamp(const float s
[4], unsigned size
,
301 int icoord0
[4], int icoord1
[4], float w
[4])
304 for (ch
= 0; ch
< 4; ch
++) {
305 float u
= CLAMP(s
[ch
], 0.0F
, 1.0F
);
307 icoord0
[ch
] = util_ifloor(u
);
308 icoord1
[ch
] = icoord0
[ch
] + 1;
314 wrap_linear_clamp_to_edge(const float s
[4], unsigned size
,
315 int icoord0
[4], int icoord1
[4], float w
[4])
318 for (ch
= 0; ch
< 4; ch
++) {
319 float u
= CLAMP(s
[ch
], 0.0F
, 1.0F
);
321 icoord0
[ch
] = util_ifloor(u
);
322 icoord1
[ch
] = icoord0
[ch
] + 1;
325 if (icoord1
[ch
] >= (int) size
)
326 icoord1
[ch
] = size
- 1;
332 wrap_linear_clamp_to_border(const float s
[4], unsigned size
,
333 int icoord0
[4], int icoord1
[4], float w
[4])
335 const float min
= -1.0F
/ (2.0F
* size
);
336 const float max
= 1.0F
- min
;
338 for (ch
= 0; ch
< 4; ch
++) {
339 float u
= CLAMP(s
[ch
], min
, max
);
341 icoord0
[ch
] = util_ifloor(u
);
342 icoord1
[ch
] = icoord0
[ch
] + 1;
349 wrap_linear_mirror_repeat(const float s
[4], unsigned size
,
350 int icoord0
[4], int icoord1
[4], float w
[4])
353 for (ch
= 0; ch
< 4; ch
++) {
354 const int flr
= util_ifloor(s
[ch
]);
357 u
= 1.0F
- (s
[ch
] - (float) flr
);
359 u
= s
[ch
] - (float) flr
;
361 icoord0
[ch
] = util_ifloor(u
);
362 icoord1
[ch
] = icoord0
[ch
] + 1;
365 if (icoord1
[ch
] >= (int) size
)
366 icoord1
[ch
] = size
- 1;
372 wrap_linear_mirror_clamp(const float s
[4], unsigned size
,
373 int icoord0
[4], int icoord1
[4], float w
[4])
376 for (ch
= 0; ch
< 4; ch
++) {
377 float u
= fabsf(s
[ch
]);
383 icoord0
[ch
] = util_ifloor(u
);
384 icoord1
[ch
] = icoord0
[ch
] + 1;
390 wrap_linear_mirror_clamp_to_edge(const float s
[4], unsigned size
,
391 int icoord0
[4], int icoord1
[4], float w
[4])
394 for (ch
= 0; ch
< 4; ch
++) {
395 float u
= fabsf(s
[ch
]);
401 icoord0
[ch
] = util_ifloor(u
);
402 icoord1
[ch
] = icoord0
[ch
] + 1;
405 if (icoord1
[ch
] >= (int) size
)
406 icoord1
[ch
] = size
- 1;
412 wrap_linear_mirror_clamp_to_border(const float s
[4], unsigned size
,
413 int icoord0
[4], int icoord1
[4], float w
[4])
415 const float min
= -1.0F
/ (2.0F
* size
);
416 const float max
= 1.0F
- min
;
418 for (ch
= 0; ch
< 4; ch
++) {
419 float u
= fabsf(s
[ch
]);
427 icoord0
[ch
] = util_ifloor(u
);
428 icoord1
[ch
] = icoord0
[ch
] + 1;
435 * For RECT textures / unnormalized texcoords
436 * Only a subset of wrap modes supported.
439 wrap_nearest_unorm_clamp(const float s
[4], unsigned size
,
443 for (ch
= 0; ch
< 4; ch
++) {
444 int i
= util_ifloor(s
[ch
]);
445 icoord
[ch
]= CLAMP(i
, 0, (int) size
-1);
449 /* Handles clamp_to_edge and clamp_to_border:
452 wrap_nearest_unorm_clamp_to_border(const float s
[4], unsigned size
,
456 for (ch
= 0; ch
< 4; ch
++) {
457 icoord
[ch
]= util_ifloor( CLAMP(s
[ch
], 0.5F
, (float) size
- 0.5F
) );
463 * For RECT textures / unnormalized texcoords.
464 * Only a subset of wrap modes supported.
467 wrap_linear_unorm_clamp(const float s
[4], unsigned size
,
468 int icoord0
[4], int icoord1
[4], float w
[4])
471 for (ch
= 0; ch
< 4; ch
++) {
472 /* Not exactly what the spec says, but it matches NVIDIA output */
473 float u
= CLAMP(s
[ch
] - 0.5F
, 0.0f
, (float) size
- 1.0f
);
474 icoord0
[ch
] = util_ifloor(u
);
475 icoord1
[ch
] = icoord0
[ch
] + 1;
481 wrap_linear_unorm_clamp_to_border( const float s
[4], unsigned size
,
482 int icoord0
[4], int icoord1
[4], float w
[4])
485 for (ch
= 0; ch
< 4; ch
++) {
486 float u
= CLAMP(s
[ch
], 0.5F
, (float) size
- 0.5F
);
488 icoord0
[ch
] = util_ifloor(u
);
489 icoord1
[ch
] = icoord0
[ch
] + 1;
490 if (icoord1
[ch
] > (int) size
- 1)
491 icoord1
[ch
] = size
- 1;
501 * Examine the quad's texture coordinates to compute the partial
502 * derivatives w.r.t X and Y, then compute lambda (level of detail).
505 compute_lambda_1d(const struct sp_sampler_varient
*samp
,
506 const float s
[QUAD_SIZE
],
507 const float t
[QUAD_SIZE
],
508 const float p
[QUAD_SIZE
],
511 const struct pipe_texture
*texture
= samp
->texture
;
512 const struct pipe_sampler_state
*sampler
= samp
->sampler
;
513 float dsdx
= fabsf(s
[QUAD_BOTTOM_RIGHT
] - s
[QUAD_BOTTOM_LEFT
]);
514 float dsdy
= fabsf(s
[QUAD_TOP_LEFT
] - s
[QUAD_BOTTOM_LEFT
]);
515 float rho
= MAX2(dsdx
, dsdy
) * texture
->width
[0];
518 lambda
= util_fast_log2(rho
);
519 lambda
+= lodbias
+ sampler
->lod_bias
;
520 lambda
= CLAMP(lambda
, sampler
->min_lod
, sampler
->max_lod
);
526 compute_lambda_2d(const struct sp_sampler_varient
*samp
,
527 const float s
[QUAD_SIZE
],
528 const float t
[QUAD_SIZE
],
529 const float p
[QUAD_SIZE
],
532 const struct pipe_texture
*texture
= samp
->texture
;
533 const struct pipe_sampler_state
*sampler
= samp
->sampler
;
534 float dsdx
= fabsf(s
[QUAD_BOTTOM_RIGHT
] - s
[QUAD_BOTTOM_LEFT
]);
535 float dsdy
= fabsf(s
[QUAD_TOP_LEFT
] - s
[QUAD_BOTTOM_LEFT
]);
536 float dtdx
= fabsf(t
[QUAD_BOTTOM_RIGHT
] - t
[QUAD_BOTTOM_LEFT
]);
537 float dtdy
= fabsf(t
[QUAD_TOP_LEFT
] - t
[QUAD_BOTTOM_LEFT
]);
538 float maxx
= MAX2(dsdx
, dsdy
) * texture
->width
[0];
539 float maxy
= MAX2(dtdx
, dtdy
) * texture
->height
[0];
540 float rho
= MAX2(maxx
, maxy
);
543 lambda
= util_fast_log2(rho
);
544 lambda
+= lodbias
+ sampler
->lod_bias
;
545 lambda
= CLAMP(lambda
, sampler
->min_lod
, sampler
->max_lod
);
552 compute_lambda_3d(const struct sp_sampler_varient
*samp
,
553 const float s
[QUAD_SIZE
],
554 const float t
[QUAD_SIZE
],
555 const float p
[QUAD_SIZE
],
558 const struct pipe_texture
*texture
= samp
->texture
;
559 const struct pipe_sampler_state
*sampler
= samp
->sampler
;
560 float dsdx
= fabsf(s
[QUAD_BOTTOM_RIGHT
] - s
[QUAD_BOTTOM_LEFT
]);
561 float dsdy
= fabsf(s
[QUAD_TOP_LEFT
] - s
[QUAD_BOTTOM_LEFT
]);
562 float dtdx
= fabsf(t
[QUAD_BOTTOM_RIGHT
] - t
[QUAD_BOTTOM_LEFT
]);
563 float dtdy
= fabsf(t
[QUAD_TOP_LEFT
] - t
[QUAD_BOTTOM_LEFT
]);
564 float dpdx
= fabsf(p
[QUAD_BOTTOM_RIGHT
] - p
[QUAD_BOTTOM_LEFT
]);
565 float dpdy
= fabsf(p
[QUAD_TOP_LEFT
] - p
[QUAD_BOTTOM_LEFT
]);
566 float maxx
= MAX2(dsdx
, dsdy
) * texture
->width
[0];
567 float maxy
= MAX2(dtdx
, dtdy
) * texture
->height
[0];
568 float maxz
= MAX2(dpdx
, dpdy
) * texture
->depth
[0];
571 rho
= MAX2(maxx
, maxy
);
572 rho
= MAX2(rho
, maxz
);
574 lambda
= util_fast_log2(rho
);
575 lambda
+= lodbias
+ sampler
->lod_bias
;
576 lambda
= CLAMP(lambda
, sampler
->min_lod
, sampler
->max_lod
);
584 compute_lambda_vert(const struct sp_sampler_varient
*samp
,
585 const float s
[QUAD_SIZE
],
586 const float t
[QUAD_SIZE
],
587 const float p
[QUAD_SIZE
],
596 * Get a texel from a texture, using the texture tile cache.
598 * \param face the cube face in 0..5
599 * \param level the mipmap level
600 * \param x the x coord of texel within 2D image
601 * \param y the y coord of texel within 2D image
602 * \param z which slice of a 3D texture
603 * \param rgba the quad to put the texel/color into
604 * \param j which element of the rgba quad to write to
606 * XXX maybe move this into sp_tile_cache.c and merge with the
607 * sp_get_cached_tile_tex() function. Also, get 4 texels instead of 1...
610 get_texel_quad_2d(const struct tgsi_sampler
*tgsi_sampler
,
611 unsigned face
, unsigned level
, int x
, int y
,
614 const struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
616 const struct softpipe_cached_tile
*tile
617 = sp_get_cached_tile_tex(samp
->cache
,
618 tile_address(x
, y
, 0, face
, level
));
623 out
[0] = &tile
->data
.color
[y
][x
][0];
624 out
[1] = &tile
->data
.color
[y
][x
+1][0];
625 out
[2] = &tile
->data
.color
[y
+1][x
][0];
626 out
[3] = &tile
->data
.color
[y
+1][x
+1][0];
629 static INLINE
const float *
630 get_texel_2d_ptr(const struct tgsi_sampler
*tgsi_sampler
,
631 unsigned face
, unsigned level
, int x
, int y
)
633 const struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
635 const struct softpipe_cached_tile
*tile
636 = sp_get_cached_tile_tex(samp
->cache
,
637 tile_address(x
, y
, 0, face
, level
));
642 return &tile
->data
.color
[y
][x
][0];
647 get_texel_quad_2d_mt(const struct tgsi_sampler
*tgsi_sampler
,
648 unsigned face
, unsigned level
,
655 for (i
= 0; i
< 4; i
++) {
656 unsigned tx
= (i
& 1) ? x1
: x0
;
657 unsigned ty
= (i
>> 1) ? y1
: y0
;
659 out
[i
] = get_texel_2d_ptr( tgsi_sampler
, face
, level
, tx
, ty
);
664 get_texel(const struct tgsi_sampler
*tgsi_sampler
,
665 unsigned face
, unsigned level
, int x
, int y
, int z
,
666 float rgba
[NUM_CHANNELS
][QUAD_SIZE
], unsigned j
)
668 const struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
669 const struct pipe_texture
*texture
= samp
->texture
;
670 const struct pipe_sampler_state
*sampler
= samp
->sampler
;
672 if (x
< 0 || x
>= (int) texture
->width
[level
] ||
673 y
< 0 || y
>= (int) texture
->height
[level
] ||
674 z
< 0 || z
>= (int) texture
->depth
[level
]) {
675 rgba
[0][j
] = sampler
->border_color
[0];
676 rgba
[1][j
] = sampler
->border_color
[1];
677 rgba
[2][j
] = sampler
->border_color
[2];
678 rgba
[3][j
] = sampler
->border_color
[3];
681 const unsigned tx
= x
% TILE_SIZE
;
682 const unsigned ty
= y
% TILE_SIZE
;
683 const struct softpipe_cached_tile
*tile
;
685 tile
= sp_get_cached_tile_tex(samp
->cache
,
686 tile_address(x
, y
, z
, face
, level
));
688 rgba
[0][j
] = tile
->data
.color
[ty
][tx
][0];
689 rgba
[1][j
] = tile
->data
.color
[ty
][tx
][1];
690 rgba
[2][j
] = tile
->data
.color
[ty
][tx
][2];
691 rgba
[3][j
] = tile
->data
.color
[ty
][tx
][3];
694 debug_printf("Get texel %f %f %f %f from %s\n",
695 rgba
[0][j
], rgba
[1][j
], rgba
[2][j
], rgba
[3][j
],
696 pf_name(texture
->format
));
706 img_filter_2d_linear_repeat_POT(struct tgsi_sampler
*tgsi_sampler
,
707 const float s
[QUAD_SIZE
],
708 const float t
[QUAD_SIZE
],
709 const float p
[QUAD_SIZE
],
711 float rgba
[NUM_CHANNELS
][QUAD_SIZE
])
713 const struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
715 unsigned level
= samp
->level
;
716 unsigned xpot
= 1 << (samp
->xpot
- level
);
717 unsigned ypot
= 1 << (samp
->ypot
- level
);
718 unsigned xmax
= (xpot
- 1) & (TILE_SIZE
- 1); /* MIN2(TILE_SIZE, xpot) - 1; */
719 unsigned ymax
= (ypot
- 1) & (TILE_SIZE
- 1); /* MIN2(TILE_SIZE, ypot) - 1; */
721 for (j
= 0; j
< QUAD_SIZE
; j
++) {
724 float u
= s
[j
] * xpot
- 0.5F
;
725 float v
= t
[j
] * ypot
- 0.5F
;
727 int uflr
= util_ifloor(u
);
728 int vflr
= util_ifloor(v
);
730 float xw
= u
- (float)uflr
;
731 float yw
= v
- (float)vflr
;
733 int x0
= uflr
& (xpot
- 1);
734 int y0
= vflr
& (ypot
- 1);
739 /* Can we fetch all four at once:
741 if (x0
< xmax
&& y0
< ymax
)
743 get_texel_quad_2d(tgsi_sampler
, 0, level
, x0
, y0
, tx
);
747 unsigned x1
= (x0
+ 1) & (xpot
- 1);
748 unsigned y1
= (y0
+ 1) & (ypot
- 1);
749 get_texel_quad_2d_mt(tgsi_sampler
, 0, level
,
754 /* interpolate R, G, B, A */
755 for (c
= 0; c
< 4; c
++) {
756 rgba
[c
][j
] = lerp_2d(xw
, yw
,
765 img_filter_2d_nearest_repeat_POT(struct tgsi_sampler
*tgsi_sampler
,
766 const float s
[QUAD_SIZE
],
767 const float t
[QUAD_SIZE
],
768 const float p
[QUAD_SIZE
],
770 float rgba
[NUM_CHANNELS
][QUAD_SIZE
])
772 const struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
774 unsigned level
= samp
->level
;
775 unsigned xpot
= 1 << (samp
->xpot
- level
);
776 unsigned ypot
= 1 << (samp
->ypot
- level
);
778 for (j
= 0; j
< QUAD_SIZE
; j
++) {
781 float u
= s
[j
] * xpot
;
782 float v
= t
[j
] * ypot
;
784 int uflr
= util_ifloor(u
);
785 int vflr
= util_ifloor(v
);
787 int x0
= uflr
& (xpot
- 1);
788 int y0
= vflr
& (ypot
- 1);
790 const float *out
= get_texel_2d_ptr(tgsi_sampler
, 0, level
, x0
, y0
);
792 for (c
= 0; c
< 4; c
++) {
800 img_filter_2d_nearest_clamp_POT(struct tgsi_sampler
*tgsi_sampler
,
801 const float s
[QUAD_SIZE
],
802 const float t
[QUAD_SIZE
],
803 const float p
[QUAD_SIZE
],
805 float rgba
[NUM_CHANNELS
][QUAD_SIZE
])
807 const struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
809 unsigned level
= samp
->level
;
810 unsigned xpot
= 1 << (samp
->xpot
- level
);
811 unsigned ypot
= 1 << (samp
->ypot
- level
);
813 for (j
= 0; j
< QUAD_SIZE
; j
++) {
816 float u
= s
[j
] * xpot
;
817 float v
= t
[j
] * ypot
;
825 else if (x0
> xpot
- 1)
831 else if (y0
> ypot
- 1)
834 out
= get_texel_2d_ptr(tgsi_sampler
, 0, level
, x0
, y0
);
836 for (c
= 0; c
< 4; c
++) {
843 img_filter_1d_nearest(struct tgsi_sampler
*tgsi_sampler
,
844 const float s
[QUAD_SIZE
],
845 const float t
[QUAD_SIZE
],
846 const float p
[QUAD_SIZE
],
848 float rgba
[NUM_CHANNELS
][QUAD_SIZE
])
850 const struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
851 const struct pipe_texture
*texture
= samp
->texture
;
856 level0
= samp
->level
;
857 width
= texture
->width
[level0
];
861 samp
->nearest_texcoord_s(s
, width
, x
);
863 for (j
= 0; j
< QUAD_SIZE
; j
++) {
864 get_texel(tgsi_sampler
, 0, level0
, x
[j
], 0, 0, rgba
, j
);
870 img_filter_2d_nearest(struct tgsi_sampler
*tgsi_sampler
,
871 const float s
[QUAD_SIZE
],
872 const float t
[QUAD_SIZE
],
873 const float p
[QUAD_SIZE
],
875 float rgba
[NUM_CHANNELS
][QUAD_SIZE
])
877 const struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
878 const struct pipe_texture
*texture
= samp
->texture
;
879 const unsigned *faces
= samp
->faces
; /* zero when not cube-mapping */
884 level0
= samp
->level
;
885 width
= texture
->width
[level0
];
886 height
= texture
->height
[level0
];
890 samp
->nearest_texcoord_s(s
, width
, x
);
891 samp
->nearest_texcoord_t(t
, height
, y
);
893 for (j
= 0; j
< QUAD_SIZE
; j
++) {
894 get_texel(tgsi_sampler
, faces
[j
], level0
, x
[j
], y
[j
], 0, rgba
, j
);
900 img_filter_3d_nearest(struct tgsi_sampler
*tgsi_sampler
,
901 const float s
[QUAD_SIZE
],
902 const float t
[QUAD_SIZE
],
903 const float p
[QUAD_SIZE
],
905 float rgba
[NUM_CHANNELS
][QUAD_SIZE
])
907 const struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
908 const struct pipe_texture
*texture
= samp
->texture
;
910 int width
, height
, depth
;
911 int x
[4], y
[4], z
[4];
913 level0
= samp
->level
;
914 width
= texture
->width
[level0
];
915 height
= texture
->height
[level0
];
916 depth
= texture
->depth
[level0
];
922 samp
->nearest_texcoord_s(s
, width
, x
);
923 samp
->nearest_texcoord_t(t
, height
, y
);
924 samp
->nearest_texcoord_p(p
, depth
, z
);
926 for (j
= 0; j
< QUAD_SIZE
; j
++) {
927 get_texel(tgsi_sampler
, 0, level0
, x
[j
], y
[j
], z
[j
], rgba
, j
);
933 img_filter_1d_linear(struct tgsi_sampler
*tgsi_sampler
,
934 const float s
[QUAD_SIZE
],
935 const float t
[QUAD_SIZE
],
936 const float p
[QUAD_SIZE
],
938 float rgba
[NUM_CHANNELS
][QUAD_SIZE
])
940 const struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
941 const struct pipe_texture
*texture
= samp
->texture
;
945 float xw
[4]; /* weights */
948 level0
= samp
->level
;
949 width
= texture
->width
[level0
];
953 samp
->linear_texcoord_s(s
, width
, x0
, x1
, xw
);
956 for (j
= 0; j
< QUAD_SIZE
; j
++) {
957 float tx
[4][4]; /* texels */
959 get_texel(tgsi_sampler
, 0, level0
, x0
[j
], 0, 0, tx
, 0);
960 get_texel(tgsi_sampler
, 0, level0
, x1
[j
], 0, 0, tx
, 1);
962 /* interpolate R, G, B, A */
963 for (c
= 0; c
< 4; c
++) {
964 rgba
[c
][j
] = lerp(xw
[j
], tx
[c
][0], tx
[c
][1]);
970 img_filter_2d_linear(struct tgsi_sampler
*tgsi_sampler
,
971 const float s
[QUAD_SIZE
],
972 const float t
[QUAD_SIZE
],
973 const float p
[QUAD_SIZE
],
975 float rgba
[NUM_CHANNELS
][QUAD_SIZE
])
977 const struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
978 const struct pipe_texture
*texture
= samp
->texture
;
979 const unsigned *faces
= samp
->faces
; /* zero when not cube-mapping */
982 int x0
[4], y0
[4], x1
[4], y1
[4];
983 float xw
[4], yw
[4]; /* weights */
986 level0
= samp
->level
;
987 width
= texture
->width
[level0
];
988 height
= texture
->height
[level0
];
992 samp
->linear_texcoord_s(s
, width
, x0
, x1
, xw
);
993 samp
->linear_texcoord_t(t
, height
, y0
, y1
, yw
);
995 for (j
= 0; j
< QUAD_SIZE
; j
++) {
996 float tx
[4][4]; /* texels */
998 get_texel(tgsi_sampler
, faces
[j
], level0
, x0
[j
], y0
[j
], 0, tx
, 0);
999 get_texel(tgsi_sampler
, faces
[j
], level0
, x1
[j
], y0
[j
], 0, tx
, 1);
1000 get_texel(tgsi_sampler
, faces
[j
], level0
, x0
[j
], y1
[j
], 0, tx
, 2);
1001 get_texel(tgsi_sampler
, faces
[j
], level0
, x1
[j
], y1
[j
], 0, tx
, 3);
1003 /* interpolate R, G, B, A */
1004 for (c
= 0; c
< 4; c
++) {
1005 rgba
[c
][j
] = lerp_2d(xw
[j
], yw
[j
],
1007 tx
[c
][2], tx
[c
][3]);
1014 img_filter_3d_linear(struct tgsi_sampler
*tgsi_sampler
,
1015 const float s
[QUAD_SIZE
],
1016 const float t
[QUAD_SIZE
],
1017 const float p
[QUAD_SIZE
],
1019 float rgba
[NUM_CHANNELS
][QUAD_SIZE
])
1021 const struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
1022 const struct pipe_texture
*texture
= samp
->texture
;
1024 int width
, height
, depth
;
1025 int x0
[4], x1
[4], y0
[4], y1
[4], z0
[4], z1
[4];
1026 float xw
[4], yw
[4], zw
[4]; /* interpolation weights */
1028 level0
= samp
->level
;
1029 width
= texture
->width
[level0
];
1030 height
= texture
->height
[level0
];
1031 depth
= texture
->depth
[level0
];
1037 samp
->linear_texcoord_s(s
, width
, x0
, x1
, xw
);
1038 samp
->linear_texcoord_t(t
, height
, y0
, y1
, yw
);
1039 samp
->linear_texcoord_p(p
, depth
, z0
, z1
, zw
);
1041 for (j
= 0; j
< QUAD_SIZE
; j
++) {
1042 float tx0
[4][4], tx1
[4][4];
1045 get_texel(tgsi_sampler
, 0, level0
, x0
[j
], y0
[j
], z0
[j
], tx0
, 0);
1046 get_texel(tgsi_sampler
, 0, level0
, x1
[j
], y0
[j
], z0
[j
], tx0
, 1);
1047 get_texel(tgsi_sampler
, 0, level0
, x0
[j
], y1
[j
], z0
[j
], tx0
, 2);
1048 get_texel(tgsi_sampler
, 0, level0
, x1
[j
], y1
[j
], z0
[j
], tx0
, 3);
1049 get_texel(tgsi_sampler
, 0, level0
, x0
[j
], y0
[j
], z1
[j
], tx1
, 0);
1050 get_texel(tgsi_sampler
, 0, level0
, x1
[j
], y0
[j
], z1
[j
], tx1
, 1);
1051 get_texel(tgsi_sampler
, 0, level0
, x0
[j
], y1
[j
], z1
[j
], tx1
, 2);
1052 get_texel(tgsi_sampler
, 0, level0
, x1
[j
], y1
[j
], z1
[j
], tx1
, 3);
1054 /* interpolate R, G, B, A */
1055 for (c
= 0; c
< 4; c
++) {
1056 rgba
[c
][j
] = lerp_3d(xw
[j
], yw
[j
], zw
[j
],
1057 tx0
[c
][0], tx0
[c
][1],
1058 tx0
[c
][2], tx0
[c
][3],
1059 tx1
[c
][0], tx1
[c
][1],
1060 tx1
[c
][2], tx1
[c
][3]);
1072 mip_filter_linear(struct tgsi_sampler
*tgsi_sampler
,
1073 const float s
[QUAD_SIZE
],
1074 const float t
[QUAD_SIZE
],
1075 const float p
[QUAD_SIZE
],
1077 float rgba
[NUM_CHANNELS
][QUAD_SIZE
])
1079 struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
1080 const struct pipe_texture
*texture
= samp
->texture
;
1084 lambda
= samp
->compute_lambda(samp
, s
, t
, p
, lodbias
);
1085 level0
= (int)lambda
;
1089 samp
->mag_img_filter( tgsi_sampler
, s
, t
, p
, 0, rgba
);
1091 else if (level0
>= texture
->last_level
) {
1092 samp
->level
= texture
->last_level
;
1093 samp
->min_img_filter( tgsi_sampler
, s
, t
, p
, 0, rgba
);
1096 float levelBlend
= lambda
- level0
;
1101 samp
->level
= level0
;
1102 samp
->min_img_filter( tgsi_sampler
, s
, t
, p
, 0, rgba0
);
1104 samp
->level
= level0
+1;
1105 samp
->min_img_filter( tgsi_sampler
, s
, t
, p
, 0, rgba1
);
1107 for (j
= 0; j
< QUAD_SIZE
; j
++) {
1108 for (c
= 0; c
< 4; c
++) {
1109 rgba
[c
][j
] = lerp(levelBlend
, rgba0
[c
][j
], rgba1
[c
][j
]);
1118 mip_filter_nearest(struct tgsi_sampler
*tgsi_sampler
,
1119 const float s
[QUAD_SIZE
],
1120 const float t
[QUAD_SIZE
],
1121 const float p
[QUAD_SIZE
],
1123 float rgba
[NUM_CHANNELS
][QUAD_SIZE
])
1125 struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
1126 const struct pipe_texture
*texture
= samp
->texture
;
1129 lambda
= samp
->compute_lambda(samp
, s
, t
, p
, lodbias
);
1133 samp
->mag_img_filter( tgsi_sampler
, s
, t
, p
, 0, rgba
);
1136 samp
->level
= (int)(lambda
+ 0.5) ;
1137 samp
->level
= MIN2(samp
->level
, (int)texture
->last_level
);
1138 samp
->min_img_filter( tgsi_sampler
, s
, t
, p
, 0, rgba
);
1144 mip_filter_none(struct tgsi_sampler
*tgsi_sampler
,
1145 const float s
[QUAD_SIZE
],
1146 const float t
[QUAD_SIZE
],
1147 const float p
[QUAD_SIZE
],
1149 float rgba
[NUM_CHANNELS
][QUAD_SIZE
])
1151 struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
1152 float lambda
= samp
->compute_lambda(samp
, s
, t
, p
, lodbias
);
1155 samp
->mag_img_filter( tgsi_sampler
, s
, t
, p
, 0, rgba
);
1158 samp
->min_img_filter( tgsi_sampler
, s
, t
, p
, 0, rgba
);
1164 /* Specialized version of mip_filter_linear with hard-wired calls to
1165 * 2d lambda calculation and 2d_linear_repeat_POT img filters.
1168 mip_filter_linear_2d_linear_repeat_POT(
1169 struct tgsi_sampler
*tgsi_sampler
,
1170 const float s
[QUAD_SIZE
],
1171 const float t
[QUAD_SIZE
],
1172 const float p
[QUAD_SIZE
],
1174 float rgba
[NUM_CHANNELS
][QUAD_SIZE
])
1176 struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
1177 const struct pipe_texture
*texture
= samp
->texture
;
1181 lambda
= compute_lambda_2d(samp
, s
, t
, p
, lodbias
);
1182 level0
= (int)lambda
;
1184 /* Catches both negative and large values of level0:
1186 if ((unsigned)level0
>= texture
->last_level
) {
1190 samp
->level
= texture
->last_level
;
1192 img_filter_2d_linear_repeat_POT( tgsi_sampler
, s
, t
, p
, 0, rgba
);
1195 float levelBlend
= lambda
- level0
;
1200 samp
->level
= level0
;
1201 img_filter_2d_linear_repeat_POT( tgsi_sampler
, s
, t
, p
, 0, rgba0
);
1203 samp
->level
= level0
+1;
1204 img_filter_2d_linear_repeat_POT( tgsi_sampler
, s
, t
, p
, 0, rgba1
);
1206 for (j
= 0; j
< QUAD_SIZE
; j
++) {
1207 for (c
= 0; c
< 4; c
++) {
1208 rgba
[c
][j
] = lerp(levelBlend
, rgba0
[c
][j
], rgba1
[c
][j
]);
1216 /* Compare stage in the little sampling pipeline.
1219 sample_compare(struct tgsi_sampler
*tgsi_sampler
,
1220 const float s
[QUAD_SIZE
],
1221 const float t
[QUAD_SIZE
],
1222 const float p
[QUAD_SIZE
],
1224 float rgba
[NUM_CHANNELS
][QUAD_SIZE
])
1226 struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
1227 const struct pipe_sampler_state
*sampler
= samp
->sampler
;
1228 int j
, k0
, k1
, k2
, k3
;
1231 samp
->mip_filter( tgsi_sampler
, s
, t
, p
, lodbias
, rgba
);
1235 * Compare texcoord 'p' (aka R) against texture value 'rgba[0]'
1236 * When we sampled the depth texture, the depth value was put into all
1237 * RGBA channels. We look at the red channel here.
1240 /* compare four texcoords vs. four texture samples */
1241 switch (sampler
->compare_func
) {
1242 case PIPE_FUNC_LESS
:
1243 k0
= p
[0] < rgba
[0][0];
1244 k1
= p
[1] < rgba
[0][1];
1245 k2
= p
[2] < rgba
[0][2];
1246 k3
= p
[3] < rgba
[0][3];
1248 case PIPE_FUNC_LEQUAL
:
1249 k0
= p
[0] <= rgba
[0][0];
1250 k1
= p
[1] <= rgba
[0][1];
1251 k2
= p
[2] <= rgba
[0][2];
1252 k3
= p
[3] <= rgba
[0][3];
1254 case PIPE_FUNC_GREATER
:
1255 k0
= p
[0] > rgba
[0][0];
1256 k1
= p
[1] > rgba
[0][1];
1257 k2
= p
[2] > rgba
[0][2];
1258 k3
= p
[3] > rgba
[0][3];
1260 case PIPE_FUNC_GEQUAL
:
1261 k0
= p
[0] >= rgba
[0][0];
1262 k1
= p
[1] >= rgba
[0][1];
1263 k2
= p
[2] >= rgba
[0][2];
1264 k3
= p
[3] >= rgba
[0][3];
1266 case PIPE_FUNC_EQUAL
:
1267 k0
= p
[0] == rgba
[0][0];
1268 k1
= p
[1] == rgba
[0][1];
1269 k2
= p
[2] == rgba
[0][2];
1270 k3
= p
[3] == rgba
[0][3];
1272 case PIPE_FUNC_NOTEQUAL
:
1273 k0
= p
[0] != rgba
[0][0];
1274 k1
= p
[1] != rgba
[0][1];
1275 k2
= p
[2] != rgba
[0][2];
1276 k3
= p
[3] != rgba
[0][3];
1278 case PIPE_FUNC_ALWAYS
:
1279 k0
= k1
= k2
= k3
= 1;
1281 case PIPE_FUNC_NEVER
:
1282 k0
= k1
= k2
= k3
= 0;
1285 k0
= k1
= k2
= k3
= 0;
1290 /* convert four pass/fail values to an intensity in [0,1] */
1291 val
= 0.25F
* (k0
+ k1
+ k2
+ k3
);
1293 /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */
1294 for (j
= 0; j
< 4; j
++) {
1295 rgba
[0][j
] = rgba
[1][j
] = rgba
[2][j
] = val
;
1300 /* Calculate cube faces.
1303 sample_cube(struct tgsi_sampler
*tgsi_sampler
,
1304 const float s
[QUAD_SIZE
],
1305 const float t
[QUAD_SIZE
],
1306 const float p
[QUAD_SIZE
],
1308 float rgba
[NUM_CHANNELS
][QUAD_SIZE
])
1310 struct sp_sampler_varient
*samp
= sp_sampler_varient(tgsi_sampler
);
1312 float ssss
[4], tttt
[4];
1316 direction target sc tc ma
1317 ---------- ------------------------------- --- --- ---
1318 +rx TEXTURE_CUBE_MAP_POSITIVE_X_EXT -rz -ry rx
1319 -rx TEXTURE_CUBE_MAP_NEGATIVE_X_EXT +rz -ry rx
1320 +ry TEXTURE_CUBE_MAP_POSITIVE_Y_EXT +rx +rz ry
1321 -ry TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT +rx -rz ry
1322 +rz TEXTURE_CUBE_MAP_POSITIVE_Z_EXT +rx -ry rz
1323 -rz TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT -rx -ry rz
1325 for (j
= 0; j
< QUAD_SIZE
; j
++) {
1329 const float arx
= fabsf(rx
), ary
= fabsf(ry
), arz
= fabsf(rz
);
1333 if (arx
> ary
&& arx
> arz
) {
1335 face
= PIPE_TEX_FACE_POS_X
;
1341 face
= PIPE_TEX_FACE_NEG_X
;
1347 else if (ary
> arx
&& ary
> arz
) {
1349 face
= PIPE_TEX_FACE_POS_Y
;
1355 face
= PIPE_TEX_FACE_NEG_Y
;
1363 face
= PIPE_TEX_FACE_POS_Z
;
1369 face
= PIPE_TEX_FACE_NEG_Z
;
1376 ssss
[j
] = ( sc
/ ma
+ 1.0F
) * 0.5F
;
1377 tttt
[j
] = ( tc
/ ma
+ 1.0F
) * 0.5F
;
1378 samp
->faces
[j
] = face
;
1381 /* In our little pipeline, the compare stage is next. If compare
1382 * is not active, this will point somewhere deeper into the
1383 * pipeline, eg. to mip_filter or even img_filter.
1385 samp
->compare(tgsi_sampler
, ssss
, tttt
, NULL
, lodbias
, rgba
);
1391 static wrap_nearest_func
get_nearest_unorm_wrap( unsigned mode
)
1394 case PIPE_TEX_WRAP_CLAMP
:
1395 return wrap_nearest_unorm_clamp
;
1396 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
1397 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
1398 return wrap_nearest_unorm_clamp_to_border
;
1401 return wrap_nearest_unorm_clamp
;
1406 static wrap_nearest_func
get_nearest_wrap( unsigned mode
)
1409 case PIPE_TEX_WRAP_REPEAT
:
1410 return wrap_nearest_repeat
;
1411 case PIPE_TEX_WRAP_CLAMP
:
1412 return wrap_nearest_clamp
;
1413 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
1414 return wrap_nearest_clamp_to_edge
;
1415 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
1416 return wrap_nearest_clamp_to_border
;
1417 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
1418 return wrap_nearest_mirror_repeat
;
1419 case PIPE_TEX_WRAP_MIRROR_CLAMP
:
1420 return wrap_nearest_mirror_clamp
;
1421 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
:
1422 return wrap_nearest_mirror_clamp_to_edge
;
1423 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
:
1424 return wrap_nearest_mirror_clamp_to_border
;
1427 return wrap_nearest_repeat
;
1431 static wrap_linear_func
get_linear_unorm_wrap( unsigned mode
)
1434 case PIPE_TEX_WRAP_CLAMP
:
1435 return wrap_linear_unorm_clamp
;
1436 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
1437 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
1438 return wrap_linear_unorm_clamp_to_border
;
1441 return wrap_linear_unorm_clamp
;
1445 static wrap_linear_func
get_linear_wrap( unsigned mode
)
1448 case PIPE_TEX_WRAP_REPEAT
:
1449 return wrap_linear_repeat
;
1450 case PIPE_TEX_WRAP_CLAMP
:
1451 return wrap_linear_clamp
;
1452 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
1453 return wrap_linear_clamp_to_edge
;
1454 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
1455 return wrap_linear_clamp_to_border
;
1456 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
1457 return wrap_linear_mirror_repeat
;
1458 case PIPE_TEX_WRAP_MIRROR_CLAMP
:
1459 return wrap_linear_mirror_clamp
;
1460 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
:
1461 return wrap_linear_mirror_clamp_to_edge
;
1462 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
:
1463 return wrap_linear_mirror_clamp_to_border
;
1466 return wrap_linear_repeat
;
1470 static compute_lambda_func
get_lambda_func( const union sp_sampler_key key
)
1472 if (key
.bits
.processor
== TGSI_PROCESSOR_VERTEX
)
1473 return compute_lambda_vert
;
1475 switch (key
.bits
.target
) {
1476 case PIPE_TEXTURE_1D
:
1477 return compute_lambda_1d
;
1478 case PIPE_TEXTURE_2D
:
1479 case PIPE_TEXTURE_CUBE
:
1480 return compute_lambda_2d
;
1481 case PIPE_TEXTURE_3D
:
1482 return compute_lambda_3d
;
1485 return compute_lambda_1d
;
1489 static filter_func
get_img_filter( const union sp_sampler_key key
,
1491 const struct pipe_sampler_state
*sampler
)
1493 switch (key
.bits
.target
) {
1494 case PIPE_TEXTURE_1D
:
1495 if (filter
== PIPE_TEX_FILTER_NEAREST
)
1496 return img_filter_1d_nearest
;
1498 return img_filter_1d_linear
;
1500 case PIPE_TEXTURE_2D
:
1501 /* Try for fast path:
1503 if (key
.bits
.is_pot
&&
1504 sampler
->wrap_s
== sampler
->wrap_t
&&
1505 sampler
->normalized_coords
)
1507 switch (sampler
->wrap_s
) {
1508 case PIPE_TEX_WRAP_REPEAT
:
1510 case PIPE_TEX_FILTER_NEAREST
:
1511 return img_filter_2d_nearest_repeat_POT
;
1512 case PIPE_TEX_FILTER_LINEAR
:
1513 return img_filter_2d_linear_repeat_POT
;
1518 case PIPE_TEX_WRAP_CLAMP
:
1520 case PIPE_TEX_FILTER_NEAREST
:
1521 return img_filter_2d_nearest_clamp_POT
;
1527 /* Fallthrough to default versions:
1529 case PIPE_TEXTURE_CUBE
:
1530 if (filter
== PIPE_TEX_FILTER_NEAREST
)
1531 return img_filter_2d_nearest
;
1533 return img_filter_2d_linear
;
1535 case PIPE_TEXTURE_3D
:
1536 if (filter
== PIPE_TEX_FILTER_NEAREST
)
1537 return img_filter_3d_nearest
;
1539 return img_filter_3d_linear
;
1543 return img_filter_1d_nearest
;
1549 sp_sampler_varient_bind_texture( struct sp_sampler_varient
*samp
,
1550 struct softpipe_tile_cache
*tex_cache
,
1551 const struct pipe_texture
*texture
)
1553 const struct pipe_sampler_state
*sampler
= samp
->sampler
;
1555 samp
->texture
= texture
;
1556 samp
->cache
= tex_cache
;
1557 samp
->xpot
= util_unsigned_logbase2( texture
->width
[0] );
1558 samp
->ypot
= util_unsigned_logbase2( texture
->height
[0] );
1559 samp
->level
= CLAMP((int) sampler
->min_lod
, 0, (int) texture
->last_level
);
1564 sp_sampler_varient_destroy( struct sp_sampler_varient
*samp
)
1570 /* Create a sampler varient for a given set of non-orthogonal state. Currently the
1572 struct sp_sampler_varient
*
1573 sp_create_sampler_varient( const struct pipe_sampler_state
*sampler
,
1574 const union sp_sampler_key key
)
1576 struct sp_sampler_varient
*samp
= CALLOC_STRUCT(sp_sampler_varient
);
1580 samp
->sampler
= sampler
;
1583 /* Note that (for instance) linear_texcoord_s and
1584 * nearest_texcoord_s may be active at the same time, if the
1585 * sampler min_img_filter differs from its mag_img_filter.
1587 if (sampler
->normalized_coords
) {
1588 samp
->linear_texcoord_s
= get_linear_wrap( sampler
->wrap_s
);
1589 samp
->linear_texcoord_t
= get_linear_wrap( sampler
->wrap_t
);
1590 samp
->linear_texcoord_p
= get_linear_wrap( sampler
->wrap_r
);
1592 samp
->nearest_texcoord_s
= get_nearest_wrap( sampler
->wrap_s
);
1593 samp
->nearest_texcoord_t
= get_nearest_wrap( sampler
->wrap_t
);
1594 samp
->nearest_texcoord_p
= get_nearest_wrap( sampler
->wrap_r
);
1597 samp
->linear_texcoord_s
= get_linear_unorm_wrap( sampler
->wrap_s
);
1598 samp
->linear_texcoord_t
= get_linear_unorm_wrap( sampler
->wrap_t
);
1599 samp
->linear_texcoord_p
= get_linear_unorm_wrap( sampler
->wrap_r
);
1601 samp
->nearest_texcoord_s
= get_nearest_unorm_wrap( sampler
->wrap_s
);
1602 samp
->nearest_texcoord_t
= get_nearest_unorm_wrap( sampler
->wrap_t
);
1603 samp
->nearest_texcoord_p
= get_nearest_unorm_wrap( sampler
->wrap_r
);
1606 samp
->compute_lambda
= get_lambda_func( key
);
1608 samp
->min_img_filter
= get_img_filter(key
, sampler
->min_img_filter
, sampler
);
1609 samp
->mag_img_filter
= get_img_filter(key
, sampler
->mag_img_filter
, sampler
);
1611 switch (sampler
->min_mip_filter
) {
1612 case PIPE_TEX_MIPFILTER_NONE
:
1613 if (sampler
->min_img_filter
== sampler
->mag_img_filter
)
1614 samp
->mip_filter
= samp
->min_img_filter
;
1616 samp
->mip_filter
= mip_filter_none
;
1619 case PIPE_TEX_MIPFILTER_NEAREST
:
1620 samp
->mip_filter
= mip_filter_nearest
;
1623 case PIPE_TEX_MIPFILTER_LINEAR
:
1624 if (key
.bits
.is_pot
&&
1625 sampler
->min_img_filter
== sampler
->mag_img_filter
&&
1626 sampler
->normalized_coords
&&
1627 sampler
->wrap_s
== PIPE_TEX_WRAP_REPEAT
&&
1628 sampler
->wrap_t
== PIPE_TEX_WRAP_REPEAT
&&
1629 sampler
->min_img_filter
== PIPE_TEX_FILTER_LINEAR
)
1631 samp
->mip_filter
= mip_filter_linear_2d_linear_repeat_POT
;
1635 samp
->mip_filter
= mip_filter_linear
;
1640 if (sampler
->compare_mode
!= FALSE
) {
1641 samp
->compare
= sample_compare
;
1644 /* Skip compare operation by promoting the mip_filter function
1647 samp
->compare
= samp
->mip_filter
;
1650 if (key
.bits
.target
== PIPE_TEXTURE_CUBE
) {
1651 samp
->base
.get_samples
= sample_cube
;
1659 /* Skip cube face determination by promoting the compare
1662 samp
->base
.get_samples
= samp
->compare
;