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