wined3d: Use the correct relative address for constant buffers in the GLSL shader...
[wine] / dlls / wined3d / shader_sm1.c
1 /*
2  * Copyright 2002-2003 Jason Edmeades
3  * Copyright 2002-2003 Raphael Junqueira
4  * Copyright 2004 Christian Costa
5  * Copyright 2005 Oliver Stieber
6  * Copyright 2006 Ivan Gyurdiev
7  * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
8  * Copyright 2009 Henri Verbeet for CodeWeavers
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24
25 #include "config.h"
26 #include "wine/port.h"
27
28 #include "wined3d_private.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
31
32 /* DCL usage masks */
33 #define WINED3DSP_DCL_USAGE_SHIFT               0
34 #define WINED3DSP_DCL_USAGE_MASK                (0xf << WINED3DSP_DCL_USAGE_SHIFT)
35 #define WINED3DSP_DCL_USAGEINDEX_SHIFT          16
36 #define WINED3DSP_DCL_USAGEINDEX_MASK           (0xf << WINED3DSP_DCL_USAGEINDEX_SHIFT)
37
38 /* DCL sampler type */
39 #define WINED3DSP_TEXTURETYPE_SHIFT             27
40 #define WINED3DSP_TEXTURETYPE_MASK              (0xf << WINED3DSP_TEXTURETYPE_SHIFT)
41
42 /* Opcode-related masks */
43 #define WINED3DSI_OPCODE_MASK                   0x0000ffff
44
45 #define WINED3D_OPCODESPECIFICCONTROL_SHIFT     16
46 #define WINED3D_OPCODESPECIFICCONTROL_MASK      (0xff << WINED3D_OPCODESPECIFICCONTROL_SHIFT)
47
48 #define WINED3DSI_INSTLENGTH_SHIFT              24
49 #define WINED3DSI_INSTLENGTH_MASK               (0xf << WINED3DSI_INSTLENGTH_SHIFT)
50
51 #define WINED3DSI_COISSUE                       (1 << 30)
52
53 #define WINED3DSI_COMMENTSIZE_SHIFT             16
54 #define WINED3DSI_COMMENTSIZE_MASK              (0x7fff << WINED3DSI_COMMENTSIZE_SHIFT)
55
56 #define WINED3DSHADER_INSTRUCTION_PREDICATED    (1 << 28)
57
58 /* Register number mask */
59 #define WINED3DSP_REGNUM_MASK                   0x000007ff
60
61 /* Register type masks  */
62 #define WINED3DSP_REGTYPE_SHIFT                 28
63 #define WINED3DSP_REGTYPE_MASK                  (0x7 << WINED3DSP_REGTYPE_SHIFT)
64 #define WINED3DSP_REGTYPE_SHIFT2                8
65 #define WINED3DSP_REGTYPE_MASK2                 (0x18 << WINED3DSP_REGTYPE_SHIFT2)
66
67 /* Relative addressing mask */
68 #define WINED3DSHADER_ADDRESSMODE_SHIFT         13
69 #define WINED3DSHADER_ADDRESSMODE_MASK          (1 << WINED3DSHADER_ADDRESSMODE_SHIFT)
70
71 /* Destination modifier mask */
72 #define WINED3DSP_DSTMOD_SHIFT                  20
73 #define WINED3DSP_DSTMOD_MASK                   (0xf << WINED3DSP_DSTMOD_SHIFT)
74
75 /* Destination shift mask */
76 #define WINED3DSP_DSTSHIFT_SHIFT                24
77 #define WINED3DSP_DSTSHIFT_MASK                 (0xf << WINED3DSP_DSTSHIFT_SHIFT)
78
79 /* Write mask */
80 #define WINED3D_SM1_WRITEMASK_SHIFT             16
81 #define WINED3D_SM1_WRITEMASK_MASK              (0xf << WINED3D_SM1_WRITEMASK_SHIFT)
82
83 /* Swizzle mask */
84 #define WINED3DSP_SWIZZLE_SHIFT                 16
85 #define WINED3DSP_SWIZZLE_MASK                  (0xff << WINED3DSP_SWIZZLE_SHIFT)
86
87 /* Source modifier mask */
88 #define WINED3DSP_SRCMOD_SHIFT                  24
89 #define WINED3DSP_SRCMOD_MASK                   (0xf << WINED3DSP_SRCMOD_SHIFT)
90
91 #define WINED3DSP_END                           0x0000ffff
92
93 #define WINED3D_SM1_VERSION_MAJOR(version)      (((version) >> 8) & 0xff)
94 #define WINED3D_SM1_VERSION_MINOR(version)      (((version) >> 0) & 0xff)
95
96 enum WINED3DSHADER_ADDRESSMODE_TYPE
97 {
98     WINED3DSHADER_ADDRMODE_ABSOLUTE = 0 << WINED3DSHADER_ADDRESSMODE_SHIFT,
99     WINED3DSHADER_ADDRMODE_RELATIVE = 1 << WINED3DSHADER_ADDRESSMODE_SHIFT,
100 };
101
102 enum wined3d_sm1_opcode
103 {
104     WINED3D_SM1_OP_NOP          = 0x00,
105     WINED3D_SM1_OP_MOV          = 0x01,
106     WINED3D_SM1_OP_ADD          = 0x02,
107     WINED3D_SM1_OP_SUB          = 0x03,
108     WINED3D_SM1_OP_MAD          = 0x04,
109     WINED3D_SM1_OP_MUL          = 0x05,
110     WINED3D_SM1_OP_RCP          = 0x06,
111     WINED3D_SM1_OP_RSQ          = 0x07,
112     WINED3D_SM1_OP_DP3          = 0x08,
113     WINED3D_SM1_OP_DP4          = 0x09,
114     WINED3D_SM1_OP_MIN          = 0x0a,
115     WINED3D_SM1_OP_MAX          = 0x0b,
116     WINED3D_SM1_OP_SLT          = 0x0c,
117     WINED3D_SM1_OP_SGE          = 0x0d,
118     WINED3D_SM1_OP_EXP          = 0x0e,
119     WINED3D_SM1_OP_LOG          = 0x0f,
120     WINED3D_SM1_OP_LIT          = 0x10,
121     WINED3D_SM1_OP_DST          = 0x11,
122     WINED3D_SM1_OP_LRP          = 0x12,
123     WINED3D_SM1_OP_FRC          = 0x13,
124     WINED3D_SM1_OP_M4x4         = 0x14,
125     WINED3D_SM1_OP_M4x3         = 0x15,
126     WINED3D_SM1_OP_M3x4         = 0x16,
127     WINED3D_SM1_OP_M3x3         = 0x17,
128     WINED3D_SM1_OP_M3x2         = 0x18,
129     WINED3D_SM1_OP_CALL         = 0x19,
130     WINED3D_SM1_OP_CALLNZ       = 0x1a,
131     WINED3D_SM1_OP_LOOP         = 0x1b,
132     WINED3D_SM1_OP_RET          = 0x1c,
133     WINED3D_SM1_OP_ENDLOOP      = 0x1d,
134     WINED3D_SM1_OP_LABEL        = 0x1e,
135     WINED3D_SM1_OP_DCL          = 0x1f,
136     WINED3D_SM1_OP_POW          = 0x20,
137     WINED3D_SM1_OP_CRS          = 0x21,
138     WINED3D_SM1_OP_SGN          = 0x22,
139     WINED3D_SM1_OP_ABS          = 0x23,
140     WINED3D_SM1_OP_NRM          = 0x24,
141     WINED3D_SM1_OP_SINCOS       = 0x25,
142     WINED3D_SM1_OP_REP          = 0x26,
143     WINED3D_SM1_OP_ENDREP       = 0x27,
144     WINED3D_SM1_OP_IF           = 0x28,
145     WINED3D_SM1_OP_IFC          = 0x29,
146     WINED3D_SM1_OP_ELSE         = 0x2a,
147     WINED3D_SM1_OP_ENDIF        = 0x2b,
148     WINED3D_SM1_OP_BREAK        = 0x2c,
149     WINED3D_SM1_OP_BREAKC       = 0x2d,
150     WINED3D_SM1_OP_MOVA         = 0x2e,
151     WINED3D_SM1_OP_DEFB         = 0x2f,
152     WINED3D_SM1_OP_DEFI         = 0x30,
153
154     WINED3D_SM1_OP_TEXCOORD     = 0x40,
155     WINED3D_SM1_OP_TEXKILL      = 0x41,
156     WINED3D_SM1_OP_TEX          = 0x42,
157     WINED3D_SM1_OP_TEXBEM       = 0x43,
158     WINED3D_SM1_OP_TEXBEML      = 0x44,
159     WINED3D_SM1_OP_TEXREG2AR    = 0x45,
160     WINED3D_SM1_OP_TEXREG2GB    = 0x46,
161     WINED3D_SM1_OP_TEXM3x2PAD   = 0x47,
162     WINED3D_SM1_OP_TEXM3x2TEX   = 0x48,
163     WINED3D_SM1_OP_TEXM3x3PAD   = 0x49,
164     WINED3D_SM1_OP_TEXM3x3TEX   = 0x4a,
165     WINED3D_SM1_OP_TEXM3x3DIFF  = 0x4b,
166     WINED3D_SM1_OP_TEXM3x3SPEC  = 0x4c,
167     WINED3D_SM1_OP_TEXM3x3VSPEC = 0x4d,
168     WINED3D_SM1_OP_EXPP         = 0x4e,
169     WINED3D_SM1_OP_LOGP         = 0x4f,
170     WINED3D_SM1_OP_CND          = 0x50,
171     WINED3D_SM1_OP_DEF          = 0x51,
172     WINED3D_SM1_OP_TEXREG2RGB   = 0x52,
173     WINED3D_SM1_OP_TEXDP3TEX    = 0x53,
174     WINED3D_SM1_OP_TEXM3x2DEPTH = 0x54,
175     WINED3D_SM1_OP_TEXDP3       = 0x55,
176     WINED3D_SM1_OP_TEXM3x3      = 0x56,
177     WINED3D_SM1_OP_TEXDEPTH     = 0x57,
178     WINED3D_SM1_OP_CMP          = 0x58,
179     WINED3D_SM1_OP_BEM          = 0x59,
180     WINED3D_SM1_OP_DP2ADD       = 0x5a,
181     WINED3D_SM1_OP_DSX          = 0x5b,
182     WINED3D_SM1_OP_DSY          = 0x5c,
183     WINED3D_SM1_OP_TEXLDD       = 0x5d,
184     WINED3D_SM1_OP_SETP         = 0x5e,
185     WINED3D_SM1_OP_TEXLDL       = 0x5f,
186     WINED3D_SM1_OP_BREAKP       = 0x60,
187
188     WINED3D_SM1_OP_PHASE        = 0xfffd,
189     WINED3D_SM1_OP_COMMENT      = 0xfffe,
190     WINED3D_SM1_OP_END          = 0Xffff,
191 };
192
193 struct wined3d_sm1_opcode_info
194 {
195     enum wined3d_sm1_opcode opcode;
196     UINT dst_count;
197     UINT param_count;
198     enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
199     DWORD min_version;
200     DWORD max_version;
201 };
202
203 struct wined3d_sm1_data
204 {
205     struct wined3d_shader_version shader_version;
206     const struct wined3d_sm1_opcode_info *opcode_table;
207
208     struct wined3d_shader_src_param src_rel_addr[4];
209     struct wined3d_shader_src_param pred_rel_addr;
210     struct wined3d_shader_src_param dst_rel_addr;
211     struct wined3d_shader_src_param src_param[4];
212     struct wined3d_shader_src_param pred_param;
213     struct wined3d_shader_dst_param dst_param;
214 };
215
216 /* This table is not order or position dependent. */
217 static const struct wined3d_sm1_opcode_info vs_opcode_table[] =
218 {
219     /* Arithmetic */
220     {WINED3D_SM1_OP_NOP,      0, 0, WINED3DSIH_NOP,          0,                           0                          },
221     {WINED3D_SM1_OP_MOV,      1, 2, WINED3DSIH_MOV,          0,                           0                          },
222     {WINED3D_SM1_OP_MOVA,     1, 2, WINED3DSIH_MOVA,         WINED3D_SHADER_VERSION(2,0), -1                         },
223     {WINED3D_SM1_OP_ADD,      1, 3, WINED3DSIH_ADD,          0,                           0                          },
224     {WINED3D_SM1_OP_SUB,      1, 3, WINED3DSIH_SUB,          0,                           0                          },
225     {WINED3D_SM1_OP_MAD,      1, 4, WINED3DSIH_MAD,          0,                           0                          },
226     {WINED3D_SM1_OP_MUL,      1, 3, WINED3DSIH_MUL,          0,                           0                          },
227     {WINED3D_SM1_OP_RCP,      1, 2, WINED3DSIH_RCP,          0,                           0                          },
228     {WINED3D_SM1_OP_RSQ,      1, 2, WINED3DSIH_RSQ,          0,                           0                          },
229     {WINED3D_SM1_OP_DP3,      1, 3, WINED3DSIH_DP3,          0,                           0                          },
230     {WINED3D_SM1_OP_DP4,      1, 3, WINED3DSIH_DP4,          0,                           0                          },
231     {WINED3D_SM1_OP_MIN,      1, 3, WINED3DSIH_MIN,          0,                           0                          },
232     {WINED3D_SM1_OP_MAX,      1, 3, WINED3DSIH_MAX,          0,                           0                          },
233     {WINED3D_SM1_OP_SLT,      1, 3, WINED3DSIH_SLT,          0,                           0                          },
234     {WINED3D_SM1_OP_SGE,      1, 3, WINED3DSIH_SGE,          0,                           0                          },
235     {WINED3D_SM1_OP_ABS,      1, 2, WINED3DSIH_ABS,          0,                           0                          },
236     {WINED3D_SM1_OP_EXP,      1, 2, WINED3DSIH_EXP,          0,                           0                          },
237     {WINED3D_SM1_OP_LOG,      1, 2, WINED3DSIH_LOG,          0,                           0                          },
238     {WINED3D_SM1_OP_EXPP,     1, 2, WINED3DSIH_EXPP,         0,                           0                          },
239     {WINED3D_SM1_OP_LOGP,     1, 2, WINED3DSIH_LOGP,         0,                           0                          },
240     {WINED3D_SM1_OP_LIT,      1, 2, WINED3DSIH_LIT,          0,                           0                          },
241     {WINED3D_SM1_OP_DST,      1, 3, WINED3DSIH_DST,          0,                           0                          },
242     {WINED3D_SM1_OP_LRP,      1, 4, WINED3DSIH_LRP,          0,                           0                          },
243     {WINED3D_SM1_OP_FRC,      1, 2, WINED3DSIH_FRC,          0,                           0                          },
244     {WINED3D_SM1_OP_POW,      1, 3, WINED3DSIH_POW,          0,                           0                          },
245     {WINED3D_SM1_OP_CRS,      1, 3, WINED3DSIH_CRS,          0,                           0                          },
246     {WINED3D_SM1_OP_SGN,      1, 4, WINED3DSIH_SGN,          WINED3D_SHADER_VERSION(2,0), WINED3D_SHADER_VERSION(2,1)},
247     {WINED3D_SM1_OP_SGN,      1, 2, WINED3DSIH_SGN,          WINED3D_SHADER_VERSION(3,0), -1                         },
248     {WINED3D_SM1_OP_NRM,      1, 2, WINED3DSIH_NRM,          0,                           0                          },
249     {WINED3D_SM1_OP_SINCOS,   1, 4, WINED3DSIH_SINCOS,       WINED3D_SHADER_VERSION(2,0), WINED3D_SHADER_VERSION(2,1)},
250     {WINED3D_SM1_OP_SINCOS,   1, 2, WINED3DSIH_SINCOS,       WINED3D_SHADER_VERSION(3,0), -1                         },
251     /* Matrix */
252     {WINED3D_SM1_OP_M4x4,     1, 3, WINED3DSIH_M4x4,         0,                           0                          },
253     {WINED3D_SM1_OP_M4x3,     1, 3, WINED3DSIH_M4x3,         0,                           0                          },
254     {WINED3D_SM1_OP_M3x4,     1, 3, WINED3DSIH_M3x4,         0,                           0                          },
255     {WINED3D_SM1_OP_M3x3,     1, 3, WINED3DSIH_M3x3,         0,                           0                          },
256     {WINED3D_SM1_OP_M3x2,     1, 3, WINED3DSIH_M3x2,         0,                           0                          },
257     /* Declare registers */
258     {WINED3D_SM1_OP_DCL,      0, 2, WINED3DSIH_DCL,          0,                           0                          },
259     /* Constant definitions */
260     {WINED3D_SM1_OP_DEF,      1, 5, WINED3DSIH_DEF,          0,                           0                          },
261     {WINED3D_SM1_OP_DEFB,     1, 2, WINED3DSIH_DEFB,         0,                           0                          },
262     {WINED3D_SM1_OP_DEFI,     1, 5, WINED3DSIH_DEFI,         0,                           0                          },
263     /* Flow control */
264     {WINED3D_SM1_OP_REP,      0, 1, WINED3DSIH_REP,          WINED3D_SHADER_VERSION(2,0), -1                         },
265     {WINED3D_SM1_OP_ENDREP,   0, 0, WINED3DSIH_ENDREP,       WINED3D_SHADER_VERSION(2,0), -1                         },
266     {WINED3D_SM1_OP_IF,       0, 1, WINED3DSIH_IF,           WINED3D_SHADER_VERSION(2,0), -1                         },
267     {WINED3D_SM1_OP_IFC,      0, 2, WINED3DSIH_IFC,          WINED3D_SHADER_VERSION(2,1), -1                         },
268     {WINED3D_SM1_OP_ELSE,     0, 0, WINED3DSIH_ELSE,         WINED3D_SHADER_VERSION(2,0), -1                         },
269     {WINED3D_SM1_OP_ENDIF,    0, 0, WINED3DSIH_ENDIF,        WINED3D_SHADER_VERSION(2,0), -1                         },
270     {WINED3D_SM1_OP_BREAK,    0, 0, WINED3DSIH_BREAK,        WINED3D_SHADER_VERSION(2,1), -1                         },
271     {WINED3D_SM1_OP_BREAKC,   0, 2, WINED3DSIH_BREAKC,       WINED3D_SHADER_VERSION(2,1), -1                         },
272     {WINED3D_SM1_OP_BREAKP,   0, 1, WINED3DSIH_BREAKP,       0,                           0                          },
273     {WINED3D_SM1_OP_CALL,     0, 1, WINED3DSIH_CALL,         WINED3D_SHADER_VERSION(2,0), -1                         },
274     {WINED3D_SM1_OP_CALLNZ,   0, 2, WINED3DSIH_CALLNZ,       WINED3D_SHADER_VERSION(2,0), -1                         },
275     {WINED3D_SM1_OP_LOOP,     0, 2, WINED3DSIH_LOOP,         WINED3D_SHADER_VERSION(2,0), -1                         },
276     {WINED3D_SM1_OP_RET,      0, 0, WINED3DSIH_RET,          WINED3D_SHADER_VERSION(2,0), -1                         },
277     {WINED3D_SM1_OP_ENDLOOP,  0, 0, WINED3DSIH_ENDLOOP,      WINED3D_SHADER_VERSION(2,0), -1                         },
278     {WINED3D_SM1_OP_LABEL,    0, 1, WINED3DSIH_LABEL,        WINED3D_SHADER_VERSION(2,0), -1                         },
279
280     {WINED3D_SM1_OP_SETP,     1, 3, WINED3DSIH_SETP,         0,                           0                          },
281     {WINED3D_SM1_OP_TEXLDL,   1, 3, WINED3DSIH_TEXLDL,       WINED3D_SHADER_VERSION(3,0), -1                         },
282     {0,                       0, 0, WINED3DSIH_TABLE_SIZE,   0,                           0                          },
283 };
284
285 static const struct wined3d_sm1_opcode_info ps_opcode_table[] =
286 {
287     /* Arithmetic */
288     {WINED3D_SM1_OP_NOP,      0, 0, WINED3DSIH_NOP,          0,                           0                          },
289     {WINED3D_SM1_OP_MOV,      1, 2, WINED3DSIH_MOV,          0,                           0                          },
290     {WINED3D_SM1_OP_ADD,      1, 3, WINED3DSIH_ADD,          0,                           0                          },
291     {WINED3D_SM1_OP_SUB,      1, 3, WINED3DSIH_SUB,          0,                           0                          },
292     {WINED3D_SM1_OP_MAD,      1, 4, WINED3DSIH_MAD,          0,                           0                          },
293     {WINED3D_SM1_OP_MUL,      1, 3, WINED3DSIH_MUL,          0,                           0                          },
294     {WINED3D_SM1_OP_RCP,      1, 2, WINED3DSIH_RCP,          0,                           0                          },
295     {WINED3D_SM1_OP_RSQ,      1, 2, WINED3DSIH_RSQ,          0,                           0                          },
296     {WINED3D_SM1_OP_DP3,      1, 3, WINED3DSIH_DP3,          0,                           0                          },
297     {WINED3D_SM1_OP_DP4,      1, 3, WINED3DSIH_DP4,          0,                           0                          },
298     {WINED3D_SM1_OP_MIN,      1, 3, WINED3DSIH_MIN,          0,                           0                          },
299     {WINED3D_SM1_OP_MAX,      1, 3, WINED3DSIH_MAX,          0,                           0                          },
300     {WINED3D_SM1_OP_SLT,      1, 3, WINED3DSIH_SLT,          0,                           0                          },
301     {WINED3D_SM1_OP_SGE,      1, 3, WINED3DSIH_SGE,          0,                           0                          },
302     {WINED3D_SM1_OP_ABS,      1, 2, WINED3DSIH_ABS,          0,                           0                          },
303     {WINED3D_SM1_OP_EXP,      1, 2, WINED3DSIH_EXP,          0,                           0                          },
304     {WINED3D_SM1_OP_LOG,      1, 2, WINED3DSIH_LOG,          0,                           0                          },
305     {WINED3D_SM1_OP_EXPP,     1, 2, WINED3DSIH_EXPP,         0,                           0                          },
306     {WINED3D_SM1_OP_LOGP,     1, 2, WINED3DSIH_LOGP,         0,                           0                          },
307     {WINED3D_SM1_OP_DST,      1, 3, WINED3DSIH_DST,          0,                           0                          },
308     {WINED3D_SM1_OP_LRP,      1, 4, WINED3DSIH_LRP,          0,                           0                          },
309     {WINED3D_SM1_OP_FRC,      1, 2, WINED3DSIH_FRC,          0,                           0                          },
310     {WINED3D_SM1_OP_CND,      1, 4, WINED3DSIH_CND,          WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,4)},
311     {WINED3D_SM1_OP_CMP,      1, 4, WINED3DSIH_CMP,          WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(3,0)},
312     {WINED3D_SM1_OP_POW,      1, 3, WINED3DSIH_POW,          0,                           0                          },
313     {WINED3D_SM1_OP_CRS,      1, 3, WINED3DSIH_CRS,          0,                           0                          },
314     {WINED3D_SM1_OP_NRM,      1, 2, WINED3DSIH_NRM,          0,                           0                          },
315     {WINED3D_SM1_OP_SINCOS,   1, 4, WINED3DSIH_SINCOS,       WINED3D_SHADER_VERSION(2,0), WINED3D_SHADER_VERSION(2,1)},
316     {WINED3D_SM1_OP_SINCOS,   1, 2, WINED3DSIH_SINCOS,       WINED3D_SHADER_VERSION(3,0), -1                         },
317     {WINED3D_SM1_OP_DP2ADD,   1, 4, WINED3DSIH_DP2ADD,       WINED3D_SHADER_VERSION(2,0), -1                         },
318     /* Matrix */
319     {WINED3D_SM1_OP_M4x4,     1, 3, WINED3DSIH_M4x4,         0,                           0                          },
320     {WINED3D_SM1_OP_M4x3,     1, 3, WINED3DSIH_M4x3,         0,                           0                          },
321     {WINED3D_SM1_OP_M3x4,     1, 3, WINED3DSIH_M3x4,         0,                           0                          },
322     {WINED3D_SM1_OP_M3x3,     1, 3, WINED3DSIH_M3x3,         0,                           0                          },
323     {WINED3D_SM1_OP_M3x2,     1, 3, WINED3DSIH_M3x2,         0,                           0                          },
324     /* Register declarations */
325     {WINED3D_SM1_OP_DCL,      0, 2, WINED3DSIH_DCL,          0,                           0                          },
326     /* Flow control */
327     {WINED3D_SM1_OP_REP,      0, 1, WINED3DSIH_REP,          WINED3D_SHADER_VERSION(2,1), -1                         },
328     {WINED3D_SM1_OP_ENDREP,   0, 0, WINED3DSIH_ENDREP,       WINED3D_SHADER_VERSION(2,1), -1                         },
329     {WINED3D_SM1_OP_IF,       0, 1, WINED3DSIH_IF,           WINED3D_SHADER_VERSION(2,1), -1                         },
330     {WINED3D_SM1_OP_IFC,      0, 2, WINED3DSIH_IFC,          WINED3D_SHADER_VERSION(2,1), -1                         },
331     {WINED3D_SM1_OP_ELSE,     0, 0, WINED3DSIH_ELSE,         WINED3D_SHADER_VERSION(2,1), -1                         },
332     {WINED3D_SM1_OP_ENDIF,    0, 0, WINED3DSIH_ENDIF,        WINED3D_SHADER_VERSION(2,1), -1                         },
333     {WINED3D_SM1_OP_BREAK,    0, 0, WINED3DSIH_BREAK,        WINED3D_SHADER_VERSION(2,1), -1                         },
334     {WINED3D_SM1_OP_BREAKC,   0, 2, WINED3DSIH_BREAKC,       WINED3D_SHADER_VERSION(2,1), -1                         },
335     {WINED3D_SM1_OP_BREAKP,   0, 1, WINED3DSIH_BREAKP,       0,                           0                          },
336     {WINED3D_SM1_OP_CALL,     0, 1, WINED3DSIH_CALL,         WINED3D_SHADER_VERSION(2,1), -1                         },
337     {WINED3D_SM1_OP_CALLNZ,   0, 2, WINED3DSIH_CALLNZ,       WINED3D_SHADER_VERSION(2,1), -1                         },
338     {WINED3D_SM1_OP_LOOP,     0, 2, WINED3DSIH_LOOP,         WINED3D_SHADER_VERSION(3,0), -1                         },
339     {WINED3D_SM1_OP_RET,      0, 0, WINED3DSIH_RET,          WINED3D_SHADER_VERSION(2,1), -1                         },
340     {WINED3D_SM1_OP_ENDLOOP,  0, 0, WINED3DSIH_ENDLOOP,      WINED3D_SHADER_VERSION(3,0), -1                         },
341     {WINED3D_SM1_OP_LABEL,    0, 1, WINED3DSIH_LABEL,        WINED3D_SHADER_VERSION(2,1), -1                         },
342     /* Constant definitions */
343     {WINED3D_SM1_OP_DEF,      1, 5, WINED3DSIH_DEF,          0,                           0                          },
344     {WINED3D_SM1_OP_DEFB,     1, 2, WINED3DSIH_DEFB,         0,                           0                          },
345     {WINED3D_SM1_OP_DEFI,     1, 5, WINED3DSIH_DEFI,         0,                           0                          },
346     /* Texture */
347     {WINED3D_SM1_OP_TEXCOORD, 1, 1, WINED3DSIH_TEXCOORD,     0,                           WINED3D_SHADER_VERSION(1,3)},
348     {WINED3D_SM1_OP_TEXCOORD, 1, 2, WINED3DSIH_TEXCOORD,     WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
349     {WINED3D_SM1_OP_TEXKILL,  1, 1, WINED3DSIH_TEXKILL,      WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(3,0)},
350     {WINED3D_SM1_OP_TEX,      1, 1, WINED3DSIH_TEX,          0,                           WINED3D_SHADER_VERSION(1,3)},
351     {WINED3D_SM1_OP_TEX,      1, 2, WINED3DSIH_TEX,          WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
352     {WINED3D_SM1_OP_TEX,      1, 3, WINED3DSIH_TEX,          WINED3D_SHADER_VERSION(2,0), -1                         },
353     {WINED3D_SM1_OP_TEXBEM,   1, 2, WINED3DSIH_TEXBEM,       0,                           WINED3D_SHADER_VERSION(1,3)},
354     {WINED3D_SM1_OP_TEXBEML,  1, 2, WINED3DSIH_TEXBEML,      WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
355     {WINED3D_SM1_OP_TEXREG2AR,      1, 2, WINED3DSIH_TEXREG2AR,    WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
356     {WINED3D_SM1_OP_TEXREG2GB,      1, 2, WINED3DSIH_TEXREG2GB,    WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
357     {WINED3D_SM1_OP_TEXREG2RGB,     1, 2, WINED3DSIH_TEXREG2RGB,   WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
358     {WINED3D_SM1_OP_TEXM3x2PAD,     1, 2, WINED3DSIH_TEXM3x2PAD,   WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
359     {WINED3D_SM1_OP_TEXM3x2TEX,     1, 2, WINED3DSIH_TEXM3x2TEX,   WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
360     {WINED3D_SM1_OP_TEXM3x3PAD,     1, 2, WINED3DSIH_TEXM3x3PAD,   WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
361     {WINED3D_SM1_OP_TEXM3x3DIFF,    1, 2, WINED3DSIH_TEXM3x3DIFF,  WINED3D_SHADER_VERSION(0,0), WINED3D_SHADER_VERSION(0,0)},
362     {WINED3D_SM1_OP_TEXM3x3SPEC,    1, 3, WINED3DSIH_TEXM3x3SPEC,  WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
363     {WINED3D_SM1_OP_TEXM3x3VSPEC,   1, 2, WINED3DSIH_TEXM3x3VSPEC, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
364     {WINED3D_SM1_OP_TEXM3x3TEX,     1, 2, WINED3DSIH_TEXM3x3TEX,   WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
365     {WINED3D_SM1_OP_TEXDP3TEX,      1, 2, WINED3DSIH_TEXDP3TEX,    WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
366     {WINED3D_SM1_OP_TEXM3x2DEPTH,   1, 2, WINED3DSIH_TEXM3x2DEPTH, WINED3D_SHADER_VERSION(1,3), WINED3D_SHADER_VERSION(1,3)},
367     {WINED3D_SM1_OP_TEXDP3,   1, 2, WINED3DSIH_TEXDP3,       WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
368     {WINED3D_SM1_OP_TEXM3x3,  1, 2, WINED3DSIH_TEXM3x3,      WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
369     {WINED3D_SM1_OP_TEXDEPTH, 1, 1, WINED3DSIH_TEXDEPTH,     WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
370     {WINED3D_SM1_OP_BEM,      1, 3, WINED3DSIH_BEM,          WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
371     {WINED3D_SM1_OP_DSX,      1, 2, WINED3DSIH_DSX,          WINED3D_SHADER_VERSION(2,1), -1                         },
372     {WINED3D_SM1_OP_DSY,      1, 2, WINED3DSIH_DSY,          WINED3D_SHADER_VERSION(2,1), -1                         },
373     {WINED3D_SM1_OP_TEXLDD,   1, 5, WINED3DSIH_TEXLDD,       WINED3D_SHADER_VERSION(2,1), -1                         },
374     {WINED3D_SM1_OP_SETP,     1, 3, WINED3DSIH_SETP,         0,                           0                          },
375     {WINED3D_SM1_OP_TEXLDL,   1, 3, WINED3DSIH_TEXLDL,       WINED3D_SHADER_VERSION(3,0), -1                         },
376     {WINED3D_SM1_OP_PHASE,    0, 0, WINED3DSIH_PHASE,        0,                           0                          },
377     {0,                       0, 0, WINED3DSIH_TABLE_SIZE,   0,                           0                          },
378 };
379
380 /* Read a parameter opcode from the input stream,
381  * and possibly a relative addressing token.
382  * Return the number of tokens read */
383 static int shader_get_param(const struct wined3d_sm1_data *priv, const DWORD *ptr, DWORD *token, DWORD *addr_token)
384 {
385     UINT count = 1;
386
387     *token = *ptr;
388
389     /* PS >= 3.0 have relative addressing (with token)
390      * VS >= 2.0 have relative addressing (with token)
391      * VS >= 1.0 < 2.0 have relative addressing (without token)
392      * The version check below should work in general */
393     if (*ptr & WINED3DSHADER_ADDRMODE_RELATIVE)
394     {
395         if (priv->shader_version.major < 2)
396         {
397             *addr_token = (1 << 31)
398                     | ((WINED3DSPR_ADDR << WINED3DSP_REGTYPE_SHIFT2) & WINED3DSP_REGTYPE_MASK2)
399                     | ((WINED3DSPR_ADDR << WINED3DSP_REGTYPE_SHIFT) & WINED3DSP_REGTYPE_MASK)
400                     | (WINED3DSP_NOSWIZZLE << WINED3DSP_SWIZZLE_SHIFT);
401         }
402         else
403         {
404             *addr_token = *(ptr + 1);
405             ++count;
406         }
407     }
408
409     return count;
410 }
411
412 static const struct wined3d_sm1_opcode_info *shader_get_opcode(const struct wined3d_sm1_data *priv, DWORD code)
413 {
414     DWORD shader_version = WINED3D_SHADER_VERSION(priv->shader_version.major, priv->shader_version.minor);
415     const struct wined3d_sm1_opcode_info *opcode_table = priv->opcode_table;
416     DWORD i = 0;
417
418     while (opcode_table[i].handler_idx != WINED3DSIH_TABLE_SIZE)
419     {
420         if ((code & WINED3DSI_OPCODE_MASK) == opcode_table[i].opcode
421                 && shader_version >= opcode_table[i].min_version
422                 && (!opcode_table[i].max_version || shader_version <= opcode_table[i].max_version))
423         {
424             return &opcode_table[i];
425         }
426         ++i;
427     }
428
429     FIXME("Unsupported opcode %#x(%d) masked %#x, shader version %#x\n",
430             code, code, code & WINED3DSI_OPCODE_MASK, shader_version);
431
432     return NULL;
433 }
434
435 /* Return the number of parameters to skip for an opcode */
436 static int shader_skip_opcode(const struct wined3d_sm1_data *priv,
437         const struct wined3d_sm1_opcode_info *opcode_info, DWORD opcode_token)
438 {
439    /* Shaders >= 2.0 may contain address tokens, but fortunately they
440     * have a useful length mask - use it here. Shaders 1.0 contain no such tokens */
441     return (priv->shader_version.major >= 2)
442             ? ((opcode_token & WINED3DSI_INSTLENGTH_MASK) >> WINED3DSI_INSTLENGTH_SHIFT) : opcode_info->param_count;
443 }
444
445 static void shader_parse_src_param(DWORD param, const struct wined3d_shader_src_param *rel_addr,
446         struct wined3d_shader_src_param *src)
447 {
448     src->reg.type = ((param & WINED3DSP_REGTYPE_MASK) >> WINED3DSP_REGTYPE_SHIFT)
449             | ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2);
450     src->reg.data_type = WINED3D_DATA_FLOAT;
451     src->reg.idx = param & WINED3DSP_REGNUM_MASK;
452     src->reg.array_idx = ~0U;
453     src->swizzle = (param & WINED3DSP_SWIZZLE_MASK) >> WINED3DSP_SWIZZLE_SHIFT;
454     src->modifiers = (param & WINED3DSP_SRCMOD_MASK) >> WINED3DSP_SRCMOD_SHIFT;
455     src->reg.rel_addr = rel_addr;
456 }
457
458 static void shader_parse_dst_param(DWORD param, const struct wined3d_shader_src_param *rel_addr,
459         struct wined3d_shader_dst_param *dst)
460 {
461     dst->reg.type = ((param & WINED3DSP_REGTYPE_MASK) >> WINED3DSP_REGTYPE_SHIFT)
462             | ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2);
463     dst->reg.data_type = WINED3D_DATA_FLOAT;
464     dst->reg.idx = param & WINED3DSP_REGNUM_MASK;
465     dst->reg.array_idx = ~0U;
466     dst->write_mask = (param & WINED3D_SM1_WRITEMASK_MASK) >> WINED3D_SM1_WRITEMASK_SHIFT;
467     dst->modifiers = (param & WINED3DSP_DSTMOD_MASK) >> WINED3DSP_DSTMOD_SHIFT;
468     dst->shift = (param & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT;
469     dst->reg.rel_addr = rel_addr;
470 }
471
472 /* Read the parameters of an unrecognized opcode from the input stream
473  * Return the number of tokens read.
474  *
475  * Note: This function assumes source or destination token format.
476  * It will not work with specially-formatted tokens like DEF or DCL,
477  * but hopefully those would be recognized */
478 static int shader_skip_unrecognized(const struct wined3d_sm1_data *priv, const DWORD *ptr)
479 {
480     int tokens_read = 0;
481     int i = 0;
482
483     /* TODO: Think of a good name for 0x80000000 and replace it with a constant */
484     while (*ptr & 0x80000000)
485     {
486         DWORD token, addr_token = 0;
487         struct wined3d_shader_src_param rel_addr;
488
489         tokens_read += shader_get_param(priv, ptr, &token, &addr_token);
490         ptr += tokens_read;
491
492         FIXME("Unrecognized opcode param: token=0x%08x addr_token=0x%08x name=", token, addr_token);
493
494         if (token & WINED3DSHADER_ADDRMODE_RELATIVE) shader_parse_src_param(addr_token, NULL, &rel_addr);
495
496         if (!i)
497         {
498             struct wined3d_shader_dst_param dst;
499
500             shader_parse_dst_param(token, token & WINED3DSHADER_ADDRMODE_RELATIVE ? &rel_addr : NULL, &dst);
501             shader_dump_dst_param(&dst, &priv->shader_version);
502         }
503         else
504         {
505             struct wined3d_shader_src_param src;
506
507             shader_parse_src_param(token, token & WINED3DSHADER_ADDRMODE_RELATIVE ? &rel_addr : NULL, &src);
508             shader_dump_src_param(&src, &priv->shader_version);
509         }
510         FIXME("\n");
511         ++i;
512     }
513     return tokens_read;
514 }
515
516 static void *shader_sm1_init(const DWORD *byte_code, const struct wined3d_shader_signature *output_signature)
517 {
518     struct wined3d_sm1_data *priv;
519     BYTE major, minor;
520
521     major = WINED3D_SM1_VERSION_MAJOR(*byte_code);
522     minor = WINED3D_SM1_VERSION_MINOR(*byte_code);
523     if (WINED3D_SHADER_VERSION(major, minor) > WINED3D_SHADER_VERSION(3, 0))
524     {
525         WARN("Invalid shader version %u.%u (%#x).\n", major, minor, *byte_code);
526         return NULL;
527     }
528
529     priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv));
530     if (!priv)
531     {
532         ERR("Failed to allocate private data\n");
533         return NULL;
534     }
535
536     if (output_signature)
537     {
538         FIXME("SM 1-3 shader shouldn't have output signatures.\n");
539     }
540
541     switch (*byte_code >> 16)
542     {
543         case WINED3D_SM1_VS:
544             priv->shader_version.type = WINED3D_SHADER_TYPE_VERTEX;
545             priv->opcode_table = vs_opcode_table;
546             break;
547
548         case WINED3D_SM1_PS:
549             priv->shader_version.type = WINED3D_SHADER_TYPE_PIXEL;
550             priv->opcode_table = ps_opcode_table;
551             break;
552
553         default:
554             FIXME("Unrecognized shader type %#x\n", *byte_code >> 16);
555             HeapFree(GetProcessHeap(), 0, priv);
556             return NULL;
557     }
558
559     return priv;
560 }
561
562 static void shader_sm1_free(void *data)
563 {
564     HeapFree(GetProcessHeap(), 0, data);
565 }
566
567 static void shader_sm1_read_header(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version)
568 {
569     struct wined3d_sm1_data *priv = data;
570     DWORD version_token;
571
572     version_token = *(*ptr)++;
573     TRACE("version: 0x%08x\n", version_token);
574
575     priv->shader_version.major = WINED3D_SM1_VERSION_MAJOR(version_token);
576     priv->shader_version.minor = WINED3D_SM1_VERSION_MINOR(version_token);
577     *shader_version = priv->shader_version;
578 }
579
580 static void shader_sm1_read_src_param(struct wined3d_sm1_data *priv, const DWORD **ptr,
581         struct wined3d_shader_src_param *src_param, struct wined3d_shader_src_param *src_rel_addr)
582 {
583     DWORD token, addr_token;
584
585     *ptr += shader_get_param(priv, *ptr, &token, &addr_token);
586     if (token & WINED3DSHADER_ADDRMODE_RELATIVE)
587     {
588         shader_parse_src_param(addr_token, NULL, src_rel_addr);
589         shader_parse_src_param(token, src_rel_addr, src_param);
590     }
591     else
592     {
593         shader_parse_src_param(token, NULL, src_param);
594     }
595 }
596
597 static void shader_sm1_read_dst_param(struct wined3d_sm1_data *priv, const DWORD **ptr,
598         struct wined3d_shader_dst_param *dst_param, struct wined3d_shader_src_param *dst_rel_addr)
599 {
600     DWORD token, addr_token;
601
602     *ptr += shader_get_param(priv, *ptr, &token, &addr_token);
603     if (token & WINED3DSHADER_ADDRMODE_RELATIVE)
604     {
605         shader_parse_src_param(addr_token, NULL, dst_rel_addr);
606         shader_parse_dst_param(token, dst_rel_addr, dst_param);
607     }
608     else
609     {
610         shader_parse_dst_param(token, NULL, dst_param);
611     }
612 }
613
614 static void shader_sm1_read_semantic(const DWORD **ptr, struct wined3d_shader_semantic *semantic)
615 {
616     DWORD usage_token = *(*ptr)++;
617     DWORD dst_token = *(*ptr)++;
618
619     semantic->usage = (usage_token & WINED3DSP_DCL_USAGE_MASK) >> WINED3DSP_DCL_USAGE_SHIFT;
620     semantic->usage_idx = (usage_token & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
621     semantic->sampler_type = (usage_token & WINED3DSP_TEXTURETYPE_MASK) >> WINED3DSP_TEXTURETYPE_SHIFT;
622     shader_parse_dst_param(dst_token, NULL, &semantic->reg);
623 }
624
625 static void shader_sm1_read_immconst(const DWORD **ptr, struct wined3d_shader_src_param *src_param,
626         enum wined3d_immconst_type type, enum wined3d_data_type data_type)
627 {
628     UINT count = type == WINED3D_IMMCONST_VEC4 ? 4 : 1;
629     src_param->reg.type = WINED3DSPR_IMMCONST;
630     src_param->reg.data_type = data_type;
631     src_param->reg.idx = ~0U;
632     src_param->reg.array_idx = ~0U;
633     src_param->reg.rel_addr = NULL;
634     src_param->reg.immconst_type = type;
635     memcpy(src_param->reg.immconst_data, *ptr, count * sizeof(DWORD));
636     src_param->swizzle = WINED3DSP_NOSWIZZLE;
637     src_param->modifiers = 0;
638
639     *ptr += count;
640 }
641
642 static void shader_sm1_read_instruction(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins)
643 {
644     const struct wined3d_sm1_opcode_info *opcode_info;
645     struct wined3d_sm1_data *priv = data;
646     DWORD opcode_token;
647     unsigned int i;
648     const DWORD *p;
649
650     opcode_token = *(*ptr)++;
651     if (!(opcode_info = shader_get_opcode(priv, opcode_token)))
652     {
653         FIXME("Unrecognized opcode: token=0x%08x.\n", opcode_token);
654         ins->handler_idx = WINED3DSIH_TABLE_SIZE;
655         *ptr += shader_skip_unrecognized(priv, *ptr);
656         return;
657     }
658
659     ins->handler_idx = opcode_info->handler_idx;
660     ins->flags = (opcode_token & WINED3D_OPCODESPECIFICCONTROL_MASK) >> WINED3D_OPCODESPECIFICCONTROL_SHIFT;
661     ins->coissue = opcode_token & WINED3DSI_COISSUE;
662     ins->predicate = opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED ? &priv->pred_param : NULL;
663     ins->dst_count = opcode_info->dst_count ? 1 : 0;
664     ins->dst = &priv->dst_param;
665     ins->src_count = opcode_info->param_count - opcode_info->dst_count;
666     ins->src = priv->src_param;
667
668     p = *ptr;
669     *ptr += shader_skip_opcode(priv, opcode_info, opcode_token);
670
671     if (ins->handler_idx == WINED3DSIH_DCL)
672     {
673         shader_sm1_read_semantic(&p, &ins->declaration.semantic);
674     }
675     else if (ins->handler_idx == WINED3DSIH_DEF)
676     {
677         shader_sm1_read_dst_param(priv, &p, &priv->dst_param, &priv->dst_rel_addr);
678         shader_sm1_read_immconst(&p, &priv->src_param[0], WINED3D_IMMCONST_VEC4, WINED3D_DATA_FLOAT);
679     }
680     else if (ins->handler_idx == WINED3DSIH_DEFI)
681     {
682         shader_sm1_read_dst_param(priv, &p, &priv->dst_param, &priv->dst_rel_addr);
683         shader_sm1_read_immconst(&p, &priv->src_param[0], WINED3D_IMMCONST_VEC4, WINED3D_DATA_INT);
684     }
685     else if (ins->handler_idx == WINED3DSIH_DEFB)
686     {
687         shader_sm1_read_dst_param(priv, &p, &priv->dst_param, &priv->dst_rel_addr);
688         shader_sm1_read_immconst(&p, &priv->src_param[0], WINED3D_IMMCONST_SCALAR, WINED3D_DATA_UINT);
689     }
690     else
691     {
692         /* Destination token */
693         if (ins->dst_count)
694             shader_sm1_read_dst_param(priv, &p, &priv->dst_param, &priv->dst_rel_addr);
695
696         /* Predication token */
697         if (ins->predicate)
698             shader_sm1_read_src_param(priv, &p, &priv->pred_param, &priv->pred_rel_addr);
699
700         /* Other source tokens */
701         for (i = 0; i < ins->src_count; ++i)
702         {
703             shader_sm1_read_src_param(priv, &p, &priv->src_param[i], &priv->src_rel_addr[i]);
704         }
705     }
706 }
707
708 static void shader_sm1_read_comment(const DWORD **ptr, const char **comment, UINT *comment_size)
709 {
710     DWORD token = **ptr;
711     UINT size;
712
713     if ((token & WINED3DSI_OPCODE_MASK) != WINED3D_SM1_OP_COMMENT)
714     {
715         *comment = NULL;
716         return;
717     }
718
719     size = (token & WINED3DSI_COMMENTSIZE_MASK) >> WINED3DSI_COMMENTSIZE_SHIFT;
720     *comment = (const char *)++(*ptr);
721     *comment_size = size * sizeof(DWORD);
722     *ptr += size;
723 }
724
725 static BOOL shader_sm1_is_end(void *data, const DWORD **ptr)
726 {
727     if (**ptr == WINED3DSP_END)
728     {
729         ++(*ptr);
730         return TRUE;
731     }
732
733     return FALSE;
734 }
735
736 const struct wined3d_shader_frontend sm1_shader_frontend =
737 {
738     shader_sm1_init,
739     shader_sm1_free,
740     shader_sm1_read_header,
741     shader_sm1_read_instruction,
742     shader_sm1_read_comment,
743     shader_sm1_is_end,
744 };