[6/6] wined3d: Simplify the get_write_mask and get_swizzle functions

H. Verbeet hverbeet at gmail.com
Fri Dec 29 08:32:10 CST 2006


Most of the complexity in these functions is for generating code
that's pretty to look at. eg R0 is exactly the same as R0.xyzw.
Getting rid of this makes these functions quite a bit simpler. More
importantly, this makes it easier to count the number of components in
the write mask, and to only request a certain amount of swizzle
components. That's something we need to know in order to generate
proper code. The current code works around not having this information
by extending everything to vec4 and adding the destination write mask.
That works, but it's a bit of a hack, and causes GLSL compiler
warnings about register components being potentially used without
being initialized.

Changelog:
  - Simplify the get_write_mask and get_swizzle functions
-------------- next part --------------
---

 dlls/wined3d/arb_program_shader.c |   38 +++++++++++--------------------------
 dlls/wined3d/glsl_shader.c        |   38 +++++++++++--------------------------
 2 files changed, 22 insertions(+), 54 deletions(-)

diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index a8e4c9a..e0d10a6 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -209,14 +209,11 @@ static const char * const shift_tab[] = 
 static void shader_arb_get_write_mask(const DWORD param, char *write_mask) {
     char *ptr = write_mask;
 
-    if ((param & WINED3DSP_WRITEMASK_ALL) != WINED3DSP_WRITEMASK_ALL) {
-        *ptr++ = '.';
-        if (param & WINED3DSP_WRITEMASK_0) *ptr++ = 'x';
-        if (param & WINED3DSP_WRITEMASK_1) *ptr++ = 'y';
-        if (param & WINED3DSP_WRITEMASK_2) *ptr++ = 'z';
-        if (param & WINED3DSP_WRITEMASK_3) *ptr++ = 'w';
-    }
-
+    *ptr++ = '.';
+    if (param & WINED3DSP_WRITEMASK_0) *ptr++ = 'x';
+    if (param & WINED3DSP_WRITEMASK_1) *ptr++ = 'y';
+    if (param & WINED3DSP_WRITEMASK_2) *ptr++ = 'z';
+    if (param & WINED3DSP_WRITEMASK_3) *ptr++ = 'w';
     *ptr = '\0';
 }
 
@@ -226,28 +223,15 @@ static void shader_arb_get_swizzle(const
      * and z components. */
     const char *swizzle_chars = fixup ? "zyxw" : "xyzw";
     char *ptr = swizzle_str;
+    DWORD swizzle = (param & WINED3DSP_SWIZZLE_MASK) >> WINED3DSP_SWIZZLE_SHIFT;
+    size_t i = 0;
 
+    *ptr++ = '.';
     /* swizzle bits fields: wwzzyyxx */
-    DWORD swizzle = (param & WINED3DSP_SWIZZLE_MASK) >> WINED3DSP_SWIZZLE_SHIFT;
-    DWORD swizzle_x = swizzle & 0x03;
-    DWORD swizzle_y = (swizzle >> 2) & 0x03;
-    DWORD swizzle_z = (swizzle >> 4) & 0x03;
-    DWORD swizzle_w = (swizzle >> 6) & 0x03;
-
-    /* If the swizzle is the default swizzle (ie, "xyzw"), we don't need to
-     * generate a swizzle string. Unless we need to our own swizzling. */
-    if ((WINED3DSP_NOSWIZZLE >> WINED3DSP_SWIZZLE_SHIFT) != swizzle || fixup) {
-        *ptr++ = '.';
-        if (swizzle_x == swizzle_y && swizzle_x == swizzle_z && swizzle_x == swizzle_w) {
-            *ptr++ = swizzle_chars[swizzle_x];
-        } else {
-            *ptr++ = swizzle_chars[swizzle_x];
-            *ptr++ = swizzle_chars[swizzle_y];
-            *ptr++ = swizzle_chars[swizzle_z];
-            *ptr++ = swizzle_chars[swizzle_w];
-        }
+    for (i = 0; i < 4; ++i) {
+        *ptr++ = swizzle_chars[swizzle & 0x3];
+        swizzle >>= 2;
     }
-
     *ptr = '\0';
 }
 
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c
index 4aed644..03d5dd3 100644
--- a/dlls/wined3d/glsl_shader.c
+++ b/dlls/wined3d/glsl_shader.c
@@ -722,14 +722,11 @@ static void shader_glsl_get_register_nam
 static void shader_glsl_get_write_mask(const DWORD param, char *write_mask) {
     char *ptr = write_mask;
 
-    if ((param & WINED3DSP_WRITEMASK_ALL) != WINED3DSP_WRITEMASK_ALL) {
-        *ptr++ = '.';
-        if (param & WINED3DSP_WRITEMASK_0) *ptr++ = 'x';
-        if (param & WINED3DSP_WRITEMASK_1) *ptr++ = 'y';
-        if (param & WINED3DSP_WRITEMASK_2) *ptr++ = 'z';
-        if (param & WINED3DSP_WRITEMASK_3) *ptr++ = 'w';
-    }
-
+    *ptr++ = '.';
+    if (param & WINED3DSP_WRITEMASK_0) *ptr++ = 'x';
+    if (param & WINED3DSP_WRITEMASK_1) *ptr++ = 'y';
+    if (param & WINED3DSP_WRITEMASK_2) *ptr++ = 'z';
+    if (param & WINED3DSP_WRITEMASK_3) *ptr++ = 'w';
     *ptr = '\0';
 }
 
@@ -739,28 +736,15 @@ static void shader_glsl_get_swizzle(cons
      * and z components. */
     const char *swizzle_chars = fixup ? "zyxw" : "xyzw";
     char *ptr = swizzle_str;
+    DWORD swizzle = (param & WINED3DSP_SWIZZLE_MASK) >> WINED3DSP_SWIZZLE_SHIFT;
+    size_t i = 0;
 
+    *ptr++ = '.';
     /* swizzle bits fields: wwzzyyxx */
-    DWORD swizzle = (param & WINED3DSP_SWIZZLE_MASK) >> WINED3DSP_SWIZZLE_SHIFT;
-    DWORD swizzle_x = swizzle & 0x03;
-    DWORD swizzle_y = (swizzle >> 2) & 0x03;
-    DWORD swizzle_z = (swizzle >> 4) & 0x03;
-    DWORD swizzle_w = (swizzle >> 6) & 0x03;
-
-    /* If the swizzle is the default swizzle (ie, "xyzw"), we don't need to
-     * generate a swizzle string. Unless we need to our own swizzling. */
-    if ((WINED3DSP_NOSWIZZLE >> WINED3DSP_SWIZZLE_SHIFT) != swizzle || fixup) {
-        *ptr++ = '.';
-        if (swizzle_x == swizzle_y && swizzle_x == swizzle_z && swizzle_x == swizzle_w) {
-            *ptr++ = swizzle_chars[swizzle_x];
-        } else {
-            *ptr++ = swizzle_chars[swizzle_x];
-            *ptr++ = swizzle_chars[swizzle_y];
-            *ptr++ = swizzle_chars[swizzle_z];
-            *ptr++ = swizzle_chars[swizzle_w];
-        }
+    for (i = 0; i < 4; ++i) {
+        *ptr++ = swizzle_chars[swizzle & 0x3];
+        swizzle >>= 2;
     }
-
     *ptr = '\0';
 }
 


More information about the wine-patches mailing list