summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/gallivm
diff options
context:
space:
mode:
authorFabian Bieler <[email protected]>2011-03-31 12:32:52 +0200
committerMarek Olšák <[email protected]>2011-04-08 04:47:04 +0200
commit08070cead0bb79d4441d8c5b900d1571bb63c670 (patch)
treee0d48b89d5defed950110c757463621db43724fc /src/gallium/auxiliary/gallivm
parent9acdd7739b729375444f8669fc2419d9eb57acc5 (diff)
llvmpipe: Take the sampler view's first_level into account when sampling.
Diffstat (limited to 'src/gallium/auxiliary/gallivm')
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_sample.c54
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_sample.h6
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c7
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c7
4 files changed, 50 insertions, 24 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c
index 8ad34598a92..4636371a0f5 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c
@@ -51,6 +51,10 @@
*/
#define BRILINEAR_FACTOR 2
+static LLVMValueRef
+lp_build_minify(struct lp_build_context *bld,
+ LLVMValueRef base_size,
+ LLVMValueRef level);
/**
* Does the given texture wrap mode allow sampling the texture border color?
@@ -184,9 +188,11 @@ lp_sampler_static_state(struct lp_sampler_static_state *state,
*/
static LLVMValueRef
lp_build_rho(struct lp_build_sample_context *bld,
+ unsigned unit,
const LLVMValueRef ddx[4],
const LLVMValueRef ddy[4])
{
+ struct lp_build_context *int_size_bld = &bld->int_size_bld;
struct lp_build_context *float_size_bld = &bld->float_size_bld;
struct lp_build_context *float_bld = &bld->float_bld;
const unsigned dims = bld->dims;
@@ -198,8 +204,9 @@ lp_build_rho(struct lp_build_sample_context *bld,
LLVMValueRef dsdx, dsdy, dtdx, dtdy, drdx, drdy;
LLVMValueRef rho_x, rho_y;
LLVMValueRef rho_vec;
- LLVMValueRef float_size;
+ LLVMValueRef int_size, float_size;
LLVMValueRef rho;
+ LLVMValueRef first_level, first_level_vec;
dsdx = ddx[0];
dsdy = ddy[0];
@@ -235,7 +242,11 @@ lp_build_rho(struct lp_build_sample_context *bld,
rho_vec = lp_build_max(float_size_bld, rho_x, rho_y);
- float_size = lp_build_int_to_float(float_size_bld, bld->int_size);
+ first_level = bld->dynamic_state->first_level(bld->dynamic_state,
+ bld->gallivm, unit);
+ first_level_vec = lp_build_broadcast_scalar(&bld->int_size_bld, first_level);
+ int_size = lp_build_minify(int_size_bld, bld->int_size, first_level_vec);
+ float_size = lp_build_int_to_float(float_size_bld, int_size);
rho_vec = lp_build_mul(float_size_bld, rho_vec, float_size);
@@ -442,7 +453,7 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
else {
LLVMValueRef rho;
- rho = lp_build_rho(bld, ddx, ddy);
+ rho = lp_build_rho(bld, unit, ddx, ddy);
/*
* Compute lod = log2(rho)
@@ -542,18 +553,18 @@ lp_build_nearest_mip_level(struct lp_build_sample_context *bld,
LLVMValueRef *level_out)
{
struct lp_build_context *int_bld = &bld->int_bld;
- LLVMValueRef last_level, level;
-
- LLVMValueRef zero = lp_build_const_int32(bld->gallivm, 0);
+ LLVMValueRef first_level, last_level, level;
+ first_level = bld->dynamic_state->first_level(bld->dynamic_state,
+ bld->gallivm, unit);
last_level = bld->dynamic_state->last_level(bld->dynamic_state,
bld->gallivm, unit);
/* convert float lod to integer */
- level = lod_ipart;
+ level = lp_build_add(int_bld, lod_ipart, first_level);
/* clamp level to legal range of levels */
- *level_out = lp_build_clamp(int_bld, level, zero, last_level);
+ *level_out = lp_build_clamp(int_bld, level, first_level, last_level);
}
@@ -573,39 +584,42 @@ lp_build_linear_mip_levels(struct lp_build_sample_context *bld,
LLVMBuilderRef builder = bld->gallivm->builder;
struct lp_build_context *int_bld = &bld->int_bld;
struct lp_build_context *float_bld = &bld->float_bld;
- LLVMValueRef last_level;
+ LLVMValueRef first_level, last_level;
LLVMValueRef clamp_min;
LLVMValueRef clamp_max;
- *level0_out = lod_ipart;
- *level1_out = lp_build_add(int_bld, lod_ipart, int_bld->one);
+ first_level = bld->dynamic_state->first_level(bld->dynamic_state,
+ bld->gallivm, unit);
+
+ *level0_out = lp_build_add(int_bld, lod_ipart, first_level);
+ *level1_out = lp_build_add(int_bld, *level0_out, int_bld->one);
last_level = bld->dynamic_state->last_level(bld->dynamic_state,
bld->gallivm, unit);
/*
- * Clamp both lod_ipart and lod_ipart + 1 to [0, last_level], with the
- * minimum number of comparisons, and zeroing lod_fpart in the extreme
+ * Clamp both *level0_out and *level1_out to [first_level, last_level], with
+ * the minimum number of comparisons, and zeroing lod_fpart in the extreme
* ends in the process.
*/
- /* lod_ipart < 0 */
+ /* *level0_out < first_level */
clamp_min = LLVMBuildICmp(builder, LLVMIntSLT,
- lod_ipart, int_bld->zero,
- "clamp_lod_to_zero");
+ *level0_out, first_level,
+ "clamp_lod_to_first");
*level0_out = LLVMBuildSelect(builder, clamp_min,
- int_bld->zero, *level0_out, "");
+ first_level, *level0_out, "");
*level1_out = LLVMBuildSelect(builder, clamp_min,
- int_bld->zero, *level1_out, "");
+ first_level, *level1_out, "");
*lod_fpart_inout = LLVMBuildSelect(builder, clamp_min,
float_bld->zero, *lod_fpart_inout, "");
- /* lod_ipart >= last_level */
+ /* *level0_out >= last_level */
clamp_max = LLVMBuildICmp(builder, LLVMIntSGE,
- lod_ipart, last_level,
+ *level0_out, last_level,
"clamp_lod_to_last");
*level0_out = LLVMBuildSelect(builder, clamp_max,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h
index 8c9d5df4e43..a71e656fe0e 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h
@@ -120,6 +120,12 @@ struct lp_sampler_dynamic_state
struct gallivm_state *gallivm,
unsigned unit);
+ /** Obtain the first mipmap level (base level) (returns int32) */
+ LLVMValueRef
+ (*first_level)( const struct lp_sampler_dynamic_state *state,
+ struct gallivm_state *gallivm,
+ unsigned unit);
+
/** Obtain the number of mipmap levels minus one (returns int32) */
LLVMValueRef
(*last_level)( const struct lp_sampler_dynamic_state *state,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c
index e61cf9541ea..4f160159968 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c
@@ -939,6 +939,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
LLVMValueRef unswizzled[4];
LLVMValueRef face_ddx[4], face_ddy[4];
struct lp_build_context h16_bld;
+ LLVMValueRef first_level;
LLVMValueRef i32t_zero = lp_build_const_int32(bld->gallivm, 0);
/* we only support the common/simple wrap modes at this time */
@@ -1008,7 +1009,9 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
lp_build_nearest_mip_level(bld, unit, lod_ipart, &ilevel0);
}
else {
- ilevel0 = i32t_zero;
+ first_level = bld->dynamic_state->first_level(bld->dynamic_state,
+ bld->gallivm, unit);
+ ilevel0 = first_level;
}
break;
case PIPE_TEX_MIPFILTER_NEAREST:
@@ -1065,7 +1068,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
lp_build_sample_mipmap(bld,
mag_filter, PIPE_TEX_MIPFILTER_NONE,
s, t, r,
- i32t_zero, NULL, NULL,
+ ilevel0, NULL, NULL,
packed_lo, packed_hi);
}
lp_build_endif(&if_ctx);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
index 9961ba08f3a..4ea7b4bd8a2 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
@@ -943,6 +943,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld,
LLVMValueRef ilevel0, ilevel1 = NULL;
LLVMValueRef face_ddx[4], face_ddy[4];
LLVMValueRef texels[4];
+ LLVMValueRef first_level;
LLVMValueRef i32t_zero = lp_build_const_int32(bld->gallivm, 0);
unsigned chan;
@@ -1009,7 +1010,9 @@ lp_build_sample_general(struct lp_build_sample_context *bld,
lp_build_nearest_mip_level(bld, unit, lod_ipart, &ilevel0);
}
else {
- ilevel0 = i32t_zero;
+ first_level = bld->dynamic_state->first_level(bld->dynamic_state,
+ bld->gallivm, unit);
+ ilevel0 = first_level;
}
break;
case PIPE_TEX_MIPFILTER_NEAREST:
@@ -1068,7 +1071,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld,
lp_build_sample_mipmap(bld, unit,
mag_filter, PIPE_TEX_MIPFILTER_NONE,
s, t, r,
- i32t_zero, NULL, NULL,
+ ilevel0, NULL, NULL,
texels);
}
lp_build_endif(&if_ctx);