From c71d609fb630e1b8d5f8a489226ffe2f2e0a5831 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B3zef=20Kucia?= <jkucia@codeweavers.com>
Date: Mon, 24 Jul 2017 19:43:50 +0200
Subject: [PATCH] libs/vkd3d-shader: Fix write mask for
 vThreadIDInGroupFlattened.

---
 libs/vkd3d-shader/spirv.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c
index b5341a1ce5..a5c760ca25 100644
--- a/libs/vkd3d-shader/spirv.c
+++ b/libs/vkd3d-shader/spirv.c
@@ -1890,6 +1890,7 @@ static void vkd3d_dxbc_compiler_emit_store_reg(struct vkd3d_dxbc_compiler *compi
     uint32_t reg_id;
 
     assert(reg->type != VKD3DSPR_IMMCONST);
+    assert(write_mask);
 
     component_count = vkd3d_write_mask_component_count(write_mask);
 
@@ -2045,21 +2046,18 @@ static uint32_t vkd3d_dxbc_compiler_emit_input(struct vkd3d_dxbc_compiler *compi
     SpvStorageClass storage_class;
     struct rb_entry *entry = NULL;
     bool use_private_var = false;
+    DWORD write_mask;
 
     builtin = vkd3d_get_spirv_builtin(dst->reg.type, sysval);
 
     /* vThreadIDInGroupFlattened is declared with no write mask in shader
      * bytecode generated by fxc. */
-    if (!dst->write_mask && dst->reg.type == VKD3DSPR_LOCALTHREADINDEX)
-    {
-        component_idx = 0;
-        component_count = 1;
-    }
-    else
-    {
-        component_idx = vkd3d_write_mask_get_component_idx(dst->write_mask);
-        component_count = vkd3d_write_mask_component_count(dst->write_mask);
-    }
+    write_mask = dst->write_mask;
+    if (!write_mask && dst->reg.type == VKD3DSPR_LOCALTHREADINDEX)
+        write_mask = VKD3DSP_WRITEMASK_0;
+
+    component_idx = vkd3d_write_mask_get_component_idx(write_mask);
+    component_count = vkd3d_write_mask_component_count(write_mask);
     if (builtin)
     {
         component_type = builtin->component_type;
@@ -2105,7 +2103,7 @@ static uint32_t vkd3d_dxbc_compiler_emit_input(struct vkd3d_dxbc_compiler *compi
     }
 
     if (val_id && input_component_count != component_count)
-        val_id = vkd3d_dxbc_compiler_emit_swizzle(compiler, val_id, VKD3DSP_NOSWIZZLE, dst->write_mask);
+        val_id = vkd3d_dxbc_compiler_emit_swizzle(compiler, val_id, VKD3DSP_NOSWIZZLE, write_mask);
 
     vkd3d_symbol_make_register(&reg_symbol, &dst->reg);
 
@@ -2131,7 +2129,7 @@ static uint32_t vkd3d_dxbc_compiler_emit_input(struct vkd3d_dxbc_compiler *compi
     if (use_private_var)
     {
         assert(val_id);
-        vkd3d_dxbc_compiler_emit_store_reg(compiler, &dst->reg, dst->write_mask, val_id);
+        vkd3d_dxbc_compiler_emit_store_reg(compiler, &dst->reg, write_mask, val_id);
     }
 
     return input_id;
-- 
GitLab