st/vega: Move masking after blending.
authorChia-I Wu <olv@lunarg.com>
Sat, 4 Dec 2010 03:23:41 +0000 (11:23 +0800)
committerChia-I Wu <olv@lunarg.com>
Sat, 4 Dec 2010 05:20:38 +0000 (13:20 +0800)
Masking should happen after blending.  The shader is not entirely
correct, but leave it as is for now.

src/gallium/state_trackers/vega/asm_fill.h
src/gallium/state_trackers/vega/shader.c
src/gallium/state_trackers/vega/shaders_cache.c
src/gallium/state_trackers/vega/shaders_cache.h

index 19a2d93fe598131c3baf4da9d663fd63a102a534..22ad6ac39a51e6365710f981956a19313eca32a9 100644 (file)
@@ -173,38 +173,6 @@ paint_degenerate( struct ureg_program *ureg,
    ureg_TEX(ureg, *out, TGSI_TEXTURE_1D, ureg_src(temp[1]), sampler[0]);
 }
 
-static INLINE void
-color_transform( struct ureg_program *ureg,
-                 struct ureg_dst *out,
-                 struct ureg_src *in,
-                 struct ureg_src *sampler,
-                 struct ureg_dst *temp,
-                 struct ureg_src *constant)
-{
-   ureg_MAD(ureg, temp[1], ureg_src(temp[0]), constant[0], constant[1]);
-   /* clamp to [0.0f, 1.0f] */
-   ureg_CLAMP(ureg, temp[1],
-              ureg_src(temp[1]),
-              ureg_scalar(constant[3], TGSI_SWIZZLE_X),
-              ureg_scalar(constant[3], TGSI_SWIZZLE_Y));
-   ureg_MOV(ureg, *out, ureg_src(temp[1]));
-}
-
-static INLINE void
-mask( struct ureg_program *ureg,
-      struct ureg_dst *out,
-      struct ureg_src *in,
-      struct ureg_src *sampler,
-      struct ureg_dst *temp,
-      struct ureg_src *constant)
-{
-   ureg_TEX(ureg, temp[1], TGSI_TEXTURE_2D, in[0], sampler[1]);
-   ureg_MUL(ureg, ureg_writemask(temp[0], TGSI_WRITEMASK_W),
-            ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W),
-            ureg_scalar(ureg_src(temp[1]), TGSI_SWIZZLE_W));
-   ureg_MOV(ureg, *out, ureg_src(temp[0]));
-}
-
 static INLINE void
 image_normal( struct ureg_program *ureg,
               struct ureg_dst *out,
@@ -242,6 +210,23 @@ image_stencil( struct ureg_program *ureg,
    ureg_MUL(ureg, *out, ureg_src(temp[0]), ureg_src(temp[1]));
 }
 
+static INLINE void
+color_transform( struct ureg_program *ureg,
+                 struct ureg_dst *out,
+                 struct ureg_src *in,
+                 struct ureg_src *sampler,
+                 struct ureg_dst *temp,
+                 struct ureg_src *constant)
+{
+   ureg_MAD(ureg, temp[1], ureg_src(temp[0]), constant[0], constant[1]);
+   /* clamp to [0.0f, 1.0f] */
+   ureg_CLAMP(ureg, temp[1],
+              ureg_src(temp[1]),
+              ureg_scalar(constant[3], TGSI_SWIZZLE_X),
+              ureg_scalar(constant[3], TGSI_SWIZZLE_Y));
+   ureg_MOV(ureg, *out, ureg_src(temp[1]));
+}
+
 /**
  * Emit instructions for the specified blend mode.  Colors should be
  * premultiplied.  Two temporary registers are required.
@@ -395,6 +380,21 @@ blend_lighten( struct ureg_program *ureg,
                  temp + 2);
 }
 
+static INLINE void
+mask( struct ureg_program *ureg,
+      struct ureg_dst *out,
+      struct ureg_src *in,
+      struct ureg_src *sampler,
+      struct ureg_dst *temp,
+      struct ureg_src *constant)
+{
+   ureg_TEX(ureg, temp[1], TGSI_TEXTURE_2D, in[0], sampler[1]);
+   ureg_MUL(ureg, ureg_writemask(temp[0], TGSI_WRITEMASK_W),
+            ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W),
+            ureg_scalar(ureg_src(temp[1]), TGSI_SWIZZLE_W));
+   ureg_MOV(ureg, *out, ureg_src(temp[0]));
+}
+
 static INLINE void
 premultiply( struct ureg_program *ureg,
                 struct ureg_dst *out,
@@ -500,11 +500,6 @@ static const struct shader_asm_info shaders_color_transform_asm[] = {
     VG_FALSE, 0, 4, 0, 0, 0, 2}
 };
 
-static const struct shader_asm_info shaders_mask_asm[] = {
-   {VEGA_MASK_SHADER, mask,
-    VG_TRUE,  0, 0, 1, 1, 0, 2}
-};
-
 /* extra blend modes */
 static const struct shader_asm_info shaders_blend_asm[] = {
    {VEGA_BLEND_MULTIPLY_SHADER, blend_multiply,
@@ -517,6 +512,11 @@ static const struct shader_asm_info shaders_blend_asm[] = {
     VG_TRUE,  3, 1, 2, 1, 0, 4},
 };
 
+static const struct shader_asm_info shaders_mask_asm[] = {
+   {VEGA_MASK_SHADER, mask,
+    VG_TRUE,  0, 0, 1, 1, 0, 2}
+};
+
 /* premultiply */
 static const struct shader_asm_info shaders_premultiply_asm[] = {
    {VEGA_PREMULTIPLY_SHADER, premultiply,
index db410e3dadba6b3a365b1bf777819bd0868a803e..20ced813b4b9a7d719c96a96beea4b4885c235c0 100644 (file)
@@ -255,9 +255,6 @@ static void setup_shader_program(struct shader *shader)
    if (shader->color_transform)
       shader_id |= VEGA_COLOR_TRANSFORM_SHADER;
 
-   if (shader->masking)
-      shader_id |= VEGA_MASK_SHADER;
-
    switch(blend_mode) {
    case VG_BLEND_MULTIPLY:
       shader_id |= VEGA_BLEND_MULTIPLY_SHADER;
@@ -276,6 +273,9 @@ static void setup_shader_program(struct shader *shader)
       break;
    }
 
+   if (shader->masking)
+      shader_id |= VEGA_MASK_SHADER;
+
    if (black_white)
       shader_id |= VEGA_BW_SHADER;
 
index d1ebe7e67797d6b65ea85352fbc3a115bee3c624..76bac5139f412584123f66215613eb8d501de504 100644 (file)
@@ -53,8 +53,8 @@
  * 1) Paint generation (color/gradient/pattern)
  * 2) Image composition (normal/multiply/stencil)
  * 3) Color transform
- * 4) Mask
- * 5) Extended blend (multiply/screen/darken/lighten)
+ * 4) Extended blend (multiply/screen/darken/lighten)
+ * 5) Mask
  * 6) Premultiply/Unpremultiply
  * 7) Color transform (to black and white)
  */
