#include "sp_tile_cache.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
+#include "pipe/p_shader_tokens.h"
#include "util/u_math.h"
#include "util/u_memory.h"
* This is only done for fragment shaders, not vertex shaders.
*/
static float
-compute_lambda(const struct pipe_texture *tex,
- const struct pipe_sampler_state *sampler,
+compute_lambda(struct tgsi_sampler *tgsi_sampler,
const float s[QUAD_SIZE],
const float t[QUAD_SIZE],
const float p[QUAD_SIZE],
float lodbias)
{
+ const struct sp_shader_sampler *samp = sp_shader_sampler(tgsi_sampler);
+ const struct pipe_texture *texture = samp->texture;
+ const struct pipe_sampler_state *sampler = samp->sampler;
float rho, lambda;
+ if (samp->processor == TGSI_PROCESSOR_VERTEX)
+ return lodbias;
+
assert(sampler->normalized_coords);
assert(s);
float dsdy = s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT];
dsdx = fabsf(dsdx);
dsdy = fabsf(dsdy);
- rho = MAX2(dsdx, dsdy) * tex->width[0];
+ rho = MAX2(dsdx, dsdy) * texture->width[0];
}
if (t) {
float dtdx = t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT];
float max;
dtdx = fabsf(dtdx);
dtdy = fabsf(dtdy);
- max = MAX2(dtdx, dtdy) * tex->height[0];
+ max = MAX2(dtdx, dtdy) * texture->height[0];
rho = MAX2(rho, max);
}
if (p) {
float max;
dpdx = fabsf(dpdx);
dpdy = fabsf(dpdy);
- max = MAX2(dpdx, dpdy) * tex->depth[0];
+ max = MAX2(dpdx, dpdy) * texture->depth[0];
rho = MAX2(rho, max);
}
* \param imgFilter Returns either the min or mag filter, depending on lambda
*/
static void
-choose_mipmap_levels(const struct pipe_texture *texture,
- const struct pipe_sampler_state *sampler,
+choose_mipmap_levels(struct tgsi_sampler *tgsi_sampler,
const float s[QUAD_SIZE],
const float t[QUAD_SIZE],
const float p[QUAD_SIZE],
- boolean computeLambda,
float lodbias,
unsigned *level0, unsigned *level1, float *levelBlend,
unsigned *imgFilter)
{
+ const struct sp_shader_sampler *samp = sp_shader_sampler(tgsi_sampler);
+ const struct pipe_texture *texture = samp->texture;
+ const struct pipe_sampler_state *sampler = samp->sampler;
+
if (sampler->min_mip_filter == PIPE_TEX_MIPFILTER_NONE) {
/* no mipmap selection needed */
*level0 = *level1 = CLAMP((int) sampler->min_lod,
/* non-mipmapped texture, but still need to determine if doing
* minification or magnification.
*/
- float lambda = compute_lambda(texture, sampler, s, t, p, lodbias);
+ float lambda = compute_lambda(tgsi_sampler, s, t, p, lodbias);
if (lambda <= 0.0) {
*imgFilter = sampler->mag_img_filter;
}
}
}
else {
- float lambda;
-
- if (computeLambda)
- /* fragment shader */
- lambda = compute_lambda(texture, sampler, s, t, p, lodbias);
- else
- /* vertex shader */
- lambda = lodbias; /* not really a bias, but absolute LOD */
+ float lambda = compute_lambda(tgsi_sampler, s, t, p, lodbias);
if (lambda <= 0.0) { /* XXX threshold depends on the filter */
/* magnifying */
{
struct sp_shader_sampler *samp = sp_shader_sampler(tgsi_sampler);
const struct pipe_texture *texture = samp->texture;
- const struct pipe_sampler_state *sampler = samp->sampler;
int level0;
float lambda;
- lambda = compute_lambda(texture, sampler, s, t, p, lodbias);
+ lambda = compute_lambda(tgsi_sampler, s, t, p, lodbias);
level0 = (int)lambda;
if (lambda < 0.0) {
* Could probably extend for 3D...
*/
static void
-sp_get_samples_2d_common(const struct tgsi_sampler *tgsi_sampler,
+sp_get_samples_2d_common(struct tgsi_sampler *tgsi_sampler,
const float s[QUAD_SIZE],
const float t[QUAD_SIZE],
const float p[QUAD_SIZE],
- boolean computeLambda,
float lodbias,
float rgba[NUM_CHANNELS][QUAD_SIZE],
const unsigned faces[4])
int width, height;
float levelBlend;
- choose_mipmap_levels(texture, sampler, s, t, p, computeLambda, lodbias,
+ choose_mipmap_levels(tgsi_sampler, s, t, p,
+ lodbias,
&level0, &level1, &levelBlend, &imgFilter);
assert(sampler->normalized_coords);
static INLINE void
-sp_get_samples_1d(const struct tgsi_sampler *sampler,
+sp_get_samples_1d(struct tgsi_sampler *sampler,
const float s[QUAD_SIZE],
const float t[QUAD_SIZE],
const float p[QUAD_SIZE],
- boolean computeLambda,
float lodbias,
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
static const unsigned faces[4] = {0, 0, 0, 0};
static const float tzero[4] = {0, 0, 0, 0};
sp_get_samples_2d_common(sampler, s, tzero, NULL,
- computeLambda, lodbias, rgba, faces);
+ lodbias, rgba, faces);
}
static INLINE void
-sp_get_samples_2d(const struct tgsi_sampler *sampler,
+sp_get_samples_2d(struct tgsi_sampler *sampler,
const float s[QUAD_SIZE],
const float t[QUAD_SIZE],
const float p[QUAD_SIZE],
- boolean computeLambda,
float lodbias,
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
static const unsigned faces[4] = {0, 0, 0, 0};
sp_get_samples_2d_common(sampler, s, t, p,
- computeLambda, lodbias, rgba, faces);
+ lodbias, rgba, faces);
}
static INLINE void
-sp_get_samples_3d(const struct tgsi_sampler *tgsi_sampler,
+sp_get_samples_3d(struct tgsi_sampler *tgsi_sampler,
const float s[QUAD_SIZE],
const float t[QUAD_SIZE],
const float p[QUAD_SIZE],
- boolean computeLambda,
float lodbias,
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
float levelBlend;
const uint face = 0;
- choose_mipmap_levels(texture, sampler, s, t, p, computeLambda, lodbias,
+ choose_mipmap_levels(tgsi_sampler, s, t, p,
+ lodbias,
&level0, &level1, &levelBlend, &imgFilter);
assert(sampler->normalized_coords);
static void
-sp_get_samples_cube(const struct tgsi_sampler *sampler,
+sp_get_samples_cube(struct tgsi_sampler *sampler,
const float s[QUAD_SIZE],
const float t[QUAD_SIZE],
const float p[QUAD_SIZE],
- boolean computeLambda,
float lodbias,
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
faces[j] = choose_cube_face(s[j], t[j], p[j], ssss + j, tttt + j);
}
sp_get_samples_2d_common(sampler, ssss, tttt, NULL,
- computeLambda, lodbias, rgba, faces);
+ lodbias, rgba, faces);
}
static void
-sp_get_samples_rect(const struct tgsi_sampler *tgsi_sampler,
+sp_get_samples_rect(struct tgsi_sampler *tgsi_sampler,
const float s[QUAD_SIZE],
const float t[QUAD_SIZE],
const float p[QUAD_SIZE],
- boolean computeLambda,
float lodbias,
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
int width, height;
float levelBlend;
- choose_mipmap_levels(texture, sampler, s, t, p, computeLambda, lodbias,
+ choose_mipmap_levels(tgsi_sampler, s, t, p,
+ lodbias,
&level0, &level1, &levelBlend, &imgFilter);
/* texture RECTS cannot be mipmapped */
/**
- * Common code for vertex/fragment program texture sampling.
+ * Error condition handler
*/
static INLINE void
+sp_get_samples_null(struct tgsi_sampler *tgsi_sampler,
+ const float s[QUAD_SIZE],
+ const float t[QUAD_SIZE],
+ const float p[QUAD_SIZE],
+ float lodbias,
+ float rgba[NUM_CHANNELS][QUAD_SIZE])
+{
+ int i,j;
+
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 4; j++)
+ rgba[i][j] = 1.0;
+}
+
+/**
+ * Called via tgsi_sampler::get_samples() when using a sampler for the
+ * first time. Determine the actual sampler function, link it in and
+ * call it.
+ */
+void
sp_get_samples(struct tgsi_sampler *tgsi_sampler,
const float s[QUAD_SIZE],
const float t[QUAD_SIZE],
const float p[QUAD_SIZE],
- boolean computeLambda,
float lodbias,
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
- const struct sp_shader_sampler *samp = sp_shader_sampler(tgsi_sampler);
+ struct sp_shader_sampler *samp = sp_shader_sampler(tgsi_sampler);
const struct pipe_texture *texture = samp->texture;
const struct pipe_sampler_state *sampler = samp->sampler;
- if (!texture)
- return;
+ /* Default to the 'undefined' case:
+ */
+ tgsi_sampler->get_samples = sp_get_samples_null;
+
+ if (!texture) {
+ assert(0); /* is this legal?? */
+ goto out;
+ }
+
+ if (!sampler->normalized_coords) {
+ assert (texture->target == PIPE_TEXTURE_2D);
+ tgsi_sampler->get_samples = sp_get_samples_rect;
+ goto out;
+ }
switch (texture->target) {
case PIPE_TEXTURE_1D:
- assert(sampler->normalized_coords);
- sp_get_samples_1d(tgsi_sampler, s, t, p, computeLambda, lodbias, rgba);
+ tgsi_sampler->get_samples = sp_get_samples_1d;
break;
case PIPE_TEXTURE_2D:
- if (sampler->normalized_coords)
- sp_get_samples_2d(tgsi_sampler, s, t, p, computeLambda, lodbias, rgba);
- else
- sp_get_samples_rect(tgsi_sampler, s, t, p, computeLambda, lodbias, rgba);
+ tgsi_sampler->get_samples = sp_get_samples_2d;
break;
case PIPE_TEXTURE_3D:
- assert(sampler->normalized_coords);
- sp_get_samples_3d(tgsi_sampler, s, t, p, computeLambda, lodbias, rgba);
+ tgsi_sampler->get_samples = sp_get_samples_3d;
break;
case PIPE_TEXTURE_CUBE:
- assert(sampler->normalized_coords);
- sp_get_samples_cube(tgsi_sampler, s, t, p, computeLambda, lodbias, rgba);
+ tgsi_sampler->get_samples = sp_get_samples_cube;
break;
default:
assert(0);
+ break;
}
-#if 0 /* DEBUG */
- {
- int i;
- printf("Sampled at %f, %f, %f:\n", s[0], t[0], p[0]);
- for (i = 0; i < 4; i++) {
- printf("Frag %d: %f %f %f %f\n", i,
- rgba[0][i],
- rgba[1][i],
- rgba[2][i],
- rgba[3][i]);
- }
- }
-#endif
-}
-
-static void
-sp_get_samples_fallback(struct tgsi_sampler *tgsi_sampler,
- const float s[QUAD_SIZE],
- const float t[QUAD_SIZE],
- const float p[QUAD_SIZE],
- float lodbias,
- float rgba[NUM_CHANNELS][QUAD_SIZE])
-{
- sp_get_samples(tgsi_sampler, s, t, p, TRUE, lodbias, rgba);
-}
-
-/**
- * Called via tgsi_sampler::get_samples() when running a fragment shader.
- * Get four filtered RGBA values from the sampler's texture.
- */
-void
-sp_get_samples_fragment(struct tgsi_sampler *tgsi_sampler,
- const float s[QUAD_SIZE],
- const float t[QUAD_SIZE],
- const float p[QUAD_SIZE],
- float lodbias,
- float rgba[NUM_CHANNELS][QUAD_SIZE])
-{
- struct sp_shader_sampler *samp = sp_shader_sampler(tgsi_sampler);
- const struct pipe_texture *texture = samp->texture;
- const struct pipe_sampler_state *sampler = samp->sampler;
-
- tgsi_sampler->get_samples = sp_get_samples_fallback;
+ /* Do this elsewhere:
+ */
+ samp->xpot = util_unsigned_logbase2( samp->texture->width[0] );
+ samp->ypot = util_unsigned_logbase2( samp->texture->height[0] );
/* Try to hook in a faster sampler. Ultimately we'll have to
* code-generate these. Luckily most of this looks like it is
sampler->compare_mode == FALSE &&
sampler->normalized_coords)
{
- samp->xpot = util_unsigned_logbase2( samp->texture->width[0] );
- samp->ypot = util_unsigned_logbase2( samp->texture->height[0] );
-
if (sampler->min_mip_filter == PIPE_TEX_MIPFILTER_NONE) {
samp->level = CLAMP((int) sampler->min_lod,
0, (int) texture->last_level);
sampler->normalized_coords, TRUE);
}
+out:
tgsi_sampler->get_samples( tgsi_sampler, s, t, p, lodbias, rgba );
}
-
-/**
- * Called via tgsi_sampler::get_samples() when running a vertex shader.
- * Get four filtered RGBA values from the sampler's texture.
- */
-void
-sp_get_samples_vertex(struct tgsi_sampler *tgsi_sampler,
- const float s[QUAD_SIZE],
- const float t[QUAD_SIZE],
- const float p[QUAD_SIZE],
- float lodbias,
- float rgba[NUM_CHANNELS][QUAD_SIZE])
-{
- sp_get_samples(tgsi_sampler, s, t, p, FALSE, lodbias, rgba);
-}