[PATCH vkd3d v3 2/4] vkd3d-shader/hlsl: Take writemask into account when emitting a SM4 constant.

Giovanni Mascellani gmascellani at codeweavers.com
Tue Nov 16 12:54:59 CST 2021


Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
---
 libs/vkd3d-shader/hlsl_sm4.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c
index c56a74d4..9b48aa8b 100644
--- a/libs/vkd3d-shader/hlsl_sm4.c
+++ b/libs/vkd3d-shader/hlsl_sm4.c
@@ -1166,7 +1166,7 @@ static void write_sm4_constant(struct hlsl_ctx *ctx,
 {
     const unsigned int dimx = constant->node.data_type->dimx;
     struct sm4_instruction instr;
-    unsigned int i;
+    struct sm4_register *reg = &instr.srcs[0].reg;
 
     memset(&instr, 0, sizeof(instr));
     instr.opcode = VKD3D_SM4_OP_MOV;
@@ -1174,10 +1174,23 @@ static void write_sm4_constant(struct hlsl_ctx *ctx,
     sm4_register_from_node(&instr.dsts[0].reg, &instr.dsts[0].writemask, &constant->node);
     instr.dst_count = 1;
 
-    instr.srcs[0].reg.dim = (dimx > 1) ? VKD3D_SM4_DIMENSION_VEC4 : VKD3D_SM4_DIMENSION_SCALAR;
-    instr.srcs[0].reg.type = VKD3D_SM4_RT_IMMCONST;
-    for (i = 0; i < dimx; ++i)
-        instr.srcs[0].reg.immconst_uint[i] = constant->value[i].u;
+    reg->type = VKD3D_SM4_RT_IMMCONST;
+    if (dimx == 1)
+    {
+        reg->dim = VKD3D_SM4_DIMENSION_SCALAR;
+        reg->immconst_uint[0] = constant->value[0].u;
+    }
+    else
+    {
+        unsigned int i, j = 0;
+
+        reg->dim = VKD3D_SM4_DIMENSION_VEC4;
+        for (i = 0; i < 4; ++i)
+        {
+            if (instr.dsts[0].writemask & (1u << i))
+                reg->immconst_uint[i] = constant->value[j++].u;
+        }
+    }
     instr.src_count = 1,
 
     write_sm4_instruction(buffer, &instr);
-- 
2.33.1




More information about the wine-devel mailing list