gallivm: handle texel swizzles correctly for d3d10-style sample opcodes
authorRoland Scheidegger <sroland@vmware.com>
Sat, 27 Jul 2013 14:36:25 +0000 (16:36 +0200)
committerRoland Scheidegger <sroland@vmware.com>
Sat, 27 Jul 2013 14:41:29 +0000 (16:41 +0200)
unlike OpenGL, the texel swizzle is embedded in the instruction, so honor
that.
(Technically we now execute both the sampler_view swizzle and the
per-instruction swizzle but this should be quite ok.)

v2: add documentation note as it's not obvious.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
src/gallium/docs/source/tgsi.rst

index 4355b3a92d11c2c93a2d3fcaffbff64b890c10a4..c199385998cf8d8bd7080f4153a5b2c6fbc1cd4c 100644 (file)
@@ -1859,6 +1859,19 @@ emit_sample(struct lp_build_tgsi_soa_context *bld,
                                   deriv_ptr,
                                   lod_bias, explicit_lod, scalar_lod,
                                   texel);
+
+   if (inst->Src[1].Register.SwizzleX != PIPE_SWIZZLE_RED ||
+       inst->Src[1].Register.SwizzleY != PIPE_SWIZZLE_GREEN ||
+       inst->Src[1].Register.SwizzleZ != PIPE_SWIZZLE_BLUE ||
+       inst->Src[1].Register.SwizzleW != PIPE_SWIZZLE_ALPHA) {
+      unsigned char swizzles[4];
+      swizzles[0] = inst->Src[1].Register.SwizzleX;
+      swizzles[1] = inst->Src[1].Register.SwizzleY;
+      swizzles[2] = inst->Src[1].Register.SwizzleZ;
+      swizzles[3] = inst->Src[1].Register.SwizzleW;
+
+      lp_build_swizzle_soa_inplace(&bld->bld_base.base, texel, swizzles);
+   }
 }
 
 static void
@@ -1954,6 +1967,20 @@ emit_fetch_texels( struct lp_build_tgsi_soa_context *bld,
                                   NULL,
                                   NULL, explicit_lod, scalar_lod,
                                   texel);
+
+   if (is_samplei &&
+       (inst->Src[1].Register.SwizzleX != PIPE_SWIZZLE_RED ||
+        inst->Src[1].Register.SwizzleY != PIPE_SWIZZLE_GREEN ||
+        inst->Src[1].Register.SwizzleZ != PIPE_SWIZZLE_BLUE ||
+        inst->Src[1].Register.SwizzleW != PIPE_SWIZZLE_ALPHA)) {
+      unsigned char swizzles[4];
+      swizzles[0] = inst->Src[1].Register.SwizzleX;
+      swizzles[1] = inst->Src[1].Register.SwizzleY;
+      swizzles[2] = inst->Src[1].Register.SwizzleZ;
+      swizzles[3] = inst->Src[1].Register.SwizzleW;
+
+      lp_build_swizzle_soa_inplace(&bld->bld_base.base, texel, swizzles);
+   }
 }
 
 static void
index 4d26c465579e24238dfb20b8428a1bb79727b0ba..0557ce0f94bf48f54b9c53eb2dc9a77726372124 100644 (file)
@@ -1730,6 +1730,8 @@ Resource Sampling Opcodes
 
 Those opcodes follow very closely semantics of the respective Direct3D
 instructions. If in doubt double check Direct3D documentation.
+Note that the swizzle on SVIEW (src1) determines texel swizzling
+after lookup.
 
 .. opcode:: SAMPLE - Using provided address, sample data from the
                specified texture using the filtering mode identified