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