wined3d: Handle the source modifier shift in the frontend rather than the backend.
[wine] / dlls / wined3d / baseshader.c
1 /*
2  * shaders implementation
3  *
4  * Copyright 2002-2003 Jason Edmeades
5  * Copyright 2002-2003 Raphael Junqueira
6  * Copyright 2004 Christian Costa
7  * Copyright 2005 Oliver Stieber
8  * Copyright 2006 Ivan Gyurdiev
9  * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
10  * Copyright 2009 Henri Verbeet for CodeWeavers
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26
27 #include "config.h"
28 #include <string.h>
29 #include <stdio.h>
30 #include "wined3d_private.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
33 WINE_DECLARE_DEBUG_CHANNEL(d3d);
34
35 static void shader_dump_param(const DWORD param, const DWORD addr_token, int input, DWORD shader_version);
36
37 static inline BOOL shader_is_version_token(DWORD token) {
38     return shader_is_pshader_version(token) ||
39            shader_is_vshader_version(token);
40 }
41
42 void shader_buffer_init(struct SHADER_BUFFER *buffer)
43 {
44     buffer->buffer = HeapAlloc(GetProcessHeap(), 0, SHADER_PGMSIZE);
45     buffer->buffer[0] = '\0';
46     buffer->bsize = 0;
47     buffer->lineNo = 0;
48     buffer->newline = TRUE;
49 }
50
51 void shader_buffer_free(struct SHADER_BUFFER *buffer)
52 {
53     HeapFree(GetProcessHeap(), 0, buffer->buffer);
54 }
55
56 int shader_vaddline(SHADER_BUFFER* buffer, const char *format, va_list args)
57 {
58     char* base = buffer->buffer + buffer->bsize;
59     int rc;
60
61     rc = vsnprintf(base, SHADER_PGMSIZE - 1 - buffer->bsize, format, args);
62
63     if (rc < 0 ||                                   /* C89 */ 
64         rc > SHADER_PGMSIZE - 1 - buffer->bsize) {  /* C99 */
65
66         ERR("The buffer allocated for the shader program string "
67             "is too small at %d bytes.\n", SHADER_PGMSIZE);
68         buffer->bsize = SHADER_PGMSIZE - 1;
69         return -1;
70     }
71
72     if (buffer->newline) {
73         TRACE("GL HW (%u, %u) : %s", buffer->lineNo + 1, buffer->bsize, base);
74         buffer->newline = FALSE;
75     } else {
76         TRACE("%s", base);
77     }
78
79     buffer->bsize += rc;
80     if (buffer->buffer[buffer->bsize-1] == '\n') {
81         buffer->lineNo++;
82         buffer->newline = TRUE;
83     }
84     return 0;
85 }
86
87 int shader_addline(SHADER_BUFFER* buffer, const char *format, ...)
88 {
89     int ret;
90     va_list args;
91
92     va_start(args, format);
93     ret = shader_vaddline(buffer, format, args);
94     va_end(args);
95
96     return ret;
97 }
98
99 void shader_init(struct IWineD3DBaseShaderClass *shader,
100         IWineD3DDevice *device, const SHADER_OPCODE *instruction_table)
101 {
102     shader->ref = 1;
103     shader->device = device;
104     shader->shader_ins = instruction_table;
105     list_init(&shader->linked_programs);
106 }
107
108 const SHADER_OPCODE *shader_get_opcode(const SHADER_OPCODE *opcode_table, DWORD shader_version, DWORD code)
109 {
110     DWORD i = 0;
111
112     /** TODO: use dichotomic search */
113     while (opcode_table[i].name)
114     {
115         if ((code & WINED3DSI_OPCODE_MASK) == opcode_table[i].opcode
116                 && shader_version >= opcode_table[i].min_version
117                 && (!opcode_table[i].max_version || shader_version <= opcode_table[i].max_version))
118         {
119             return &opcode_table[i];
120         }
121         ++i;
122     }
123
124     FIXME("Unsupported opcode %#x(%d) masked %#x, shader version %#x\n",
125             code, code, code & WINED3DSI_OPCODE_MASK, shader_version);
126
127     return NULL;
128 }
129
130 /* Read a parameter opcode from the input stream,
131  * and possibly a relative addressing token.
132  * Return the number of tokens read */
133 static int shader_get_param(const DWORD *pToken, DWORD shader_version, DWORD *param, DWORD *addr_token)
134 {
135     UINT count = 1;
136
137     *param = *pToken;
138
139     /* PS >= 3.0 have relative addressing (with token)
140      * VS >= 2.0 have relative addressing (with token)
141      * VS >= 1.0 < 2.0 have relative addressing (without token)
142      * The version check below should work in general */
143     if (*pToken & WINED3DSHADER_ADDRMODE_RELATIVE)
144     {
145         if (WINED3DSHADER_VERSION_MAJOR(shader_version) < 2)
146         {
147             *addr_token = (1 << 31)
148                     | ((WINED3DSPR_ADDR << WINED3DSP_REGTYPE_SHIFT2) & WINED3DSP_REGTYPE_MASK2)
149                     | ((WINED3DSPR_ADDR << WINED3DSP_REGTYPE_SHIFT) & WINED3DSP_REGTYPE_MASK)
150                     | (WINED3DSP_NOSWIZZLE << WINED3DSP_SWIZZLE_SHIFT);
151         }
152         else
153         {
154             *addr_token = *(pToken + 1);
155             ++count;
156         }
157     }
158
159     return count;
160 }
161
162 /* Return the number of parameters to skip for an opcode */
163 static inline int shader_skip_opcode(const SHADER_OPCODE *curOpcode, DWORD opcode_token, DWORD shader_version)
164 {
165    /* Shaders >= 2.0 may contain address tokens, but fortunately they
166     * have a useful length mask - use it here. Shaders 1.0 contain no such tokens */
167     return (WINED3DSHADER_VERSION_MAJOR(shader_version) >= 2)
168             ? ((opcode_token & WINED3DSI_INSTLENGTH_MASK) >> WINED3DSI_INSTLENGTH_SHIFT) : curOpcode->num_params;
169 }
170
171 /* Read the parameters of an unrecognized opcode from the input stream
172  * Return the number of tokens read. 
173  * 
174  * Note: This function assumes source or destination token format.
175  * It will not work with specially-formatted tokens like DEF or DCL, 
176  * but hopefully those would be recognized */
177 static int shader_skip_unrecognized(const DWORD *pToken, DWORD shader_version)
178 {
179     int tokens_read = 0;
180     int i = 0;
181
182     /* TODO: Think of a good name for 0x80000000 and replace it with a constant */
183     while (*pToken & 0x80000000) {
184
185         DWORD param, addr_token = 0;
186         tokens_read += shader_get_param(pToken, shader_version, &param, &addr_token);
187         pToken += tokens_read;
188
189         FIXME("Unrecognized opcode param: token=0x%08x "
190             "addr_token=0x%08x name=", param, addr_token);
191         shader_dump_param(param, addr_token, i, shader_version);
192         FIXME("\n");
193         ++i;
194     }
195     return tokens_read;
196 }
197
198 /* Convert floating point offset relative
199  * to a register file to an absolute offset for float constants */
200 static unsigned int shader_get_float_offset(const DWORD reg)
201 {
202      unsigned int regnum = reg & WINED3DSP_REGNUM_MASK;
203      int regtype = shader_get_regtype(reg);
204
205      switch (regtype) {
206         case WINED3DSPR_CONST: return regnum;
207         case WINED3DSPR_CONST2: return 2048 + regnum;
208         case WINED3DSPR_CONST3: return 4096 + regnum;
209         case WINED3DSPR_CONST4: return 6144 + regnum;
210         default:
211             FIXME("Unsupported register type: %d\n", regtype);
212             return regnum;
213      }
214 }
215
216 static void shader_delete_constant_list(struct list* clist) {
217
218     struct list *ptr;
219     struct local_constant* constant;
220
221     ptr = list_head(clist);
222     while (ptr) {
223         constant = LIST_ENTRY(ptr, struct local_constant, entry);
224         ptr = list_next(clist, ptr);
225         HeapFree(GetProcessHeap(), 0, constant);
226     }
227     list_init(clist);
228 }
229
230 static void shader_parse_dst_param(DWORD param, const struct wined3d_shader_src_param *rel_addr,
231         struct wined3d_shader_dst_param *dst)
232 {
233     dst->register_type = ((param & WINED3DSP_REGTYPE_MASK) >> WINED3DSP_REGTYPE_SHIFT)
234             | ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2);
235     dst->register_idx = param & WINED3DSP_REGNUM_MASK;
236     dst->write_mask = param & WINED3DSP_WRITEMASK_ALL;
237     dst->modifiers = param & WINED3DSP_DSTMOD_MASK;
238     dst->shift = (param & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT;
239     dst->rel_addr = rel_addr;
240 }
241
242 static void shader_parse_src_param(DWORD param, const struct wined3d_shader_src_param *rel_addr,
243         struct wined3d_shader_src_param *src)
244 {
245     src->register_type = ((param & WINED3DSP_REGTYPE_MASK) >> WINED3DSP_REGTYPE_SHIFT)
246             | ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2);
247     src->register_idx = param & WINED3DSP_REGNUM_MASK;
248     src->swizzle = (param & WINED3DSP_SWIZZLE_MASK) >> WINED3DSP_SWIZZLE_SHIFT;
249     src->modifiers = (param & WINED3DSP_SRCMOD_MASK) >> WINED3DSP_SRCMOD_SHIFT;
250     src->rel_addr = rel_addr;
251 }
252
253 /* Note that this does not count the loop register
254  * as an address register. */
255
256 HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, struct shader_reg_maps *reg_maps,
257         struct wined3d_shader_semantic *semantics_in, struct wined3d_shader_semantic *semantics_out,
258         const DWORD *byte_code)
259 {
260     IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
261     const SHADER_OPCODE *shader_ins = This->baseShader.shader_ins;
262     DWORD shader_version;
263     unsigned int cur_loop_depth = 0, max_loop_depth = 0;
264     const DWORD* pToken = byte_code;
265     char pshader;
266
267     /* There are some minor differences between pixel and vertex shaders */
268
269     memset(reg_maps->bumpmat, 0, sizeof(reg_maps->bumpmat));
270     memset(reg_maps->luminanceparams, 0, sizeof(reg_maps->luminanceparams));
271
272     /* get_registers_used is called on every compile on some 1.x shaders, which can result
273      * in stacking up a collection of local constants. Delete the old constants if existing
274      */
275     shader_delete_constant_list(&This->baseShader.constantsF);
276     shader_delete_constant_list(&This->baseShader.constantsB);
277     shader_delete_constant_list(&This->baseShader.constantsI);
278
279     /* The version token is supposed to be the first token */
280     if (!shader_is_version_token(*pToken))
281     {
282         FIXME("First token is not a version token, invalid shader.\n");
283         return WINED3DERR_INVALIDCALL;
284     }
285     reg_maps->shader_version = shader_version = *pToken++;
286     pshader = shader_is_pshader_version(shader_version);
287
288     while (WINED3DVS_END() != *pToken) {
289         CONST SHADER_OPCODE* curOpcode;
290         DWORD opcode_token;
291
292         /* Skip comments */
293         if (shader_is_comment(*pToken))
294         {
295              DWORD comment_len = (*pToken & WINED3DSI_COMMENTSIZE_MASK) >> WINED3DSI_COMMENTSIZE_SHIFT;
296              ++pToken;
297              pToken += comment_len;
298              continue;
299         }
300
301         /* Fetch opcode */
302         opcode_token = *pToken++;
303         curOpcode = shader_get_opcode(shader_ins, shader_version, opcode_token);
304
305         /* Unhandled opcode, and its parameters */
306         if (NULL == curOpcode) {
307            while (*pToken & 0x80000000)
308                ++pToken;
309
310         /* Handle declarations */
311         } else if (WINED3DSIO_DCL == curOpcode->opcode) {
312
313             DWORD usage = *pToken++;
314             DWORD param = *pToken++;
315             DWORD regtype = shader_get_regtype(param);
316             unsigned int regnum = param & WINED3DSP_REGNUM_MASK;
317
318             /* Vshader: mark attributes used
319                Pshader: mark 3.0 input registers used, save token */
320             if (WINED3DSPR_INPUT == regtype) {
321
322                 if (!pshader)
323                     reg_maps->attributes[regnum] = 1;
324                 else
325                     reg_maps->packed_input[regnum] = 1;
326
327                 semantics_in[regnum].usage = (usage & WINED3DSP_DCL_USAGE_MASK) >> WINED3DSP_DCL_USAGE_SHIFT;
328                 semantics_in[regnum].usage_idx =
329                         (usage & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
330                 shader_parse_dst_param(param, NULL, &semantics_in[regnum].reg);
331
332             /* Vshader: mark 3.0 output registers used, save token */
333             } else if (WINED3DSPR_OUTPUT == regtype) {
334                 reg_maps->packed_output[regnum] = 1;
335                 semantics_out[regnum].usage = (usage & WINED3DSP_DCL_USAGE_MASK) >> WINED3DSP_DCL_USAGE_SHIFT;
336                 semantics_out[regnum].usage_idx =
337                         (usage & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
338                 shader_parse_dst_param(param, NULL, &semantics_out[regnum].reg);
339
340                 if (usage & (WINED3DDECLUSAGE_FOG << WINED3DSP_DCL_USAGE_SHIFT))
341                     reg_maps->fog = 1;
342
343             /* Save sampler usage token */
344             } else if (WINED3DSPR_SAMPLER == regtype)
345                 reg_maps->samplers[regnum] = usage;
346
347         } else if (WINED3DSIO_DEF == curOpcode->opcode) {
348
349             local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
350             if (!lconst) return E_OUTOFMEMORY;
351             lconst->idx = *pToken & WINED3DSP_REGNUM_MASK;
352             memcpy(lconst->value, pToken + 1, 4 * sizeof(DWORD));
353
354             /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
355             if (WINED3DSHADER_VERSION_MAJOR(shader_version) == 1 && pshader)
356             {
357                 float *value = (float *) lconst->value;
358                 if(value[0] < -1.0) value[0] = -1.0;
359                 else if(value[0] >  1.0) value[0] =  1.0;
360                 if(value[1] < -1.0) value[1] = -1.0;
361                 else if(value[1] >  1.0) value[1] =  1.0;
362                 if(value[2] < -1.0) value[2] = -1.0;
363                 else if(value[2] >  1.0) value[2] =  1.0;
364                 if(value[3] < -1.0) value[3] = -1.0;
365                 else if(value[3] >  1.0) value[3] =  1.0;
366             }
367
368             list_add_head(&This->baseShader.constantsF, &lconst->entry);
369             pToken += curOpcode->num_params;
370
371         } else if (WINED3DSIO_DEFI == curOpcode->opcode) {
372
373             local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
374             if (!lconst) return E_OUTOFMEMORY;
375             lconst->idx = *pToken & WINED3DSP_REGNUM_MASK;
376             memcpy(lconst->value, pToken + 1, 4 * sizeof(DWORD));
377             list_add_head(&This->baseShader.constantsI, &lconst->entry);
378             pToken += curOpcode->num_params;
379
380         } else if (WINED3DSIO_DEFB == curOpcode->opcode) {
381
382             local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
383             if (!lconst) return E_OUTOFMEMORY;
384             lconst->idx = *pToken & WINED3DSP_REGNUM_MASK;
385             memcpy(lconst->value, pToken + 1, 1 * sizeof(DWORD));
386             list_add_head(&This->baseShader.constantsB, &lconst->entry);
387             pToken += curOpcode->num_params;
388
389         /* If there's a loop in the shader */
390         } else if (WINED3DSIO_LOOP == curOpcode->opcode ||
391                    WINED3DSIO_REP == curOpcode->opcode) {
392             cur_loop_depth++;
393             if(cur_loop_depth > max_loop_depth)
394                 max_loop_depth = cur_loop_depth;
395             pToken += curOpcode->num_params;
396
397             /* Rep and Loop always use an integer constant for the control parameters */
398             This->baseShader.uses_int_consts = TRUE;
399         } else if (WINED3DSIO_ENDLOOP == curOpcode->opcode ||
400                    WINED3DSIO_ENDREP == curOpcode->opcode) {
401             cur_loop_depth--;
402
403         /* For subroutine prototypes */
404         } else if (WINED3DSIO_LABEL == curOpcode->opcode) {
405
406             DWORD snum = *pToken & WINED3DSP_REGNUM_MASK; 
407             reg_maps->labels[snum] = 1;
408             pToken += curOpcode->num_params;
409
410         /* Set texture, address, temporary registers */
411         } else {
412             int i, limit;
413
414             /* Declare 1.X samplers implicitly, based on the destination reg. number */
415             if (WINED3DSHADER_VERSION_MAJOR(shader_version) == 1
416                     && pshader /* Filter different instructions with the same enum values in VS */
417                     && (WINED3DSIO_TEX == curOpcode->opcode
418                         || WINED3DSIO_TEXBEM == curOpcode->opcode
419                         || WINED3DSIO_TEXBEML == curOpcode->opcode
420                         || WINED3DSIO_TEXDP3TEX == curOpcode->opcode
421                         || WINED3DSIO_TEXM3x2TEX == curOpcode->opcode
422                         || WINED3DSIO_TEXM3x3SPEC == curOpcode->opcode
423                         || WINED3DSIO_TEXM3x3TEX == curOpcode->opcode
424                         || WINED3DSIO_TEXM3x3VSPEC == curOpcode->opcode
425                         || WINED3DSIO_TEXREG2AR == curOpcode->opcode
426                         || WINED3DSIO_TEXREG2GB == curOpcode->opcode
427                         || WINED3DSIO_TEXREG2RGB == curOpcode->opcode))
428             {
429                 /* Fake sampler usage, only set reserved bit and ttype */
430                 DWORD sampler_code = *pToken & WINED3DSP_REGNUM_MASK;
431
432                 TRACE("Setting fake 2D sampler for 1.x pixelshader\n");
433                 reg_maps->samplers[sampler_code] = (0x1 << 31) | WINED3DSTT_2D;
434
435                 /* texbem is only valid with < 1.4 pixel shaders */
436                 if(WINED3DSIO_TEXBEM  == curOpcode->opcode ||
437                     WINED3DSIO_TEXBEML == curOpcode->opcode) {
438                     reg_maps->bumpmat[sampler_code] = TRUE;
439                     if(WINED3DSIO_TEXBEML == curOpcode->opcode) {
440                         reg_maps->luminanceparams[sampler_code] = TRUE;
441                     }
442                 }
443             }
444             if(WINED3DSIO_NRM  == curOpcode->opcode) {
445                 reg_maps->usesnrm = 1;
446             } else if(WINED3DSIO_BEM == curOpcode->opcode && pshader) {
447                 DWORD regnum = *pToken & WINED3DSP_REGNUM_MASK;
448                 reg_maps->bumpmat[regnum] = TRUE;
449             } else if(WINED3DSIO_DSY  == curOpcode->opcode) {
450                 reg_maps->usesdsy = 1;
451             }
452
453             /* This will loop over all the registers and try to
454              * make a bitmask of the ones we're interested in. 
455              *
456              * Relative addressing tokens are ignored, but that's 
457              * okay, since we'll catch any address registers when 
458              * they are initialized (required by spec) */
459
460             limit = (opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED)?
461                 curOpcode->num_params + 1: curOpcode->num_params;
462
463             for (i = 0; i < limit; ++i) {
464
465                 DWORD param, addr_token, reg, regtype;
466                 pToken += shader_get_param(pToken, shader_version, &param, &addr_token);
467
468                 regtype = shader_get_regtype(param);
469                 reg = param & WINED3DSP_REGNUM_MASK;
470
471                 if (WINED3DSPR_TEXTURE == regtype) { /* vs: WINED3DSPR_ADDR */
472
473                     if (pshader)
474                         reg_maps->texcoord[reg] = 1;
475                     else
476                         reg_maps->address[reg] = 1;
477                 }
478
479                 else if (WINED3DSPR_TEMP == regtype)
480                     reg_maps->temporary[reg] = 1;
481
482                 else if (WINED3DSPR_INPUT == regtype) {
483                     if( !pshader)
484                         reg_maps->attributes[reg] = 1;
485                     else {
486                         if(param & WINED3DSHADER_ADDRMODE_RELATIVE) {
487                             /* If relative addressing is used, we must assume that all registers
488                              * are used. Even if it is a construct like v3[aL], we can't assume
489                              * that v0, v1 and v2 aren't read because aL can be negative
490                              */
491                             unsigned int i;
492                             for(i = 0; i < MAX_REG_INPUT; i++) {
493                                 ((IWineD3DPixelShaderImpl *) This)->input_reg_used[i] = TRUE;
494                             }
495                         } else {
496                             ((IWineD3DPixelShaderImpl *) This)->input_reg_used[reg] = TRUE;
497                         }
498                     }
499                 }
500
501                 else if (WINED3DSPR_RASTOUT == regtype && reg == 1)
502                     reg_maps->fog = 1;
503
504                 else if (WINED3DSPR_MISCTYPE == regtype && reg == 0 && pshader)
505                     reg_maps->vpos = 1;
506
507                 else if(WINED3DSPR_CONST == regtype) {
508                     if(param & WINED3DSHADER_ADDRMODE_RELATIVE) {
509                         if(!pshader) {
510                             if(reg <= ((IWineD3DVertexShaderImpl *) This)->min_rel_offset) {
511                                 ((IWineD3DVertexShaderImpl *) This)->min_rel_offset = reg;
512                             } else if(reg >= ((IWineD3DVertexShaderImpl *) This)->max_rel_offset) {
513                                 ((IWineD3DVertexShaderImpl *) This)->max_rel_offset = reg;
514                             }
515                         }
516                         reg_maps->usesrelconstF = TRUE;
517                     }
518                 }
519                 else if(WINED3DSPR_CONSTINT == regtype) {
520                     This->baseShader.uses_int_consts = TRUE;
521                 }
522                 else if(WINED3DSPR_CONSTBOOL == regtype) {
523                     This->baseShader.uses_bool_consts = TRUE;
524                 }
525
526                 /* WINED3DSPR_TEXCRDOUT is the same as WINED3DSPR_OUTPUT. _OUTPUT can be > MAX_REG_TEXCRD and is used
527                  * in >= 3.0 shaders. Filter 3.0 shaders to prevent overflows, and also filter pixel shaders because TECRDOUT
528                  * isn't used in them, but future register types might cause issues
529                  */
530                 else if (WINED3DSPR_TEXCRDOUT == regtype && i == 0 /* Only look at writes */
531                         && !pshader && WINED3DSHADER_VERSION_MAJOR(shader_version) < 3)
532                 {
533                     reg_maps->texcoord_mask[reg] |= shader_get_writemask(param);
534                 }
535             }
536         }
537     }
538     ++pToken;
539     reg_maps->loop_depth = max_loop_depth;
540
541     This->baseShader.functionLength = ((char *)pToken - (char *)byte_code);
542
543     return WINED3D_OK;
544 }
545
546 static void shader_dump_decl_usage(DWORD decl, DWORD param, DWORD shader_version)
547 {
548     DWORD regtype = shader_get_regtype(param);
549
550     TRACE("dcl");
551
552     if (regtype == WINED3DSPR_SAMPLER) {
553         DWORD ttype = decl & WINED3DSP_TEXTURETYPE_MASK;
554
555         switch (ttype) {
556             case WINED3DSTT_2D: TRACE("_2d"); break;
557             case WINED3DSTT_CUBE: TRACE("_cube"); break;
558             case WINED3DSTT_VOLUME: TRACE("_volume"); break;
559             default: TRACE("_unknown_ttype(0x%08x)", ttype);
560        }
561
562     } else { 
563
564         DWORD usage = decl & WINED3DSP_DCL_USAGE_MASK;
565         DWORD idx = (decl & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
566
567         /* Pixel shaders 3.0 don't have usage semantics */
568         if (shader_is_pshader_version(shader_version) && shader_version < WINED3DPS_VERSION(3,0))
569             return;
570         else
571             TRACE("_");
572
573         switch(usage) {
574         case WINED3DDECLUSAGE_POSITION:
575             TRACE("position%d", idx);
576             break;
577         case WINED3DDECLUSAGE_BLENDINDICES:
578             TRACE("blend");
579             break;
580         case WINED3DDECLUSAGE_BLENDWEIGHT:
581             TRACE("weight");
582             break;
583         case WINED3DDECLUSAGE_NORMAL:
584             TRACE("normal%d", idx);
585             break;
586         case WINED3DDECLUSAGE_PSIZE:
587             TRACE("psize");
588             break;
589         case WINED3DDECLUSAGE_COLOR:
590             if(idx == 0)  {
591                 TRACE("color");
592             } else {
593                 TRACE("specular%d", (idx - 1));
594             }
595             break;
596         case WINED3DDECLUSAGE_TEXCOORD:
597             TRACE("texture%d", idx);
598             break;
599         case WINED3DDECLUSAGE_TANGENT:
600             TRACE("tangent");
601             break;
602         case WINED3DDECLUSAGE_BINORMAL:
603             TRACE("binormal");
604             break;
605         case WINED3DDECLUSAGE_TESSFACTOR:
606             TRACE("tessfactor");
607             break;
608         case WINED3DDECLUSAGE_POSITIONT:
609             TRACE("positionT%d", idx);
610             break;
611         case WINED3DDECLUSAGE_FOG:
612             TRACE("fog");
613             break;
614         case WINED3DDECLUSAGE_DEPTH:
615             TRACE("depth");
616             break;
617         case WINED3DDECLUSAGE_SAMPLE:
618             TRACE("sample");
619             break;
620         default:
621             FIXME("unknown_semantics(0x%08x)", usage);
622         }
623     }
624 }
625
626 static void shader_dump_arr_entry(const DWORD param, const DWORD addr_token,
627         unsigned int reg, int input, DWORD shader_version)
628 {
629     char relative =
630         ((param & WINED3DSHADER_ADDRESSMODE_MASK) == WINED3DSHADER_ADDRMODE_RELATIVE);
631
632     if (relative) {
633         TRACE("[");
634         if (addr_token)
635             shader_dump_param(addr_token, 0, input, shader_version);
636         else
637             TRACE("a0.x");
638         TRACE(" + ");
639      }
640      TRACE("%u", reg);
641      if (relative)
642          TRACE("]");
643 }
644
645 static void shader_dump_param(const DWORD param, const DWORD addr_token, int input, DWORD shader_version)
646 {
647     static const char * const rastout_reg_names[] = { "oPos", "oFog", "oPts" };
648     static const char * const misctype_reg_names[] = { "vPos", "vFace"};
649     const char *swizzle_reg_chars = "xyzw";
650
651     DWORD reg = param & WINED3DSP_REGNUM_MASK;
652     DWORD regtype = shader_get_regtype(param);
653     DWORD modifier = param & WINED3DSP_SRCMOD_MASK;
654
655     /* There are some minor differences between pixel and vertex shaders */
656     char pshader = shader_is_pshader_version(shader_version);
657
658     if (input) {
659         if ( (modifier == WINED3DSPSM_NEG) ||
660              (modifier == WINED3DSPSM_BIASNEG) ||
661              (modifier == WINED3DSPSM_SIGNNEG) ||
662              (modifier == WINED3DSPSM_X2NEG) ||
663              (modifier == WINED3DSPSM_ABSNEG) )
664             TRACE("-");
665         else if (modifier == WINED3DSPSM_COMP)
666             TRACE("1-");
667         else if (modifier == WINED3DSPSM_NOT)
668             TRACE("!");
669
670         if (modifier == WINED3DSPSM_ABS || modifier == WINED3DSPSM_ABSNEG) 
671             TRACE("abs(");
672     }
673
674     switch (regtype) {
675         case WINED3DSPR_TEMP:
676             TRACE("r%u", reg);
677             break;
678         case WINED3DSPR_INPUT:
679             TRACE("v");
680             shader_dump_arr_entry(param, addr_token, reg, input, shader_version);
681             break;
682         case WINED3DSPR_CONST:
683         case WINED3DSPR_CONST2:
684         case WINED3DSPR_CONST3:
685         case WINED3DSPR_CONST4:
686             TRACE("c");
687             shader_dump_arr_entry(param, addr_token, shader_get_float_offset(param), input, shader_version);
688             break;
689         case WINED3DSPR_TEXTURE: /* vs: case D3DSPR_ADDR */
690             TRACE("%c%u", (pshader? 't':'a'), reg);
691             break;        
692         case WINED3DSPR_RASTOUT:
693             TRACE("%s", rastout_reg_names[reg]);
694             break;
695         case WINED3DSPR_COLOROUT:
696             TRACE("oC%u", reg);
697             break;
698         case WINED3DSPR_DEPTHOUT:
699             TRACE("oDepth");
700             break;
701         case WINED3DSPR_ATTROUT:
702             TRACE("oD%u", reg);
703             break;
704         case WINED3DSPR_TEXCRDOUT: 
705
706             /* Vertex shaders >= 3.0 use general purpose output registers
707              * (WINED3DSPR_OUTPUT), which can include an address token */
708
709             if (WINED3DSHADER_VERSION_MAJOR(shader_version) >= 3) {
710                 TRACE("o");
711                 shader_dump_arr_entry(param, addr_token, reg, input, shader_version);
712             }
713             else 
714                TRACE("oT%u", reg);
715             break;
716         case WINED3DSPR_CONSTINT:
717             TRACE("i");
718             shader_dump_arr_entry(param, addr_token, reg, input, shader_version);
719             break;
720         case WINED3DSPR_CONSTBOOL:
721             TRACE("b");
722             shader_dump_arr_entry(param, addr_token, reg, input, shader_version);
723             break;
724         case WINED3DSPR_LABEL:
725             TRACE("l%u", reg);
726             break;
727         case WINED3DSPR_LOOP:
728             TRACE("aL");
729             break;
730         case WINED3DSPR_SAMPLER:
731             TRACE("s%u", reg);
732             break;
733         case WINED3DSPR_MISCTYPE:
734             if (reg > 1) {
735                 FIXME("Unhandled misctype register %d\n", reg);
736             } else {
737                 TRACE("%s", misctype_reg_names[reg]);
738             }
739             break;
740         case WINED3DSPR_PREDICATE:
741             TRACE("p%u", reg);
742             break;
743         default:
744             TRACE("unhandled_rtype(%#x)", regtype);
745             break;
746    }
747
748    if (!input) {
749        /* operand output (for modifiers and shift, see dump_ins_modifiers) */
750
751        if ((param & WINED3DSP_WRITEMASK_ALL) != WINED3DSP_WRITEMASK_ALL) {
752            TRACE(".");
753            if (param & WINED3DSP_WRITEMASK_0) TRACE("%c", swizzle_reg_chars[0]);
754            if (param & WINED3DSP_WRITEMASK_1) TRACE("%c", swizzle_reg_chars[1]);
755            if (param & WINED3DSP_WRITEMASK_2) TRACE("%c", swizzle_reg_chars[2]);
756            if (param & WINED3DSP_WRITEMASK_3) TRACE("%c", swizzle_reg_chars[3]);
757        }
758
759    } else {
760         /** operand input */
761         DWORD swizzle = (param & WINED3DSP_SWIZZLE_MASK) >> WINED3DSP_SWIZZLE_SHIFT;
762         DWORD swizzle_x = swizzle & 0x03;
763         DWORD swizzle_y = (swizzle >> 2) & 0x03;
764         DWORD swizzle_z = (swizzle >> 4) & 0x03;
765         DWORD swizzle_w = (swizzle >> 6) & 0x03;
766
767         if (0 != modifier) {
768             switch (modifier) {
769                 case WINED3DSPSM_NONE:    break;
770                 case WINED3DSPSM_NEG:     break;
771                 case WINED3DSPSM_NOT:     break;
772                 case WINED3DSPSM_BIAS:    TRACE("_bias"); break;
773                 case WINED3DSPSM_BIASNEG: TRACE("_bias"); break;
774                 case WINED3DSPSM_SIGN:    TRACE("_bx2"); break;
775                 case WINED3DSPSM_SIGNNEG: TRACE("_bx2"); break;
776                 case WINED3DSPSM_COMP:    break;
777                 case WINED3DSPSM_X2:      TRACE("_x2"); break;
778                 case WINED3DSPSM_X2NEG:   TRACE("_x2"); break;
779                 case WINED3DSPSM_DZ:      TRACE("_dz"); break;
780                 case WINED3DSPSM_DW:      TRACE("_dw"); break;
781                 case WINED3DSPSM_ABSNEG:  TRACE(")"); break;
782                 case WINED3DSPSM_ABS:     TRACE(")"); break;
783                 default:
784                     TRACE("_unknown_modifier(%#x)", modifier);
785             }
786         }
787
788         /**
789         * swizzle bits fields:
790         *  RRGGBBAA
791         */
792         if (swizzle != WINED3DSP_NOSWIZZLE)
793         {
794             if (swizzle_x == swizzle_y &&
795                 swizzle_x == swizzle_z &&
796                 swizzle_x == swizzle_w) {
797                     TRACE(".%c", swizzle_reg_chars[swizzle_x]);
798             } else {
799                 TRACE(".%c%c%c%c",
800                 swizzle_reg_chars[swizzle_x],
801                 swizzle_reg_chars[swizzle_y],
802                 swizzle_reg_chars[swizzle_z],
803                 swizzle_reg_chars[swizzle_w]);
804             }
805         }
806     }
807 }
808
809 /* Shared code in order to generate the bulk of the shader string.
810  * NOTE: A description of how to parse tokens can be found on msdn */
811 void shader_generate_main(IWineD3DBaseShader *iface, SHADER_BUFFER* buffer,
812         const shader_reg_maps* reg_maps, CONST DWORD* pFunction)
813 {
814     IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
815     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) This->baseShader.device; /* To access shader backend callbacks */
816     const SHADER_OPCODE *opcode_table = This->baseShader.shader_ins;
817     const SHADER_HANDLER *handler_table = device->shader_backend->shader_instruction_handler_table;
818     DWORD shader_version = reg_maps->shader_version;
819     struct wined3d_shader_src_param src_rel_addr[4];
820     struct wined3d_shader_src_param src_param[4];
821     struct wined3d_shader_src_param dst_rel_addr;
822     struct wined3d_shader_dst_param dst_param;
823     struct wined3d_shader_instruction ins;
824     struct wined3d_shader_context ctx;
825     const DWORD *pToken = pFunction;
826     const SHADER_OPCODE *curOpcode;
827     SHADER_HANDLER hw_fct;
828     DWORD i;
829
830     /* Initialize current parsing state */
831     ctx.shader = iface;
832     ctx.reg_maps = reg_maps;
833     ctx.buffer = buffer;
834
835     ins.ctx = &ctx;
836     ins.dst = &dst_param;
837     ins.src = src_param;
838     This->baseShader.parse_state.current_row = 0;
839
840     while (WINED3DPS_END() != *pToken)
841     {
842         DWORD opcode_token;
843
844         /* Skip version token */
845         if (shader_is_version_token(*pToken))
846         {
847             ++pToken;
848             continue;
849         }
850
851         /* Skip comment tokens */
852         if (shader_is_comment(*pToken))
853         {
854             pToken += (*pToken & WINED3DSI_COMMENTSIZE_MASK) >> WINED3DSI_COMMENTSIZE_SHIFT;
855             ++pToken;
856             continue;
857         }
858
859         /* Read opcode */
860         opcode_token = *pToken++;
861         curOpcode = shader_get_opcode(opcode_table, shader_version, opcode_token);
862
863         /* Unknown opcode and its parameters */
864         if (!curOpcode)
865         {
866             FIXME("Unrecognized opcode: token=0x%08x\n", opcode_token);
867             pToken += shader_skip_unrecognized(pToken, shader_version);
868             continue;
869         }
870
871         /* Nothing to do */
872         if (WINED3DSIO_DCL == curOpcode->opcode
873                 || WINED3DSIO_NOP == curOpcode->opcode
874                 || WINED3DSIO_DEF == curOpcode->opcode
875                 || WINED3DSIO_DEFI == curOpcode->opcode
876                 || WINED3DSIO_DEFB == curOpcode->opcode
877                 || WINED3DSIO_PHASE == curOpcode->opcode
878                 || WINED3DSIO_RET == curOpcode->opcode)
879         {
880             pToken += shader_skip_opcode(curOpcode, opcode_token, shader_version);
881             continue;
882         }
883
884         /* Select handler */
885         hw_fct = handler_table[curOpcode->handler_idx];
886
887         /* Unhandled opcode */
888         if (!hw_fct)
889         {
890             FIXME("Can't handle opcode %s in hwShader\n", curOpcode->name);
891             pToken += shader_skip_opcode(curOpcode, opcode_token, shader_version);
892             continue;
893         }
894
895         ins.handler_idx = curOpcode->handler_idx;
896         ins.flags = opcode_token & WINED3D_OPCODESPECIFICCONTROL_MASK;
897         ins.coissue = opcode_token & WINED3DSI_COISSUE;
898
899         /* Destination token */
900         ins.dst_count = curOpcode->dst_token ? 1 : 0;
901         if (ins.dst_count)
902         {
903             DWORD param, addr_param;
904             pToken += shader_get_param(pToken, shader_version, &param, &addr_param);
905
906             if (param & WINED3DSHADER_ADDRMODE_RELATIVE)
907             {
908                 shader_parse_src_param(addr_param, NULL, &dst_rel_addr);
909                 shader_parse_dst_param(param, &dst_rel_addr, &dst_param);
910             }
911             else
912             {
913                 shader_parse_dst_param(param, NULL, &dst_param);
914             }
915         }
916
917         /* Predication token */
918         if (opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED) ins.predicate = *pToken++;
919
920         /* Other source tokens */
921         ins.src_count = curOpcode->num_params - curOpcode->dst_token;
922         for (i = 0; i < ins.src_count; ++i)
923         {
924             DWORD param, addr_param;
925             pToken += shader_get_param(pToken, shader_version, &param, &addr_param);
926             if (param & WINED3DSHADER_ADDRMODE_RELATIVE)
927             {
928                 shader_parse_src_param(addr_param, NULL, &src_rel_addr[i]);
929                 shader_parse_src_param(param, &src_rel_addr[i], &src_param[i]);
930             }
931             else
932             {
933                 shader_parse_src_param(param, NULL, &src_param[i]);
934             }
935         }
936
937         /* Call appropriate function for output target */
938         hw_fct(&ins);
939
940         /* Process instruction modifiers for GLSL apps ( _sat, etc. ) */
941         /* FIXME: This should be internal to the shader backend.
942          * Also, right now this is the only reason "shader_mode" exists. */
943         if (This->baseShader.shader_mode == SHADER_GLSL) shader_glsl_add_instruction_modifiers(&ins);
944     }
945 }
946
947 static void shader_dump_ins_modifiers(const DWORD output)
948 {
949     DWORD shift = (output & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT;
950     DWORD mmask = output & WINED3DSP_DSTMOD_MASK;
951
952     switch (shift) {
953         case 0: break;
954         case 13: TRACE("_d8"); break;
955         case 14: TRACE("_d4"); break;
956         case 15: TRACE("_d2"); break;
957         case 1: TRACE("_x2"); break;
958         case 2: TRACE("_x4"); break;
959         case 3: TRACE("_x8"); break;
960         default: TRACE("_unhandled_shift(%d)", shift); break;
961     }
962
963     if (mmask & WINED3DSPDM_SATURATE)         TRACE("_sat");
964     if (mmask & WINED3DSPDM_PARTIALPRECISION) TRACE("_pp");
965     if (mmask & WINED3DSPDM_MSAMPCENTROID)    TRACE("_centroid");
966
967     mmask &= ~(WINED3DSPDM_SATURATE | WINED3DSPDM_PARTIALPRECISION | WINED3DSPDM_MSAMPCENTROID);
968     if (mmask)
969         FIXME("_unrecognized_modifier(%#x)", mmask >> WINED3DSP_DSTMOD_SHIFT);
970 }
971
972 void shader_trace_init(const DWORD *pFunction, const SHADER_OPCODE *opcode_table)
973 {
974     const DWORD* pToken = pFunction;
975     const SHADER_OPCODE* curOpcode = NULL;
976     DWORD shader_version;
977     DWORD opcode_token;
978     DWORD i;
979
980     TRACE("Parsing %p\n", pFunction);
981
982     /* The version token is supposed to be the first token */
983     if (!shader_is_version_token(*pToken))
984     {
985         FIXME("First token is not a version token, invalid shader.\n");
986         return;
987     }
988     shader_version = *pToken++;
989     TRACE("%s_%u_%u\n", shader_is_pshader_version(shader_version) ? "ps": "vs",
990             WINED3DSHADER_VERSION_MAJOR(shader_version), WINED3DSHADER_VERSION_MINOR(shader_version));
991
992     while (WINED3DVS_END() != *pToken)
993     {
994         if (shader_is_comment(*pToken)) /* comment */
995         {
996             DWORD comment_len = (*pToken & WINED3DSI_COMMENTSIZE_MASK) >> WINED3DSI_COMMENTSIZE_SHIFT;
997             ++pToken;
998             TRACE("//%s\n", (const char*)pToken);
999             pToken += comment_len;
1000             continue;
1001         }
1002         opcode_token = *pToken++;
1003         curOpcode = shader_get_opcode(opcode_table, shader_version, opcode_token);
1004
1005         if (!curOpcode)
1006         {
1007             int tokens_read;
1008             FIXME("Unrecognized opcode: token=0x%08x\n", opcode_token);
1009             tokens_read = shader_skip_unrecognized(pToken, shader_version);
1010             pToken += tokens_read;
1011         }
1012         else
1013         {
1014             if (curOpcode->opcode == WINED3DSIO_DCL)
1015             {
1016                 DWORD usage = *pToken;
1017                 DWORD param = *(pToken + 1);
1018
1019                 shader_dump_decl_usage(usage, param, shader_version);
1020                 shader_dump_ins_modifiers(param);
1021                 TRACE(" ");
1022                 shader_dump_param(param, 0, 0, shader_version);
1023                 pToken += 2;
1024             }
1025             else if (curOpcode->opcode == WINED3DSIO_DEF)
1026             {
1027                 unsigned int offset = shader_get_float_offset(*pToken);
1028
1029                 TRACE("def c%u = %f, %f, %f, %f", offset,
1030                         *(const float *)(pToken + 1),
1031                         *(const float *)(pToken + 2),
1032                         *(const float *)(pToken + 3),
1033                         *(const float *)(pToken + 4));
1034                 pToken += 5;
1035             }
1036             else if (curOpcode->opcode == WINED3DSIO_DEFI)
1037             {
1038                 TRACE("defi i%u = %d, %d, %d, %d", *pToken & WINED3DSP_REGNUM_MASK,
1039                         *(pToken + 1),
1040                         *(pToken + 2),
1041                         *(pToken + 3),
1042                         *(pToken + 4));
1043                 pToken += 5;
1044             }
1045             else if (curOpcode->opcode == WINED3DSIO_DEFB)
1046             {
1047                 TRACE("defb b%u = %s", *pToken & WINED3DSP_REGNUM_MASK,
1048                         *(pToken + 1)? "true": "false");
1049                 pToken += 2;
1050             }
1051             else
1052             {
1053                 DWORD param, addr_token = 0;
1054                 int tokens_read;
1055
1056                 /* Print out predication source token first - it follows
1057                  * the destination token. */
1058                 if (opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED)
1059                 {
1060                     TRACE("(");
1061                     shader_dump_param(*(pToken + 2), 0, 1, shader_version);
1062                     TRACE(") ");
1063                 }
1064                 if (opcode_token & WINED3DSI_COISSUE)
1065                 {
1066                     /* PixWin marks instructions with the coissue flag with a '+' */
1067                     TRACE("+");
1068                 }
1069
1070                 TRACE("%s", curOpcode->name);
1071
1072                 if (curOpcode->opcode == WINED3DSIO_IFC
1073                         || curOpcode->opcode == WINED3DSIO_BREAKC)
1074                 {
1075                     DWORD op = (opcode_token & INST_CONTROLS_MASK) >> INST_CONTROLS_SHIFT;
1076
1077                     switch (op)
1078                     {
1079                         case COMPARISON_GT: TRACE("_gt"); break;
1080                         case COMPARISON_EQ: TRACE("_eq"); break;
1081                         case COMPARISON_GE: TRACE("_ge"); break;
1082                         case COMPARISON_LT: TRACE("_lt"); break;
1083                         case COMPARISON_NE: TRACE("_ne"); break;
1084                         case COMPARISON_LE: TRACE("_le"); break;
1085                         default: TRACE("_(%u)", op);
1086                     }
1087                 }
1088                 else if (curOpcode->opcode == WINED3DSIO_TEX
1089                         && shader_version >= WINED3DPS_VERSION(2,0)
1090                         && (opcode_token & WINED3DSI_TEXLD_PROJECT))
1091                 {
1092                     TRACE("p");
1093                 }
1094
1095                 /* Destination token */
1096                 if (curOpcode->dst_token)
1097                 {
1098                     tokens_read = shader_get_param(pToken, shader_version, &param, &addr_token);
1099                     pToken += tokens_read;
1100
1101                     shader_dump_ins_modifiers(param);
1102                     TRACE(" ");
1103                     shader_dump_param(param, addr_token, 0, shader_version);
1104                 }
1105
1106                 /* Predication token - already printed out, just skip it */
1107                 if (opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED)
1108                 {
1109                     pToken++;
1110                 }
1111
1112                 /* Other source tokens */
1113                 for (i = curOpcode->dst_token; i < curOpcode->num_params; ++i)
1114                 {
1115                     tokens_read = shader_get_param(pToken, shader_version, &param, &addr_token);
1116                     pToken += tokens_read;
1117
1118                     TRACE((i == 0)? " " : ", ");
1119                     shader_dump_param(param, addr_token, 1, shader_version);
1120                 }
1121             }
1122             TRACE("\n");
1123         }
1124     }
1125 }
1126
1127 void shader_cleanup(IWineD3DBaseShader *iface)
1128 {
1129     IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)iface;
1130
1131     ((IWineD3DDeviceImpl *)This->baseShader.device)->shader_backend->shader_destroy(iface);
1132     HeapFree(GetProcessHeap(), 0, This->baseShader.function);
1133     shader_delete_constant_list(&This->baseShader.constantsF);
1134     shader_delete_constant_list(&This->baseShader.constantsB);
1135     shader_delete_constant_list(&This->baseShader.constantsI);
1136     list_remove(&This->baseShader.shader_list_entry);
1137 }
1138
1139 static const SHADER_HANDLER shader_none_instruction_handler_table[WINED3DSIH_TABLE_SIZE] = {0};
1140 static void shader_none_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {}
1141 static void shader_none_select_depth_blt(IWineD3DDevice *iface, enum tex_types tex_type) {}
1142 static void shader_none_deselect_depth_blt(IWineD3DDevice *iface) {}
1143 static void shader_none_update_float_vertex_constants(IWineD3DDevice *iface, UINT start, UINT count) {}
1144 static void shader_none_update_float_pixel_constants(IWineD3DDevice *iface, UINT start, UINT count) {}
1145 static void shader_none_load_constants(IWineD3DDevice *iface, char usePS, char useVS) {}
1146 static void shader_none_load_np2fixup_constants(IWineD3DDevice *iface, char usePS, char useVS) {}
1147 static void shader_none_destroy(IWineD3DBaseShader *iface) {}
1148 static HRESULT shader_none_alloc(IWineD3DDevice *iface) {return WINED3D_OK;}
1149 static void shader_none_free(IWineD3DDevice *iface) {}
1150 static BOOL shader_none_dirty_const(IWineD3DDevice *iface) {return FALSE;}
1151 static GLuint shader_none_generate_pshader(IWineD3DPixelShader *iface, SHADER_BUFFER *buffer, const struct ps_compile_args *args) {
1152     FIXME("NONE shader backend asked to generate a pixel shader\n");
1153     return 0;
1154 }
1155 static GLuint shader_none_generate_vshader(IWineD3DVertexShader *iface, SHADER_BUFFER *buffer, const struct vs_compile_args *args) {
1156     FIXME("NONE shader backend asked to generate a vertex shader\n");
1157     return 0;
1158 }
1159
1160 #define GLINFO_LOCATION      (*gl_info)
1161 static void shader_none_get_caps(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct shader_caps *pCaps)
1162 {
1163     /* Set the shader caps to 0 for the none shader backend */
1164     pCaps->VertexShaderVersion  = 0;
1165     pCaps->PixelShaderVersion    = 0;
1166     pCaps->PixelShader1xMaxValue = 0.0;
1167 }
1168 #undef GLINFO_LOCATION
1169 static BOOL shader_none_color_fixup_supported(struct color_fixup_desc fixup)
1170 {
1171     if (TRACE_ON(d3d_shader) && TRACE_ON(d3d))
1172     {
1173         TRACE("Checking support for fixup:\n");
1174         dump_color_fixup_desc(fixup);
1175     }
1176
1177     /* Faked to make some apps happy. */
1178     if (!is_yuv_fixup(fixup))
1179     {
1180         TRACE("[OK]\n");
1181         return TRUE;
1182     }
1183
1184     TRACE("[FAILED]\n");
1185     return FALSE;
1186 }
1187
1188 const shader_backend_t none_shader_backend = {
1189     shader_none_instruction_handler_table,
1190     shader_none_select,
1191     shader_none_select_depth_blt,
1192     shader_none_deselect_depth_blt,
1193     shader_none_update_float_vertex_constants,
1194     shader_none_update_float_pixel_constants,
1195     shader_none_load_constants,
1196     shader_none_load_np2fixup_constants,
1197     shader_none_destroy,
1198     shader_none_alloc,
1199     shader_none_free,
1200     shader_none_dirty_const,
1201     shader_none_generate_pshader,
1202     shader_none_generate_vshader,
1203     shader_none_get_caps,
1204     shader_none_color_fixup_supported,
1205 };