@@ -301,10 +301,13 @@ create_shader(struct pipe_context *pipe,
    }
 
    /* fourth stage */
-   sh = SHADERS_GET_MASK_SHADER(id);
+   sh = SHADERS_GET_BLEND_SHADER(id);
    switch (sh) {
-   case VEGA_MASK_SHADER:
-      shaders[idx] = &shaders_mask_asm[(sh >> SHADERS_MASK_SHIFT) - 1];
+   case VEGA_BLEND_MULTIPLY_SHADER:
+   case VEGA_BLEND_SCREEN_SHADER:
+   case VEGA_BLEND_DARKEN_SHADER:
+   case VEGA_BLEND_LIGHTEN_SHADER:
+      shaders[idx] = &shaders_blend_asm[(sh >> SHADERS_BLEND_SHIFT) - 1];
       assert(shaders[idx]->id == sh);
       idx++;
       break;
@@ -313,13 +316,10 @@ create_shader(struct pipe_context *pipe,
    }
 
    /* fifth stage */
-   sh = SHADERS_GET_BLEND_SHADER(id);
+   sh = SHADERS_GET_MASK_SHADER(id);
    switch (sh) {
-   case VEGA_BLEND_MULTIPLY_SHADER:
-   case VEGA_BLEND_SCREEN_SHADER:
-   case VEGA_BLEND_DARKEN_SHADER:
-   case VEGA_BLEND_LIGHTEN_SHADER:
-      shaders[idx] = &shaders_blend_asm[(sh >> SHADERS_BLEND_SHIFT) - 1];
+   case VEGA_MASK_SHADER:
+      shaders[idx] = &shaders_mask_asm[(sh >> SHADERS_MASK_SHIFT) - 1];
       assert(shaders[idx]->id == sh);
       idx++;
       break;
index b626045f9af5cd6f1bc6bd385987914dcd7d78c9..008e4f5b94b19e67009eba474a83fafd9d495f3c 100644 (file)
@@ -36,17 +36,17 @@ struct shaders_cache;
 #define _SHADERS_PAINT_BITS            3
 #define _SHADERS_IMAGE_BITS            2
 #define _SHADERS_COLOR_TRANSFORM_BITS  1
-#define _SHADERS_MASK_BITS             1
 #define _SHADERS_BLEND_BITS            3
+#define _SHADERS_MASK_BITS             1
 #define _SHADERS_PREMULTIPLY_BITS      2
 #define _SHADERS_BW_BITS               1
 
 #define SHADERS_PAINT_SHIFT           (0)
 #define SHADERS_IMAGE_SHIFT           (SHADERS_PAINT_SHIFT + _SHADERS_PAINT_BITS)
 #define SHADERS_COLOR_TRANSFORM_SHIFT (SHADERS_IMAGE_SHIFT + _SHADERS_IMAGE_BITS)
-#define SHADERS_MASK_SHIFT            (SHADERS_COLOR_TRANSFORM_SHIFT + _SHADERS_COLOR_TRANSFORM_BITS)
-#define SHADERS_BLEND_SHIFT           (SHADERS_MASK_SHIFT + _SHADERS_MASK_BITS)
-#define SHADERS_PREMULTIPLY_SHIFT     (SHADERS_BLEND_SHIFT + _SHADERS_BLEND_BITS)
+#define SHADERS_BLEND_SHIFT           (SHADERS_COLOR_TRANSFORM_SHIFT + _SHADERS_COLOR_TRANSFORM_BITS)
+#define SHADERS_MASK_SHIFT            (SHADERS_BLEND_SHIFT + _SHADERS_BLEND_BITS)
+#define SHADERS_PREMULTIPLY_SHIFT     (SHADERS_MASK_SHIFT + _SHADERS_MASK_BITS)
 #define SHADERS_BW_SHIFT              (SHADERS_PREMULTIPLY_SHIFT + _SHADERS_PREMULTIPLY_BITS)
 
 #define _SHADERS_GET_STAGE(stage, id) \
@@ -55,8 +55,8 @@ struct shaders_cache;
 #define SHADERS_GET_PAINT_SHADER(id)           _SHADERS_GET_STAGE(PAINT, id)
 #define SHADERS_GET_IMAGE_SHADER(id)           _SHADERS_GET_STAGE(IMAGE, id)
 #define SHADERS_GET_COLOR_TRANSFORM_SHADER(id) _SHADERS_GET_STAGE(COLOR_TRANSFORM, id)
-#define SHADERS_GET_MASK_SHADER(id)            _SHADERS_GET_STAGE(MASK, id)
 #define SHADERS_GET_BLEND_SHADER(id)           _SHADERS_GET_STAGE(BLEND, id)
+#define SHADERS_GET_MASK_SHADER(id)            _SHADERS_GET_STAGE(MASK, id)
 #define SHADERS_GET_PREMULTIPLY_SHADER(id)     _SHADERS_GET_STAGE(PREMULTIPLY, id)
 #define SHADERS_GET_BW_SHADER(id)              _SHADERS_GET_STAGE(BW, id)
 
@@ -73,13 +73,13 @@ enum VegaShaderType {
 
    VEGA_COLOR_TRANSFORM_SHADER    = 1 <<  SHADERS_COLOR_TRANSFORM_SHIFT,
 
-   VEGA_MASK_SHADER               = 1 << SHADERS_MASK_SHIFT,
-
    VEGA_BLEND_MULTIPLY_SHADER     = 1 << SHADERS_BLEND_SHIFT,
    VEGA_BLEND_SCREEN_SHADER       = 2 << SHADERS_BLEND_SHIFT,
    VEGA_BLEND_DARKEN_SHADER       = 3 << SHADERS_BLEND_SHIFT,
    VEGA_BLEND_LIGHTEN_SHADER      = 4 << SHADERS_BLEND_SHIFT,
 
+   VEGA_MASK_SHADER               = 1 << SHADERS_MASK_SHIFT,
+
    VEGA_PREMULTIPLY_SHADER        = 1 << SHADERS_PREMULTIPLY_SHIFT,
    VEGA_UNPREMULTIPLY_SHADER      = 2 << SHADERS_PREMULTIPLY_SHIFT,