msvcp90: Remove unused thiscall functions.
[wine] / dlls / wined3d / shader_sm4.c
1 /*
2  * Copyright 2009 Henri Verbeet for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "config.h"
20 #include "wine/port.h"
21
22 #include "wined3d_private.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
25
26 #define WINED3D_SM4_INSTRUCTION_MODIFIER        (1 << 31)
27
28 #define WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT    24
29 #define WINED3D_SM4_INSTRUCTION_LENGTH_MASK     (0xf << WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT)
30
31 #define WINED3D_SM4_OPCODE_MASK                 0xff
32
33 #define WINED3D_SM4_REGISTER_MODIFIER           (1 << 31)
34
35 #define WINED3D_SM4_REGISTER_ORDER_SHIFT        20
36 #define WINED3D_SM4_REGISTER_ORDER_MASK         (0x3 << WINED3D_SM4_REGISTER_ORDER_SHIFT)
37
38 #define WINED3D_SM4_REGISTER_TYPE_SHIFT         12
39 #define WINED3D_SM4_REGISTER_TYPE_MASK          (0xf << WINED3D_SM4_REGISTER_TYPE_SHIFT)
40
41 #define WINED3D_SM4_IMMCONST_TYPE_SHIFT         0
42 #define WINED3D_SM4_IMMCONST_TYPE_MASK          (0x3 << WINED3D_SM4_IMMCONST_TYPE_SHIFT)
43
44 #define WINED3D_SM4_WRITEMASK_SHIFT             4
45 #define WINED3D_SM4_WRITEMASK_MASK              (0xf << WINED3D_SM4_WRITEMASK_SHIFT)
46
47 #define WINED3D_SM4_SWIZZLE_SHIFT               4
48 #define WINED3D_SM4_SWIZZLE_MASK                (0xff << WINED3D_SM4_SWIZZLE_SHIFT)
49
50 #define WINED3D_SM4_VERSION_MAJOR(version)      (((version) >> 4) & 0xf)
51 #define WINED3D_SM4_VERSION_MINOR(version)      (((version) >> 0) & 0xf)
52
53 enum wined3d_sm4_opcode
54 {
55     WINED3D_SM4_OP_ADD          = 0x00,
56     WINED3D_SM4_OP_AND          = 0x01,
57     WINED3D_SM4_OP_BREAK        = 0x02,
58     WINED3D_SM4_OP_BREAKC       = 0x03,
59     WINED3D_SM4_OP_CUT          = 0x09,
60     WINED3D_SM4_OP_DERIV_RTX    = 0x0b,
61     WINED3D_SM4_OP_DERIV_RTY    = 0x0c,
62     WINED3D_SM4_OP_DIV          = 0x0e,
63     WINED3D_SM4_OP_DP3          = 0x10,
64     WINED3D_SM4_OP_DP4          = 0x11,
65     WINED3D_SM4_OP_EMIT         = 0x13,
66     WINED3D_SM4_OP_ENDIF        = 0x15,
67     WINED3D_SM4_OP_ENDLOOP      = 0x16,
68     WINED3D_SM4_OP_EQ           = 0x18,
69     WINED3D_SM4_OP_EXP          = 0x19,
70     WINED3D_SM4_OP_FRC          = 0x1a,
71     WINED3D_SM4_OP_FTOI         = 0x1b,
72     WINED3D_SM4_OP_GE           = 0x1d,
73     WINED3D_SM4_OP_IADD         = 0x1e,
74     WINED3D_SM4_OP_IF           = 0x1f,
75     WINED3D_SM4_OP_IEQ          = 0x20,
76     WINED3D_SM4_OP_IGE          = 0x21,
77     WINED3D_SM4_OP_IMUL         = 0x26,
78     WINED3D_SM4_OP_ITOF         = 0x2b,
79     WINED3D_SM4_OP_LD           = 0x2d,
80     WINED3D_SM4_OP_LOG          = 0x2f,
81     WINED3D_SM4_OP_LOOP         = 0x30,
82     WINED3D_SM4_OP_LT           = 0x31,
83     WINED3D_SM4_OP_MAD          = 0x32,
84     WINED3D_SM4_OP_MIN          = 0x33,
85     WINED3D_SM4_OP_MAX          = 0x34,
86     WINED3D_SM4_OP_MOV          = 0x36,
87     WINED3D_SM4_OP_MOVC         = 0x37,
88     WINED3D_SM4_OP_MUL          = 0x38,
89     WINED3D_SM4_OP_RET          = 0x3e,
90     WINED3D_SM4_OP_ROUND_NI     = 0x41,
91     WINED3D_SM4_OP_RSQ          = 0x44,
92     WINED3D_SM4_OP_SAMPLE       = 0x45,
93     WINED3D_SM4_OP_SAMPLE_LOD   = 0x48,
94     WINED3D_SM4_OP_SAMPLE_GRAD  = 0x49,
95     WINED3D_SM4_OP_SQRT         = 0x4b,
96     WINED3D_SM4_OP_SINCOS       = 0x4d,
97     WINED3D_SM4_OP_UDIV         = 0x4e,
98     WINED3D_SM4_OP_USHR         = 0x55,
99     WINED3D_SM4_OP_UTOF         = 0x56,
100     WINED3D_SM4_OP_XOR          = 0x57,
101 };
102
103 enum wined3d_sm4_register_type
104 {
105     WINED3D_SM4_RT_TEMP         = 0x0,
106     WINED3D_SM4_RT_INPUT        = 0x1,
107     WINED3D_SM4_RT_OUTPUT       = 0x2,
108     WINED3D_SM4_RT_IMMCONST     = 0x4,
109     WINED3D_SM4_RT_SAMPLER      = 0x6,
110     WINED3D_SM4_RT_CONSTBUFFER  = 0x8,
111     WINED3D_SM4_RT_NULL         = 0xd,
112 };
113
114 enum wined3d_sm4_immconst_type
115 {
116     WINED3D_SM4_IMMCONST_SCALAR = 0x1,
117     WINED3D_SM4_IMMCONST_VEC4   = 0x2,
118 };
119
120 struct wined3d_sm4_data
121 {
122     struct wined3d_shader_version shader_version;
123     const DWORD *end;
124     const struct wined3d_shader_signature *output_signature;
125
126     struct wined3d_shader_src_param src_rel_addr[5];
127     struct wined3d_shader_src_param dst_rel_addr[2];
128     struct wined3d_shader_src_param src_param[5];
129     struct wined3d_shader_dst_param dst_param[2];
130 };
131
132 struct wined3d_sm4_opcode_info
133 {
134     enum wined3d_sm4_opcode opcode;
135     enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
136     const char *dst_info;
137     const char *src_info;
138 };
139
140 struct sysval_map
141 {
142     enum wined3d_sysval_semantic sysval;
143     enum wined3d_shader_register_type register_type;
144     UINT register_idx;
145 };
146
147 /*
148  * F -> WINED3D_DATA_FLOAT
149  * I -> WINED3D_DATA_INT
150  * R -> WINED3D_DATA_RESOURCE
151  * S -> WINED3D_DATA_SAMPLER
152  * U -> WINED3D_DATA_UINT
153  */
154 static const struct wined3d_sm4_opcode_info opcode_table[] =
155 {
156     {WINED3D_SM4_OP_ADD,        WINED3DSIH_ADD,         "F",    "FF"},
157     {WINED3D_SM4_OP_AND,        WINED3DSIH_AND,         "U",    "UU"},
158     {WINED3D_SM4_OP_BREAK,      WINED3DSIH_BREAK,       "",     ""},
159     {WINED3D_SM4_OP_BREAKC,     WINED3DSIH_BREAKP,      "",     "U"},
160     {WINED3D_SM4_OP_CUT,        WINED3DSIH_CUT,         "",     ""},
161     {WINED3D_SM4_OP_DERIV_RTX,  WINED3DSIH_DSX,         "F",    "F"},
162     {WINED3D_SM4_OP_DERIV_RTY,  WINED3DSIH_DSY,         "F",    "F"},
163     {WINED3D_SM4_OP_DIV,        WINED3DSIH_DIV,         "F",    "FF"},
164     {WINED3D_SM4_OP_DP3,        WINED3DSIH_DP3,         "F",    "FF"},
165     {WINED3D_SM4_OP_DP4,        WINED3DSIH_DP4,         "F",    "FF"},
166     {WINED3D_SM4_OP_EMIT,       WINED3DSIH_EMIT,        "",     ""},
167     {WINED3D_SM4_OP_ENDIF,      WINED3DSIH_ENDIF,       "",     ""},
168     {WINED3D_SM4_OP_ENDLOOP,    WINED3DSIH_ENDLOOP,     "",     ""},
169     {WINED3D_SM4_OP_EQ,         WINED3DSIH_EQ,          "U",    "FF"},
170     {WINED3D_SM4_OP_EXP,        WINED3DSIH_EXP,         "F",    "F"},
171     {WINED3D_SM4_OP_FRC,        WINED3DSIH_FRC,         "F",    "F"},
172     {WINED3D_SM4_OP_FTOI,       WINED3DSIH_FTOI,        "I",    "F"},
173     {WINED3D_SM4_OP_GE,         WINED3DSIH_GE,          "U",    "FF"},
174     {WINED3D_SM4_OP_IADD,       WINED3DSIH_IADD,        "I",    "II"},
175     {WINED3D_SM4_OP_IF,         WINED3DSIH_IF,          "",     "U"},
176     {WINED3D_SM4_OP_IEQ,        WINED3DSIH_IEQ,         "U",    "II"},
177     {WINED3D_SM4_OP_IGE,        WINED3DSIH_IGE,         "U",    "II"},
178     {WINED3D_SM4_OP_IMUL,       WINED3DSIH_IMUL,        "II",   "II"},
179     {WINED3D_SM4_OP_ITOF,       WINED3DSIH_ITOF,        "F",    "I"},
180     {WINED3D_SM4_OP_LD,         WINED3DSIH_LD,          "U",    "FR"},
181     {WINED3D_SM4_OP_LOG,        WINED3DSIH_LOG,         "F",    "F"},
182     {WINED3D_SM4_OP_LOOP,       WINED3DSIH_LOOP,        "",     ""},
183     {WINED3D_SM4_OP_LT,         WINED3DSIH_LT,          "U",    "FF"},
184     {WINED3D_SM4_OP_MAD,        WINED3DSIH_MAD,         "F",    "FFF"},
185     {WINED3D_SM4_OP_MIN,        WINED3DSIH_MIN,         "F",    "FF"},
186     {WINED3D_SM4_OP_MAX,        WINED3DSIH_MAX,         "F",    "FF"},
187     {WINED3D_SM4_OP_MOV,        WINED3DSIH_MOV,         "F",    "F"},
188     {WINED3D_SM4_OP_MOVC,       WINED3DSIH_MOVC,        "F",    "UFF"},
189     {WINED3D_SM4_OP_MUL,        WINED3DSIH_MUL,         "F",    "FF"},
190     {WINED3D_SM4_OP_RET,        WINED3DSIH_RET,         "",     ""},
191     {WINED3D_SM4_OP_ROUND_NI,   WINED3DSIH_ROUND_NI,    "F",    "F"},
192     {WINED3D_SM4_OP_RSQ,        WINED3DSIH_RSQ,         "F",    "F"},
193     {WINED3D_SM4_OP_SAMPLE,     WINED3DSIH_SAMPLE,      "U",    "FRS"},
194     {WINED3D_SM4_OP_SAMPLE_LOD, WINED3DSIH_SAMPLE_LOD,  "U",    "FRSF"},
195     {WINED3D_SM4_OP_SAMPLE_GRAD,WINED3DSIH_SAMPLE_GRAD, "U",    "FRSFF"},
196     {WINED3D_SM4_OP_SQRT,       WINED3DSIH_SQRT,        "F",    "F"},
197     {WINED3D_SM4_OP_SINCOS,     WINED3DSIH_SINCOS,      "FF",   "F"},
198     {WINED3D_SM4_OP_UDIV,       WINED3DSIH_UDIV,        "UU",   "UU"},
199     {WINED3D_SM4_OP_USHR,       WINED3DSIH_USHR,        "U",    "UU"},
200     {WINED3D_SM4_OP_UTOF,       WINED3DSIH_UTOF,        "F",    "U"},
201     {WINED3D_SM4_OP_XOR,        WINED3DSIH_XOR,         "U",    "UU"},
202 };
203
204 static const enum wined3d_shader_register_type register_type_table[] =
205 {
206     /* WINED3D_SM4_RT_TEMP */           WINED3DSPR_TEMP,
207     /* WINED3D_SM4_RT_INPUT */          WINED3DSPR_INPUT,
208     /* WINED3D_SM4_RT_OUTPUT */         WINED3DSPR_OUTPUT,
209     /* UNKNOWN */                       0,
210     /* WINED3D_SM4_RT_IMMCONST */       WINED3DSPR_IMMCONST,
211     /* UNKNOWN */                       0,
212     /* WINED3D_SM4_RT_SAMPLER */        WINED3DSPR_SAMPLER,
213     /* WINED3D_SM4_RT_RESOURCE */       WINED3DSPR_RESOURCE,
214     /* WINED3D_SM4_RT_CONSTBUFFER */    WINED3DSPR_CONSTBUFFER,
215     /* UNKNOWN */                       0,
216     /* UNKNOWN */                       0,
217     /* UNKNOWN */                       0,
218     /* UNKNOWN */                       0,
219     /* WINED3D_SM4_RT_NULL */           WINED3DSPR_NULL,
220 };
221
222 static const struct sysval_map sysval_map[] =
223 {
224     {WINED3D_SV_DEPTH,      WINED3DSPR_DEPTHOUT,    0},
225     {WINED3D_SV_TARGET0,    WINED3DSPR_COLOROUT,    0},
226     {WINED3D_SV_TARGET1,    WINED3DSPR_COLOROUT,    1},
227     {WINED3D_SV_TARGET2,    WINED3DSPR_COLOROUT,    2},
228     {WINED3D_SV_TARGET3,    WINED3DSPR_COLOROUT,    3},
229     {WINED3D_SV_TARGET4,    WINED3DSPR_COLOROUT,    4},
230     {WINED3D_SV_TARGET5,    WINED3DSPR_COLOROUT,    5},
231     {WINED3D_SV_TARGET6,    WINED3DSPR_COLOROUT,    6},
232     {WINED3D_SV_TARGET7,    WINED3DSPR_COLOROUT,    7},
233 };
234
235 static const struct wined3d_sm4_opcode_info *get_opcode_info(enum wined3d_sm4_opcode opcode)
236 {
237     unsigned int i;
238
239     for (i = 0; i < sizeof(opcode_table) / sizeof(*opcode_table); ++i)
240     {
241         if (opcode == opcode_table[i].opcode) return &opcode_table[i];
242     }
243
244     return NULL;
245 }
246
247 static void map_sysval(enum wined3d_sysval_semantic sysval, struct wined3d_shader_register *reg)
248 {
249     unsigned int i;
250
251     for (i = 0; i < sizeof(sysval_map) / sizeof(*sysval_map); ++i)
252     {
253         if (sysval == sysval_map[i].sysval)
254         {
255             reg->type = sysval_map[i].register_type;
256             reg->idx = sysval_map[i].register_idx;
257         }
258     }
259 }
260
261 static void map_register(const struct wined3d_sm4_data *priv, struct wined3d_shader_register *reg)
262 {
263     switch (priv->shader_version.type)
264     {
265         case WINED3D_SHADER_TYPE_PIXEL:
266             if (reg->type == WINED3DSPR_OUTPUT)
267             {
268                 unsigned int i;
269                 const struct wined3d_shader_signature *s = priv->output_signature;
270
271                 if (!s)
272                 {
273                     ERR("Shader has no output signature, unable to map register.\n");
274                     break;
275                 }
276
277                 for (i = 0; i < s->element_count; ++i)
278                 {
279                     if (s->elements[i].register_idx == reg->idx)
280                     {
281                         map_sysval(s->elements[i].sysval_semantic, reg);
282                         break;
283                     }
284                 }
285             }
286             break;
287
288         default:
289             break;
290     }
291 }
292
293 static enum wined3d_data_type map_data_type(char t)
294 {
295     switch (t)
296     {
297         case 'F':
298             return WINED3D_DATA_FLOAT;
299         case 'I':
300             return WINED3D_DATA_INT;
301         case 'R':
302             return WINED3D_DATA_RESOURCE;
303         case 'S':
304             return WINED3D_DATA_SAMPLER;
305         case 'U':
306             return WINED3D_DATA_UINT;
307         default:
308             ERR("Invalid data type '%c'.\n", t);
309             return WINED3D_DATA_FLOAT;
310     }
311 }
312
313 static void *shader_sm4_init(const DWORD *byte_code, const struct wined3d_shader_signature *output_signature)
314 {
315     struct wined3d_sm4_data *priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv));
316     if (!priv)
317     {
318         ERR("Failed to allocate private data\n");
319         return NULL;
320     }
321
322     priv->output_signature = output_signature;
323
324     return priv;
325 }
326
327 static void shader_sm4_free(void *data)
328 {
329     HeapFree(GetProcessHeap(), 0, data);
330 }
331
332 static void shader_sm4_read_header(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version)
333 {
334     struct wined3d_sm4_data *priv = data;
335     DWORD version_token;
336
337     priv->end = *ptr;
338
339     version_token = *(*ptr)++;
340     TRACE("version: 0x%08x\n", version_token);
341
342     TRACE("token count: %u\n", **ptr);
343     priv->end += *(*ptr)++;
344
345     switch (version_token >> 16)
346     {
347         case WINED3D_SM4_PS:
348             priv->shader_version.type = WINED3D_SHADER_TYPE_PIXEL;
349             break;
350
351         case WINED3D_SM4_VS:
352             priv->shader_version.type = WINED3D_SHADER_TYPE_VERTEX;
353             break;
354
355         case WINED3D_SM4_GS:
356             priv->shader_version.type = WINED3D_SHADER_TYPE_GEOMETRY;
357             break;
358
359         default:
360             FIXME("Unrecognized shader type %#x\n", version_token >> 16);
361     }
362     priv->shader_version.major = WINED3D_SM4_VERSION_MAJOR(version_token);
363     priv->shader_version.minor = WINED3D_SM4_VERSION_MINOR(version_token);
364
365     *shader_version = priv->shader_version;
366 }
367
368 static void shader_sm4_read_src_param(struct wined3d_sm4_data *priv, const DWORD **ptr,
369         enum wined3d_data_type data_type, struct wined3d_shader_src_param *src_param,
370         struct wined3d_shader_src_param *src_rel_addr)
371 {
372     DWORD token = *(*ptr)++;
373     enum wined3d_sm4_register_type register_type;
374     DWORD order;
375
376     register_type = (token & WINED3D_SM4_REGISTER_TYPE_MASK) >> WINED3D_SM4_REGISTER_TYPE_SHIFT;
377     if (register_type >= sizeof(register_type_table) / sizeof(*register_type_table))
378     {
379         FIXME("Unhandled register type %#x\n", register_type);
380         src_param->reg.type = WINED3DSPR_TEMP;
381     }
382     else
383     {
384         src_param->reg.type = register_type_table[register_type];
385     }
386     src_param->reg.data_type = data_type;
387
388     if (token & WINED3D_SM4_REGISTER_MODIFIER)
389     {
390         DWORD modifier = *(*ptr)++;
391
392         /* FIXME: This will probably break down at some point. The SM4
393          * modifiers look like flags, while wined3d currently has an enum
394          * with possible combinations, e.g. WINED3DSPSM_ABSNEG. */
395         switch (modifier)
396         {
397             case 0x41:
398                 src_param->modifiers = WINED3DSPSM_NEG;
399                 break;
400
401             case 0x81:
402                 src_param->modifiers = WINED3DSPSM_ABS;
403                 break;
404
405             default:
406                 FIXME("Skipping modifier 0x%08x.\n", modifier);
407                 src_param->modifiers = WINED3DSPSM_NONE;
408                 break;
409         }
410     }
411     else
412     {
413         src_param->modifiers = WINED3DSPSM_NONE;
414     }
415
416     order = (token & WINED3D_SM4_REGISTER_ORDER_MASK) >> WINED3D_SM4_REGISTER_ORDER_SHIFT;
417
418     if (order < 1) src_param->reg.idx = ~0U;
419     else src_param->reg.idx = *(*ptr)++;
420
421     if (order < 2) src_param->reg.array_idx = ~0U;
422     else src_param->reg.array_idx = *(*ptr)++;
423
424     if (order > 2) FIXME("Unhandled order %u.\n", order);
425
426     if (register_type == WINED3D_SM4_RT_IMMCONST)
427     {
428         enum wined3d_sm4_immconst_type immconst_type =
429                 (token & WINED3D_SM4_IMMCONST_TYPE_MASK) >> WINED3D_SM4_IMMCONST_TYPE_SHIFT;
430         src_param->swizzle = WINED3DSP_NOSWIZZLE;
431
432         switch(immconst_type)
433         {
434             case WINED3D_SM4_IMMCONST_SCALAR:
435                 src_param->reg.immconst_type = WINED3D_IMMCONST_SCALAR;
436                 memcpy(src_param->reg.immconst_data, *ptr, 1 * sizeof(DWORD));
437                 *ptr += 1;
438                 break;
439
440             case WINED3D_SM4_IMMCONST_VEC4:
441                 src_param->reg.immconst_type = WINED3D_IMMCONST_VEC4;
442                 memcpy(src_param->reg.immconst_data, *ptr, 4 * sizeof(DWORD));
443                 *ptr += 4;
444                 break;
445
446             default:
447                 FIXME("Unhandled immediate constant type %#x\n", immconst_type);
448                 break;
449         }
450     }
451     else
452     {
453         src_param->swizzle = (token & WINED3D_SM4_SWIZZLE_MASK) >> WINED3D_SM4_SWIZZLE_SHIFT;
454     }
455
456     src_param->reg.rel_addr = NULL;
457
458     map_register(priv, &src_param->reg);
459 }
460
461 static void shader_sm4_read_dst_param(struct wined3d_sm4_data *priv, const DWORD **ptr,
462         enum wined3d_data_type data_type, struct wined3d_shader_dst_param *dst_param,
463         struct wined3d_shader_src_param *dst_rel_addr)
464 {
465     DWORD token = *(*ptr)++;
466     enum wined3d_sm4_register_type register_type;
467     DWORD order;
468
469     register_type = (token & WINED3D_SM4_REGISTER_TYPE_MASK) >> WINED3D_SM4_REGISTER_TYPE_SHIFT;
470     if (register_type >= sizeof(register_type_table) / sizeof(*register_type_table))
471     {
472         FIXME("Unhandled register type %#x\n", register_type);
473         dst_param->reg.type = WINED3DSPR_TEMP;
474     }
475     else
476     {
477         dst_param->reg.type = register_type_table[register_type];
478     }
479     dst_param->reg.data_type = data_type;
480
481     order = (token & WINED3D_SM4_REGISTER_ORDER_MASK) >> WINED3D_SM4_REGISTER_ORDER_SHIFT;
482
483     if (order < 1) dst_param->reg.idx = ~0U;
484     else dst_param->reg.idx = *(*ptr)++;
485
486     if (order < 2) dst_param->reg.array_idx = ~0U;
487     else dst_param->reg.array_idx = *(*ptr)++;
488
489     if (order > 2) FIXME("Unhandled order %u.\n", order);
490
491     dst_param->write_mask = (token & WINED3D_SM4_WRITEMASK_MASK) >> WINED3D_SM4_WRITEMASK_SHIFT;
492     dst_param->modifiers = 0;
493     dst_param->shift = 0;
494     dst_param->reg.rel_addr = NULL;
495
496     map_register(priv, &dst_param->reg);
497 }
498
499 static void shader_sm4_read_instruction(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins)
500 {
501     const struct wined3d_sm4_opcode_info *opcode_info;
502     struct wined3d_sm4_data *priv = data;
503     DWORD opcode_token, opcode;
504     const DWORD *p;
505     UINT i, len;
506
507     opcode_token = *(*ptr)++;
508     opcode = opcode_token & WINED3D_SM4_OPCODE_MASK;
509     len = ((opcode_token & WINED3D_SM4_INSTRUCTION_LENGTH_MASK) >> WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT) - 1;
510
511     if (!(opcode_info = get_opcode_info(opcode)))
512     {
513         FIXME("Unrecognized opcode %#x, opcode_token 0x%08x.\n", opcode, opcode_token);
514         ins->handler_idx = WINED3DSIH_TABLE_SIZE;
515         *ptr += len;
516         return;
517     }
518
519     ins->handler_idx = opcode_info->handler_idx;
520     ins->flags = 0;
521     ins->coissue = 0;
522     ins->predicate = NULL;
523     ins->dst_count = strlen(opcode_info->dst_info);
524     ins->dst = priv->dst_param;
525     ins->src_count = strlen(opcode_info->src_info);
526     ins->src = priv->src_param;
527
528     p = *ptr;
529     *ptr += len;
530
531     if (opcode_token & WINED3D_SM4_INSTRUCTION_MODIFIER)
532     {
533         DWORD modifier = *p++;
534         FIXME("Skipping modifier 0x%08x.\n", modifier);
535     }
536
537     for (i = 0; i < ins->dst_count; ++i)
538     {
539         shader_sm4_read_dst_param(priv, &p, map_data_type(opcode_info->dst_info[i]),
540                 &priv->dst_param[i], &priv->dst_rel_addr[i]);
541     }
542
543     for (i = 0; i < ins->src_count; ++i)
544     {
545         shader_sm4_read_src_param(priv, &p, map_data_type(opcode_info->src_info[i]),
546                 &priv->src_param[i], &priv->src_rel_addr[i]);
547     }
548 }
549
550 static void shader_sm4_read_comment(const DWORD **ptr, const char **comment, UINT *comment_size)
551 {
552     FIXME("ptr %p, comment %p, comment_size %p stub!\n", ptr, comment, comment_size);
553     *comment = NULL;
554 }
555
556 static BOOL shader_sm4_is_end(void *data, const DWORD **ptr)
557 {
558     struct wined3d_sm4_data *priv = data;
559     return *ptr == priv->end;
560 }
561
562 const struct wined3d_shader_frontend sm4_shader_frontend =
563 {
564     shader_sm4_init,
565     shader_sm4_free,
566     shader_sm4_read_header,
567     shader_sm4_read_instruction,
568     shader_sm4_read_comment,
569     shader_sm4_is_end,
570 };