wined3d: Use the "input_registers" bitmap for vertex shader attributes as well.
[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 const char *shader_opcode_names[] =
36 {
37     /* WINED3DSIH_ABS           */ "abs",
38     /* WINED3DSIH_ADD           */ "add",
39     /* WINED3DSIH_BEM           */ "bem",
40     /* WINED3DSIH_BREAK         */ "break",
41     /* WINED3DSIH_BREAKC        */ "breakc",
42     /* WINED3DSIH_BREAKP        */ "breakp",
43     /* WINED3DSIH_CALL          */ "call",
44     /* WINED3DSIH_CALLNZ        */ "callnz",
45     /* WINED3DSIH_CMP           */ "cmp",
46     /* WINED3DSIH_CND           */ "cnd",
47     /* WINED3DSIH_CRS           */ "crs",
48     /* WINED3DSIH_DCL           */ "dcl",
49     /* WINED3DSIH_DEF           */ "def",
50     /* WINED3DSIH_DEFB          */ "defb",
51     /* WINED3DSIH_DEFI          */ "defi",
52     /* WINED3DSIH_DP2ADD        */ "dp2add",
53     /* WINED3DSIH_DP3           */ "dp3",
54     /* WINED3DSIH_DP4           */ "dp4",
55     /* WINED3DSIH_DST           */ "dst",
56     /* WINED3DSIH_DSX           */ "dsx",
57     /* WINED3DSIH_DSY           */ "dsy",
58     /* WINED3DSIH_ELSE          */ "else",
59     /* WINED3DSIH_ENDIF         */ "endif",
60     /* WINED3DSIH_ENDLOOP       */ "endloop",
61     /* WINED3DSIH_ENDREP        */ "endrep",
62     /* WINED3DSIH_EXP           */ "exp",
63     /* WINED3DSIH_EXPP          */ "expp",
64     /* WINED3DSIH_FRC           */ "frc",
65     /* WINED3DSIH_IF            */ "if",
66     /* WINED3DSIH_IFC           */ "ifc",
67     /* WINED3DSIH_LABEL         */ "label",
68     /* WINED3DSIH_LIT           */ "lit",
69     /* WINED3DSIH_LOG           */ "log",
70     /* WINED3DSIH_LOGP          */ "logp",
71     /* WINED3DSIH_LOOP          */ "loop",
72     /* WINED3DSIH_LRP           */ "lrp",
73     /* WINED3DSIH_M3x2          */ "m3x2",
74     /* WINED3DSIH_M3x3          */ "m3x3",
75     /* WINED3DSIH_M3x4          */ "m3x4",
76     /* WINED3DSIH_M4x3          */ "m4x3",
77     /* WINED3DSIH_M4x4          */ "m4x4",
78     /* WINED3DSIH_MAD           */ "mad",
79     /* WINED3DSIH_MAX           */ "max",
80     /* WINED3DSIH_MIN           */ "min",
81     /* WINED3DSIH_MOV           */ "mov",
82     /* WINED3DSIH_MOVA          */ "mova",
83     /* WINED3DSIH_MUL           */ "mul",
84     /* WINED3DSIH_NOP           */ "nop",
85     /* WINED3DSIH_NRM           */ "nrm",
86     /* WINED3DSIH_PHASE         */ "phase",
87     /* WINED3DSIH_POW           */ "pow",
88     /* WINED3DSIH_RCP           */ "rcp",
89     /* WINED3DSIH_REP           */ "rep",
90     /* WINED3DSIH_RET           */ "ret",
91     /* WINED3DSIH_RSQ           */ "rsq",
92     /* WINED3DSIH_SETP          */ "setp",
93     /* WINED3DSIH_SGE           */ "sge",
94     /* WINED3DSIH_SGN           */ "sgn",
95     /* WINED3DSIH_SINCOS        */ "sincos",
96     /* WINED3DSIH_SLT           */ "slt",
97     /* WINED3DSIH_SUB           */ "sub",
98     /* WINED3DSIH_TEX           */ "texld",
99     /* WINED3DSIH_TEXBEM        */ "texbem",
100     /* WINED3DSIH_TEXBEML       */ "texbeml",
101     /* WINED3DSIH_TEXCOORD      */ "texcrd",
102     /* WINED3DSIH_TEXDEPTH      */ "texdepth",
103     /* WINED3DSIH_TEXDP3        */ "texdp3",
104     /* WINED3DSIH_TEXDP3TEX     */ "texdp3tex",
105     /* WINED3DSIH_TEXKILL       */ "texkill",
106     /* WINED3DSIH_TEXLDD        */ "texldd",
107     /* WINED3DSIH_TEXLDL        */ "texldl",
108     /* WINED3DSIH_TEXM3x2DEPTH  */ "texm3x2depth",
109     /* WINED3DSIH_TEXM3x2PAD    */ "texm3x2pad",
110     /* WINED3DSIH_TEXM3x2TEX    */ "texm3x2tex",
111     /* WINED3DSIH_TEXM3x3       */ "texm3x3",
112     /* WINED3DSIH_TEXM3x3DIFF   */ "texm3x3diff",
113     /* WINED3DSIH_TEXM3x3PAD    */ "texm3x3pad",
114     /* WINED3DSIH_TEXM3x3SPEC   */ "texm3x3spec",
115     /* WINED3DSIH_TEXM3x3TEX    */ "texm3x3tex",
116     /* WINED3DSIH_TEXM3x3VSPEC  */ "texm3x3vspec",
117     /* WINED3DSIH_TEXREG2AR     */ "texreg2ar",
118     /* WINED3DSIH_TEXREG2GB     */ "texreg2gb",
119     /* WINED3DSIH_TEXREG2RGB    */ "texreg2rgb",
120 };
121
122 const struct wined3d_shader_frontend *shader_select_frontend(DWORD version_token)
123 {
124     switch (version_token >> 16)
125     {
126         case WINED3D_SM1_VS:
127         case WINED3D_SM1_PS:
128             return &sm1_shader_frontend;
129
130         case WINED3D_SM4_PS:
131         case WINED3D_SM4_VS:
132         case WINED3D_SM4_GS:
133             return &sm4_shader_frontend;
134
135         default:
136             FIXME("Unrecognised version token %#x\n", version_token);
137             return NULL;
138     }
139 }
140
141 static inline BOOL shader_is_version_token(DWORD token) {
142     return shader_is_pshader_version(token) ||
143            shader_is_vshader_version(token);
144 }
145
146 void shader_buffer_init(struct SHADER_BUFFER *buffer)
147 {
148     buffer->buffer = HeapAlloc(GetProcessHeap(), 0, SHADER_PGMSIZE);
149     buffer->buffer[0] = '\0';
150     buffer->bsize = 0;
151     buffer->lineNo = 0;
152     buffer->newline = TRUE;
153 }
154
155 void shader_buffer_free(struct SHADER_BUFFER *buffer)
156 {
157     HeapFree(GetProcessHeap(), 0, buffer->buffer);
158 }
159
160 int shader_vaddline(SHADER_BUFFER* buffer, const char *format, va_list args)
161 {
162     char* base = buffer->buffer + buffer->bsize;
163     int rc;
164
165     rc = vsnprintf(base, SHADER_PGMSIZE - 1 - buffer->bsize, format, args);
166
167     if (rc < 0 ||                                   /* C89 */ 
168         rc > SHADER_PGMSIZE - 1 - buffer->bsize) {  /* C99 */
169
170         ERR("The buffer allocated for the shader program string "
171             "is too small at %d bytes.\n", SHADER_PGMSIZE);
172         buffer->bsize = SHADER_PGMSIZE - 1;
173         return -1;
174     }
175
176     if (buffer->newline) {
177         TRACE("GL HW (%u, %u) : %s", buffer->lineNo + 1, buffer->bsize, base);
178         buffer->newline = FALSE;
179     } else {
180         TRACE("%s", base);
181     }
182
183     buffer->bsize += rc;
184     if (buffer->buffer[buffer->bsize-1] == '\n') {
185         buffer->lineNo++;
186         buffer->newline = TRUE;
187     }
188     return 0;
189 }
190
191 int shader_addline(SHADER_BUFFER* buffer, const char *format, ...)
192 {
193     int ret;
194     va_list args;
195
196     va_start(args, format);
197     ret = shader_vaddline(buffer, format, args);
198     va_end(args);
199
200     return ret;
201 }
202
203 void shader_init(struct IWineD3DBaseShaderClass *shader, IWineD3DDevice *device)
204 {
205     shader->ref = 1;
206     shader->device = device;
207     list_init(&shader->linked_programs);
208 }
209
210 /* Convert floating point offset relative
211  * to a register file to an absolute offset for float constants */
212 static unsigned int shader_get_float_offset(WINED3DSHADER_PARAM_REGISTER_TYPE register_type, UINT register_idx)
213 {
214     switch (register_type)
215     {
216         case WINED3DSPR_CONST: return register_idx;
217         case WINED3DSPR_CONST2: return 2048 + register_idx;
218         case WINED3DSPR_CONST3: return 4096 + register_idx;
219         case WINED3DSPR_CONST4: return 6144 + register_idx;
220         default:
221             FIXME("Unsupported register type: %d\n", register_type);
222             return register_idx;
223     }
224 }
225
226 static void shader_delete_constant_list(struct list* clist) {
227
228     struct list *ptr;
229     struct local_constant* constant;
230
231     ptr = list_head(clist);
232     while (ptr) {
233         constant = LIST_ENTRY(ptr, struct local_constant, entry);
234         ptr = list_next(clist, ptr);
235         HeapFree(GetProcessHeap(), 0, constant);
236     }
237     list_init(clist);
238 }
239
240 static inline void set_bitmap_bit(DWORD *bitmap, DWORD bit)
241 {
242     DWORD idx, shift;
243     idx = bit >> 5;
244     shift = bit & 0x1f;
245     bitmap[idx] |= (1 << shift);
246 }
247
248 static void shader_record_register_usage(IWineD3DBaseShaderImpl *This, struct shader_reg_maps *reg_maps,
249         const struct wined3d_shader_register *reg, BOOL pshader)
250 {
251     switch (reg->type)
252     {
253         case WINED3DSPR_TEXTURE: /* WINED3DSPR_ADDR */
254             if (pshader) reg_maps->texcoord[reg->idx] = 1;
255             else reg_maps->address[reg->idx] = 1;
256             break;
257
258         case WINED3DSPR_TEMP:
259             reg_maps->temporary[reg->idx] = 1;
260             break;
261
262         case WINED3DSPR_INPUT:
263             if (!pshader) reg_maps->input_registers |= 1 << reg->idx;
264             else
265             {
266                 if (reg->rel_addr)
267                 {
268                     /* If relative addressing is used, we must assume that all registers
269                      * are used. Even if it is a construct like v3[aL], we can't assume
270                      * that v0, v1 and v2 aren't read because aL can be negative */
271                     unsigned int i;
272                     for (i = 0; i < MAX_REG_INPUT; ++i)
273                     {
274                         ((IWineD3DPixelShaderImpl *)This)->input_reg_used[i] = TRUE;
275                     }
276                 }
277                 else
278                 {
279                     ((IWineD3DPixelShaderImpl *)This)->input_reg_used[reg->idx] = TRUE;
280                 }
281             }
282             break;
283
284         case WINED3DSPR_RASTOUT:
285             if (reg->idx == 1) reg_maps->fog = 1;
286             break;
287
288         case WINED3DSPR_MISCTYPE:
289             if (pshader && reg->idx == 0) reg_maps->vpos = 1;
290             break;
291
292         case WINED3DSPR_CONST:
293             if (reg->rel_addr)
294             {
295                 if (!pshader)
296                 {
297                     if (reg->idx <= ((IWineD3DVertexShaderImpl *)This)->min_rel_offset)
298                         ((IWineD3DVertexShaderImpl *)This)->min_rel_offset = reg->idx;
299                     else if (reg->idx >= ((IWineD3DVertexShaderImpl *)This)->max_rel_offset)
300                         ((IWineD3DVertexShaderImpl *)This)->max_rel_offset = reg->idx;
301                 }
302                 reg_maps->usesrelconstF = TRUE;
303             }
304             else
305             {
306                 set_bitmap_bit(reg_maps->constf, reg->idx);
307             }
308             break;
309
310         case WINED3DSPR_CONSTINT:
311             reg_maps->integer_constants |= (1 << reg->idx);
312             break;
313
314         case WINED3DSPR_CONSTBOOL:
315             reg_maps->boolean_constants |= (1 << reg->idx);
316             break;
317
318         default:
319             TRACE("Not recording register of type %#x and idx %u\n", reg->type, reg->idx);
320             break;
321     }
322 }
323
324 static unsigned int get_instr_extra_regcount(enum WINED3D_SHADER_INSTRUCTION_HANDLER instr, unsigned int param)
325 {
326     switch(instr)
327     {
328         case WINED3DSIH_M4x4:
329         case WINED3DSIH_M3x4:
330             return param == 1 ? 3 : 0;
331
332         case WINED3DSIH_M4x3:
333         case WINED3DSIH_M3x3:
334             return param == 1 ? 2 : 0;
335
336         case WINED3DSIH_M3x2:
337             return param == 1 ? 1 : 0;
338
339         default:
340             return 0;
341     }
342 }
343
344 /* Note that this does not count the loop register
345  * as an address register. */
346
347 HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, const struct wined3d_shader_frontend *fe,
348         struct shader_reg_maps *reg_maps, struct wined3d_shader_semantic *semantics_in,
349         struct wined3d_shader_semantic *semantics_out, const DWORD *byte_code, DWORD constf_size)
350 {
351     IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
352     void *fe_data = This->baseShader.frontend_data;
353     struct wined3d_shader_version shader_version;
354     unsigned int cur_loop_depth = 0, max_loop_depth = 0;
355     const DWORD* pToken = byte_code;
356     char pshader;
357
358     /* There are some minor differences between pixel and vertex shaders */
359
360     memset(reg_maps, 0, sizeof(*reg_maps));
361
362     /* get_registers_used is called on every compile on some 1.x shaders, which can result
363      * in stacking up a collection of local constants. Delete the old constants if existing
364      */
365     shader_delete_constant_list(&This->baseShader.constantsF);
366     shader_delete_constant_list(&This->baseShader.constantsB);
367     shader_delete_constant_list(&This->baseShader.constantsI);
368
369     fe->shader_read_header(fe_data, &pToken, &shader_version);
370     reg_maps->shader_version = shader_version;
371     pshader = shader_is_pshader_version(shader_version.type);
372
373     reg_maps->constf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
374                                  sizeof(*reg_maps->constf) * ((constf_size + 31) / 32));
375     if(!reg_maps->constf) {
376         ERR("Out of memory\n");
377         return E_OUTOFMEMORY;
378     }
379
380     while (!fe->shader_is_end(fe_data, &pToken))
381     {
382         struct wined3d_shader_instruction ins;
383         const char *comment;
384         UINT param_size;
385
386         /* Skip comments */
387         fe->shader_read_comment(&pToken, &comment);
388         if (comment) continue;
389
390         /* Fetch opcode */
391         fe->shader_read_opcode(fe_data, &pToken, &ins, &param_size);
392
393         /* Unhandled opcode, and its parameters */
394         if (ins.handler_idx == WINED3DSIH_TABLE_SIZE)
395         {
396             TRACE("Skipping unrecognized instruction.\n");
397             pToken += param_size;
398             continue;
399         }
400
401         /* Handle declarations */
402         if (ins.handler_idx == WINED3DSIH_DCL)
403         {
404             struct wined3d_shader_semantic semantic;
405
406             fe->shader_read_semantic(&pToken, &semantic);
407
408             switch (semantic.reg.reg.type)
409             {
410                 /* Vshader: mark attributes used
411                  * Pshader: mark 3.0 input registers used, save token */
412                 case WINED3DSPR_INPUT:
413                     reg_maps->input_registers |= 1 << semantic.reg.reg.idx;
414                     semantics_in[semantic.reg.reg.idx] = semantic;
415                     break;
416
417                 /* Vshader: mark 3.0 output registers used, save token */
418                 case WINED3DSPR_OUTPUT:
419                     reg_maps->packed_output[semantic.reg.reg.idx] = 1;
420                     semantics_out[semantic.reg.reg.idx] = semantic;
421                     if (semantic.usage == WINED3DDECLUSAGE_FOG) reg_maps->fog = 1;
422                     break;
423
424                 /* Save sampler usage token */
425                 case WINED3DSPR_SAMPLER:
426                     reg_maps->sampler_type[semantic.reg.reg.idx] = semantic.sampler_type;
427                     break;
428
429                 default:
430                     TRACE("Not recording DCL register type %#x.\n", semantic.reg.reg.type);
431                     break;
432             }
433         }
434         else if (ins.handler_idx == WINED3DSIH_DEF)
435         {
436             struct wined3d_shader_dst_param dst;
437             struct wined3d_shader_src_param rel_addr;
438
439             local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
440             if (!lconst) return E_OUTOFMEMORY;
441
442             fe->shader_read_dst_param(fe_data, &pToken, &dst, &rel_addr);
443             lconst->idx = dst.reg.idx;
444
445             memcpy(lconst->value, pToken, 4 * sizeof(DWORD));
446             pToken += 4;
447
448             /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
449             if (shader_version.major == 1 && pshader)
450             {
451                 float *value = (float *) lconst->value;
452                 if(value[0] < -1.0) value[0] = -1.0;
453                 else if(value[0] >  1.0) value[0] =  1.0;
454                 if(value[1] < -1.0) value[1] = -1.0;
455                 else if(value[1] >  1.0) value[1] =  1.0;
456                 if(value[2] < -1.0) value[2] = -1.0;
457                 else if(value[2] >  1.0) value[2] =  1.0;
458                 if(value[3] < -1.0) value[3] = -1.0;
459                 else if(value[3] >  1.0) value[3] =  1.0;
460             }
461
462             list_add_head(&This->baseShader.constantsF, &lconst->entry);
463         }
464         else if (ins.handler_idx == WINED3DSIH_DEFI)
465         {
466             struct wined3d_shader_dst_param dst;
467             struct wined3d_shader_src_param rel_addr;
468
469             local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
470             if (!lconst) return E_OUTOFMEMORY;
471
472             fe->shader_read_dst_param(fe_data, &pToken, &dst, &rel_addr);
473             lconst->idx = dst.reg.idx;
474
475             memcpy(lconst->value, pToken, 4 * sizeof(DWORD));
476             pToken += 4;
477
478             list_add_head(&This->baseShader.constantsI, &lconst->entry);
479         }
480         else if (ins.handler_idx == WINED3DSIH_DEFB)
481         {
482             struct wined3d_shader_dst_param dst;
483             struct wined3d_shader_src_param rel_addr;
484
485             local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
486             if (!lconst) return E_OUTOFMEMORY;
487
488             fe->shader_read_dst_param(fe_data, &pToken, &dst, &rel_addr);
489             lconst->idx = dst.reg.idx;
490
491             memcpy(lconst->value, pToken, sizeof(DWORD));
492             ++pToken;
493
494             list_add_head(&This->baseShader.constantsB, &lconst->entry);
495         }
496         /* If there's a loop in the shader */
497         else if (ins.handler_idx == WINED3DSIH_LOOP
498                 || ins.handler_idx == WINED3DSIH_REP)
499         {
500             struct wined3d_shader_src_param src, rel_addr;
501
502             fe->shader_read_src_param(fe_data, &pToken, &src, &rel_addr);
503
504             /* Rep and Loop always use an integer constant for the control parameters */
505             if (ins.handler_idx == WINED3DSIH_REP)
506             {
507                 reg_maps->integer_constants |= 1 << src.reg.idx;
508             }
509             else
510             {
511                 fe->shader_read_src_param(fe_data, &pToken, &src, &rel_addr);
512                 reg_maps->integer_constants |= 1 << src.reg.idx;
513             }
514
515             cur_loop_depth++;
516             if(cur_loop_depth > max_loop_depth)
517                 max_loop_depth = cur_loop_depth;
518         }
519         else if (ins.handler_idx == WINED3DSIH_ENDLOOP
520                 || ins.handler_idx == WINED3DSIH_ENDREP)
521         {
522             cur_loop_depth--;
523         }
524         /* For subroutine prototypes */
525         else if (ins.handler_idx == WINED3DSIH_LABEL)
526         {
527             struct wined3d_shader_src_param src, rel_addr;
528
529             fe->shader_read_src_param(fe_data, &pToken, &src, &rel_addr);
530             reg_maps->labels[src.reg.idx] = 1;
531         }
532         /* Set texture, address, temporary registers */
533         else
534         {
535             int i, limit;
536
537             /* This will loop over all the registers and try to
538              * make a bitmask of the ones we're interested in.
539              *
540              * Relative addressing tokens are ignored, but that's
541              * okay, since we'll catch any address registers when
542              * they are initialized (required by spec) */
543
544             if (ins.dst_count)
545             {
546                 struct wined3d_shader_dst_param dst_param;
547                 struct wined3d_shader_src_param dst_rel_addr;
548
549                 fe->shader_read_dst_param(fe_data, &pToken, &dst_param, &dst_rel_addr);
550
551                 /* WINED3DSPR_TEXCRDOUT is the same as WINED3DSPR_OUTPUT. _OUTPUT can be > MAX_REG_TEXCRD and
552                  * is used in >= 3.0 shaders. Filter 3.0 shaders to prevent overflows, and also filter pixel
553                  * shaders because TECRDOUT isn't used in them, but future register types might cause issues */
554                 if (!pshader && shader_version.major < 3 && dst_param.reg.type == WINED3DSPR_TEXCRDOUT)
555                 {
556                     reg_maps->texcoord_mask[dst_param.reg.type] |= dst_param.write_mask;
557                 }
558                 else
559                 {
560                     shader_record_register_usage(This, reg_maps, &dst_param.reg, pshader);
561                 }
562
563                 /* Declare 1.X samplers implicitly, based on the destination reg. number */
564                 if (shader_version.major == 1
565                         && pshader /* Filter different instructions with the same enum values in VS */
566                         && (ins.handler_idx == WINED3DSIH_TEX
567                             || ins.handler_idx == WINED3DSIH_TEXBEM
568                             || ins.handler_idx == WINED3DSIH_TEXBEML
569                             || ins.handler_idx == WINED3DSIH_TEXDP3TEX
570                             || ins.handler_idx == WINED3DSIH_TEXM3x2TEX
571                             || ins.handler_idx == WINED3DSIH_TEXM3x3SPEC
572                             || ins.handler_idx == WINED3DSIH_TEXM3x3TEX
573                             || ins.handler_idx == WINED3DSIH_TEXM3x3VSPEC
574                             || ins.handler_idx == WINED3DSIH_TEXREG2AR
575                             || ins.handler_idx == WINED3DSIH_TEXREG2GB
576                             || ins.handler_idx == WINED3DSIH_TEXREG2RGB))
577                 {
578                     /* Fake sampler usage, only set reserved bit and ttype */
579                     DWORD sampler_code = dst_param.reg.idx;
580
581                     TRACE("Setting fake 2D sampler for 1.x pixelshader\n");
582                     reg_maps->sampler_type[sampler_code] = WINED3DSTT_2D;
583
584                     /* texbem is only valid with < 1.4 pixel shaders */
585                     if (ins.handler_idx == WINED3DSIH_TEXBEM
586                             || ins.handler_idx == WINED3DSIH_TEXBEML)
587                     {
588                         reg_maps->bumpmat[sampler_code] = TRUE;
589                         if (ins.handler_idx == WINED3DSIH_TEXBEML)
590                         {
591                             reg_maps->luminanceparams[sampler_code] = TRUE;
592                         }
593                     }
594                 }
595                 else if (pshader && ins.handler_idx == WINED3DSIH_BEM)
596                 {
597                     reg_maps->bumpmat[dst_param.reg.idx] = TRUE;
598                 }
599             }
600
601             if (ins.handler_idx == WINED3DSIH_NRM)
602             {
603                 reg_maps->usesnrm = 1;
604             }
605             else if (ins.handler_idx == WINED3DSIH_DSY)
606             {
607                 reg_maps->usesdsy = 1;
608             }
609             else if(ins.handler_idx == WINED3DSIH_TEXLDD)
610             {
611                 reg_maps->usestexldd = 1;
612             }
613             else if(ins.handler_idx == WINED3DSIH_MOVA)
614             {
615                 reg_maps->usesmova = 1;
616             }
617
618             limit = ins.src_count + (ins.predicate ? 1 : 0);
619             for (i = 0; i < limit; ++i)
620             {
621                 struct wined3d_shader_src_param src_param, src_rel_addr;
622                 unsigned int count;
623
624                 fe->shader_read_src_param(fe_data, &pToken, &src_param, &src_rel_addr);
625                 count = get_instr_extra_regcount(ins.handler_idx, i);
626
627                 shader_record_register_usage(This, reg_maps, &src_param.reg, pshader);
628                 while (count)
629                 {
630                     ++src_param.reg.idx;
631                     shader_record_register_usage(This, reg_maps, &src_param.reg, pshader);
632                     --count;
633                 }
634             }
635         }
636     }
637     reg_maps->loop_depth = max_loop_depth;
638
639     This->baseShader.functionLength = ((char *)pToken - (char *)byte_code);
640
641     return WINED3D_OK;
642 }
643
644 static void shader_dump_decl_usage(const struct wined3d_shader_semantic *semantic,
645         const struct wined3d_shader_version *shader_version)
646 {
647     TRACE("dcl");
648
649     if (semantic->reg.reg.type == WINED3DSPR_SAMPLER)
650     {
651         switch (semantic->sampler_type)
652         {
653             case WINED3DSTT_2D: TRACE("_2d"); break;
654             case WINED3DSTT_CUBE: TRACE("_cube"); break;
655             case WINED3DSTT_VOLUME: TRACE("_volume"); break;
656             default: TRACE("_unknown_ttype(0x%08x)", semantic->sampler_type);
657         }
658     }
659     else
660     {
661         /* Pixel shaders 3.0 don't have usage semantics */
662         if (shader_is_pshader_version(shader_version->type) && shader_version->major < 3)
663             return;
664         else
665             TRACE("_");
666
667         switch (semantic->usage)
668         {
669             case WINED3DDECLUSAGE_POSITION:
670                 TRACE("position%d", semantic->usage_idx);
671                 break;
672             case WINED3DDECLUSAGE_BLENDINDICES:
673                 TRACE("blend");
674                 break;
675             case WINED3DDECLUSAGE_BLENDWEIGHT:
676                 TRACE("weight");
677                 break;
678             case WINED3DDECLUSAGE_NORMAL:
679                 TRACE("normal%d", semantic->usage_idx);
680                 break;
681             case WINED3DDECLUSAGE_PSIZE:
682                 TRACE("psize");
683                 break;
684             case WINED3DDECLUSAGE_COLOR:
685                 if (semantic->usage_idx == 0) TRACE("color");
686                 else TRACE("specular%d", (semantic->usage_idx - 1));
687                 break;
688             case WINED3DDECLUSAGE_TEXCOORD:
689                 TRACE("texture%d", semantic->usage_idx);
690                 break;
691             case WINED3DDECLUSAGE_TANGENT:
692                 TRACE("tangent");
693                 break;
694             case WINED3DDECLUSAGE_BINORMAL:
695                 TRACE("binormal");
696                 break;
697             case WINED3DDECLUSAGE_TESSFACTOR:
698                 TRACE("tessfactor");
699                 break;
700             case WINED3DDECLUSAGE_POSITIONT:
701                 TRACE("positionT%d", semantic->usage_idx);
702                 break;
703             case WINED3DDECLUSAGE_FOG:
704                 TRACE("fog");
705                 break;
706             case WINED3DDECLUSAGE_DEPTH:
707                 TRACE("depth");
708                 break;
709             case WINED3DDECLUSAGE_SAMPLE:
710                 TRACE("sample");
711                 break;
712             default:
713                 FIXME("unknown_semantics(0x%08x)", semantic->usage);
714         }
715     }
716 }
717
718 static void shader_dump_register(const struct wined3d_shader_register *reg,
719         const struct wined3d_shader_version *shader_version)
720 {
721     static const char * const rastout_reg_names[] = {"oPos", "oFog", "oPts"};
722     static const char * const misctype_reg_names[] = {"vPos", "vFace"};
723     UINT offset = reg->idx;
724
725     switch (reg->type)
726     {
727         case WINED3DSPR_TEMP:
728             TRACE("r");
729             break;
730
731         case WINED3DSPR_INPUT:
732             TRACE("v");
733             break;
734
735         case WINED3DSPR_CONST:
736         case WINED3DSPR_CONST2:
737         case WINED3DSPR_CONST3:
738         case WINED3DSPR_CONST4:
739             TRACE("c");
740             offset = shader_get_float_offset(reg->type, reg->idx);
741             break;
742
743         case WINED3DSPR_TEXTURE: /* vs: case WINED3DSPR_ADDR */
744             TRACE("%c", shader_is_pshader_version(shader_version->type) ? 't' : 'a');
745             break;
746
747         case WINED3DSPR_RASTOUT:
748             TRACE("%s", rastout_reg_names[reg->idx]);
749             break;
750
751         case WINED3DSPR_COLOROUT:
752             TRACE("oC");
753             break;
754
755         case WINED3DSPR_DEPTHOUT:
756             TRACE("oDepth");
757             break;
758
759         case WINED3DSPR_ATTROUT:
760             TRACE("oD");
761             break;
762
763         case WINED3DSPR_TEXCRDOUT:
764             /* Vertex shaders >= 3.0 use general purpose output registers
765              * (WINED3DSPR_OUTPUT), which can include an address token */
766             if (shader_version->major >= 3) TRACE("o");
767             else TRACE("oT");
768             break;
769
770         case WINED3DSPR_CONSTINT:
771             TRACE("i");
772             break;
773
774         case WINED3DSPR_CONSTBOOL:
775             TRACE("b");
776             break;
777
778         case WINED3DSPR_LABEL:
779             TRACE("l");
780             break;
781
782         case WINED3DSPR_LOOP:
783             TRACE("aL");
784             break;
785
786         case WINED3DSPR_SAMPLER:
787             TRACE("s");
788             break;
789
790         case WINED3DSPR_MISCTYPE:
791             if (reg->idx > 1) FIXME("Unhandled misctype register %d\n", reg->idx);
792             else TRACE("%s", misctype_reg_names[reg->idx]);
793             break;
794
795         case WINED3DSPR_PREDICATE:
796             TRACE("p");
797             break;
798
799         case WINED3DSPR_IMMCONST:
800             TRACE("l");
801             break;
802
803         default:
804             TRACE("unhandled_rtype(%#x)", reg->type);
805             break;
806     }
807
808     if (reg->type == WINED3DSPR_IMMCONST)
809     {
810         TRACE("(");
811         switch (reg->immconst_type)
812         {
813             case WINED3D_IMMCONST_FLOAT:
814                 TRACE("%.8e", *(float *)reg->immconst_data);
815                 break;
816
817             case WINED3D_IMMCONST_FLOAT4:
818                 TRACE("%.8e, %.8e, %.8e, %.8e",
819                         *(float *)&reg->immconst_data[0], *(float *)&reg->immconst_data[1],
820                         *(float *)&reg->immconst_data[2], *(float *)&reg->immconst_data[3]);
821                 break;
822
823             default:
824                 TRACE("<unhandled immconst_type %#x>", reg->immconst_type);
825                 break;
826         }
827         TRACE(")");
828     }
829     else if (reg->type != WINED3DSPR_RASTOUT && reg->type != WINED3DSPR_MISCTYPE)
830     {
831         if (reg->rel_addr)
832         {
833             TRACE("[");
834             shader_dump_src_param(reg->rel_addr, shader_version);
835             TRACE(" + ");
836         }
837         TRACE("%u", offset);
838         if (reg->rel_addr) TRACE("]");
839     }
840 }
841
842 void shader_dump_dst_param(const struct wined3d_shader_dst_param *param,
843         const struct wined3d_shader_version *shader_version)
844 {
845     DWORD write_mask = param->write_mask;
846
847     shader_dump_register(&param->reg, shader_version);
848
849     if (write_mask != WINED3DSP_WRITEMASK_ALL)
850     {
851         static const char *write_mask_chars = "xyzw";
852
853         TRACE(".");
854         if (write_mask & WINED3DSP_WRITEMASK_0) TRACE("%c", write_mask_chars[0]);
855         if (write_mask & WINED3DSP_WRITEMASK_1) TRACE("%c", write_mask_chars[1]);
856         if (write_mask & WINED3DSP_WRITEMASK_2) TRACE("%c", write_mask_chars[2]);
857         if (write_mask & WINED3DSP_WRITEMASK_3) TRACE("%c", write_mask_chars[3]);
858     }
859 }
860
861 void shader_dump_src_param(const struct wined3d_shader_src_param *param,
862         const struct wined3d_shader_version *shader_version)
863 {
864     DWORD src_modifier = param->modifiers;
865     DWORD swizzle = param->swizzle;
866
867     if (src_modifier == WINED3DSPSM_NEG
868             || src_modifier == WINED3DSPSM_BIASNEG
869             || src_modifier == WINED3DSPSM_SIGNNEG
870             || src_modifier == WINED3DSPSM_X2NEG
871             || src_modifier == WINED3DSPSM_ABSNEG)
872         TRACE("-");
873     else if (src_modifier == WINED3DSPSM_COMP)
874         TRACE("1-");
875     else if (src_modifier == WINED3DSPSM_NOT)
876         TRACE("!");
877
878     if (src_modifier == WINED3DSPSM_ABS || src_modifier == WINED3DSPSM_ABSNEG)
879         TRACE("abs(");
880
881     shader_dump_register(&param->reg, shader_version);
882
883     if (src_modifier)
884     {
885         switch (src_modifier)
886         {
887             case WINED3DSPSM_NONE:    break;
888             case WINED3DSPSM_NEG:     break;
889             case WINED3DSPSM_NOT:     break;
890             case WINED3DSPSM_BIAS:    TRACE("_bias"); break;
891             case WINED3DSPSM_BIASNEG: TRACE("_bias"); break;
892             case WINED3DSPSM_SIGN:    TRACE("_bx2"); break;
893             case WINED3DSPSM_SIGNNEG: TRACE("_bx2"); break;
894             case WINED3DSPSM_COMP:    break;
895             case WINED3DSPSM_X2:      TRACE("_x2"); break;
896             case WINED3DSPSM_X2NEG:   TRACE("_x2"); break;
897             case WINED3DSPSM_DZ:      TRACE("_dz"); break;
898             case WINED3DSPSM_DW:      TRACE("_dw"); break;
899             case WINED3DSPSM_ABSNEG:  TRACE(")"); break;
900             case WINED3DSPSM_ABS:     TRACE(")"); break;
901             default:
902                                       TRACE("_unknown_modifier(%#x)", src_modifier);
903         }
904     }
905
906     if (swizzle != WINED3DSP_NOSWIZZLE)
907     {
908         static const char *swizzle_chars = "xyzw";
909         DWORD swizzle_x = swizzle & 0x03;
910         DWORD swizzle_y = (swizzle >> 2) & 0x03;
911         DWORD swizzle_z = (swizzle >> 4) & 0x03;
912         DWORD swizzle_w = (swizzle >> 6) & 0x03;
913
914         if (swizzle_x == swizzle_y
915                 && swizzle_x == swizzle_z
916                 && swizzle_x == swizzle_w)
917         {
918             TRACE(".%c", swizzle_chars[swizzle_x]);
919         }
920         else
921         {
922             TRACE(".%c%c%c%c", swizzle_chars[swizzle_x], swizzle_chars[swizzle_y],
923                     swizzle_chars[swizzle_z], swizzle_chars[swizzle_w]);
924         }
925     }
926 }
927
928 /* Shared code in order to generate the bulk of the shader string.
929  * NOTE: A description of how to parse tokens can be found on msdn */
930 void shader_generate_main(IWineD3DBaseShader *iface, SHADER_BUFFER *buffer,
931         const shader_reg_maps *reg_maps, const DWORD *pFunction, void *backend_ctx)
932 {
933     IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
934     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) This->baseShader.device; /* To access shader backend callbacks */
935     const SHADER_HANDLER *handler_table = device->shader_backend->shader_instruction_handler_table;
936     const struct wined3d_shader_frontend *fe = This->baseShader.frontend;
937     void *fe_data = This->baseShader.frontend_data;
938     struct wined3d_shader_src_param src_rel_addr[4];
939     struct wined3d_shader_src_param src_param[4];
940     struct wined3d_shader_version shader_version;
941     struct wined3d_shader_src_param dst_rel_addr;
942     struct wined3d_shader_dst_param dst_param;
943     struct wined3d_shader_instruction ins;
944     struct wined3d_shader_context ctx;
945     const DWORD *pToken = pFunction;
946     SHADER_HANDLER hw_fct;
947     DWORD i;
948
949     /* Initialize current parsing state */
950     ctx.shader = iface;
951     ctx.reg_maps = reg_maps;
952     ctx.buffer = buffer;
953     ctx.backend_data = backend_ctx;
954
955     ins.ctx = &ctx;
956     ins.dst = &dst_param;
957     ins.src = src_param;
958     This->baseShader.parse_state.current_row = 0;
959
960     fe->shader_read_header(fe_data, &pToken, &shader_version);
961
962     while (!fe->shader_is_end(fe_data, &pToken))
963     {
964         const char *comment;
965         UINT param_size;
966
967         /* Skip comment tokens */
968         fe->shader_read_comment(&pToken, &comment);
969         if (comment) continue;
970
971         /* Read opcode */
972         fe->shader_read_opcode(fe_data, &pToken, &ins, &param_size);
973
974         /* Unknown opcode and its parameters */
975         if (ins.handler_idx == WINED3DSIH_TABLE_SIZE)
976         {
977             TRACE("Skipping unrecognized instruction.\n");
978             pToken += param_size;
979             continue;
980         }
981
982         /* Nothing to do */
983         if (ins.handler_idx == WINED3DSIH_DCL
984                 || ins.handler_idx == WINED3DSIH_NOP
985                 || ins.handler_idx == WINED3DSIH_DEF
986                 || ins.handler_idx == WINED3DSIH_DEFI
987                 || ins.handler_idx == WINED3DSIH_DEFB
988                 || ins.handler_idx == WINED3DSIH_PHASE
989                 || ins.handler_idx == WINED3DSIH_RET)
990         {
991             pToken += param_size;
992             continue;
993         }
994
995         /* Select handler */
996         hw_fct = handler_table[ins.handler_idx];
997
998         /* Unhandled opcode */
999         if (!hw_fct)
1000         {
1001             FIXME("Backend can't handle opcode %#x\n", ins.handler_idx);
1002             pToken += param_size;
1003             continue;
1004         }
1005
1006         /* Destination token */
1007         if (ins.dst_count) fe->shader_read_dst_param(fe_data, &pToken, &dst_param, &dst_rel_addr);
1008
1009         /* Predication token */
1010         if (ins.predicate) ins.predicate = *pToken++;
1011
1012         /* Other source tokens */
1013         for (i = 0; i < ins.src_count; ++i)
1014         {
1015             fe->shader_read_src_param(fe_data, &pToken, &src_param[i], &src_rel_addr[i]);
1016         }
1017
1018         /* Call appropriate function for output target */
1019         hw_fct(&ins);
1020
1021         /* Process instruction modifiers for GLSL apps ( _sat, etc. ) */
1022         device->shader_backend->shader_add_instruction_modifiers(&ins);
1023     }
1024 }
1025
1026 static void shader_dump_ins_modifiers(const struct wined3d_shader_dst_param *dst)
1027 {
1028     DWORD mmask = dst->modifiers;
1029
1030     switch (dst->shift)
1031     {
1032         case 0: break;
1033         case 13: TRACE("_d8"); break;
1034         case 14: TRACE("_d4"); break;
1035         case 15: TRACE("_d2"); break;
1036         case 1: TRACE("_x2"); break;
1037         case 2: TRACE("_x4"); break;
1038         case 3: TRACE("_x8"); break;
1039         default: TRACE("_unhandled_shift(%d)", dst->shift); break;
1040     }
1041
1042     if (mmask & WINED3DSPDM_SATURATE)         TRACE("_sat");
1043     if (mmask & WINED3DSPDM_PARTIALPRECISION) TRACE("_pp");
1044     if (mmask & WINED3DSPDM_MSAMPCENTROID)    TRACE("_centroid");
1045
1046     mmask &= ~(WINED3DSPDM_SATURATE | WINED3DSPDM_PARTIALPRECISION | WINED3DSPDM_MSAMPCENTROID);
1047     if (mmask)
1048         FIXME("_unrecognized_modifier(%#x)", mmask);
1049 }
1050
1051 void shader_trace_init(const struct wined3d_shader_frontend *fe, void *fe_data, const DWORD *pFunction)
1052 {
1053     struct wined3d_shader_version shader_version;
1054     const DWORD* pToken = pFunction;
1055     DWORD i;
1056
1057     TRACE("Parsing %p\n", pFunction);
1058
1059     fe->shader_read_header(fe_data, &pToken, &shader_version);
1060
1061     TRACE("%s_%u_%u\n", shader_is_pshader_version(shader_version.type) ? "ps": "vs",
1062             shader_version.major, shader_version.minor);
1063
1064     while (!fe->shader_is_end(fe_data, &pToken))
1065     {
1066         struct wined3d_shader_instruction ins;
1067         const char *comment;
1068         UINT param_size;
1069
1070         /* comment */
1071         fe->shader_read_comment(&pToken, &comment);
1072         if (comment)
1073         {
1074             TRACE("//%s\n", comment);
1075             continue;
1076         }
1077
1078         fe->shader_read_opcode(fe_data, &pToken, &ins, &param_size);
1079         if (ins.handler_idx == WINED3DSIH_TABLE_SIZE)
1080         {
1081             TRACE("Skipping unrecognized instruction.\n");
1082             pToken += param_size;
1083             continue;
1084         }
1085
1086         if (ins.handler_idx == WINED3DSIH_DCL)
1087         {
1088             struct wined3d_shader_semantic semantic;
1089
1090             fe->shader_read_semantic(&pToken, &semantic);
1091
1092             shader_dump_decl_usage(&semantic, &shader_version);
1093             shader_dump_ins_modifiers(&semantic.reg);
1094             TRACE(" ");
1095             shader_dump_dst_param(&semantic.reg, &shader_version);
1096         }
1097         else if (ins.handler_idx == WINED3DSIH_DEF)
1098         {
1099             struct wined3d_shader_dst_param dst;
1100             struct wined3d_shader_src_param rel_addr;
1101
1102             fe->shader_read_dst_param(fe_data, &pToken, &dst, &rel_addr);
1103
1104             TRACE("def c%u = %f, %f, %f, %f", shader_get_float_offset(dst.reg.type, dst.reg.idx),
1105                     *(const float *)(pToken),
1106                     *(const float *)(pToken + 1),
1107                     *(const float *)(pToken + 2),
1108                     *(const float *)(pToken + 3));
1109             pToken += 4;
1110         }
1111         else if (ins.handler_idx == WINED3DSIH_DEFI)
1112         {
1113             struct wined3d_shader_dst_param dst;
1114             struct wined3d_shader_src_param rel_addr;
1115
1116             fe->shader_read_dst_param(fe_data, &pToken, &dst, &rel_addr);
1117
1118             TRACE("defi i%u = %d, %d, %d, %d", dst.reg.idx,
1119                     *(pToken),
1120                     *(pToken + 1),
1121                     *(pToken + 2),
1122                     *(pToken + 3));
1123             pToken += 4;
1124         }
1125         else if (ins.handler_idx == WINED3DSIH_DEFB)
1126         {
1127             struct wined3d_shader_dst_param dst;
1128             struct wined3d_shader_src_param rel_addr;
1129
1130             fe->shader_read_dst_param(fe_data, &pToken, &dst, &rel_addr);
1131
1132             TRACE("defb b%u = %s", dst.reg.idx, *pToken ? "true" : "false");
1133             ++pToken;
1134         }
1135         else
1136         {
1137             struct wined3d_shader_src_param dst_rel_addr, src_rel_addr;
1138             struct wined3d_shader_dst_param dst_param;
1139             struct wined3d_shader_src_param src_param;
1140
1141             if (ins.dst_count)
1142             {
1143                 fe->shader_read_dst_param(fe_data, &pToken, &dst_param, &dst_rel_addr);
1144             }
1145
1146             /* Print out predication source token first - it follows
1147              * the destination token. */
1148             if (ins.predicate)
1149             {
1150                 fe->shader_read_src_param(fe_data, &pToken, &src_param, &src_rel_addr);
1151                 TRACE("(");
1152                 shader_dump_src_param(&src_param, &shader_version);
1153                 TRACE(") ");
1154             }
1155
1156             /* PixWin marks instructions with the coissue flag with a '+' */
1157             if (ins.coissue) TRACE("+");
1158
1159             TRACE("%s", shader_opcode_names[ins.handler_idx]);
1160
1161             if (ins.handler_idx == WINED3DSIH_IFC
1162                     || ins.handler_idx == WINED3DSIH_BREAKC)
1163             {
1164                 switch (ins.flags)
1165                 {
1166                     case COMPARISON_GT: TRACE("_gt"); break;
1167                     case COMPARISON_EQ: TRACE("_eq"); break;
1168                     case COMPARISON_GE: TRACE("_ge"); break;
1169                     case COMPARISON_LT: TRACE("_lt"); break;
1170                     case COMPARISON_NE: TRACE("_ne"); break;
1171                     case COMPARISON_LE: TRACE("_le"); break;
1172                     default: TRACE("_(%u)", ins.flags);
1173                 }
1174             }
1175             else if (ins.handler_idx == WINED3DSIH_TEX
1176                     && shader_version.major >= 2
1177                     && (ins.flags & WINED3DSI_TEXLD_PROJECT))
1178             {
1179                 TRACE("p");
1180             }
1181
1182             /* We already read the destination token, print it. */
1183             if (ins.dst_count)
1184             {
1185                 shader_dump_ins_modifiers(&dst_param);
1186                 TRACE(" ");
1187                 shader_dump_dst_param(&dst_param, &shader_version);
1188             }
1189
1190             /* Other source tokens */
1191             for (i = ins.dst_count; i < (ins.dst_count + ins.src_count); ++i)
1192             {
1193                 fe->shader_read_src_param(fe_data, &pToken, &src_param, &src_rel_addr);
1194                 TRACE(!i ? " " : ", ");
1195                 shader_dump_src_param(&src_param, &shader_version);
1196             }
1197         }
1198         TRACE("\n");
1199     }
1200 }
1201
1202 void shader_cleanup(IWineD3DBaseShader *iface)
1203 {
1204     IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)iface;
1205
1206     ((IWineD3DDeviceImpl *)This->baseShader.device)->shader_backend->shader_destroy(iface);
1207     HeapFree(GetProcessHeap(), 0, This->baseShader.reg_maps.constf);
1208     HeapFree(GetProcessHeap(), 0, This->baseShader.function);
1209     shader_delete_constant_list(&This->baseShader.constantsF);
1210     shader_delete_constant_list(&This->baseShader.constantsB);
1211     shader_delete_constant_list(&This->baseShader.constantsI);
1212     list_remove(&This->baseShader.shader_list_entry);
1213
1214     if (This->baseShader.frontend && This->baseShader.frontend_data)
1215     {
1216         This->baseShader.frontend->shader_free(This->baseShader.frontend_data);
1217     }
1218 }
1219
1220 static const SHADER_HANDLER shader_none_instruction_handler_table[WINED3DSIH_TABLE_SIZE] = {0};
1221 static void shader_none_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {}
1222 static void shader_none_select_depth_blt(IWineD3DDevice *iface, enum tex_types tex_type) {}
1223 static void shader_none_deselect_depth_blt(IWineD3DDevice *iface) {}
1224 static void shader_none_update_float_vertex_constants(IWineD3DDevice *iface, UINT start, UINT count) {}
1225 static void shader_none_update_float_pixel_constants(IWineD3DDevice *iface, UINT start, UINT count) {}
1226 static void shader_none_load_constants(IWineD3DDevice *iface, char usePS, char useVS) {}
1227 static void shader_none_load_np2fixup_constants(IWineD3DDevice *iface, char usePS, char useVS) {}
1228 static void shader_none_destroy(IWineD3DBaseShader *iface) {}
1229 static HRESULT shader_none_alloc(IWineD3DDevice *iface) {return WINED3D_OK;}
1230 static void shader_none_free(IWineD3DDevice *iface) {}
1231 static BOOL shader_none_dirty_const(IWineD3DDevice *iface) {return FALSE;}
1232 static GLuint shader_none_generate_pshader(IWineD3DPixelShader *iface,
1233         SHADER_BUFFER *buffer, const struct ps_compile_args *args)
1234 {
1235     FIXME("NONE shader backend asked to generate a pixel shader\n");
1236     return 0;
1237 }
1238 static GLuint shader_none_generate_vshader(IWineD3DVertexShader *iface,
1239         SHADER_BUFFER *buffer, const struct vs_compile_args *args)
1240 {
1241     FIXME("NONE shader backend asked to generate a vertex shader\n");
1242     return 0;
1243 }
1244 static void shader_none_add_instruction_modifiers(const struct wined3d_shader_instruction *ins) {}
1245
1246 #define GLINFO_LOCATION      (*gl_info)
1247 static void shader_none_get_caps(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct shader_caps *pCaps)
1248 {
1249     /* Set the shader caps to 0 for the none shader backend */
1250     pCaps->VertexShaderVersion  = 0;
1251     pCaps->PixelShaderVersion    = 0;
1252     pCaps->PixelShader1xMaxValue = 0.0;
1253 }
1254 #undef GLINFO_LOCATION
1255 static BOOL shader_none_color_fixup_supported(struct color_fixup_desc fixup)
1256 {
1257     if (TRACE_ON(d3d_shader) && TRACE_ON(d3d))
1258     {
1259         TRACE("Checking support for fixup:\n");
1260         dump_color_fixup_desc(fixup);
1261     }
1262
1263     /* Faked to make some apps happy. */
1264     if (!is_yuv_fixup(fixup))
1265     {
1266         TRACE("[OK]\n");
1267         return TRUE;
1268     }
1269
1270     TRACE("[FAILED]\n");
1271     return FALSE;
1272 }
1273
1274 const shader_backend_t none_shader_backend = {
1275     shader_none_instruction_handler_table,
1276     shader_none_select,
1277     shader_none_select_depth_blt,
1278     shader_none_deselect_depth_blt,
1279     shader_none_update_float_vertex_constants,
1280     shader_none_update_float_pixel_constants,
1281     shader_none_load_constants,
1282     shader_none_load_np2fixup_constants,
1283     shader_none_destroy,
1284     shader_none_alloc,
1285     shader_none_free,
1286     shader_none_dirty_const,
1287     shader_none_generate_pshader,
1288     shader_none_generate_vshader,
1289     shader_none_get_caps,
1290     shader_none_color_fixup_supported,
1291     shader_none_add_instruction_modifiers,
1292 };