gallivm: fix lp_build_sample_compare()

The old code didn't really make sense.  We only need to compare the
X channel of the texture (depth) against the texcoord.

For (bi)linear sampling we should move the calls to this function
and compute the final result as (s1+s2+s3+s4) * 0.25.  Someday.

This fixes the glean glsl1 shadow2D() tests.  See fd.o bug 29307.
This commit is contained in:
Brian Paul 2010-09-21 15:25:31 -06:00
parent 83ea4878db
commit ffa2d203fb

View file

@ -47,6 +47,7 @@
#include "lp_bld_arit.h" #include "lp_bld_arit.h"
#include "lp_bld_bitarit.h" #include "lp_bld_bitarit.h"
#include "lp_bld_logic.h" #include "lp_bld_logic.h"
#include "lp_bld_printf.h"
#include "lp_bld_swizzle.h" #include "lp_bld_swizzle.h"
#include "lp_bld_flow.h" #include "lp_bld_flow.h"
#include "lp_bld_gather.h" #include "lp_bld_gather.h"
@ -1057,6 +1058,11 @@ lp_build_sample_general(struct lp_build_sample_context *bld,
} }
/**
* Do shadow test/comparison.
* \param p the texcoord Z (aka R, aka P) component
* \param texel the texel to compare against (use the X channel)
*/
static void static void
lp_build_sample_compare(struct lp_build_sample_context *bld, lp_build_sample_compare(struct lp_build_sample_context *bld,
LLVMValueRef p, LLVMValueRef p,
@ -1064,30 +1070,30 @@ lp_build_sample_compare(struct lp_build_sample_context *bld,
{ {
struct lp_build_context *texel_bld = &bld->texel_bld; struct lp_build_context *texel_bld = &bld->texel_bld;
LLVMValueRef res; LLVMValueRef res;
unsigned chan; const unsigned chan = 0;
if(bld->static_state->compare_mode == PIPE_TEX_COMPARE_NONE) if (bld->static_state->compare_mode == PIPE_TEX_COMPARE_NONE)
return; return;
/* TODO: Compare before swizzling, to avoid redundant computations */ /* debug code */
res = NULL; if (0) {
for(chan = 0; chan < 4; ++chan) { LLVMValueRef indx = lp_build_const_int32(0);
LLVMValueRef cmp; LLVMValueRef coord = LLVMBuildExtractElement(bld->builder, p, indx, "");
cmp = lp_build_cmp(texel_bld, bld->static_state->compare_func, p, texel[chan]); LLVMValueRef tex = LLVMBuildExtractElement(bld->builder,
cmp = lp_build_select(texel_bld, cmp, texel_bld->one, texel_bld->zero); texel[chan], indx, "");
lp_build_printf(bld->builder, "shadow compare coord %f to texture %f\n",
if(res) coord, tex);
res = lp_build_add(texel_bld, res, cmp);
else
res = cmp;
} }
assert(res); /* result = (p FUNC texel) ? 1 : 0 */
res = lp_build_mul(texel_bld, res, lp_build_const_vec(texel_bld->type, 0.25)); res = lp_build_cmp(texel_bld, bld->static_state->compare_func,
p, texel[chan]);
res = lp_build_select(texel_bld, res, texel_bld->one, texel_bld->zero);
/* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */ /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */
for(chan = 0; chan < 3; ++chan) texel[0] =
texel[chan] = res; texel[1] =
texel[2] = res;
texel[3] = texel_bld->one; texel[3] = texel_bld->one;
} }