summaryrefslogtreecommitdiff
path: root/src/gallium
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2010-04-26 00:32:13 +0100
committerJosé Fonseca <jfonseca@vmware.com>2010-04-26 00:32:13 +0100
commit81ab19de04e623d24cb65ad1ed3b240bce78235b (patch)
treefcaa6062dafa37eedd6ac190233d3e4d7c100240 /src/gallium
parent4dd1a568404dcf068cb111db04bb6e904b91d7bd (diff)
llvmpipe: Respect pipe_sampler_view::swizzle_r/g/b/a
This allows u_sampler_view_default_dx9_template to do its magic on DX9.
Diffstat (limited to 'src/gallium')
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_sample.c5
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_sample.h8
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c51
3 files changed, 63 insertions, 1 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c
index e1b029a879..195a4953ab 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c
@@ -77,6 +77,11 @@ lp_sampler_static_state(struct lp_sampler_static_state *state,
*/
state->format = view->format;
+ state->swizzle_r = view->swizzle_r;
+ state->swizzle_g = view->swizzle_g;
+ state->swizzle_b = view->swizzle_b;
+ state->swizzle_a = view->swizzle_a;
+
state->target = texture->target;
state->pot_width = util_is_pot(texture->width0);
state->pot_height = util_is_pot(texture->height0);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h
index e287376385..8ceb20473d 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h
@@ -54,8 +54,14 @@ struct lp_build_context;
*/
struct lp_sampler_static_state
{
- /* pipe_texture's state */
+ /* pipe_sampler_view's state */
enum pipe_format format;
+ unsigned swizzle_r:3;
+ unsigned swizzle_g:3;
+ unsigned swizzle_b:3;
+ unsigned swizzle_a:3;
+
+ /* pipe_texture's state */
unsigned target:3;
unsigned pot_width:1;
unsigned pot_height:1;
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
index 415346c15f..54ef921678 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
@@ -185,6 +185,53 @@ texture_dims(enum pipe_texture_target tex)
}
+static LLVMValueRef
+lp_build_swizzle_chan_soa(struct lp_type type,
+ const LLVMValueRef *unswizzled,
+ enum util_format_swizzle swizzle)
+{
+ switch (swizzle) {
+ case PIPE_SWIZZLE_RED:
+ case PIPE_SWIZZLE_GREEN:
+ case PIPE_SWIZZLE_BLUE:
+ case PIPE_SWIZZLE_ALPHA:
+ return unswizzled[swizzle];
+ case PIPE_SWIZZLE_ZERO:
+ return lp_build_zero(type);
+ case PIPE_SWIZZLE_ONE:
+ return lp_build_one(type);
+ default:
+ assert(0);
+ return lp_build_undef(type);
+ }
+}
+
+
+static void
+lp_build_swizzle_soa(struct lp_build_sample_context *bld,
+ LLVMValueRef *texel)
+{
+ LLVMValueRef unswizzled[4];
+ unsigned char swizzles[4];
+ unsigned chan;
+
+ for (chan = 0; chan < 4; ++chan) {
+ unswizzled[chan] = texel[chan];
+ }
+
+ swizzles[0] = bld->static_state->swizzle_r;
+ swizzles[1] = bld->static_state->swizzle_g;
+ swizzles[2] = bld->static_state->swizzle_b;
+ swizzles[3] = bld->static_state->swizzle_a;
+
+ for (chan = 0; chan < 4; ++chan) {
+ unsigned swizzle = swizzles[chan];
+ texel[chan] = lp_build_swizzle_chan_soa(bld->texel_type,
+ unswizzled, swizzle);
+ }
+}
+
+
/**
* Generate code to fetch a texel from a texture at int coords (x, y, z).
@@ -285,6 +332,8 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
i, j,
texel);
+ lp_build_swizzle_soa(bld, texel);
+
/*
* Note: if we find an app which frequently samples the texture border
* we might want to implement a true conditional here to avoid sampling
@@ -1954,6 +2003,8 @@ lp_build_sample_2d_linear_aos(struct lp_build_sample_context *bld,
lp_build_format_swizzle_soa(bld->format_desc,
bld->texel_type, unswizzled,
texel);
+
+ lp_build_swizzle_soa(bld, texel);
}