From: Józef Kucia Subject: [PATCH 2/6] wined3d: Fix swizzle for ld_raw instruction. Message-Id: <20170220121215.28199-2-jkucia@codeweavers.com> Date: Mon, 20 Feb 2017 13:12:11 +0100 In-Reply-To: <20170220121215.28199-1-jkucia@codeweavers.com> References: <20170220121215.28199-1-jkucia@codeweavers.com> Signed-off-by: Józef Kucia --- dlls/wined3d/glsl_shader.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index b583453..dff910c 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -2915,7 +2915,8 @@ static DWORD shader_glsl_get_write_mask(const struct wined3d_shader_dst_param *p return mask; } -static unsigned int shader_glsl_get_write_mask_size(DWORD write_mask) { +static unsigned int shader_glsl_get_write_mask_size(DWORD write_mask) +{ unsigned int size = 0; if (write_mask & WINED3DSP_WRITEMASK_0) ++size; @@ -2926,19 +2927,27 @@ static unsigned int shader_glsl_get_write_mask_size(DWORD write_mask) { return size; } -static void shader_glsl_swizzle_to_str(const DWORD swizzle, BOOL fixup, DWORD mask, char *str) +static unsigned int shader_glsl_swizzle_get_component(DWORD swizzle, + unsigned int component_idx) +{ + /* swizzle bits fields: wwzzyyxx */ + return (swizzle >> (2 * component_idx)) & 0x3; +} + +static void shader_glsl_swizzle_to_str(DWORD swizzle, BOOL fixup, DWORD mask, char *str) { /* For registers of type WINED3DDECLTYPE_D3DCOLOR, data is stored as "bgra", * but addressed as "rgba". To fix this we need to swap the register's x * and z components. */ const char *swizzle_chars = fixup ? "zyxw" : "xyzw"; + unsigned int i; *str++ = '.'; - /* swizzle bits fields: wwzzyyxx */ - if (mask & WINED3DSP_WRITEMASK_0) *str++ = swizzle_chars[swizzle & 0x03]; - if (mask & WINED3DSP_WRITEMASK_1) *str++ = swizzle_chars[(swizzle >> 2) & 0x03]; - if (mask & WINED3DSP_WRITEMASK_2) *str++ = swizzle_chars[(swizzle >> 4) & 0x03]; - if (mask & WINED3DSP_WRITEMASK_3) *str++ = swizzle_chars[(swizzle >> 6) & 0x03]; + for (i = 0; i < 4; ++i) + { + if (mask & (WINED3DSP_WRITEMASK_0 << i)) + *str++ = swizzle_chars[shader_glsl_swizzle_get_component(swizzle, i)]; + } *str = '\0'; } @@ -4147,7 +4156,7 @@ static void shader_glsl_conditional_move(const struct wined3d_shader_instruction /* Find the destination channels which use the current source0 channel. */ for (j = 0; j < 4; ++j) { - if (((ins->src[0].swizzle >> (2 * j)) & 0x3) == i) + if (shader_glsl_swizzle_get_component(ins->src[0].swizzle, j) == i) { write_mask |= WINED3DSP_WRITEMASK_0 << j; cmp_channel = WINED3DSP_WRITEMASK_0 << j; @@ -5038,9 +5047,8 @@ static void shader_glsl_ld_raw(const struct wined3d_shader_instruction *ins) struct wined3d_shader_dst_param dst; const char *function, *resource; struct glsl_src_param offset; - char dst_swizzle[6]; + unsigned int i, swizzle; DWORD write_mask; - unsigned int i; if (src->reg.type == WINED3DSPR_RESOURCE) { @@ -5063,9 +5071,9 @@ static void shader_glsl_ld_raw(const struct wined3d_shader_instruction *ins) &dst, dst.reg.data_type))) continue; - shader_glsl_swizzle_to_str(src->swizzle, FALSE, write_mask, dst_swizzle); - shader_addline(buffer, "%s(%s_%s%u, %s / 4)%s);\n", - function, prefix, resource, src->reg.idx[0].offset, offset.param_str, dst_swizzle); + swizzle = shader_glsl_swizzle_get_component(src->swizzle, write_mask); + shader_addline(buffer, "%s(%s_%s%u, %s / 4 + %u).x);\n", + function, prefix, resource, src->reg.idx[0].offset, offset.param_str, swizzle); } } -- 2.10.2