[PATCH 1/2] wined3d: Correctly parse SM4 dcl_immediateConstantBuffer opcode.

Józef Kucia jkucia at codeweavers.com
Thu Dec 3 04:04:17 CST 2015


Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
This fixes infinite loop when dcl_immediateConstantBuffer is parsed.

Unfortunately, I had to reindent whole wined3d_sm4_opcode enum in order to make
space for WINED3D_SM4_OP_DCL_IMMEDIATE_CONSTANT_BUFFER. I was also considering
to use a shorter name: WINED3D_SM4_OP_DCL_IMMEDIATE_BUFFER.
---
 dlls/wined3d/shader_sm4.c | 121 ++++++++++++++++++++++++----------------------
 1 file changed, 63 insertions(+), 58 deletions(-)

diff --git a/dlls/wined3d/shader_sm4.c b/dlls/wined3d/shader_sm4.c
index e4d6336..8101600 100644
--- a/dlls/wined3d/shader_sm4.c
+++ b/dlls/wined3d/shader_sm4.c
@@ -74,63 +74,64 @@ WINE_DECLARE_DEBUG_CHANNEL(d3d_bytecode);
 
 enum wined3d_sm4_opcode
 {
-    WINED3D_SM4_OP_ADD                  = 0x00,
-    WINED3D_SM4_OP_AND                  = 0x01,
-    WINED3D_SM4_OP_BREAK                = 0x02,
-    WINED3D_SM4_OP_BREAKC               = 0x03,
-    WINED3D_SM4_OP_CUT                  = 0x09,
-    WINED3D_SM4_OP_DERIV_RTX            = 0x0b,
-    WINED3D_SM4_OP_DERIV_RTY            = 0x0c,
-    WINED3D_SM4_OP_DISCARD              = 0x0d,
-    WINED3D_SM4_OP_DIV                  = 0x0e,
-    WINED3D_SM4_OP_DP2                  = 0x0f,
-    WINED3D_SM4_OP_DP3                  = 0x10,
-    WINED3D_SM4_OP_DP4                  = 0x11,
-    WINED3D_SM4_OP_EMIT                 = 0x13,
-    WINED3D_SM4_OP_ENDIF                = 0x15,
-    WINED3D_SM4_OP_ENDLOOP              = 0x16,
-    WINED3D_SM4_OP_EQ                   = 0x18,
-    WINED3D_SM4_OP_EXP                  = 0x19,
-    WINED3D_SM4_OP_FRC                  = 0x1a,
-    WINED3D_SM4_OP_FTOI                 = 0x1b,
-    WINED3D_SM4_OP_GE                   = 0x1d,
-    WINED3D_SM4_OP_IADD                 = 0x1e,
-    WINED3D_SM4_OP_IF                   = 0x1f,
-    WINED3D_SM4_OP_IEQ                  = 0x20,
-    WINED3D_SM4_OP_IGE                  = 0x21,
-    WINED3D_SM4_OP_IMUL                 = 0x26,
-    WINED3D_SM4_OP_ISHL                 = 0x29,
-    WINED3D_SM4_OP_ITOF                 = 0x2b,
-    WINED3D_SM4_OP_LD                   = 0x2d,
-    WINED3D_SM4_OP_LOG                  = 0x2f,
-    WINED3D_SM4_OP_LOOP                 = 0x30,
-    WINED3D_SM4_OP_LT                   = 0x31,
-    WINED3D_SM4_OP_MAD                  = 0x32,
-    WINED3D_SM4_OP_MIN                  = 0x33,
-    WINED3D_SM4_OP_MAX                  = 0x34,
-    WINED3D_SM4_OP_MOV                  = 0x36,
-    WINED3D_SM4_OP_MOVC                 = 0x37,
-    WINED3D_SM4_OP_MUL                  = 0x38,
-    WINED3D_SM4_OP_NE                   = 0x39,
-    WINED3D_SM4_OP_OR                   = 0x3c,
-    WINED3D_SM4_OP_RET                  = 0x3e,
-    WINED3D_SM4_OP_ROUND_NI             = 0x41,
-    WINED3D_SM4_OP_RSQ                  = 0x44,
-    WINED3D_SM4_OP_SAMPLE               = 0x45,
-    WINED3D_SM4_OP_SAMPLE_LOD           = 0x48,
-    WINED3D_SM4_OP_SAMPLE_GRAD          = 0x49,
-    WINED3D_SM4_OP_SQRT                 = 0x4b,
-    WINED3D_SM4_OP_SINCOS               = 0x4d,
-    WINED3D_SM4_OP_UDIV                 = 0x4e,
-    WINED3D_SM4_OP_UGE                  = 0x50,
-    WINED3D_SM4_OP_USHR                 = 0x55,
-    WINED3D_SM4_OP_UTOF                 = 0x56,
-    WINED3D_SM4_OP_XOR                  = 0x57,
-    WINED3D_SM4_OP_DCL_RESOURCE         = 0x58,
-    WINED3D_SM4_OP_DCL_CONSTANT_BUFFER  = 0x59,
-    WINED3D_SM4_OP_DCL_OUTPUT_TOPOLOGY  = 0x5c,
-    WINED3D_SM4_OP_DCL_INPUT_PRIMITIVE  = 0x5d,
-    WINED3D_SM4_OP_DCL_VERTICES_OUT     = 0x5e,
+    WINED3D_SM4_OP_ADD                           = 0x00,
+    WINED3D_SM4_OP_AND                           = 0x01,
+    WINED3D_SM4_OP_BREAK                         = 0x02,
+    WINED3D_SM4_OP_BREAKC                        = 0x03,
+    WINED3D_SM4_OP_CUT                           = 0x09,
+    WINED3D_SM4_OP_DERIV_RTX                     = 0x0b,
+    WINED3D_SM4_OP_DERIV_RTY                     = 0x0c,
+    WINED3D_SM4_OP_DISCARD                       = 0x0d,
+    WINED3D_SM4_OP_DIV                           = 0x0e,
+    WINED3D_SM4_OP_DP2                           = 0x0f,
+    WINED3D_SM4_OP_DP3                           = 0x10,
+    WINED3D_SM4_OP_DP4                           = 0x11,
+    WINED3D_SM4_OP_EMIT                          = 0x13,
+    WINED3D_SM4_OP_ENDIF                         = 0x15,
+    WINED3D_SM4_OP_ENDLOOP                       = 0x16,
+    WINED3D_SM4_OP_EQ                            = 0x18,
+    WINED3D_SM4_OP_EXP                           = 0x19,
+    WINED3D_SM4_OP_FRC                           = 0x1a,
+    WINED3D_SM4_OP_FTOI                          = 0x1b,
+    WINED3D_SM4_OP_GE                            = 0x1d,
+    WINED3D_SM4_OP_IADD                          = 0x1e,
+    WINED3D_SM4_OP_IF                            = 0x1f,
+    WINED3D_SM4_OP_IEQ                           = 0x20,
+    WINED3D_SM4_OP_IGE                           = 0x21,
+    WINED3D_SM4_OP_IMUL                          = 0x26,
+    WINED3D_SM4_OP_ISHL                          = 0x29,
+    WINED3D_SM4_OP_ITOF                          = 0x2b,
+    WINED3D_SM4_OP_LD                            = 0x2d,
+    WINED3D_SM4_OP_LOG                           = 0x2f,
+    WINED3D_SM4_OP_LOOP                          = 0x30,
+    WINED3D_SM4_OP_LT                            = 0x31,
+    WINED3D_SM4_OP_MAD                           = 0x32,
+    WINED3D_SM4_OP_MIN                           = 0x33,
+    WINED3D_SM4_OP_MAX                           = 0x34,
+    WINED3D_SM4_OP_DCL_IMMEDIATE_CONSTANT_BUFFER = 0x35,
+    WINED3D_SM4_OP_MOV                           = 0x36,
+    WINED3D_SM4_OP_MOVC                          = 0x37,
+    WINED3D_SM4_OP_MUL                           = 0x38,
+    WINED3D_SM4_OP_NE                            = 0x39,
+    WINED3D_SM4_OP_OR                            = 0x3c,
+    WINED3D_SM4_OP_RET                           = 0x3e,
+    WINED3D_SM4_OP_ROUND_NI                      = 0x41,
+    WINED3D_SM4_OP_RSQ                           = 0x44,
+    WINED3D_SM4_OP_SAMPLE                        = 0x45,
+    WINED3D_SM4_OP_SAMPLE_LOD                    = 0x48,
+    WINED3D_SM4_OP_SAMPLE_GRAD                   = 0x49,
+    WINED3D_SM4_OP_SQRT                          = 0x4b,
+    WINED3D_SM4_OP_SINCOS                        = 0x4d,
+    WINED3D_SM4_OP_UDIV                          = 0x4e,
+    WINED3D_SM4_OP_UGE                           = 0x50,
+    WINED3D_SM4_OP_USHR                          = 0x55,
+    WINED3D_SM4_OP_UTOF                          = 0x56,
+    WINED3D_SM4_OP_XOR                           = 0x57,
+    WINED3D_SM4_OP_DCL_RESOURCE                  = 0x58,
+    WINED3D_SM4_OP_DCL_CONSTANT_BUFFER           = 0x59,
+    WINED3D_SM4_OP_DCL_OUTPUT_TOPOLOGY           = 0x5c,
+    WINED3D_SM4_OP_DCL_INPUT_PRIMITIVE           = 0x5d,
+    WINED3D_SM4_OP_DCL_VERTICES_OUT              = 0x5e,
 };
 
 enum wined3d_sm4_register_type
@@ -761,7 +762,11 @@ static void shader_sm4_read_instruction(void *data, const DWORD **ptr, struct wi
 
     opcode_token = *(*ptr)++;
     opcode = opcode_token & WINED3D_SM4_OPCODE_MASK;
-    len = ((opcode_token & WINED3D_SM4_INSTRUCTION_LENGTH_MASK) >> WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT) - 1;
+
+    if (opcode == WINED3D_SM4_OP_DCL_IMMEDIATE_CONSTANT_BUFFER)
+        len = *(*ptr) - 1;
+    else
+        len = ((opcode_token & WINED3D_SM4_INSTRUCTION_LENGTH_MASK) >> WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT) - 1;
 
     if (TRACE_ON(d3d_bytecode))
     {
-- 
2.4.10




More information about the wine-patches mailing list